| 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.generated.resolver; | 5 library analyzer.src.generated.resolver; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
| 10 import 'package:analyzer/dart/element/type.dart'; | 10 import 'package:analyzer/dart/element/type.dart'; |
| (...skipping 3026 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3037 setter.parameters = holder.parameters; | 3037 setter.parameters = holder.parameters; |
| 3038 if (body.isAsynchronous) { | 3038 if (body.isAsynchronous) { |
| 3039 setter.asynchronous = true; | 3039 setter.asynchronous = true; |
| 3040 } | 3040 } |
| 3041 if (body.isGenerator) { | 3041 if (body.isGenerator) { |
| 3042 setter.generator = true; | 3042 setter.generator = true; |
| 3043 } | 3043 } |
| 3044 setter.variable = variable; | 3044 setter.variable = variable; |
| 3045 setter.setter = true; | 3045 setter.setter = true; |
| 3046 setter.static = true; | 3046 setter.static = true; |
| 3047 if (node.returnType == null) { |
| 3048 setter.hasImplicitReturnType = true; |
| 3049 } |
| 3047 variable.setter = setter; | 3050 variable.setter = setter; |
| 3048 variable.final2 = false; | 3051 variable.final2 = false; |
| 3049 _currentHolder.addAccessor(setter); | 3052 _currentHolder.addAccessor(setter); |
| 3050 expression.element = setter; | 3053 expression.element = setter; |
| 3051 propertyNameNode.staticElement = setter; | 3054 propertyNameNode.staticElement = setter; |
| 3052 } | 3055 } |
| 3053 } | 3056 } |
| 3054 holder.validate(); | 3057 holder.validate(); |
| 3055 } | 3058 } |
| 3056 return null; | 3059 return null; |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3263 if (body.isAsynchronous) { | 3266 if (body.isAsynchronous) { |
| 3264 setter.asynchronous = true; | 3267 setter.asynchronous = true; |
| 3265 } | 3268 } |
| 3266 if (body.isGenerator) { | 3269 if (body.isGenerator) { |
| 3267 setter.generator = true; | 3270 setter.generator = true; |
| 3268 } | 3271 } |
| 3269 setter.variable = field; | 3272 setter.variable = field; |
| 3270 setter.abstract = node.isAbstract; | 3273 setter.abstract = node.isAbstract; |
| 3271 setter.setter = true; | 3274 setter.setter = true; |
| 3272 setter.static = isStatic; | 3275 setter.static = isStatic; |
| 3276 if (node.returnType == null) { |
| 3277 setter.hasImplicitReturnType = true; |
| 3278 } |
| 3273 field.setter = setter; | 3279 field.setter = setter; |
| 3274 field.final2 = false; | 3280 field.final2 = false; |
| 3275 _currentHolder.addAccessor(setter); | 3281 _currentHolder.addAccessor(setter); |
| 3276 propertyNameNode.staticElement = setter; | 3282 propertyNameNode.staticElement = setter; |
| 3277 } | 3283 } |
| 3278 } | 3284 } |
| 3279 holder.validate(); | 3285 holder.validate(); |
| 3280 } catch (exception, stackTrace) { | 3286 } catch (exception, stackTrace) { |
| 3281 if (node.name.staticElement == null) { | 3287 if (node.name.staticElement == null) { |
| 3282 ClassDeclaration classNode = | 3288 ClassDeclaration classNode = |
| (...skipping 8468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11751 * The type representing typenames that can't be resolved. | 11757 * The type representing typenames that can't be resolved. |
| 11752 */ | 11758 */ |
| 11753 DartType _undefinedType; | 11759 DartType _undefinedType; |
| 11754 | 11760 |
| 11755 /** | 11761 /** |
| 11756 * The flag specifying if currently visited class references 'super' expressio
n. | 11762 * The flag specifying if currently visited class references 'super' expressio
n. |
| 11757 */ | 11763 */ |
| 11758 bool _hasReferenceToSuper = false; | 11764 bool _hasReferenceToSuper = false; |
| 11759 | 11765 |
| 11760 /** | 11766 /** |
| 11767 * True if we're analyzing in strong mode. |
| 11768 */ |
| 11769 bool _strongMode; |
| 11770 |
| 11771 /** |
| 11761 * Initialize a newly created visitor to resolve the nodes in an AST node. | 11772 * Initialize a newly created visitor to resolve the nodes in an AST node. |
| 11762 * | 11773 * |
| 11763 * [definingLibrary] is the element for the library containing the node being | 11774 * [definingLibrary] is the element for the library containing the node being |
| 11764 * visited. | 11775 * visited. |
| 11765 * [source] is the source representing the compilation unit containing the | 11776 * [source] is the source representing the compilation unit containing the |
| 11766 * node being visited. | 11777 * node being visited. |
| 11767 * [typeProvider] is the object used to access the types from the core | 11778 * [typeProvider] is the object used to access the types from the core |
| 11768 * library. | 11779 * library. |
| 11769 * [errorListener] is the error listener that will be informed of any errors | 11780 * [errorListener] is the error listener that will be informed of any errors |
| 11770 * that are found during resolution. | 11781 * that are found during resolution. |
| 11771 * [nameScope] is the scope used to resolve identifiers in the node that will | 11782 * [nameScope] is the scope used to resolve identifiers in the node that will |
| 11772 * first be visited. If `null` or unspecified, a new [LibraryScope] will be | 11783 * first be visited. If `null` or unspecified, a new [LibraryScope] will be |
| 11773 * created based on [definingLibrary] and [typeProvider]. | 11784 * created based on [definingLibrary] and [typeProvider]. |
| 11774 */ | 11785 */ |
| 11775 TypeResolverVisitor(LibraryElement definingLibrary, Source source, | 11786 TypeResolverVisitor(LibraryElement definingLibrary, Source source, |
| 11776 TypeProvider typeProvider, AnalysisErrorListener errorListener, | 11787 TypeProvider typeProvider, AnalysisErrorListener errorListener, |
| 11777 {Scope nameScope}) | 11788 {Scope nameScope}) |
| 11778 : super(definingLibrary, source, typeProvider, errorListener, | 11789 : super(definingLibrary, source, typeProvider, errorListener, |
| 11779 nameScope: nameScope) { | 11790 nameScope: nameScope) { |
| 11780 _dynamicType = typeProvider.dynamicType; | 11791 _dynamicType = typeProvider.dynamicType; |
| 11781 _undefinedType = typeProvider.undefinedType; | 11792 _undefinedType = typeProvider.undefinedType; |
| 11793 _strongMode = definingLibrary.context.analysisOptions.strongMode; |
| 11782 } | 11794 } |
| 11783 | 11795 |
| 11784 @override | 11796 @override |
| 11785 Object visitAnnotation(Annotation node) { | 11797 Object visitAnnotation(Annotation node) { |
| 11786 // | 11798 // |
| 11787 // Visit annotations, if the annotation is @proxy, on a class, and "proxy" | 11799 // Visit annotations, if the annotation is @proxy, on a class, and "proxy" |
| 11788 // resolves to the proxy annotation in dart.core, then create create the | 11800 // resolves to the proxy annotation in dart.core, then create create the |
| 11789 // ElementAnnotationImpl and set it as the metadata on the enclosing class. | 11801 // ElementAnnotationImpl and set it as the metadata on the enclosing class. |
| 11790 // | 11802 // |
| 11791 // Element resolution is done in the ElementResolver, and this work will be | 11803 // Element resolution is done in the ElementResolver, and this work will be |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12012 buffer.write("The element for the top-level function "); | 12024 buffer.write("The element for the top-level function "); |
| 12013 buffer.write(node.name); | 12025 buffer.write(node.name); |
| 12014 buffer.write(" in "); | 12026 buffer.write(" in "); |
| 12015 buffer.write(source.fullName); | 12027 buffer.write(source.fullName); |
| 12016 buffer.write(" was not set while trying to resolve types."); | 12028 buffer.write(" was not set while trying to resolve types."); |
| 12017 AnalysisEngine.instance.logger.logError(buffer.toString(), | 12029 AnalysisEngine.instance.logger.logError(buffer.toString(), |
| 12018 new CaughtException(new AnalysisException(), null)); | 12030 new CaughtException(new AnalysisException(), null)); |
| 12019 } | 12031 } |
| 12020 element.returnType = _computeReturnType(node.returnType); | 12032 element.returnType = _computeReturnType(node.returnType); |
| 12021 element.type = new FunctionTypeImpl(element); | 12033 element.type = new FunctionTypeImpl(element); |
| 12034 _inferSetterReturnType(element); |
| 12022 return null; | 12035 return null; |
| 12023 } | 12036 } |
| 12024 | 12037 |
| 12025 @override | 12038 @override |
| 12026 Object visitFunctionTypeAlias(FunctionTypeAlias node) { | 12039 Object visitFunctionTypeAlias(FunctionTypeAlias node) { |
| 12027 FunctionTypeAliasElementImpl element = | 12040 FunctionTypeAliasElementImpl element = |
| 12028 node.element as FunctionTypeAliasElementImpl; | 12041 node.element as FunctionTypeAliasElementImpl; |
| 12029 super.visitFunctionTypeAlias(node); | 12042 super.visitFunctionTypeAlias(node); |
| 12030 element.returnType = _computeReturnType(node.returnType); | 12043 element.returnType = _computeReturnType(node.returnType); |
| 12031 return null; | 12044 return null; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 12060 buffer.write(classNode.name.name); | 12073 buffer.write(classNode.name.name); |
| 12061 } | 12074 } |
| 12062 buffer.write(" in "); | 12075 buffer.write(" in "); |
| 12063 buffer.write(source.fullName); | 12076 buffer.write(source.fullName); |
| 12064 buffer.write(" was not set while trying to resolve types."); | 12077 buffer.write(" was not set while trying to resolve types."); |
| 12065 AnalysisEngine.instance.logger.logError(buffer.toString(), | 12078 AnalysisEngine.instance.logger.logError(buffer.toString(), |
| 12066 new CaughtException(new AnalysisException(), null)); | 12079 new CaughtException(new AnalysisException(), null)); |
| 12067 } | 12080 } |
| 12068 element.returnType = _computeReturnType(node.returnType); | 12081 element.returnType = _computeReturnType(node.returnType); |
| 12069 element.type = new FunctionTypeImpl(element); | 12082 element.type = new FunctionTypeImpl(element); |
| 12083 _inferSetterReturnType(element); |
| 12070 if (element is PropertyAccessorElement) { | 12084 if (element is PropertyAccessorElement) { |
| 12071 PropertyAccessorElement accessor = element as PropertyAccessorElement; | 12085 PropertyAccessorElement accessor = element as PropertyAccessorElement; |
| 12072 PropertyInducingElementImpl variable = | 12086 PropertyInducingElementImpl variable = |
| 12073 accessor.variable as PropertyInducingElementImpl; | 12087 accessor.variable as PropertyInducingElementImpl; |
| 12074 if (accessor.isGetter) { | 12088 if (accessor.isGetter) { |
| 12075 variable.type = element.returnType; | 12089 variable.type = element.returnType; |
| 12076 } else if (variable.type == null) { | 12090 } else if (variable.type == null) { |
| 12077 List<ParameterElement> parameters = element.parameters; | 12091 List<ParameterElement> parameters = element.parameters; |
| 12078 if (parameters != null && parameters.length > 0) { | 12092 if (parameters != null && parameters.length > 0) { |
| 12079 variable.type = parameters[0].type; | 12093 variable.type = parameters[0].type; |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12588 if (element is ClassElement) { | 12602 if (element is ClassElement) { |
| 12589 if (type != null) { | 12603 if (type != null) { |
| 12590 return null; | 12604 return null; |
| 12591 } | 12605 } |
| 12592 type = element.type; | 12606 type = element.type; |
| 12593 } | 12607 } |
| 12594 } | 12608 } |
| 12595 return type; | 12609 return type; |
| 12596 } | 12610 } |
| 12597 | 12611 |
| 12612 /** |
| 12613 * In strong mode we infer "void" as the setter return type (as void is the |
| 12614 * only legal return type for a setter). This allows us to give better |
| 12615 * errors later if an invalid type is returned. |
| 12616 */ |
| 12617 void _inferSetterReturnType(ExecutableElementImpl element) { |
| 12618 if (_strongMode && |
| 12619 element is PropertyAccessorElementImpl && |
| 12620 element.isSetter && |
| 12621 element.hasImplicitReturnType) { |
| 12622 element.returnType = VoidTypeImpl.instance; |
| 12623 } |
| 12624 } |
| 12625 |
| 12598 DartType _instantiateType(DartType type, List<DartType> typeArguments) { | 12626 DartType _instantiateType(DartType type, List<DartType> typeArguments) { |
| 12599 if (type is InterfaceTypeImpl) { | 12627 if (type is InterfaceTypeImpl) { |
| 12600 return type.substitute4(typeArguments); | 12628 return type.substitute4(typeArguments); |
| 12601 } else if (type is FunctionTypeImpl) { | 12629 } else if (type is FunctionTypeImpl) { |
| 12602 return type.instantiate(typeArguments); | 12630 return type.instantiate(typeArguments); |
| 12603 } else { | 12631 } else { |
| 12604 // TODO(brianwilkerson) Report this internal error. | 12632 // TODO(brianwilkerson) Report this internal error. |
| 12605 return type; | 12633 return type; |
| 12606 } | 12634 } |
| 12607 } | 12635 } |
| (...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13431 nonFields.add(node); | 13459 nonFields.add(node); |
| 13432 return null; | 13460 return null; |
| 13433 } | 13461 } |
| 13434 | 13462 |
| 13435 @override | 13463 @override |
| 13436 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); | 13464 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); |
| 13437 | 13465 |
| 13438 @override | 13466 @override |
| 13439 Object visitWithClause(WithClause node) => null; | 13467 Object visitWithClause(WithClause node) => null; |
| 13440 } | 13468 } |
| OLD | NEW |