| 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 engine.element; | 5 library engine.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/src/generated/utilities_general.dart'; | 10 import 'package:analyzer/src/generated/utilities_general.dart'; |
| (...skipping 2119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2130 * Mixin used by elements that represent constant variables and have | 2130 * Mixin used by elements that represent constant variables and have |
| 2131 * initializers. | 2131 * initializers. |
| 2132 * | 2132 * |
| 2133 * Note that in correct Dart code, all constant variables must have | 2133 * Note that in correct Dart code, all constant variables must have |
| 2134 * initializers. However, analyzer also needs to handle incorrect Dart code, | 2134 * initializers. However, analyzer also needs to handle incorrect Dart code, |
| 2135 * in which case there might be some constant variables that lack initializers. | 2135 * in which case there might be some constant variables that lack initializers. |
| 2136 * This interface is only used for constant variables that have initializers. | 2136 * This interface is only used for constant variables that have initializers. |
| 2137 * | 2137 * |
| 2138 * This class is not intended to be part of the public API for analyzer. | 2138 * This class is not intended to be part of the public API for analyzer. |
| 2139 */ | 2139 */ |
| 2140 abstract class ConstVariableElement implements PotentiallyConstVariableElement { | 2140 abstract class ConstVariableElement { |
| 2141 /** | 2141 /** |
| 2142 * If this element represents a constant variable, and it has an initializer, | 2142 * If this element represents a constant variable, and it has an initializer, |
| 2143 * a copy of the initializer for the constant. Otherwise `null`. | 2143 * a copy of the initializer for the constant. Otherwise `null`. |
| 2144 * | 2144 * |
| 2145 * Note that in correct Dart code, all constant variables must have | 2145 * Note that in correct Dart code, all constant variables must have |
| 2146 * initializers. However, analyzer also needs to handle incorrect Dart code, | 2146 * initializers. However, analyzer also needs to handle incorrect Dart code, |
| 2147 * in which case there might be some constant variables that lack | 2147 * in which case there might be some constant variables that lack |
| 2148 * initializers. | 2148 * initializers. |
| 2149 */ | 2149 */ |
| 2150 Expression constantInitializer; | 2150 Expression constantInitializer; |
| (...skipping 2025 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4176 * so parsing and resolving will be performed. | 4176 * so parsing and resolving will be performed. |
| 4177 */ | 4177 */ |
| 4178 @override | 4178 @override |
| 4179 AstNode computeNode(); | 4179 AstNode computeNode(); |
| 4180 } | 4180 } |
| 4181 | 4181 |
| 4182 /** | 4182 /** |
| 4183 * A concrete implementation of a [FieldElement]. | 4183 * A concrete implementation of a [FieldElement]. |
| 4184 */ | 4184 */ |
| 4185 class FieldElementImpl extends PropertyInducingElementImpl | 4185 class FieldElementImpl extends PropertyInducingElementImpl |
| 4186 with PotentiallyConstVariableElement | |
| 4187 implements FieldElement { | 4186 implements FieldElement { |
| 4188 /** | 4187 /** |
| 4189 * An empty list of field elements. | 4188 * An empty list of field elements. |
| 4190 */ | 4189 */ |
| 4191 @deprecated // Use FieldElement.EMPTY_LIST | 4190 @deprecated // Use FieldElement.EMPTY_LIST |
| 4192 static const List<FieldElement> EMPTY_ARRAY = const <FieldElement>[]; | 4191 static const List<FieldElement> EMPTY_ARRAY = const <FieldElement>[]; |
| 4193 | 4192 |
| 4194 /** | 4193 /** |
| 4195 * Initialize a newly created synthetic field element to have the given [name] | 4194 * Initialize a newly created synthetic field element to have the given [name] |
| 4196 * at the given [offset]. | 4195 * at the given [offset]. |
| (...skipping 3735 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7932 * so parsing and resolving will be performed. | 7931 * so parsing and resolving will be performed. |
| 7933 */ | 7932 */ |
| 7934 @override | 7933 @override |
| 7935 VariableDeclaration computeNode(); | 7934 VariableDeclaration computeNode(); |
| 7936 } | 7935 } |
| 7937 | 7936 |
| 7938 /** | 7937 /** |
| 7939 * A concrete implementation of a [LocalVariableElement]. | 7938 * A concrete implementation of a [LocalVariableElement]. |
| 7940 */ | 7939 */ |
| 7941 class LocalVariableElementImpl extends VariableElementImpl | 7940 class LocalVariableElementImpl extends VariableElementImpl |
| 7942 with PotentiallyConstVariableElement | |
| 7943 implements LocalVariableElement { | 7941 implements LocalVariableElement { |
| 7944 /** | 7942 /** |
| 7945 * An empty list of field elements. | 7943 * An empty list of field elements. |
| 7946 */ | 7944 */ |
| 7947 @deprecated // Use LocalVariableElement.EMPTY_LIST | 7945 @deprecated // Use LocalVariableElement.EMPTY_LIST |
| 7948 static const List<LocalVariableElement> EMPTY_ARRAY = | 7946 static const List<LocalVariableElement> EMPTY_ARRAY = |
| 7949 const <LocalVariableElement>[]; | 7947 const <LocalVariableElement>[]; |
| 7950 | 7948 |
| 7951 /** | 7949 /** |
| 7952 * The offset to the beginning of the visible range for this element. | 7950 * The offset to the beginning of the visible range for this element. |
| (...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8869 void appendToWithoutDelimiters(StringBuffer buffer); | 8867 void appendToWithoutDelimiters(StringBuffer buffer); |
| 8870 | 8868 |
| 8871 @override | 8869 @override |
| 8872 FormalParameter computeNode(); | 8870 FormalParameter computeNode(); |
| 8873 } | 8871 } |
| 8874 | 8872 |
| 8875 /** | 8873 /** |
| 8876 * A concrete implementation of a [ParameterElement]. | 8874 * A concrete implementation of a [ParameterElement]. |
| 8877 */ | 8875 */ |
| 8878 class ParameterElementImpl extends VariableElementImpl | 8876 class ParameterElementImpl extends VariableElementImpl |
| 8879 with ParameterElementMixin, PotentiallyConstVariableElement | 8877 with ParameterElementMixin |
| 8880 implements ParameterElement { | 8878 implements ParameterElement { |
| 8881 /** | 8879 /** |
| 8882 * An empty list of parameter elements. | 8880 * An empty list of parameter elements. |
| 8883 */ | 8881 */ |
| 8884 @deprecated // Use ParameterElement.EMPTY_LIST | 8882 @deprecated // Use ParameterElement.EMPTY_LIST |
| 8885 static const List<ParameterElement> EMPTY_ARRAY = const <ParameterElement>[]; | 8883 static const List<ParameterElement> EMPTY_ARRAY = const <ParameterElement>[]; |
| 8886 | 8884 |
| 8887 /** | 8885 /** |
| 8888 * A list containing all of the parameters defined by this parameter element. | 8886 * A list containing all of the parameters defined by this parameter element. |
| 8889 * There will only be parameters if this parameter is a function typed | 8887 * There will only be parameters if this parameter is a function typed |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9228 // We need to see how often the type is being re-computed. | 9226 // We need to see how often the type is being re-computed. |
| 9229 if (isFieldFormal) { | 9227 if (isFieldFormal) { |
| 9230 return new FieldFormalParameterMember( | 9228 return new FieldFormalParameterMember( |
| 9231 parameter as FieldFormalParameterElement, definingType); | 9229 parameter as FieldFormalParameterElement, definingType); |
| 9232 } | 9230 } |
| 9233 return new ParameterMember(parameter, definingType); | 9231 return new ParameterMember(parameter, definingType); |
| 9234 } | 9232 } |
| 9235 } | 9233 } |
| 9236 | 9234 |
| 9237 /** | 9235 /** |
| 9238 * Interface used by elements that might represent constant variables. | |
| 9239 * | |
| 9240 * This class may be used as a mixin in the case where [constInitializer] is | |
| 9241 * known to return null. | |
| 9242 * | |
| 9243 * This class is not intended to be part of the public API for analyzer. | |
| 9244 */ | |
| 9245 abstract class PotentiallyConstVariableElement | |
| 9246 implements VariableElementImpl, ConstantEvaluationTarget { | |
| 9247 /** | |
| 9248 * If this element represents a constant variable, and it has an initializer, | |
| 9249 * a copy of the initializer for the constant. Otherwise `null`. | |
| 9250 * | |
| 9251 * Note that in correct Dart code, all constant variables must have | |
| 9252 * initializers. However, analyzer also needs to handle incorrect Dart code, | |
| 9253 * in which case there might be some constant variables that lack | |
| 9254 * initializers. | |
| 9255 */ | |
| 9256 Expression get constantInitializer => null; | |
| 9257 } | |
| 9258 | |
| 9259 /** | |
| 9260 * A prefix used to import one or more libraries into another library. | 9236 * A prefix used to import one or more libraries into another library. |
| 9261 */ | 9237 */ |
| 9262 abstract class PrefixElement implements Element { | 9238 abstract class PrefixElement implements Element { |
| 9263 /** | 9239 /** |
| 9264 * An empty list of prefix elements. | 9240 * An empty list of prefix elements. |
| 9265 */ | 9241 */ |
| 9266 static const List<PrefixElement> EMPTY_LIST = const <PrefixElement>[]; | 9242 static const List<PrefixElement> EMPTY_LIST = const <PrefixElement>[]; |
| 9267 | 9243 |
| 9268 /** | 9244 /** |
| 9269 * Return the library into which other libraries are imported using this | 9245 * Return the library into which other libraries are imported using this |
| (...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10058 const <TopLevelVariableElement>[]; | 10034 const <TopLevelVariableElement>[]; |
| 10059 | 10035 |
| 10060 @override | 10036 @override |
| 10061 VariableDeclaration computeNode(); | 10037 VariableDeclaration computeNode(); |
| 10062 } | 10038 } |
| 10063 | 10039 |
| 10064 /** | 10040 /** |
| 10065 * A concrete implementation of a [TopLevelVariableElement]. | 10041 * A concrete implementation of a [TopLevelVariableElement]. |
| 10066 */ | 10042 */ |
| 10067 class TopLevelVariableElementImpl extends PropertyInducingElementImpl | 10043 class TopLevelVariableElementImpl extends PropertyInducingElementImpl |
| 10068 with PotentiallyConstVariableElement | |
| 10069 implements TopLevelVariableElement { | 10044 implements TopLevelVariableElement { |
| 10070 /** | 10045 /** |
| 10071 * An empty list of top-level variable elements. | 10046 * An empty list of top-level variable elements. |
| 10072 */ | 10047 */ |
| 10073 @deprecated // Use TopLevelVariableElement.EMPTY_LIST | 10048 @deprecated // Use TopLevelVariableElement.EMPTY_LIST |
| 10074 static const List<TopLevelVariableElement> EMPTY_ARRAY = | 10049 static const List<TopLevelVariableElement> EMPTY_ARRAY = |
| 10075 const <TopLevelVariableElement>[]; | 10050 const <TopLevelVariableElement>[]; |
| 10076 | 10051 |
| 10077 /** | 10052 /** |
| 10078 * Initialize a newly created synthetic top-level variable element to have the | 10053 * Initialize a newly created synthetic top-level variable element to have the |
| (...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10763 */ | 10738 */ |
| 10764 VariableElementImpl.forNode(Identifier name) : super.forNode(name); | 10739 VariableElementImpl.forNode(Identifier name) : super.forNode(name); |
| 10765 | 10740 |
| 10766 /** | 10741 /** |
| 10767 * Set whether this variable is const. | 10742 * Set whether this variable is const. |
| 10768 */ | 10743 */ |
| 10769 void set const3(bool isConst) { | 10744 void set const3(bool isConst) { |
| 10770 setModifier(Modifier.CONST, isConst); | 10745 setModifier(Modifier.CONST, isConst); |
| 10771 } | 10746 } |
| 10772 | 10747 |
| 10748 /** |
| 10749 * If this element represents a constant variable, and it has an initializer, |
| 10750 * a copy of the initializer for the constant. Otherwise `null`. |
| 10751 * |
| 10752 * Note that in correct Dart code, all constant variables must have |
| 10753 * initializers. However, analyzer also needs to handle incorrect Dart code, |
| 10754 * in which case there might be some constant variables that lack |
| 10755 * initializers. |
| 10756 */ |
| 10757 Expression get constantInitializer => null; |
| 10758 |
| 10773 @override | 10759 @override |
| 10774 DartObject get constantValue => null; | 10760 DartObject get constantValue => null; |
| 10775 | 10761 |
| 10776 /** | 10762 /** |
| 10777 * Return the result of evaluating this variable's initializer as a | 10763 * Return the result of evaluating this variable's initializer as a |
| 10778 * compile-time constant expression, or `null` if this variable is not a | 10764 * compile-time constant expression, or `null` if this variable is not a |
| 10779 * 'const' variable, if it does not have an initializer, or if the compilation | 10765 * 'const' variable, if it does not have an initializer, or if the compilation |
| 10780 * unit containing the variable has not been resolved. | 10766 * unit containing the variable has not been resolved. |
| 10781 */ | 10767 */ |
| 10782 EvaluationResultImpl get evaluationResult => null; | 10768 EvaluationResultImpl get evaluationResult => null; |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10981 | 10967 |
| 10982 @override | 10968 @override |
| 10983 void visitElement(Element element) { | 10969 void visitElement(Element element) { |
| 10984 int offset = element.nameOffset; | 10970 int offset = element.nameOffset; |
| 10985 if (offset != -1) { | 10971 if (offset != -1) { |
| 10986 map[offset] = element; | 10972 map[offset] = element; |
| 10987 } | 10973 } |
| 10988 super.visitElement(element); | 10974 super.visitElement(element); |
| 10989 } | 10975 } |
| 10990 } | 10976 } |
| OLD | NEW |