| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library analyzer.src.dart.element.element; | 5 library analyzer.src.dart.element.element; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import 'dart:math' show min; | 8 import 'dart:math' show min; |
| 9 | 9 |
| 10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 * The unlinked representation of the class in the summary. | 411 * The unlinked representation of the class in the summary. |
| 412 */ | 412 */ |
| 413 final UnlinkedClass _unlinkedClass; | 413 final UnlinkedClass _unlinkedClass; |
| 414 | 414 |
| 415 /** | 415 /** |
| 416 * The kernel of the element. | 416 * The kernel of the element. |
| 417 */ | 417 */ |
| 418 final kernel.Class _kernel; | 418 final kernel.Class _kernel; |
| 419 | 419 |
| 420 /** | 420 /** |
| 421 * If this class is resynthesized, whether it has a constant constructor. |
| 422 */ |
| 423 bool _hasConstConstructorCached; |
| 424 |
| 425 /** |
| 421 * The actual supertype extracted from desugared [_kernel]. | 426 * The actual supertype extracted from desugared [_kernel]. |
| 422 */ | 427 */ |
| 423 kernel.Supertype _kernelSupertype; | 428 kernel.Supertype _kernelSupertype; |
| 424 | 429 |
| 425 /** | 430 /** |
| 426 * The mixed-in types extracted from desugared [_kernel]. | 431 * The mixed-in types extracted from desugared [_kernel]. |
| 427 */ | 432 */ |
| 428 List<kernel.Supertype> _kernelMixins; | 433 List<kernel.Supertype> _kernelMixins; |
| 429 | 434 |
| 430 /** | 435 /** |
| (...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1011 ConstructorElement get unnamedConstructor { | 1016 ConstructorElement get unnamedConstructor { |
| 1012 for (ConstructorElement element in constructors) { | 1017 for (ConstructorElement element in constructors) { |
| 1013 String name = element.displayName; | 1018 String name = element.displayName; |
| 1014 if (name == null || name.isEmpty) { | 1019 if (name == null || name.isEmpty) { |
| 1015 return element; | 1020 return element; |
| 1016 } | 1021 } |
| 1017 } | 1022 } |
| 1018 return null; | 1023 return null; |
| 1019 } | 1024 } |
| 1020 | 1025 |
| 1021 bool get _hasConstConstructorKernel => | 1026 /** |
| 1022 _kernel != null && _kernel.constructors.any((c) => c.isConst); | 1027 * Return whether the class is resynthesized and has a constant constructor. |
| 1028 */ |
| 1029 bool get _hasConstConstructor { |
| 1030 if (_hasConstConstructorCached == null) { |
| 1031 _hasConstConstructorCached = false; |
| 1032 if (_kernel != null) { |
| 1033 _hasConstConstructorCached = _kernel.constructors.any((c) => c.isConst); |
| 1034 } |
| 1035 if (_unlinkedClass != null) { |
| 1036 _hasConstConstructorCached = _unlinkedClass.executables.any( |
| 1037 (c) => c.kind == UnlinkedExecutableKind.constructor && c.isConst); |
| 1038 } |
| 1039 } |
| 1040 return _hasConstConstructorCached; |
| 1041 } |
| 1023 | 1042 |
| 1024 @override | 1043 @override |
| 1025 void appendTo(StringBuffer buffer) { | 1044 void appendTo(StringBuffer buffer) { |
| 1026 if (isAbstract) { | 1045 if (isAbstract) { |
| 1027 buffer.write('abstract '); | 1046 buffer.write('abstract '); |
| 1028 } | 1047 } |
| 1029 buffer.write('class '); | 1048 buffer.write('class '); |
| 1030 String name = displayName; | 1049 String name = displayName; |
| 1031 if (name == null) { | 1050 if (name == null) { |
| 1032 buffer.write("{unnamed class}"); | 1051 buffer.write("{unnamed class}"); |
| (...skipping 3512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4545 */ | 4564 */ |
| 4546 FieldElementImpl.forKernel(ElementImpl enclosingElement, kernel.Field kernel) | 4565 FieldElementImpl.forKernel(ElementImpl enclosingElement, kernel.Field kernel) |
| 4547 : super.forKernel(enclosingElement, kernel); | 4566 : super.forKernel(enclosingElement, kernel); |
| 4548 | 4567 |
| 4549 /** | 4568 /** |
| 4550 * Initialize using the given kernel. | 4569 * Initialize using the given kernel. |
| 4551 */ | 4570 */ |
| 4552 factory FieldElementImpl.forKernelFactory( | 4571 factory FieldElementImpl.forKernelFactory( |
| 4553 ClassElementImpl enclosingClass, kernel.Field kernel) { | 4572 ClassElementImpl enclosingClass, kernel.Field kernel) { |
| 4554 if (kernel.isConst || | 4573 if (kernel.isConst || |
| 4555 kernel.isFinal && enclosingClass._hasConstConstructorKernel) { | 4574 kernel.isFinal && |
| 4575 !kernel.isStatic && |
| 4576 enclosingClass._hasConstConstructor) { |
| 4556 return new ConstFieldElementImpl.forKernel(enclosingClass, kernel); | 4577 return new ConstFieldElementImpl.forKernel(enclosingClass, kernel); |
| 4557 } else { | 4578 } else { |
| 4558 return new FieldElementImpl.forKernel(enclosingClass, kernel); | 4579 return new FieldElementImpl.forKernel(enclosingClass, kernel); |
| 4559 } | 4580 } |
| 4560 } | 4581 } |
| 4561 | 4582 |
| 4562 /** | 4583 /** |
| 4563 * Initialize a newly created field element to have the given [name]. | 4584 * Initialize a newly created field element to have the given [name]. |
| 4564 */ | 4585 */ |
| 4565 FieldElementImpl.forNode(Identifier name) : super.forNode(name); | 4586 FieldElementImpl.forNode(Identifier name) : super.forNode(name); |
| 4566 | 4587 |
| 4567 /** | 4588 /** |
| 4568 * Initialize using the given serialized information. | 4589 * Initialize using the given serialized information. |
| 4569 */ | 4590 */ |
| 4570 FieldElementImpl.forSerialized( | 4591 FieldElementImpl.forSerialized( |
| 4571 UnlinkedVariable unlinkedVariable, ElementImpl enclosingElement) | 4592 UnlinkedVariable unlinkedVariable, ElementImpl enclosingElement) |
| 4572 : super.forSerialized(unlinkedVariable, enclosingElement); | 4593 : super.forSerialized(unlinkedVariable, enclosingElement); |
| 4573 | 4594 |
| 4574 /** | 4595 /** |
| 4575 * Initialize using the given serialized information. | 4596 * Initialize using the given serialized information. |
| 4576 */ | 4597 */ |
| 4577 factory FieldElementImpl.forSerializedFactory( | 4598 factory FieldElementImpl.forSerializedFactory( |
| 4578 UnlinkedVariable unlinkedVariable, ClassElementImpl enclosingClass) { | 4599 UnlinkedVariable unlinkedVariable, ClassElementImpl enclosingClass) { |
| 4579 if (unlinkedVariable.initializer?.bodyExpr != null && | 4600 if (unlinkedVariable.initializer?.bodyExpr != null && |
| 4580 (unlinkedVariable.isConst || | 4601 (unlinkedVariable.isConst || |
| 4581 unlinkedVariable.isFinal && !unlinkedVariable.isStatic)) { | 4602 unlinkedVariable.isFinal && |
| 4603 !unlinkedVariable.isStatic && |
| 4604 enclosingClass._hasConstConstructor)) { |
| 4582 return new ConstFieldElementImpl.forSerialized( | 4605 return new ConstFieldElementImpl.forSerialized( |
| 4583 unlinkedVariable, enclosingClass); | 4606 unlinkedVariable, enclosingClass); |
| 4584 } else { | 4607 } else { |
| 4585 return new FieldElementImpl.forSerialized( | 4608 return new FieldElementImpl.forSerialized( |
| 4586 unlinkedVariable, enclosingClass); | 4609 unlinkedVariable, enclosingClass); |
| 4587 } | 4610 } |
| 4588 } | 4611 } |
| 4589 | 4612 |
| 4590 @override | 4613 @override |
| 4591 ClassElement get enclosingElement => super.enclosingElement as ClassElement; | 4614 ClassElement get enclosingElement => super.enclosingElement as ClassElement; |
| (...skipping 5394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9986 | 10009 |
| 9987 @override | 10010 @override |
| 9988 DartObject computeConstantValue() => null; | 10011 DartObject computeConstantValue() => null; |
| 9989 | 10012 |
| 9990 @override | 10013 @override |
| 9991 void visitChildren(ElementVisitor visitor) { | 10014 void visitChildren(ElementVisitor visitor) { |
| 9992 super.visitChildren(visitor); | 10015 super.visitChildren(visitor); |
| 9993 _initializer?.accept(visitor); | 10016 _initializer?.accept(visitor); |
| 9994 } | 10017 } |
| 9995 } | 10018 } |
| OLD | NEW |