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 3563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3574 */ | 3574 */ |
3575 List<ParameterElement> _parameters; | 3575 List<ParameterElement> _parameters; |
3576 | 3576 |
3577 /** | 3577 /** |
3578 * A list containing all of the type parameters defined for this executable | 3578 * A list containing all of the type parameters defined for this executable |
3579 * element. | 3579 * element. |
3580 */ | 3580 */ |
3581 List<TypeParameterElement> _typeParameters; | 3581 List<TypeParameterElement> _typeParameters; |
3582 | 3582 |
3583 /** | 3583 /** |
3584 * The return type defined by this executable element. | 3584 * The declared return type of this executable element. |
| 3585 */ |
| 3586 DartType _declaredReturnType; |
| 3587 |
| 3588 /** |
| 3589 * The inferred return type of this executable element. |
3585 */ | 3590 */ |
3586 DartType _returnType; | 3591 DartType _returnType; |
3587 | 3592 |
3588 /** | 3593 /** |
3589 * The type of function defined by this executable element. | 3594 * The type of function defined by this executable element. |
3590 */ | 3595 */ |
3591 FunctionType _type; | 3596 FunctionType _type; |
3592 | 3597 |
3593 /** | 3598 /** |
3594 * Initialize a newly created executable element to have the given [name] and | 3599 * Initialize a newly created executable element to have the given [name] and |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3629 } | 3634 } |
3630 | 3635 |
3631 @override | 3636 @override |
3632 int get codeOffset { | 3637 int get codeOffset { |
3633 if (serializedExecutable != null) { | 3638 if (serializedExecutable != null) { |
3634 return serializedExecutable.codeRange?.offset; | 3639 return serializedExecutable.codeRange?.offset; |
3635 } | 3640 } |
3636 return super.codeOffset; | 3641 return super.codeOffset; |
3637 } | 3642 } |
3638 | 3643 |
| 3644 void set declaredReturnType(DartType returnType) { |
| 3645 _assertNotResynthesized(serializedExecutable); |
| 3646 _declaredReturnType = returnType; |
| 3647 } |
| 3648 |
3639 @override | 3649 @override |
3640 String get displayName { | 3650 String get displayName { |
3641 if (serializedExecutable != null) { | 3651 if (serializedExecutable != null) { |
3642 return serializedExecutable.name; | 3652 return serializedExecutable.name; |
3643 } | 3653 } |
3644 return super.displayName; | 3654 return super.displayName; |
3645 } | 3655 } |
3646 | 3656 |
3647 @override | 3657 @override |
3648 String get documentationComment { | 3658 String get documentationComment { |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3840 void set parameters(List<ParameterElement> parameters) { | 3850 void set parameters(List<ParameterElement> parameters) { |
3841 _assertNotResynthesized(serializedExecutable); | 3851 _assertNotResynthesized(serializedExecutable); |
3842 for (ParameterElement parameter in parameters) { | 3852 for (ParameterElement parameter in parameters) { |
3843 (parameter as ParameterElementImpl).enclosingElement = this; | 3853 (parameter as ParameterElementImpl).enclosingElement = this; |
3844 } | 3854 } |
3845 this._parameters = parameters; | 3855 this._parameters = parameters; |
3846 } | 3856 } |
3847 | 3857 |
3848 @override | 3858 @override |
3849 DartType get returnType { | 3859 DartType get returnType { |
3850 if (serializedExecutable != null && _returnType == null) { | 3860 if (serializedExecutable != null && |
| 3861 _declaredReturnType == null && |
| 3862 _returnType == null) { |
3851 bool isSetter = | 3863 bool isSetter = |
3852 serializedExecutable.kind == UnlinkedExecutableKind.setter; | 3864 serializedExecutable.kind == UnlinkedExecutableKind.setter; |
3853 _returnType = enclosingUnit.resynthesizerContext.resolveLinkedType( | 3865 _returnType = enclosingUnit.resynthesizerContext.resolveLinkedType( |
3854 serializedExecutable.inferredReturnTypeSlot, | 3866 serializedExecutable.inferredReturnTypeSlot, typeParameterContext); |
3855 typeParameterContext) ?? | 3867 _declaredReturnType = enclosingUnit.resynthesizerContext.resolveTypeRef( |
3856 enclosingUnit.resynthesizerContext.resolveTypeRef( | 3868 serializedExecutable.returnType, typeParameterContext, |
3857 serializedExecutable.returnType, typeParameterContext, | 3869 defaultVoid: isSetter && context.analysisOptions.strongMode); |
3858 defaultVoid: isSetter && context.analysisOptions.strongMode); | |
3859 } | 3870 } |
3860 return _returnType; | 3871 return _returnType ?? _declaredReturnType; |
3861 } | 3872 } |
3862 | 3873 |
3863 void set returnType(DartType returnType) { | 3874 void set returnType(DartType returnType) { |
3864 _assertNotResynthesized(serializedExecutable); | 3875 _assertNotResynthesized(serializedExecutable); |
3865 _returnType = returnType; | 3876 _returnType = returnType; |
3866 } | 3877 } |
3867 | 3878 |
3868 @override | 3879 @override |
3869 FunctionType get type { | 3880 FunctionType get type { |
3870 if (serializedExecutable != null) { | 3881 if (serializedExecutable != null) { |
(...skipping 2892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6763 int get nameOffset { | 6774 int get nameOffset { |
6764 int offset = super.nameOffset; | 6775 int offset = super.nameOffset; |
6765 if (offset == 0 && _unlinkedVariable != null) { | 6776 if (offset == 0 && _unlinkedVariable != null) { |
6766 return _unlinkedVariable.nameOffset; | 6777 return _unlinkedVariable.nameOffset; |
6767 } | 6778 } |
6768 return offset; | 6779 return offset; |
6769 } | 6780 } |
6770 | 6781 |
6771 @override | 6782 @override |
6772 DartType get type { | 6783 DartType get type { |
6773 if (_unlinkedVariable != null && _type == null) { | 6784 if (_unlinkedVariable != null && _declaredType == null && _type == null) { |
6774 _type = enclosingUnit.resynthesizerContext.resolveLinkedType( | 6785 _type = enclosingUnit.resynthesizerContext.resolveLinkedType( |
6775 _unlinkedVariable.inferredTypeSlot, typeParameterContext) ?? | 6786 _unlinkedVariable.inferredTypeSlot, typeParameterContext); |
6776 enclosingUnit.resynthesizerContext | 6787 _declaredType = enclosingUnit.resynthesizerContext |
6777 .resolveTypeRef(_unlinkedVariable.type, typeParameterContext); | 6788 .resolveTypeRef(_unlinkedVariable.type, typeParameterContext); |
6778 } | 6789 } |
6779 return super.type; | 6790 return super.type; |
6780 } | 6791 } |
6781 | 6792 |
6782 void set type(DartType type) { | 6793 void set type(DartType type) { |
6783 _assertNotResynthesized(_unlinkedVariable); | 6794 _assertNotResynthesized(_unlinkedVariable); |
6784 _type = type; | 6795 _type = type; |
6785 } | 6796 } |
6786 | 6797 |
6787 /** | 6798 /** |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7207 void visitChildren(ElementVisitor visitor) { | 7218 void visitChildren(ElementVisitor visitor) { |
7208 super.visitChildren(visitor); | 7219 super.visitChildren(visitor); |
7209 safelyVisitChildren(parameters, visitor); | 7220 safelyVisitChildren(parameters, visitor); |
7210 } | 7221 } |
7211 | 7222 |
7212 /** | 7223 /** |
7213 * If this element is resynthesized, and its type and parameters have not | 7224 * If this element is resynthesized, and its type and parameters have not |
7214 * been build yet, build them and remember in the corresponding fields. | 7225 * been build yet, build them and remember in the corresponding fields. |
7215 */ | 7226 */ |
7216 void _resynthesizeTypeAndParameters() { | 7227 void _resynthesizeTypeAndParameters() { |
7217 if (_unlinkedParam != null && _type == null) { | 7228 if (_unlinkedParam != null && _declaredType == null && _type == null) { |
7218 if (_unlinkedParam.isFunctionTyped) { | 7229 if (_unlinkedParam.isFunctionTyped) { |
7219 CompilationUnitElementImpl enclosingUnit = this.enclosingUnit; | 7230 CompilationUnitElementImpl enclosingUnit = this.enclosingUnit; |
7220 FunctionElementImpl parameterTypeElement = | 7231 FunctionElementImpl parameterTypeElement = |
7221 new FunctionElementImpl_forFunctionTypedParameter( | 7232 new FunctionElementImpl_forFunctionTypedParameter( |
7222 enclosingUnit, this); | 7233 enclosingUnit, this); |
7223 if (!isSynthetic) { | 7234 if (!isSynthetic) { |
7224 parameterTypeElement.enclosingElement = this; | 7235 parameterTypeElement.enclosingElement = this; |
7225 } | 7236 } |
7226 List<ParameterElement> subParameters = ParameterElementImpl | 7237 List<ParameterElement> subParameters = ParameterElementImpl |
7227 .resynthesizeList(_unlinkedParam.parameters, this, | 7238 .resynthesizeList(_unlinkedParam.parameters, this, |
7228 synthetic: isSynthetic); | 7239 synthetic: isSynthetic); |
7229 if (isSynthetic) { | 7240 if (isSynthetic) { |
7230 parameterTypeElement.parameters = subParameters; | 7241 parameterTypeElement.parameters = subParameters; |
7231 } else { | 7242 } else { |
7232 _parameters = subParameters; | 7243 _parameters = subParameters; |
7233 parameterTypeElement.shareParameters(subParameters); | 7244 parameterTypeElement.shareParameters(subParameters); |
7234 } | 7245 } |
7235 parameterTypeElement.returnType = enclosingUnit.resynthesizerContext | 7246 parameterTypeElement.returnType = enclosingUnit.resynthesizerContext |
7236 .resolveTypeRef(_unlinkedParam.type, typeParameterContext); | 7247 .resolveTypeRef(_unlinkedParam.type, typeParameterContext); |
7237 FunctionTypeImpl parameterType = | 7248 FunctionTypeImpl parameterType = |
7238 new FunctionTypeImpl.elementWithNameAndArgs(parameterTypeElement, | 7249 new FunctionTypeImpl.elementWithNameAndArgs(parameterTypeElement, |
7239 null, typeParameterContext.allTypeParameterTypes, false); | 7250 null, typeParameterContext.allTypeParameterTypes, false); |
7240 parameterTypeElement.type = parameterType; | 7251 parameterTypeElement.type = parameterType; |
7241 _type = parameterType; | 7252 _type = parameterType; |
7242 } else { | 7253 } else { |
7243 _type = enclosingUnit.resynthesizerContext.resolveLinkedType( | 7254 _type = enclosingUnit.resynthesizerContext.resolveLinkedType( |
7244 _unlinkedParam.inferredTypeSlot, typeParameterContext) ?? | 7255 _unlinkedParam.inferredTypeSlot, typeParameterContext); |
7245 enclosingUnit.resynthesizerContext | 7256 _declaredType = enclosingUnit.resynthesizerContext |
7246 .resolveTypeRef(_unlinkedParam.type, typeParameterContext); | 7257 .resolveTypeRef(_unlinkedParam.type, typeParameterContext); |
7247 } | 7258 } |
7248 } | 7259 } |
7249 } | 7260 } |
7250 | 7261 |
7251 /** | 7262 /** |
7252 * Create and return [ParameterElement]s for the given [unlinkedParameters]. | 7263 * Create and return [ParameterElement]s for the given [unlinkedParameters]. |
7253 */ | 7264 */ |
7254 static List<ParameterElement> resynthesizeList( | 7265 static List<ParameterElement> resynthesizeList( |
7255 List<UnlinkedParam> unlinkedParameters, ElementImpl enclosingElement, | 7266 List<UnlinkedParam> unlinkedParameters, ElementImpl enclosingElement, |
7256 {bool synthetic: false}) { | 7267 {bool synthetic: false}) { |
(...skipping 1038 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8295 } | 8306 } |
8296 | 8307 |
8297 /** | 8308 /** |
8298 * A concrete implementation of a [VariableElement]. | 8309 * A concrete implementation of a [VariableElement]. |
8299 */ | 8310 */ |
8300 abstract class VariableElementImpl extends ElementImpl | 8311 abstract class VariableElementImpl extends ElementImpl |
8301 implements VariableElement { | 8312 implements VariableElement { |
8302 /** | 8313 /** |
8303 * The declared type of this variable. | 8314 * The declared type of this variable. |
8304 */ | 8315 */ |
| 8316 DartType _declaredType; |
| 8317 |
| 8318 /** |
| 8319 * The inferred type of this variable. |
| 8320 */ |
8305 DartType _type; | 8321 DartType _type; |
8306 | 8322 |
8307 /** | 8323 /** |
8308 * A synthetic function representing this variable's initializer, or `null` if | 8324 * A synthetic function representing this variable's initializer, or `null` if |
8309 * this variable does not have an initializer. | 8325 * this variable does not have an initializer. |
8310 */ | 8326 */ |
8311 FunctionElement _initializer; | 8327 FunctionElement _initializer; |
8312 | 8328 |
8313 /** | 8329 /** |
8314 * Initialize a newly created variable element to have the given [name] and | 8330 * Initialize a newly created variable element to have the given [name] and |
(...skipping 26 matching lines...) Expand all Loading... |
8341 * Note that in correct Dart code, all constant variables must have | 8357 * Note that in correct Dart code, all constant variables must have |
8342 * initializers. However, analyzer also needs to handle incorrect Dart code, | 8358 * initializers. However, analyzer also needs to handle incorrect Dart code, |
8343 * in which case there might be some constant variables that lack | 8359 * in which case there might be some constant variables that lack |
8344 * initializers. | 8360 * initializers. |
8345 */ | 8361 */ |
8346 Expression get constantInitializer => null; | 8362 Expression get constantInitializer => null; |
8347 | 8363 |
8348 @override | 8364 @override |
8349 DartObject get constantValue => evaluationResult?.value; | 8365 DartObject get constantValue => evaluationResult?.value; |
8350 | 8366 |
| 8367 void set declaredType(DartType type) { |
| 8368 _declaredType = type; |
| 8369 } |
| 8370 |
8351 @override | 8371 @override |
8352 String get displayName => name; | 8372 String get displayName => name; |
8353 | 8373 |
8354 /** | 8374 /** |
8355 * Return the result of evaluating this variable's initializer as a | 8375 * Return the result of evaluating this variable's initializer as a |
8356 * compile-time constant expression, or `null` if this variable is not a | 8376 * compile-time constant expression, or `null` if this variable is not a |
8357 * 'const' variable, if it does not have an initializer, or if the compilation | 8377 * 'const' variable, if it does not have an initializer, or if the compilation |
8358 * unit containing the variable has not been resolved. | 8378 * unit containing the variable has not been resolved. |
8359 */ | 8379 */ |
8360 EvaluationResultImpl get evaluationResult => null; | 8380 EvaluationResultImpl get evaluationResult => null; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8414 @override | 8434 @override |
8415 bool get isPotentiallyMutatedInClosure => false; | 8435 bool get isPotentiallyMutatedInClosure => false; |
8416 | 8436 |
8417 @override | 8437 @override |
8418 bool get isPotentiallyMutatedInScope => false; | 8438 bool get isPotentiallyMutatedInScope => false; |
8419 | 8439 |
8420 @override | 8440 @override |
8421 bool get isStatic => hasModifier(Modifier.STATIC); | 8441 bool get isStatic => hasModifier(Modifier.STATIC); |
8422 | 8442 |
8423 @override | 8443 @override |
8424 DartType get type => _type; | 8444 DartType get type => _type ?? _declaredType; |
8425 | 8445 |
8426 void set type(DartType type) { | 8446 void set type(DartType type) { |
8427 _type = type; | 8447 _type = type; |
8428 } | 8448 } |
8429 | 8449 |
8430 @override | 8450 @override |
8431 void appendTo(StringBuffer buffer) { | 8451 void appendTo(StringBuffer buffer) { |
8432 buffer.write(type); | 8452 buffer.write(type); |
8433 buffer.write(" "); | 8453 buffer.write(" "); |
8434 buffer.write(displayName); | 8454 buffer.write(displayName); |
(...skipping 19 matching lines...) Expand all Loading... |
8454 | 8474 |
8455 @override | 8475 @override |
8456 void visitElement(Element element) { | 8476 void visitElement(Element element) { |
8457 int offset = element.nameOffset; | 8477 int offset = element.nameOffset; |
8458 if (offset != -1) { | 8478 if (offset != -1) { |
8459 map[offset] = element; | 8479 map[offset] = element; |
8460 } | 8480 } |
8461 super.visitElement(element); | 8481 super.visitElement(element); |
8462 } | 8482 } |
8463 } | 8483 } |
OLD | NEW |