| 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.resolver; | 5 library engine.resolver; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'ast.dart'; | 9 import 'ast.dart'; |
| 10 import 'constant.dart'; | 10 import 'constant.dart'; |
| (...skipping 2535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2546 * A flag indicating whether a variable declaration is within the body of a me
thod or function. | 2546 * A flag indicating whether a variable declaration is within the body of a me
thod or function. |
| 2547 */ | 2547 */ |
| 2548 bool _inFunction = false; | 2548 bool _inFunction = false; |
| 2549 | 2549 |
| 2550 /** | 2550 /** |
| 2551 * A flag indicating whether the class currently being visited can be used as
a mixin. | 2551 * A flag indicating whether the class currently being visited can be used as
a mixin. |
| 2552 */ | 2552 */ |
| 2553 bool _isValidMixin = false; | 2553 bool _isValidMixin = false; |
| 2554 | 2554 |
| 2555 /** | 2555 /** |
| 2556 * A collection holding the function types defined in a class that need to hav
e their type | |
| 2557 * arguments set to the types of the type parameters for the class, or `null`
if we are not | |
| 2558 * currently processing nodes within a class. | |
| 2559 */ | |
| 2560 List<FunctionTypeImpl> _functionTypesToFix = null; | |
| 2561 | |
| 2562 /** | |
| 2563 * A table mapping field names to field elements for the fields defined in the
current class, or | 2556 * A table mapping field names to field elements for the fields defined in the
current class, or |
| 2564 * `null` if we are not in the scope of a class. | 2557 * `null` if we are not in the scope of a class. |
| 2565 */ | 2558 */ |
| 2566 HashMap<String, FieldElement> _fieldMap; | 2559 HashMap<String, FieldElement> _fieldMap; |
| 2567 | 2560 |
| 2568 /** | 2561 /** |
| 2569 * Initialize a newly created element builder to build the elements for a comp
ilation unit. | 2562 * Initialize a newly created element builder to build the elements for a comp
ilation unit. |
| 2570 * | 2563 * |
| 2571 * @param initialHolder the element holder associated with the compilation uni
t being built | 2564 * @param initialHolder the element holder associated with the compilation uni
t being built |
| 2572 */ | 2565 */ |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2607 stackTraceParameter.staticElement = stackTrace; | 2600 stackTraceParameter.staticElement = stackTrace; |
| 2608 } | 2601 } |
| 2609 } | 2602 } |
| 2610 return super.visitCatchClause(node); | 2603 return super.visitCatchClause(node); |
| 2611 } | 2604 } |
| 2612 | 2605 |
| 2613 @override | 2606 @override |
| 2614 Object visitClassDeclaration(ClassDeclaration node) { | 2607 Object visitClassDeclaration(ClassDeclaration node) { |
| 2615 ElementHolder holder = new ElementHolder(); | 2608 ElementHolder holder = new ElementHolder(); |
| 2616 _isValidMixin = true; | 2609 _isValidMixin = true; |
| 2617 _functionTypesToFix = new List<FunctionTypeImpl>(); | |
| 2618 // | 2610 // |
| 2619 // Process field declarations before constructors and methods so that field | 2611 // Process field declarations before constructors and methods so that field |
| 2620 // formal parameters can be correctly resolved to their fields. | 2612 // formal parameters can be correctly resolved to their fields. |
| 2621 // | 2613 // |
| 2622 ElementHolder previousHolder = _currentHolder; | 2614 ElementHolder previousHolder = _currentHolder; |
| 2623 _currentHolder = holder; | 2615 _currentHolder = holder; |
| 2624 try { | 2616 try { |
| 2625 List<ClassMember> nonFields = new List<ClassMember>(); | 2617 List<ClassMember> nonFields = new List<ClassMember>(); |
| 2626 node.visitChildren( | 2618 node.visitChildren( |
| 2627 new _ElementBuilder_visitClassDeclaration(this, nonFields)); | 2619 new _ElementBuilder_visitClassDeclaration(this, nonFields)); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 2648 constructors = _createDefaultConstructors(interfaceType); | 2640 constructors = _createDefaultConstructors(interfaceType); |
| 2649 } | 2641 } |
| 2650 _setDocRange(element, node); | 2642 _setDocRange(element, node); |
| 2651 element.abstract = node.isAbstract; | 2643 element.abstract = node.isAbstract; |
| 2652 element.accessors = holder.accessors; | 2644 element.accessors = holder.accessors; |
| 2653 element.constructors = constructors; | 2645 element.constructors = constructors; |
| 2654 element.fields = holder.fields; | 2646 element.fields = holder.fields; |
| 2655 element.methods = holder.methods; | 2647 element.methods = holder.methods; |
| 2656 element.typeParameters = typeParameters; | 2648 element.typeParameters = typeParameters; |
| 2657 element.validMixin = _isValidMixin; | 2649 element.validMixin = _isValidMixin; |
| 2658 int functionTypeCount = _functionTypesToFix.length; | |
| 2659 for (int i = 0; i < functionTypeCount; i++) { | |
| 2660 _functionTypesToFix[i].typeArguments = typeArguments; | |
| 2661 } | |
| 2662 _functionTypesToFix = null; | |
| 2663 _currentHolder.addType(element); | 2650 _currentHolder.addType(element); |
| 2664 className.staticElement = element; | 2651 className.staticElement = element; |
| 2665 _fieldMap = null; | 2652 _fieldMap = null; |
| 2666 holder.validate(); | 2653 holder.validate(); |
| 2667 return null; | 2654 return null; |
| 2668 } | 2655 } |
| 2669 | 2656 |
| 2670 /** | 2657 /** |
| 2671 * Implementation of this method should be synchronized with | 2658 * Implementation of this method should be synchronized with |
| 2672 * [visitClassDeclaration]. | 2659 * [visitClassDeclaration]. |
| 2673 */ | 2660 */ |
| 2674 void visitClassDeclarationIncrementally(ClassDeclaration node) { | 2661 void visitClassDeclarationIncrementally(ClassDeclaration node) { |
| 2675 // | 2662 // |
| 2676 // Process field declarations before constructors and methods so that field | 2663 // Process field declarations before constructors and methods so that field |
| 2677 // formal parameters can be correctly resolved to their fields. | 2664 // formal parameters can be correctly resolved to their fields. |
| 2678 // | 2665 // |
| 2679 ClassElement classElement = node.element; | 2666 ClassElement classElement = node.element; |
| 2680 _buildFieldMap(classElement.fields); | 2667 _buildFieldMap(classElement.fields); |
| 2681 } | 2668 } |
| 2682 | 2669 |
| 2683 @override | 2670 @override |
| 2684 Object visitClassTypeAlias(ClassTypeAlias node) { | 2671 Object visitClassTypeAlias(ClassTypeAlias node) { |
| 2685 ElementHolder holder = new ElementHolder(); | 2672 ElementHolder holder = new ElementHolder(); |
| 2686 _functionTypesToFix = new List<FunctionTypeImpl>(); | |
| 2687 _visitChildren(holder, node); | 2673 _visitChildren(holder, node); |
| 2688 SimpleIdentifier className = node.name; | 2674 SimpleIdentifier className = node.name; |
| 2689 ClassElementImpl element = new ClassElementImpl.forNode(className); | 2675 ClassElementImpl element = new ClassElementImpl.forNode(className); |
| 2690 element.abstract = node.abstractKeyword != null; | 2676 element.abstract = node.abstractKeyword != null; |
| 2691 element.mixinApplication = true; | 2677 element.mixinApplication = true; |
| 2692 List<TypeParameterElement> typeParameters = holder.typeParameters; | 2678 List<TypeParameterElement> typeParameters = holder.typeParameters; |
| 2693 element.typeParameters = typeParameters; | 2679 element.typeParameters = typeParameters; |
| 2694 List<DartType> typeArguments = _createTypeParameterTypes(typeParameters); | 2680 List<DartType> typeArguments = _createTypeParameterTypes(typeParameters); |
| 2695 InterfaceTypeImpl interfaceType = new InterfaceTypeImpl(element); | 2681 InterfaceTypeImpl interfaceType = new InterfaceTypeImpl(element); |
| 2696 interfaceType.typeArguments = typeArguments; | 2682 interfaceType.typeArguments = typeArguments; |
| 2697 element.type = interfaceType; | 2683 element.type = interfaceType; |
| 2698 // set default constructor | |
| 2699 for (FunctionTypeImpl functionType in _functionTypesToFix) { | |
| 2700 functionType.typeArguments = typeArguments; | |
| 2701 } | |
| 2702 _functionTypesToFix = null; | |
| 2703 _currentHolder.addType(element); | 2684 _currentHolder.addType(element); |
| 2704 className.staticElement = element; | 2685 className.staticElement = element; |
| 2705 holder.validate(); | 2686 holder.validate(); |
| 2706 return null; | 2687 return null; |
| 2707 } | 2688 } |
| 2708 | 2689 |
| 2709 @override | 2690 @override |
| 2710 Object visitConstructorDeclaration(ConstructorDeclaration node) { | 2691 Object visitConstructorDeclaration(ConstructorDeclaration node) { |
| 2711 _isValidMixin = false; | 2692 _isValidMixin = false; |
| 2712 ElementHolder holder = new ElementHolder(); | 2693 ElementHolder holder = new ElementHolder(); |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3031 element.generator = true; | 3012 element.generator = true; |
| 3032 } | 3013 } |
| 3033 if (_inFunction) { | 3014 if (_inFunction) { |
| 3034 Block enclosingBlock = node.getAncestor((node) => node is Block); | 3015 Block enclosingBlock = node.getAncestor((node) => node is Block); |
| 3035 if (enclosingBlock != null) { | 3016 if (enclosingBlock != null) { |
| 3036 int functionEnd = node.offset + node.length; | 3017 int functionEnd = node.offset + node.length; |
| 3037 int blockEnd = enclosingBlock.offset + enclosingBlock.length; | 3018 int blockEnd = enclosingBlock.offset + enclosingBlock.length; |
| 3038 element.setVisibleRange(functionEnd, blockEnd - functionEnd - 1); | 3019 element.setVisibleRange(functionEnd, blockEnd - functionEnd - 1); |
| 3039 } | 3020 } |
| 3040 } | 3021 } |
| 3041 FunctionTypeImpl type = new FunctionTypeImpl(element); | 3022 element.type = new FunctionTypeImpl(element); |
| 3042 if (_functionTypesToFix != null) { | |
| 3043 _functionTypesToFix.add(type); | |
| 3044 } | |
| 3045 element.type = type; | |
| 3046 element.hasImplicitReturnType = true; | 3023 element.hasImplicitReturnType = true; |
| 3047 _currentHolder.addFunction(element); | 3024 _currentHolder.addFunction(element); |
| 3048 node.element = element; | 3025 node.element = element; |
| 3049 holder.validate(); | 3026 holder.validate(); |
| 3050 return null; | 3027 return null; |
| 3051 } | 3028 } |
| 3052 | 3029 |
| 3053 @override | 3030 @override |
| 3054 Object visitFunctionTypeAlias(FunctionTypeAlias node) { | 3031 Object visitFunctionTypeAlias(FunctionTypeAlias node) { |
| 3055 ElementHolder holder = new ElementHolder(); | 3032 ElementHolder holder = new ElementHolder(); |
| 3056 _visitChildren(holder, node); | 3033 _visitChildren(holder, node); |
| 3057 SimpleIdentifier aliasName = node.name; | 3034 SimpleIdentifier aliasName = node.name; |
| 3058 List<ParameterElement> parameters = holder.parameters; | 3035 List<ParameterElement> parameters = holder.parameters; |
| 3059 List<TypeParameterElement> typeParameters = holder.typeParameters; | 3036 List<TypeParameterElement> typeParameters = holder.typeParameters; |
| 3060 FunctionTypeAliasElementImpl element = | 3037 FunctionTypeAliasElementImpl element = |
| 3061 new FunctionTypeAliasElementImpl.forNode(aliasName); | 3038 new FunctionTypeAliasElementImpl.forNode(aliasName); |
| 3062 _setDocRange(element, node); | 3039 _setDocRange(element, node); |
| 3063 element.parameters = parameters; | 3040 element.parameters = parameters; |
| 3064 element.typeParameters = typeParameters; | 3041 element.typeParameters = typeParameters; |
| 3065 FunctionTypeImpl type = new FunctionTypeImpl.forTypedef(element); | 3042 _createTypeParameterTypes(typeParameters); |
| 3066 type.typeArguments = _createTypeParameterTypes(typeParameters); | 3043 element.type = new FunctionTypeImpl.forTypedef(element); |
| 3067 element.type = type; | |
| 3068 _currentHolder.addTypeAlias(element); | 3044 _currentHolder.addTypeAlias(element); |
| 3069 aliasName.staticElement = element; | 3045 aliasName.staticElement = element; |
| 3070 holder.validate(); | 3046 holder.validate(); |
| 3071 return null; | 3047 return null; |
| 3072 } | 3048 } |
| 3073 | 3049 |
| 3074 @override | 3050 @override |
| 3075 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { | 3051 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { |
| 3076 if (node.parent is! DefaultFormalParameter) { | 3052 if (node.parent is! DefaultFormalParameter) { |
| 3077 SimpleIdentifier parameterName = node.identifier; | 3053 SimpleIdentifier parameterName = node.identifier; |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3444 * | 3420 * |
| 3445 * @param interfaceType the interface type for which to create a default const
ructor | 3421 * @param interfaceType the interface type for which to create a default const
ructor |
| 3446 * @return the [ConstructorElement]s array with the single default constructor
element | 3422 * @return the [ConstructorElement]s array with the single default constructor
element |
| 3447 */ | 3423 */ |
| 3448 List<ConstructorElement> _createDefaultConstructors( | 3424 List<ConstructorElement> _createDefaultConstructors( |
| 3449 InterfaceTypeImpl interfaceType) { | 3425 InterfaceTypeImpl interfaceType) { |
| 3450 ConstructorElementImpl constructor = | 3426 ConstructorElementImpl constructor = |
| 3451 new ConstructorElementImpl.forNode(null); | 3427 new ConstructorElementImpl.forNode(null); |
| 3452 constructor.synthetic = true; | 3428 constructor.synthetic = true; |
| 3453 constructor.returnType = interfaceType; | 3429 constructor.returnType = interfaceType; |
| 3454 FunctionTypeImpl type = new FunctionTypeImpl(constructor); | 3430 constructor.type = new FunctionTypeImpl(constructor); |
| 3455 _functionTypesToFix.add(type); | |
| 3456 constructor.type = type; | |
| 3457 return <ConstructorElement>[constructor]; | 3431 return <ConstructorElement>[constructor]; |
| 3458 } | 3432 } |
| 3459 | 3433 |
| 3460 /** | 3434 /** |
| 3461 * Create the types associated with the given type parameters, setting the typ
e of each type | 3435 * Create the types associated with the given type parameters, setting the typ
e of each type |
| 3462 * parameter, and return an array of types corresponding to the given paramete
rs. | 3436 * parameter, and return an array of types corresponding to the given paramete
rs. |
| 3463 * | 3437 * |
| 3464 * @param typeParameters the type parameters for which types are to be created | 3438 * @param typeParameters the type parameters for which types are to be created |
| 3465 * @return an array of types corresponding to the given parameters | 3439 * @return an array of types corresponding to the given parameters |
| 3466 */ | 3440 */ |
| (...skipping 10586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14053 buffer.write(classNode.name.name); | 14027 buffer.write(classNode.name.name); |
| 14054 } | 14028 } |
| 14055 buffer.write(" in "); | 14029 buffer.write(" in "); |
| 14056 buffer.write(source.fullName); | 14030 buffer.write(source.fullName); |
| 14057 buffer.write(" was not set while trying to resolve types."); | 14031 buffer.write(" was not set while trying to resolve types."); |
| 14058 AnalysisEngine.instance.logger.logError(buffer.toString(), | 14032 AnalysisEngine.instance.logger.logError(buffer.toString(), |
| 14059 new CaughtException(new AnalysisException(), null)); | 14033 new CaughtException(new AnalysisException(), null)); |
| 14060 } else { | 14034 } else { |
| 14061 ClassElement definingClass = element.enclosingElement as ClassElement; | 14035 ClassElement definingClass = element.enclosingElement as ClassElement; |
| 14062 element.returnType = definingClass.type; | 14036 element.returnType = definingClass.type; |
| 14063 FunctionTypeImpl type = new FunctionTypeImpl(element); | 14037 element.type = new FunctionTypeImpl(element); |
| 14064 type.typeArguments = definingClass.type.typeArguments; | |
| 14065 element.type = type; | |
| 14066 } | 14038 } |
| 14067 return null; | 14039 return null; |
| 14068 } | 14040 } |
| 14069 | 14041 |
| 14070 @override | 14042 @override |
| 14071 Object visitDeclaredIdentifier(DeclaredIdentifier node) { | 14043 Object visitDeclaredIdentifier(DeclaredIdentifier node) { |
| 14072 super.visitDeclaredIdentifier(node); | 14044 super.visitDeclaredIdentifier(node); |
| 14073 DartType declaredType; | 14045 DartType declaredType; |
| 14074 TypeName typeName = node.type; | 14046 TypeName typeName = node.type; |
| 14075 if (typeName == null) { | 14047 if (typeName == null) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14123 StringBuffer buffer = new StringBuffer(); | 14095 StringBuffer buffer = new StringBuffer(); |
| 14124 buffer.write("The element for the top-level function "); | 14096 buffer.write("The element for the top-level function "); |
| 14125 buffer.write(node.name); | 14097 buffer.write(node.name); |
| 14126 buffer.write(" in "); | 14098 buffer.write(" in "); |
| 14127 buffer.write(source.fullName); | 14099 buffer.write(source.fullName); |
| 14128 buffer.write(" was not set while trying to resolve types."); | 14100 buffer.write(" was not set while trying to resolve types."); |
| 14129 AnalysisEngine.instance.logger.logError(buffer.toString(), | 14101 AnalysisEngine.instance.logger.logError(buffer.toString(), |
| 14130 new CaughtException(new AnalysisException(), null)); | 14102 new CaughtException(new AnalysisException(), null)); |
| 14131 } | 14103 } |
| 14132 element.returnType = _computeReturnType(node.returnType); | 14104 element.returnType = _computeReturnType(node.returnType); |
| 14133 FunctionTypeImpl type = new FunctionTypeImpl(element); | 14105 element.type = new FunctionTypeImpl(element); |
| 14134 ClassElement definingClass = | |
| 14135 element.getAncestor((element) => element is ClassElement); | |
| 14136 if (definingClass != null) { | |
| 14137 type.typeArguments = definingClass.type.typeArguments; | |
| 14138 } | |
| 14139 element.type = type; | |
| 14140 return null; | 14106 return null; |
| 14141 } | 14107 } |
| 14142 | 14108 |
| 14143 @override | 14109 @override |
| 14144 Object visitFunctionTypeAlias(FunctionTypeAlias node) { | 14110 Object visitFunctionTypeAlias(FunctionTypeAlias node) { |
| 14145 FunctionTypeAliasElementImpl element = | 14111 FunctionTypeAliasElementImpl element = |
| 14146 node.element as FunctionTypeAliasElementImpl; | 14112 node.element as FunctionTypeAliasElementImpl; |
| 14147 super.visitFunctionTypeAlias(node); | 14113 super.visitFunctionTypeAlias(node); |
| 14148 element.returnType = _computeReturnType(node.returnType); | 14114 element.returnType = _computeReturnType(node.returnType); |
| 14149 return null; | 14115 return null; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 14177 } else { | 14143 } else { |
| 14178 buffer.write(classNode.name.name); | 14144 buffer.write(classNode.name.name); |
| 14179 } | 14145 } |
| 14180 buffer.write(" in "); | 14146 buffer.write(" in "); |
| 14181 buffer.write(source.fullName); | 14147 buffer.write(source.fullName); |
| 14182 buffer.write(" was not set while trying to resolve types."); | 14148 buffer.write(" was not set while trying to resolve types."); |
| 14183 AnalysisEngine.instance.logger.logError(buffer.toString(), | 14149 AnalysisEngine.instance.logger.logError(buffer.toString(), |
| 14184 new CaughtException(new AnalysisException(), null)); | 14150 new CaughtException(new AnalysisException(), null)); |
| 14185 } | 14151 } |
| 14186 element.returnType = _computeReturnType(node.returnType); | 14152 element.returnType = _computeReturnType(node.returnType); |
| 14187 FunctionTypeImpl type = new FunctionTypeImpl(element); | 14153 element.type = new FunctionTypeImpl(element); |
| 14188 ClassElement definingClass = | |
| 14189 element.getAncestor((element) => element is ClassElement); | |
| 14190 if (definingClass != null) { | |
| 14191 type.typeArguments = definingClass.type.typeArguments; | |
| 14192 } | |
| 14193 element.type = type; | |
| 14194 if (element is PropertyAccessorElement) { | 14154 if (element is PropertyAccessorElement) { |
| 14195 PropertyAccessorElement accessor = element as PropertyAccessorElement; | 14155 PropertyAccessorElement accessor = element as PropertyAccessorElement; |
| 14196 PropertyInducingElementImpl variable = | 14156 PropertyInducingElementImpl variable = |
| 14197 accessor.variable as PropertyInducingElementImpl; | 14157 accessor.variable as PropertyInducingElementImpl; |
| 14198 if (accessor.isGetter) { | 14158 if (accessor.isGetter) { |
| 14199 variable.type = type.baseReturnType; | 14159 variable.type = element.returnType; |
| 14200 } else if (variable.type == null) { | 14160 } else if (variable.type == null) { |
| 14201 List<ParameterElement> parameters = type.baseParameters; | 14161 List<ParameterElement> parameters = element.parameters; |
| 14202 if (parameters != null && parameters.length > 0) { | 14162 if (parameters != null && parameters.length > 0) { |
| 14203 variable.type = parameters[0].type; | 14163 variable.type = parameters[0].type; |
| 14204 } | 14164 } |
| 14205 } | 14165 } |
| 14206 } | 14166 } |
| 14207 return null; | 14167 return null; |
| 14208 } | 14168 } |
| 14209 | 14169 |
| 14210 @override | 14170 @override |
| 14211 Object visitSimpleFormalParameter(SimpleFormalParameter node) { | 14171 Object visitSimpleFormalParameter(SimpleFormalParameter node) { |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14532 declaredType = _getType(typeName); | 14492 declaredType = _getType(typeName); |
| 14533 } | 14493 } |
| 14534 Element element = node.name.staticElement; | 14494 Element element = node.name.staticElement; |
| 14535 if (element is VariableElement) { | 14495 if (element is VariableElement) { |
| 14536 (element as VariableElementImpl).type = declaredType; | 14496 (element as VariableElementImpl).type = declaredType; |
| 14537 if (element is PropertyInducingElement) { | 14497 if (element is PropertyInducingElement) { |
| 14538 PropertyInducingElement variableElement = element; | 14498 PropertyInducingElement variableElement = element; |
| 14539 PropertyAccessorElementImpl getter = | 14499 PropertyAccessorElementImpl getter = |
| 14540 variableElement.getter as PropertyAccessorElementImpl; | 14500 variableElement.getter as PropertyAccessorElementImpl; |
| 14541 getter.returnType = declaredType; | 14501 getter.returnType = declaredType; |
| 14542 FunctionTypeImpl getterType = new FunctionTypeImpl(getter); | 14502 getter.type = new FunctionTypeImpl(getter); |
| 14543 ClassElement definingClass = | |
| 14544 element.getAncestor((element) => element is ClassElement); | |
| 14545 if (definingClass != null) { | |
| 14546 getterType.typeArguments = definingClass.type.typeArguments; | |
| 14547 } | |
| 14548 getter.type = getterType; | |
| 14549 PropertyAccessorElementImpl setter = | 14503 PropertyAccessorElementImpl setter = |
| 14550 variableElement.setter as PropertyAccessorElementImpl; | 14504 variableElement.setter as PropertyAccessorElementImpl; |
| 14551 if (setter != null) { | 14505 if (setter != null) { |
| 14552 List<ParameterElement> parameters = setter.parameters; | 14506 List<ParameterElement> parameters = setter.parameters; |
| 14553 if (parameters.length > 0) { | 14507 if (parameters.length > 0) { |
| 14554 (parameters[0] as ParameterElementImpl).type = declaredType; | 14508 (parameters[0] as ParameterElementImpl).type = declaredType; |
| 14555 } | 14509 } |
| 14556 setter.returnType = VoidTypeImpl.instance; | 14510 setter.returnType = VoidTypeImpl.instance; |
| 14557 FunctionTypeImpl setterType = new FunctionTypeImpl(setter); | 14511 setter.type = new FunctionTypeImpl(setter); |
| 14558 if (definingClass != null) { | |
| 14559 setterType.typeArguments = definingClass.type.typeArguments; | |
| 14560 } | |
| 14561 setter.type = setterType; | |
| 14562 } | 14512 } |
| 14563 } | 14513 } |
| 14564 } else { | 14514 } else { |
| 14565 // TODO(brianwilkerson) Report the internal error. | 14515 // TODO(brianwilkerson) Report the internal error. |
| 14566 } | 14516 } |
| 14567 return null; | 14517 return null; |
| 14568 } | 14518 } |
| 14569 | 14519 |
| 14570 /** | 14520 /** |
| 14571 * Given a type name representing the return type of a function, compute the r
eturn type of the | 14521 * Given a type name representing the return type of a function, compute the r
eturn type of the |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14972 new FunctionTypeAliasElementImpl.forNode(null); | 14922 new FunctionTypeAliasElementImpl.forNode(null); |
| 14973 aliasElement.synthetic = true; | 14923 aliasElement.synthetic = true; |
| 14974 aliasElement.shareParameters(parameters); | 14924 aliasElement.shareParameters(parameters); |
| 14975 aliasElement.returnType = _computeReturnType(returnType); | 14925 aliasElement.returnType = _computeReturnType(returnType); |
| 14976 // FunctionTypeAliasElementImpl assumes the enclosing element is a | 14926 // FunctionTypeAliasElementImpl assumes the enclosing element is a |
| 14977 // CompilationUnitElement (because non-synthetic function types can only be | 14927 // CompilationUnitElement (because non-synthetic function types can only be |
| 14978 // declared at top level), so to avoid breaking things, go find the | 14928 // declared at top level), so to avoid breaking things, go find the |
| 14979 // compilation unit element. | 14929 // compilation unit element. |
| 14980 aliasElement.enclosingElement = | 14930 aliasElement.enclosingElement = |
| 14981 element.getAncestor((element) => element is CompilationUnitElement); | 14931 element.getAncestor((element) => element is CompilationUnitElement); |
| 14982 FunctionTypeImpl type = new FunctionTypeImpl.forTypedef(aliasElement); | |
| 14983 ClassElement definingClass = | 14932 ClassElement definingClass = |
| 14984 element.getAncestor((element) => element is ClassElement); | 14933 element.getAncestor((element) => element is ClassElement); |
| 14985 if (definingClass != null) { | 14934 if (definingClass != null) { |
| 14986 aliasElement.shareTypeParameters(definingClass.typeParameters); | 14935 aliasElement.shareTypeParameters(definingClass.typeParameters); |
| 14987 type.typeArguments = definingClass.type.typeArguments; | |
| 14988 } else { | 14936 } else { |
| 14989 FunctionTypeAliasElement alias = | 14937 FunctionTypeAliasElement alias = |
| 14990 element.getAncestor((element) => element is FunctionTypeAliasElement); | 14938 element.getAncestor((element) => element is FunctionTypeAliasElement); |
| 14991 while (alias != null && alias.isSynthetic) { | 14939 while (alias != null && alias.isSynthetic) { |
| 14992 alias = | 14940 alias = |
| 14993 alias.getAncestor((element) => element is FunctionTypeAliasElement); | 14941 alias.getAncestor((element) => element is FunctionTypeAliasElement); |
| 14994 } | 14942 } |
| 14995 if (alias != null) { | 14943 if (alias != null) { |
| 14996 aliasElement.typeParameters = alias.typeParameters; | 14944 aliasElement.typeParameters = alias.typeParameters; |
| 14997 type.typeArguments = alias.type.typeArguments; | |
| 14998 } else { | |
| 14999 type.typeArguments = DartType.EMPTY_LIST; | |
| 15000 } | 14945 } |
| 15001 } | 14946 } |
| 15002 element.type = type; | 14947 element.type = new FunctionTypeImpl.forTypedef(aliasElement); |
| 15003 } | 14948 } |
| 15004 | 14949 |
| 15005 /** | 14950 /** |
| 15006 * @return `true` if the name of the given [TypeName] is an built-in identifie
r. | 14951 * @return `true` if the name of the given [TypeName] is an built-in identifie
r. |
| 15007 */ | 14952 */ |
| 15008 static bool _isBuiltInIdentifier(TypeName node) { | 14953 static bool _isBuiltInIdentifier(TypeName node) { |
| 15009 sc.Token token = node.name.beginToken; | 14954 sc.Token token = node.name.beginToken; |
| 15010 return token.type == sc.TokenType.KEYWORD; | 14955 return token.type == sc.TokenType.KEYWORD; |
| 15011 } | 14956 } |
| 15012 | 14957 |
| (...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15604 nonFields.add(node); | 15549 nonFields.add(node); |
| 15605 return null; | 15550 return null; |
| 15606 } | 15551 } |
| 15607 | 15552 |
| 15608 @override | 15553 @override |
| 15609 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); | 15554 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); |
| 15610 | 15555 |
| 15611 @override | 15556 @override |
| 15612 Object visitWithClause(WithClause node) => null; | 15557 Object visitWithClause(WithClause node) => null; |
| 15613 } | 15558 } |
| OLD | NEW |