Chromium Code Reviews| 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 4885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4896 NOT_INIT, | 4896 NOT_INIT, |
| 4897 INIT_IN_DECLARATION, | 4897 INIT_IN_DECLARATION, |
| 4898 INIT_IN_FIELD_FORMAL, | 4898 INIT_IN_FIELD_FORMAL, |
| 4899 INIT_IN_INITIALIZERS | 4899 INIT_IN_INITIALIZERS |
| 4900 ]; | 4900 ]; |
| 4901 | 4901 |
| 4902 const INIT_STATE(String name, int ordinal) : super(name, ordinal); | 4902 const INIT_STATE(String name, int ordinal) : super(name, ordinal); |
| 4903 } | 4903 } |
| 4904 | 4904 |
| 4905 /** | 4905 /** |
| 4906 * An AST visitor that is used to re-resolve the initializers of instance | |
| 4907 * fields. Although this class is an AST visitor, clients are expected to use | |
| 4908 * the method [resolveCompilationUnit] to run it over a compilation unit. | |
| 4909 */ | |
| 4910 class InstanceFieldResolverVisitor extends ResolverVisitor { | |
| 4911 /** | |
| 4912 * Initialize a newly created visitor to resolve the nodes in an AST node. | |
| 4913 * | |
| 4914 * The [definingLibrary] is the element for the library containing the node | |
| 4915 * being visited. The [source] is the source representing the compilation unit | |
| 4916 * containing the node being visited. The [typeProvider] is the object used to | |
| 4917 * access the types from the core library. The [errorListener] is the error | |
| 4918 * listener that will be informed of any errors that are found during | |
| 4919 * resolution. The [nameScope] is the scope used to resolve identifiers in the | |
| 4920 * node that will first be visited. If `null` or unspecified, a new | |
| 4921 * [LibraryScope] will be created based on [definingLibrary] and | |
| 4922 * [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
| |
| 4923 * lookups. If `null` or unspecified, a new [InheritanceManager] will be | |
| 4924 * created based on [definingLibrary]. The [typeAnalyzerFactory] is used to | |
| 4925 * create the type analyzer. If `null` or unspecified, a type analyzer of | |
| 4926 * type [StaticTypeAnalyzer] will be created. | |
| 4927 */ | |
| 4928 InstanceFieldResolverVisitor(LibraryElement definingLibrary, Source source, | |
| 4929 TypeProvider typeProvider, AnalysisErrorListener errorListener, | |
| 4930 {Scope nameScope}) | |
| 4931 : super(definingLibrary, source, typeProvider, errorListener, | |
| 4932 nameScope: nameScope); | |
| 4933 | |
| 4934 /** | |
| 4935 * Resolve the instance fields in the given compilation unit [node]. | |
| 4936 */ | |
| 4937 void resolveCompilationUnit(CompilationUnit node) { | |
| 4938 _overrideManager.enterScope(); | |
| 4939 try { | |
| 4940 NodeList<CompilationUnitMember> declarations = node.declarations; | |
| 4941 int declarationCount = declarations.length; | |
| 4942 for (int i = 0; i < declarationCount; i++) { | |
| 4943 CompilationUnitMember declaration = declarations[i]; | |
| 4944 if (declaration is ClassDeclaration) { | |
| 4945 _resolveClassDeclaration(declaration); | |
| 4946 } | |
| 4947 } | |
| 4948 } finally { | |
| 4949 _overrideManager.exitScope(); | |
| 4950 } | |
| 4951 } | |
| 4952 | |
| 4953 /** | |
| 4954 * Resolve the instance fields in the given class declaration [node]. | |
| 4955 */ | |
| 4956 void _resolveClassDeclaration(ClassDeclaration node) { | |
| 4957 _enclosingClassDeclaration = node; | |
| 4958 ClassElement outerType = enclosingClass; | |
| 4959 Scope outerScope = nameScope; | |
| 4960 try { | |
| 4961 enclosingClass = node.element; | |
| 4962 typeAnalyzer.thisType = enclosingClass?.type; | |
| 4963 if (enclosingClass == null) { | |
| 4964 AnalysisEngine.instance.logger.logInformation( | |
| 4965 "Missing element for class declaration ${node.name.name} in ${defini ngLibrary.source.fullName}", | |
| 4966 new CaughtException(new AnalysisException(), null)); | |
| 4967 // Don't try to re-resolve the initializers if we cannot set up the | |
| 4968 // right name scope for resolution. | |
| 4969 } else { | |
| 4970 nameScope = new ClassScope(nameScope, enclosingClass); | |
| 4971 NodeList<ClassMember> members = node.members; | |
| 4972 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
| |
| 4973 ClassMember member = members[i]; | |
| 4974 if (member is FieldDeclaration) { | |
| 4975 _resolveFieldDeclaration(member); | |
| 4976 } | |
| 4977 } | |
| 4978 } | |
| 4979 } finally { | |
| 4980 nameScope = outerScope; | |
| 4981 typeAnalyzer.thisType = outerType?.type; | |
| 4982 enclosingClass = outerType; | |
| 4983 _enclosingClassDeclaration = null; | |
| 4984 } | |
| 4985 } | |
| 4986 | |
| 4987 /** | |
| 4988 * Resolve the instance fields in the given field declaration [node]. | |
| 4989 */ | |
| 4990 void _resolveFieldDeclaration(FieldDeclaration node) { | |
| 4991 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
| |
| 4992 Expression initializer = field.initializer; | |
| 4993 if (initializer != null) { | |
| 4994 initializer.accept(this); | |
|
scheglov
2016/04/25 20:45:55
field.initializer?.accept(this) maybe?
Brian Wilkerson
2016/04/25 21:08:58
Done
| |
| 4995 } | |
| 4996 } | |
| 4997 } | |
| 4998 } | |
| 4999 | |
| 5000 /** | |
| 4906 * Instances of the class `OverrideVerifier` visit all of the declarations in a compilation | 5001 * Instances of the class `OverrideVerifier` visit all of the declarations in a compilation |
| 4907 * unit to verify that if they have an override annotation it is being used corr ectly. | 5002 * unit to verify that if they have an override annotation it is being used corr ectly. |
| 4908 */ | 5003 */ |
| 4909 class OverrideVerifier extends RecursiveAstVisitor<Object> { | 5004 class OverrideVerifier extends RecursiveAstVisitor<Object> { |
| 4910 /** | 5005 /** |
| 4911 * The error reporter used to report errors. | 5006 * The error reporter used to report errors. |
| 4912 */ | 5007 */ |
| 4913 final ErrorReporter _errorReporter; | 5008 final ErrorReporter _errorReporter; |
| 4914 | 5009 |
| 4915 /** | 5010 /** |
| (...skipping 5820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10736 return null; | 10831 return null; |
| 10737 } | 10832 } |
| 10738 if (identical(node.staticElement, variable)) { | 10833 if (identical(node.staticElement, variable)) { |
| 10739 if (node.inSetterContext()) { | 10834 if (node.inSetterContext()) { |
| 10740 result = true; | 10835 result = true; |
| 10741 } | 10836 } |
| 10742 } | 10837 } |
| 10743 return null; | 10838 return null; |
| 10744 } | 10839 } |
| 10745 } | 10840 } |
| OLD | NEW |