Chromium Code Reviews| Index: pkg/analyzer/lib/src/generated/resolver.dart |
| diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart |
| index 510acdd29e1125ef219be82413ba26e780709856..621b85c1265e50a7366ad69d73a691755eb4ed44 100644 |
| --- a/pkg/analyzer/lib/src/generated/resolver.dart |
| +++ b/pkg/analyzer/lib/src/generated/resolver.dart |
| @@ -4903,6 +4903,101 @@ class INIT_STATE extends Enum<INIT_STATE> { |
| } |
| /** |
| + * An AST visitor that is used to re-resolve the initializers of instance |
| + * fields. Although this class is an AST visitor, clients are expected to use |
| + * the method [resolveCompilationUnit] to run it over a compilation unit. |
| + */ |
| +class InstanceFieldResolverVisitor extends ResolverVisitor { |
| + /** |
| + * Initialize a newly created visitor to resolve the nodes in an AST node. |
| + * |
| + * The [definingLibrary] is the element for the library containing the node |
| + * being visited. The [source] is the source representing the compilation unit |
| + * containing the node being visited. The [typeProvider] is the object used to |
| + * access the types from the core library. The [errorListener] is the error |
| + * listener that will be informed of any errors that are found during |
| + * resolution. The [nameScope] is the scope used to resolve identifiers in the |
| + * node that will first be visited. If `null` or unspecified, a new |
| + * [LibraryScope] will be created based on [definingLibrary] and |
| + * [typeProvider]. The [inheritanceManager] is used to perform inheritance |
|
scheglov
2016/04/25 20:45:55
1. AFAIK LibraryScope does not need TypeProvider.
Brian Wilkerson
2016/04/25 21:08:58
Done. The comment was copied from elsewhere and I
|
| + * lookups. If `null` or unspecified, a new [InheritanceManager] will be |
| + * created based on [definingLibrary]. The [typeAnalyzerFactory] is used to |
| + * create the type analyzer. If `null` or unspecified, a type analyzer of |
| + * type [StaticTypeAnalyzer] will be created. |
| + */ |
| + InstanceFieldResolverVisitor(LibraryElement definingLibrary, Source source, |
| + TypeProvider typeProvider, AnalysisErrorListener errorListener, |
| + {Scope nameScope}) |
| + : super(definingLibrary, source, typeProvider, errorListener, |
| + nameScope: nameScope); |
| + |
| + /** |
| + * Resolve the instance fields in the given compilation unit [node]. |
| + */ |
| + void resolveCompilationUnit(CompilationUnit node) { |
| + _overrideManager.enterScope(); |
| + try { |
| + NodeList<CompilationUnitMember> declarations = node.declarations; |
| + int declarationCount = declarations.length; |
| + for (int i = 0; i < declarationCount; i++) { |
| + CompilationUnitMember declaration = declarations[i]; |
| + if (declaration is ClassDeclaration) { |
| + _resolveClassDeclaration(declaration); |
| + } |
| + } |
| + } finally { |
| + _overrideManager.exitScope(); |
| + } |
| + } |
| + |
| + /** |
| + * Resolve the instance fields in the given class declaration [node]. |
| + */ |
| + void _resolveClassDeclaration(ClassDeclaration node) { |
| + _enclosingClassDeclaration = node; |
| + ClassElement outerType = enclosingClass; |
| + Scope outerScope = nameScope; |
| + try { |
| + enclosingClass = node.element; |
| + typeAnalyzer.thisType = enclosingClass?.type; |
| + if (enclosingClass == null) { |
| + AnalysisEngine.instance.logger.logInformation( |
| + "Missing element for class declaration ${node.name.name} in ${definingLibrary.source.fullName}", |
| + new CaughtException(new AnalysisException(), null)); |
| + // Don't try to re-resolve the initializers if we cannot set up the |
| + // right name scope for resolution. |
| + } else { |
| + nameScope = new ClassScope(nameScope, enclosingClass); |
| + NodeList<ClassMember> members = node.members; |
| + for (int i = 0; i < members.length; i++) { |
|
scheglov
2016/04/25 20:45:55
Do we want to extract members.length as we do for
Brian Wilkerson
2016/04/25 21:08:58
Done
|
| + ClassMember member = members[i]; |
| + if (member is FieldDeclaration) { |
| + _resolveFieldDeclaration(member); |
| + } |
| + } |
| + } |
| + } finally { |
| + nameScope = outerScope; |
| + typeAnalyzer.thisType = outerType?.type; |
| + enclosingClass = outerType; |
| + _enclosingClassDeclaration = null; |
| + } |
| + } |
| + |
| + /** |
| + * Resolve the instance fields in the given field declaration [node]. |
| + */ |
| + void _resolveFieldDeclaration(FieldDeclaration node) { |
| + for (VariableDeclaration field in node.fields.variables) { |
|
scheglov
2016/04/25 20:45:55
Do we need to check that it is an instance (not st
Brian Wilkerson
2016/04/25 21:08:58
Done
|
| + Expression initializer = field.initializer; |
| + if (initializer != null) { |
| + initializer.accept(this); |
|
scheglov
2016/04/25 20:45:55
field.initializer?.accept(this) maybe?
Brian Wilkerson
2016/04/25 21:08:58
Done
|
| + } |
| + } |
| + } |
| +} |
| + |
| +/** |
| * Instances of the class `OverrideVerifier` visit all of the declarations in a compilation |
| * unit to verify that if they have an override annotation it is being used correctly. |
| */ |