Chromium Code Reviews| 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 821 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 832 List<ElementAnnotation> get metadata { | 832 List<ElementAnnotation> get metadata { |
| 833 if (_unlinkedClass != null) { | 833 if (_unlinkedClass != null) { |
| 834 return _metadata ??= | 834 return _metadata ??= |
| 835 _buildAnnotations(enclosingUnit, _unlinkedClass.annotations); | 835 _buildAnnotations(enclosingUnit, _unlinkedClass.annotations); |
| 836 } | 836 } |
| 837 return super.metadata; | 837 return super.metadata; |
| 838 } | 838 } |
| 839 | 839 |
| 840 @override | 840 @override |
| 841 List<MethodElement> get methods { | 841 List<MethodElement> get methods { |
| 842 if (_kernel != null) { | |
| 843 _methods ??= _kernel.procedures | |
| 844 .where((k) => | |
| 845 k.kind == kernel.ProcedureKind.Method || | |
| 846 k.kind == kernel.ProcedureKind.Operator) | |
| 847 .map((k) => new MethodElementImpl.forKernel(this, k)) | |
| 848 .toList(growable: false); | |
| 849 } | |
| 842 if (_unlinkedClass != null) { | 850 if (_unlinkedClass != null) { |
| 843 _methods ??= _unlinkedClass.executables | 851 _methods ??= _unlinkedClass.executables |
| 844 .where((e) => e.kind == UnlinkedExecutableKind.functionOrMethod) | 852 .where((e) => e.kind == UnlinkedExecutableKind.functionOrMethod) |
| 845 .map((e) => new MethodElementImpl.forSerialized(e, this)) | 853 .map((e) => new MethodElementImpl.forSerialized(e, this)) |
| 846 .toList(growable: false); | 854 .toList(growable: false); |
| 847 } | 855 } |
| 848 return _methods ?? const <MethodElement>[]; | 856 return _methods ?? const <MethodElement>[]; |
| 849 } | 857 } |
| 850 | 858 |
| 851 /** | 859 /** |
| (...skipping 2979 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3831 /** | 3839 /** |
| 3832 * Set whether this executable element has an implicit return type. | 3840 * Set whether this executable element has an implicit return type. |
| 3833 */ | 3841 */ |
| 3834 void set hasImplicitReturnType(bool hasImplicitReturnType) { | 3842 void set hasImplicitReturnType(bool hasImplicitReturnType) { |
| 3835 _assertNotResynthesized(serializedExecutable); | 3843 _assertNotResynthesized(serializedExecutable); |
| 3836 setModifier(Modifier.IMPLICIT_TYPE, hasImplicitReturnType); | 3844 setModifier(Modifier.IMPLICIT_TYPE, hasImplicitReturnType); |
| 3837 } | 3845 } |
| 3838 | 3846 |
| 3839 @override | 3847 @override |
| 3840 bool get isAbstract { | 3848 bool get isAbstract { |
| 3849 if (_kernel != null) { | |
| 3850 return _kernel.isAbstract; | |
| 3851 } | |
| 3841 if (serializedExecutable != null) { | 3852 if (serializedExecutable != null) { |
| 3842 return serializedExecutable.isAbstract; | 3853 return serializedExecutable.isAbstract; |
| 3843 } | 3854 } |
| 3844 return hasModifier(Modifier.ABSTRACT); | 3855 return hasModifier(Modifier.ABSTRACT); |
| 3845 } | 3856 } |
| 3846 | 3857 |
| 3847 @override | 3858 @override |
| 3848 bool get isAsynchronous { | 3859 bool get isAsynchronous { |
| 3860 if (_kernel != null) { | |
| 3861 kernel.AsyncMarker marker = _kernel.function.asyncMarker; | |
| 3862 return marker == kernel.AsyncMarker.Async || | |
| 3863 marker == kernel.AsyncMarker.AsyncStar; | |
| 3864 } | |
| 3849 if (serializedExecutable != null) { | 3865 if (serializedExecutable != null) { |
| 3850 return serializedExecutable.isAsynchronous; | 3866 return serializedExecutable.isAsynchronous; |
| 3851 } | 3867 } |
| 3852 return hasModifier(Modifier.ASYNCHRONOUS); | 3868 return hasModifier(Modifier.ASYNCHRONOUS); |
| 3853 } | 3869 } |
| 3854 | 3870 |
| 3855 @override | 3871 @override |
| 3856 bool get isExternal { | 3872 bool get isExternal { |
| 3857 if (_kernel != null) { | 3873 if (_kernel != null) { |
| 3858 return _kernel.isExternal; | 3874 return _kernel.isExternal; |
| 3859 } | 3875 } |
| 3860 if (serializedExecutable != null) { | 3876 if (serializedExecutable != null) { |
| 3861 return serializedExecutable.isExternal; | 3877 return serializedExecutable.isExternal; |
| 3862 } | 3878 } |
| 3863 return hasModifier(Modifier.EXTERNAL); | 3879 return hasModifier(Modifier.EXTERNAL); |
| 3864 } | 3880 } |
| 3865 | 3881 |
| 3866 @override | 3882 @override |
| 3867 bool get isGenerator { | 3883 bool get isGenerator { |
| 3884 if (_kernel != null) { | |
| 3885 return _kernel.function.asyncMarker == kernel.AsyncMarker.AsyncStar; | |
|
Paul Berry
2017/07/17 15:22:50
... || _kernel.function.asyncMarker == kernel.Asyn
scheglov
2017/07/17 15:37:20
Done.
| |
| 3886 } | |
| 3868 if (serializedExecutable != null) { | 3887 if (serializedExecutable != null) { |
| 3869 return serializedExecutable.isGenerator; | 3888 return serializedExecutable.isGenerator; |
| 3870 } | 3889 } |
| 3871 return hasModifier(Modifier.GENERATOR); | 3890 return hasModifier(Modifier.GENERATOR); |
| 3872 } | 3891 } |
| 3873 | 3892 |
| 3874 @override | 3893 @override |
| 3875 bool get isOperator => false; | 3894 bool get isOperator => false; |
| 3876 | 3895 |
| 3877 @override | 3896 @override |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3925 void set parameters(List<ParameterElement> parameters) { | 3944 void set parameters(List<ParameterElement> parameters) { |
| 3926 _assertNotResynthesized(serializedExecutable); | 3945 _assertNotResynthesized(serializedExecutable); |
| 3927 for (ParameterElement parameter in parameters) { | 3946 for (ParameterElement parameter in parameters) { |
| 3928 (parameter as ParameterElementImpl).enclosingElement = this; | 3947 (parameter as ParameterElementImpl).enclosingElement = this; |
| 3929 } | 3948 } |
| 3930 this._parameters = parameters; | 3949 this._parameters = parameters; |
| 3931 } | 3950 } |
| 3932 | 3951 |
| 3933 @override | 3952 @override |
| 3934 DartType get returnType { | 3953 DartType get returnType { |
| 3954 if (_kernel != null) { | |
| 3955 return _returnType ??= enclosingUnit._kernelContext | |
| 3956 .getType(this, _kernel.function.returnType); | |
| 3957 } | |
| 3935 if (serializedExecutable != null && | 3958 if (serializedExecutable != null && |
| 3936 _declaredReturnType == null && | 3959 _declaredReturnType == null && |
| 3937 _returnType == null) { | 3960 _returnType == null) { |
| 3938 bool isSetter = | 3961 bool isSetter = |
| 3939 serializedExecutable.kind == UnlinkedExecutableKind.setter; | 3962 serializedExecutable.kind == UnlinkedExecutableKind.setter; |
| 3940 _returnType = enclosingUnit.resynthesizerContext | 3963 _returnType = enclosingUnit.resynthesizerContext |
| 3941 .resolveLinkedType(this, serializedExecutable.inferredReturnTypeSlot); | 3964 .resolveLinkedType(this, serializedExecutable.inferredReturnTypeSlot); |
| 3942 _declaredReturnType = enclosingUnit.resynthesizerContext.resolveTypeRef( | 3965 _declaredReturnType = enclosingUnit.resynthesizerContext.resolveTypeRef( |
| 3943 this, serializedExecutable.returnType, | 3966 this, serializedExecutable.returnType, |
| 3944 defaultVoid: isSetter && context.analysisOptions.strongMode, | 3967 defaultVoid: isSetter && context.analysisOptions.strongMode, |
| (...skipping 2597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6542 _visibleRangeOffset = offset; | 6565 _visibleRangeOffset = offset; |
| 6543 _visibleRangeLength = length; | 6566 _visibleRangeLength = length; |
| 6544 } | 6567 } |
| 6545 } | 6568 } |
| 6546 | 6569 |
| 6547 /** | 6570 /** |
| 6548 * A concrete implementation of a [MethodElement]. | 6571 * A concrete implementation of a [MethodElement]. |
| 6549 */ | 6572 */ |
| 6550 class MethodElementImpl extends ExecutableElementImpl implements MethodElement { | 6573 class MethodElementImpl extends ExecutableElementImpl implements MethodElement { |
| 6551 /** | 6574 /** |
| 6575 * The kernel of the element. | |
| 6576 */ | |
| 6577 kernel.Procedure _kernelProcedure; | |
| 6578 | |
| 6579 /** | |
| 6552 * Initialize a newly created method element to have the given [name] at the | 6580 * Initialize a newly created method element to have the given [name] at the |
| 6553 * given [offset]. | 6581 * given [offset]. |
| 6554 */ | 6582 */ |
| 6555 MethodElementImpl(String name, int offset) : super(name, offset); | 6583 MethodElementImpl(String name, int offset) : super(name, offset); |
| 6556 | 6584 |
| 6557 /** | 6585 /** |
| 6586 * Initialize using the given kernel. | |
| 6587 */ | |
| 6588 MethodElementImpl.forKernel( | |
| 6589 ClassElementImpl enclosingClass, this._kernelProcedure) | |
| 6590 : super.forKernel(enclosingClass, _kernelProcedure); | |
| 6591 | |
| 6592 /** | |
| 6558 * Initialize a newly created method element to have the given [name]. | 6593 * Initialize a newly created method element to have the given [name]. |
| 6559 */ | 6594 */ |
| 6560 MethodElementImpl.forNode(Identifier name) : super.forNode(name); | 6595 MethodElementImpl.forNode(Identifier name) : super.forNode(name); |
| 6561 | 6596 |
| 6562 /** | 6597 /** |
| 6563 * Initialize using the given serialized information. | 6598 * Initialize using the given serialized information. |
| 6564 */ | 6599 */ |
| 6565 MethodElementImpl.forSerialized( | 6600 MethodElementImpl.forSerialized( |
| 6566 UnlinkedExecutable serializedExecutable, ClassElementImpl enclosingClass) | 6601 UnlinkedExecutable serializedExecutable, ClassElementImpl enclosingClass) |
| 6567 : super.forSerialized(serializedExecutable, enclosingClass); | 6602 : super.forSerialized(serializedExecutable, enclosingClass); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6606 } | 6641 } |
| 6607 int first = name.codeUnitAt(0); | 6642 int first = name.codeUnitAt(0); |
| 6608 return !((0x61 <= first && first <= 0x7A) || | 6643 return !((0x61 <= first && first <= 0x7A) || |
| 6609 (0x41 <= first && first <= 0x5A) || | 6644 (0x41 <= first && first <= 0x5A) || |
| 6610 first == 0x5F || | 6645 first == 0x5F || |
| 6611 first == 0x24); | 6646 first == 0x24); |
| 6612 } | 6647 } |
| 6613 | 6648 |
| 6614 @override | 6649 @override |
| 6615 bool get isStatic { | 6650 bool get isStatic { |
| 6651 if (_kernel != null) { | |
| 6652 return _kernelProcedure.isStatic; | |
| 6653 } | |
| 6616 if (serializedExecutable != null) { | 6654 if (serializedExecutable != null) { |
| 6617 return serializedExecutable.isStatic; | 6655 return serializedExecutable.isStatic; |
| 6618 } | 6656 } |
| 6619 return hasModifier(Modifier.STATIC); | 6657 return hasModifier(Modifier.STATIC); |
| 6620 } | 6658 } |
| 6621 | 6659 |
| 6622 /** | 6660 /** |
| 6623 * Set whether this method is static. | 6661 * Set whether this method is static. |
| 6624 */ | 6662 */ |
| 6625 void set isStatic(bool isStatic) { | 6663 void set isStatic(bool isStatic) { |
| (...skipping 2537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9163 | 9201 |
| 9164 @override | 9202 @override |
| 9165 DartObject computeConstantValue() => null; | 9203 DartObject computeConstantValue() => null; |
| 9166 | 9204 |
| 9167 @override | 9205 @override |
| 9168 void visitChildren(ElementVisitor visitor) { | 9206 void visitChildren(ElementVisitor visitor) { |
| 9169 super.visitChildren(visitor); | 9207 super.visitChildren(visitor); |
| 9170 _initializer?.accept(visitor); | 9208 _initializer?.accept(visitor); |
| 9171 } | 9209 } |
| 9172 } | 9210 } |
| OLD | NEW |