| 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/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/ast/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
| (...skipping 6330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6341 } | 6341 } |
| 6342 ConstructorElementImpl constructor = node.element; | 6342 ConstructorElementImpl constructor = node.element; |
| 6343 constructor.constantInitializers = | 6343 constructor.constantInitializers = |
| 6344 new ConstantAstCloner().cloneNodeList(node.initializers); | 6344 new ConstantAstCloner().cloneNodeList(node.initializers); |
| 6345 return null; | 6345 return null; |
| 6346 } | 6346 } |
| 6347 | 6347 |
| 6348 @override | 6348 @override |
| 6349 void visitConstructorDeclarationInScope(ConstructorDeclaration node) { | 6349 void visitConstructorDeclarationInScope(ConstructorDeclaration node) { |
| 6350 super.visitConstructorDeclarationInScope(node); | 6350 super.visitConstructorDeclarationInScope(node); |
| 6351 // Because of needing a different scope for the initializer list, the |
| 6352 // overridden implementation of this method cannot cause the visitNode |
| 6353 // method to be invoked. As a result, we have to hard-code using the |
| 6354 // element resolver and type analyzer to visit the constructor declaration. |
| 6355 node.accept(elementResolver); |
| 6356 node.accept(typeAnalyzer); |
| 6351 safelyVisitComment(node.documentationComment); | 6357 safelyVisitComment(node.documentationComment); |
| 6352 } | 6358 } |
| 6353 | 6359 |
| 6354 @override | 6360 @override |
| 6355 Object visitConstructorFieldInitializer(ConstructorFieldInitializer node) { | 6361 Object visitConstructorFieldInitializer(ConstructorFieldInitializer node) { |
| 6356 // | 6362 // |
| 6357 // We visit the expression, but do not visit the field name because it needs | 6363 // We visit the expression, but do not visit the field name because it needs |
| 6358 // to be visited in the context of the constructor field initializer node. | 6364 // to be visited in the context of the constructor field initializer node. |
| 6359 // | 6365 // |
| 6360 FieldElement fieldElement = enclosingClass.getField(node.fieldName.name); | 6366 FieldElement fieldElement = enclosingClass.getField(node.fieldName.name); |
| (...skipping 1376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7737 */ | 7743 */ |
| 7738 ImplicitLabelScope _implicitLabelScope = ImplicitLabelScope.ROOT; | 7744 ImplicitLabelScope _implicitLabelScope = ImplicitLabelScope.ROOT; |
| 7739 | 7745 |
| 7740 /** | 7746 /** |
| 7741 * The scope used to resolve labels for `break` and `continue` statements, or | 7747 * The scope used to resolve labels for `break` and `continue` statements, or |
| 7742 * `null` if no labels have been defined in the current context. | 7748 * `null` if no labels have been defined in the current context. |
| 7743 */ | 7749 */ |
| 7744 LabelScope labelScope; | 7750 LabelScope labelScope; |
| 7745 | 7751 |
| 7746 /** | 7752 /** |
| 7753 * A flag indicating whether to enable support for allowing access to field |
| 7754 * formal parameters in a constructor's initializer list. |
| 7755 */ |
| 7756 bool enableInitializingFormalAccess = false; |
| 7757 |
| 7758 /** |
| 7747 * The class containing the AST nodes being visited, | 7759 * The class containing the AST nodes being visited, |
| 7748 * or `null` if we are not in the scope of a class. | 7760 * or `null` if we are not in the scope of a class. |
| 7749 */ | 7761 */ |
| 7750 ClassElement enclosingClass; | 7762 ClassElement enclosingClass; |
| 7751 | 7763 |
| 7752 /** | 7764 /** |
| 7753 * Initialize a newly created visitor to resolve the nodes in a compilation | 7765 * Initialize a newly created visitor to resolve the nodes in a compilation |
| 7754 * unit. | 7766 * unit. |
| 7755 * | 7767 * |
| 7756 * [definingLibrary] is the element for the library containing the | 7768 * [definingLibrary] is the element for the library containing the |
| (...skipping 10 matching lines...) Expand all Loading... |
| 7767 ScopedVisitor(this.definingLibrary, Source source, this.typeProvider, | 7779 ScopedVisitor(this.definingLibrary, Source source, this.typeProvider, |
| 7768 AnalysisErrorListener errorListener, | 7780 AnalysisErrorListener errorListener, |
| 7769 {Scope nameScope}) | 7781 {Scope nameScope}) |
| 7770 : source = source, | 7782 : source = source, |
| 7771 errorReporter = new ErrorReporter(errorListener, source) { | 7783 errorReporter = new ErrorReporter(errorListener, source) { |
| 7772 if (nameScope == null) { | 7784 if (nameScope == null) { |
| 7773 this.nameScope = new LibraryScope(definingLibrary); | 7785 this.nameScope = new LibraryScope(definingLibrary); |
| 7774 } else { | 7786 } else { |
| 7775 this.nameScope = nameScope; | 7787 this.nameScope = nameScope; |
| 7776 } | 7788 } |
| 7789 enableInitializingFormalAccess = |
| 7790 definingLibrary.context.analysisOptions.enableInitializingFormalAccess; |
| 7777 } | 7791 } |
| 7778 | 7792 |
| 7779 /** | 7793 /** |
| 7780 * Return the implicit label scope in which the current node is being | 7794 * Return the implicit label scope in which the current node is being |
| 7781 * resolved. | 7795 * resolved. |
| 7782 */ | 7796 */ |
| 7783 ImplicitLabelScope get implicitLabelScope => _implicitLabelScope; | 7797 ImplicitLabelScope get implicitLabelScope => _implicitLabelScope; |
| 7784 | 7798 |
| 7785 /** | 7799 /** |
| 7786 * Replaces the current [Scope] with the enclosing [Scope]. | 7800 * Replaces the current [Scope] with the enclosing [Scope]. |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7903 super.visitClassTypeAlias(node); | 7917 super.visitClassTypeAlias(node); |
| 7904 } finally { | 7918 } finally { |
| 7905 nameScope = outerScope; | 7919 nameScope = outerScope; |
| 7906 } | 7920 } |
| 7907 return null; | 7921 return null; |
| 7908 } | 7922 } |
| 7909 | 7923 |
| 7910 @override | 7924 @override |
| 7911 Object visitConstructorDeclaration(ConstructorDeclaration node) { | 7925 Object visitConstructorDeclaration(ConstructorDeclaration node) { |
| 7912 ConstructorElement constructorElement = node.element; | 7926 ConstructorElement constructorElement = node.element; |
| 7927 if (constructorElement == null) { |
| 7928 StringBuffer buffer = new StringBuffer(); |
| 7929 buffer.write("Missing element for constructor "); |
| 7930 buffer.write(node.returnType.name); |
| 7931 if (node.name != null) { |
| 7932 buffer.write("."); |
| 7933 buffer.write(node.name.name); |
| 7934 } |
| 7935 buffer.write(" in "); |
| 7936 buffer.write(definingLibrary.source.fullName); |
| 7937 AnalysisEngine.instance.logger.logInformation(buffer.toString(), |
| 7938 new CaughtException(new AnalysisException(), null)); |
| 7939 } |
| 7913 Scope outerScope = nameScope; | 7940 Scope outerScope = nameScope; |
| 7914 try { | 7941 try { |
| 7915 if (constructorElement == null) { | 7942 if (constructorElement != null) { |
| 7916 StringBuffer buffer = new StringBuffer(); | |
| 7917 buffer.write("Missing element for constructor "); | |
| 7918 buffer.write(node.returnType.name); | |
| 7919 if (node.name != null) { | |
| 7920 buffer.write("."); | |
| 7921 buffer.write(node.name.name); | |
| 7922 } | |
| 7923 buffer.write(" in "); | |
| 7924 buffer.write(definingLibrary.source.fullName); | |
| 7925 AnalysisEngine.instance.logger.logInformation(buffer.toString(), | |
| 7926 new CaughtException(new AnalysisException(), null)); | |
| 7927 } else { | |
| 7928 nameScope = new FunctionScope(nameScope, constructorElement); | 7943 nameScope = new FunctionScope(nameScope, constructorElement); |
| 7929 } | 7944 } |
| 7945 node.documentationComment?.accept(this); |
| 7946 node.metadata.accept(this); |
| 7947 node.returnType?.accept(this); |
| 7948 node.name?.accept(this); |
| 7949 node.parameters?.accept(this); |
| 7950 Scope functionScope = nameScope; |
| 7951 try { |
| 7952 if (constructorElement != null && enableInitializingFormalAccess) { |
| 7953 nameScope = |
| 7954 new ConstructorInitializerScope(nameScope, constructorElement); |
| 7955 } |
| 7956 node.initializers.accept(this); |
| 7957 } finally { |
| 7958 nameScope = functionScope; |
| 7959 } |
| 7960 node.redirectedConstructor?.accept(this); |
| 7930 visitConstructorDeclarationInScope(node); | 7961 visitConstructorDeclarationInScope(node); |
| 7931 } finally { | 7962 } finally { |
| 7932 nameScope = outerScope; | 7963 nameScope = outerScope; |
| 7933 } | 7964 } |
| 7934 return null; | 7965 return null; |
| 7935 } | 7966 } |
| 7936 | 7967 |
| 7937 void visitConstructorDeclarationInScope(ConstructorDeclaration node) { | 7968 void visitConstructorDeclarationInScope(ConstructorDeclaration node) { |
| 7938 super.visitConstructorDeclaration(node); | 7969 node.body?.accept(this); |
| 7939 } | 7970 } |
| 7940 | 7971 |
| 7941 @override | 7972 @override |
| 7942 Object visitDeclaredIdentifier(DeclaredIdentifier node) { | 7973 Object visitDeclaredIdentifier(DeclaredIdentifier node) { |
| 7943 VariableElement element = node.element; | 7974 VariableElement element = node.element; |
| 7944 if (element != null) { | 7975 if (element != null) { |
| 7945 nameScope.define(element); | 7976 nameScope.define(element); |
| 7946 } | 7977 } |
| 7947 super.visitDeclaredIdentifier(node); | 7978 super.visitDeclaredIdentifier(node); |
| 7948 return null; | 7979 return null; |
| (...skipping 3209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11158 return null; | 11189 return null; |
| 11159 } | 11190 } |
| 11160 if (identical(node.staticElement, variable)) { | 11191 if (identical(node.staticElement, variable)) { |
| 11161 if (node.inSetterContext()) { | 11192 if (node.inSetterContext()) { |
| 11162 result = true; | 11193 result = true; |
| 11163 } | 11194 } |
| 11164 } | 11195 } |
| 11165 return null; | 11196 return null; |
| 11166 } | 11197 } |
| 11167 } | 11198 } |
| OLD | NEW |