Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(254)

Side by Side Diff: pkg/analyzer/lib/src/generated/resolver.dart

Issue 197213036: New analyzer snapshot. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove marker Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.resolver; 8 library engine.resolver;
9 9
10 import 'dart:collection'; 10 import 'dart:collection';
(...skipping 3845 matching lines...) Expand 10 before | Expand all | Expand 10 after
3856 } 3856 }
3857 3857
3858 /** 3858 /**
3859 * Given some [NodeList] of [Annotation]s, ensure that the identifiers are vis ited by 3859 * Given some [NodeList] of [Annotation]s, ensure that the identifiers are vis ited by
3860 * this visitor. Specifically, this covers the cases where AST nodes don't hav e their identifiers 3860 * this visitor. Specifically, this covers the cases where AST nodes don't hav e their identifiers
3861 * visited by this visitor, but still need their annotations visited. 3861 * visited by this visitor, but still need their annotations visited.
3862 * 3862 *
3863 * @param annotations the list of annotations to visit 3863 * @param annotations the list of annotations to visit
3864 */ 3864 */
3865 void _visitMetadata(NodeList<Annotation> annotations) { 3865 void _visitMetadata(NodeList<Annotation> annotations) {
3866 for (Annotation annotation in annotations) { 3866 int count = annotations.length;
3867 Identifier name = annotation.name; 3867 for (int i = 0; i < count; i++) {
3868 _visitIdentifier(name.staticElement, name.name); 3868 annotations[i].accept(this);
3869 } 3869 }
3870 } 3870 }
3871 } 3871 }
3872 3872
3873 /** 3873 /**
3874 * Instances of the class `OverrideVerifier` visit all of the declarations in a compilation 3874 * Instances of the class `OverrideVerifier` visit all of the declarations in a compilation
3875 * unit to verify that if they have an override annotation it is being used corr ectly. 3875 * unit to verify that if they have an override annotation it is being used corr ectly.
3876 */ 3876 */
3877 class OverrideVerifier extends RecursiveAstVisitor<Object> { 3877 class OverrideVerifier extends RecursiveAstVisitor<Object> {
3878 /** 3878 /**
(...skipping 1653 matching lines...) Expand 10 before | Expand all | Expand 10 after
5532 Expression leftHandSide = node.leftHandSide; 5532 Expression leftHandSide = node.leftHandSide;
5533 if (leftHandSide != null) { 5533 if (leftHandSide != null) {
5534 String methodName = operatorType.lexeme; 5534 String methodName = operatorType.lexeme;
5535 DartType staticType = _getStaticType(leftHandSide); 5535 DartType staticType = _getStaticType(leftHandSide);
5536 MethodElement staticMethod = _lookUpMethod(leftHandSide, staticType, met hodName); 5536 MethodElement staticMethod = _lookUpMethod(leftHandSide, staticType, met hodName);
5537 node.staticElement = staticMethod; 5537 node.staticElement = staticMethod;
5538 DartType propagatedType = _getPropagatedType(leftHandSide); 5538 DartType propagatedType = _getPropagatedType(leftHandSide);
5539 MethodElement propagatedMethod = _lookUpMethod(leftHandSide, propagatedT ype, methodName); 5539 MethodElement propagatedMethod = _lookUpMethod(leftHandSide, propagatedT ype, methodName);
5540 node.propagatedElement = propagatedMethod; 5540 node.propagatedElement = propagatedMethod;
5541 if (_shouldReportMissingMember(staticType, staticMethod)) { 5541 if (_shouldReportMissingMember(staticType, staticMethod)) {
5542 _resolver.reportErrorProxyConditionalAnalysisError(staticType.element, StaticTypeWarningCode.UNDEFINED_METHOD, operator, [methodName, staticType.displ ayName]); 5542 _resolver.reportProxyConditionalErrorForToken(staticType.element, Stat icTypeWarningCode.UNDEFINED_METHOD, operator, [methodName, staticType.displayNam e]);
5543 } else if (_enableHints && _shouldReportMissingMember(propagatedType, pr opagatedMethod) && !_memberFoundInSubclass(propagatedType.element, methodName, t rue, false)) { 5543 } else if (_enableHints && _shouldReportMissingMember(propagatedType, pr opagatedMethod) && !_memberFoundInSubclass(propagatedType.element, methodName, t rue, false)) {
5544 _resolver.reportErrorProxyConditionalAnalysisError(propagatedType.elem ent, HintCode.UNDEFINED_METHOD, operator, [methodName, propagatedType.displayNam e]); 5544 _resolver.reportProxyConditionalErrorForToken(propagatedType.element, HintCode.UNDEFINED_METHOD, operator, [methodName, propagatedType.displayName]);
5545 } 5545 }
5546 } 5546 }
5547 } 5547 }
5548 return null; 5548 return null;
5549 } 5549 }
5550 5550
5551 @override 5551 @override
5552 Object visitBinaryExpression(BinaryExpression node) { 5552 Object visitBinaryExpression(BinaryExpression node) {
5553 sc.Token operator = node.operator; 5553 sc.Token operator = node.operator;
5554 if (operator.isUserDefinableOperator) { 5554 if (operator.isUserDefinableOperator) {
5555 Expression leftOperand = node.leftOperand; 5555 Expression leftOperand = node.leftOperand;
5556 if (leftOperand != null) { 5556 if (leftOperand != null) {
5557 String methodName = operator.lexeme; 5557 String methodName = operator.lexeme;
5558 DartType staticType = _getStaticType(leftOperand); 5558 DartType staticType = _getStaticType(leftOperand);
5559 MethodElement staticMethod = _lookUpMethod(leftOperand, staticType, meth odName); 5559 MethodElement staticMethod = _lookUpMethod(leftOperand, staticType, meth odName);
5560 node.staticElement = staticMethod; 5560 node.staticElement = staticMethod;
5561 DartType propagatedType = _getPropagatedType(leftOperand); 5561 DartType propagatedType = _getPropagatedType(leftOperand);
5562 MethodElement propagatedMethod = _lookUpMethod(leftOperand, propagatedTy pe, methodName); 5562 MethodElement propagatedMethod = _lookUpMethod(leftOperand, propagatedTy pe, methodName);
5563 node.propagatedElement = propagatedMethod; 5563 node.propagatedElement = propagatedMethod;
5564 if (_shouldReportMissingMember(staticType, staticMethod)) { 5564 if (_shouldReportMissingMember(staticType, staticMethod)) {
5565 _resolver.reportErrorProxyConditionalAnalysisError(staticType.element, StaticTypeWarningCode.UNDEFINED_OPERATOR, operator, [methodName, staticType.dis playName]); 5565 _resolver.reportProxyConditionalErrorForToken(staticType.element, Stat icTypeWarningCode.UNDEFINED_OPERATOR, operator, [methodName, staticType.displayN ame]);
5566 } else if (_enableHints && _shouldReportMissingMember(propagatedType, pr opagatedMethod) && !_memberFoundInSubclass(propagatedType.element, methodName, t rue, false)) { 5566 } else if (_enableHints && _shouldReportMissingMember(propagatedType, pr opagatedMethod) && !_memberFoundInSubclass(propagatedType.element, methodName, t rue, false)) {
5567 _resolver.reportErrorProxyConditionalAnalysisError(propagatedType.elem ent, HintCode.UNDEFINED_OPERATOR, operator, [methodName, propagatedType.displayN ame]); 5567 _resolver.reportProxyConditionalErrorForToken(propagatedType.element, HintCode.UNDEFINED_OPERATOR, operator, [methodName, propagatedType.displayName]) ;
5568 } 5568 }
5569 } 5569 }
5570 } 5570 }
5571 return null; 5571 return null;
5572 } 5572 }
5573 5573
5574 @override 5574 @override
5575 Object visitBreakStatement(BreakStatement node) { 5575 Object visitBreakStatement(BreakStatement node) {
5576 _lookupLabel(node, node.label); 5576 _lookupLabel(node, node.label);
5577 return null; 5577 return null;
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
6052 Object visitPostfixExpression(PostfixExpression node) { 6052 Object visitPostfixExpression(PostfixExpression node) {
6053 Expression operand = node.operand; 6053 Expression operand = node.operand;
6054 String methodName = _getPostfixOperator(node); 6054 String methodName = _getPostfixOperator(node);
6055 DartType staticType = _getStaticType(operand); 6055 DartType staticType = _getStaticType(operand);
6056 MethodElement staticMethod = _lookUpMethod(operand, staticType, methodName); 6056 MethodElement staticMethod = _lookUpMethod(operand, staticType, methodName);
6057 node.staticElement = staticMethod; 6057 node.staticElement = staticMethod;
6058 DartType propagatedType = _getPropagatedType(operand); 6058 DartType propagatedType = _getPropagatedType(operand);
6059 MethodElement propagatedMethod = _lookUpMethod(operand, propagatedType, meth odName); 6059 MethodElement propagatedMethod = _lookUpMethod(operand, propagatedType, meth odName);
6060 node.propagatedElement = propagatedMethod; 6060 node.propagatedElement = propagatedMethod;
6061 if (_shouldReportMissingMember(staticType, staticMethod)) { 6061 if (_shouldReportMissingMember(staticType, staticMethod)) {
6062 _resolver.reportErrorProxyConditionalAnalysisError(staticType.element, Sta ticTypeWarningCode.UNDEFINED_OPERATOR, node.operator, [methodName, staticType.di splayName]); 6062 _resolver.reportProxyConditionalErrorForToken(staticType.element, StaticTy peWarningCode.UNDEFINED_OPERATOR, node.operator, [methodName, staticType.display Name]);
6063 } else if (_enableHints && _shouldReportMissingMember(propagatedType, propag atedMethod) && !_memberFoundInSubclass(propagatedType.element, methodName, true, false)) { 6063 } else if (_enableHints && _shouldReportMissingMember(propagatedType, propag atedMethod) && !_memberFoundInSubclass(propagatedType.element, methodName, true, false)) {
6064 _resolver.reportErrorProxyConditionalAnalysisError(propagatedType.element, HintCode.UNDEFINED_OPERATOR, node.operator, [methodName, propagatedType.display Name]); 6064 _resolver.reportProxyConditionalErrorForToken(propagatedType.element, Hint Code.UNDEFINED_OPERATOR, node.operator, [methodName, propagatedType.displayName] );
6065 } 6065 }
6066 return null; 6066 return null;
6067 } 6067 }
6068 6068
6069 @override 6069 @override
6070 Object visitPrefixedIdentifier(PrefixedIdentifier node) { 6070 Object visitPrefixedIdentifier(PrefixedIdentifier node) {
6071 SimpleIdentifier prefix = node.prefix; 6071 SimpleIdentifier prefix = node.prefix;
6072 SimpleIdentifier identifier = node.identifier; 6072 SimpleIdentifier identifier = node.identifier;
6073 // 6073 //
6074 // First, check to see whether the prefix is really a prefix. 6074 // First, check to see whether the prefix is really a prefix.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
6131 if (operatorType.isUserDefinableOperator || identical(operatorType, sc.Token Type.PLUS_PLUS) || identical(operatorType, sc.TokenType.MINUS_MINUS)) { 6131 if (operatorType.isUserDefinableOperator || identical(operatorType, sc.Token Type.PLUS_PLUS) || identical(operatorType, sc.TokenType.MINUS_MINUS)) {
6132 Expression operand = node.operand; 6132 Expression operand = node.operand;
6133 String methodName = _getPrefixOperator(node); 6133 String methodName = _getPrefixOperator(node);
6134 DartType staticType = _getStaticType(operand); 6134 DartType staticType = _getStaticType(operand);
6135 MethodElement staticMethod = _lookUpMethod(operand, staticType, methodName ); 6135 MethodElement staticMethod = _lookUpMethod(operand, staticType, methodName );
6136 node.staticElement = staticMethod; 6136 node.staticElement = staticMethod;
6137 DartType propagatedType = _getPropagatedType(operand); 6137 DartType propagatedType = _getPropagatedType(operand);
6138 MethodElement propagatedMethod = _lookUpMethod(operand, propagatedType, me thodName); 6138 MethodElement propagatedMethod = _lookUpMethod(operand, propagatedType, me thodName);
6139 node.propagatedElement = propagatedMethod; 6139 node.propagatedElement = propagatedMethod;
6140 if (_shouldReportMissingMember(staticType, staticMethod)) { 6140 if (_shouldReportMissingMember(staticType, staticMethod)) {
6141 _resolver.reportErrorProxyConditionalAnalysisError(staticType.element, S taticTypeWarningCode.UNDEFINED_OPERATOR, operator, [methodName, staticType.displ ayName]); 6141 _resolver.reportProxyConditionalErrorForToken(staticType.element, Static TypeWarningCode.UNDEFINED_OPERATOR, operator, [methodName, staticType.displayNam e]);
6142 } else if (_enableHints && _shouldReportMissingMember(propagatedType, prop agatedMethod) && !_memberFoundInSubclass(propagatedType.element, methodName, tru e, false)) { 6142 } else if (_enableHints && _shouldReportMissingMember(propagatedType, prop agatedMethod) && !_memberFoundInSubclass(propagatedType.element, methodName, tru e, false)) {
6143 _resolver.reportErrorProxyConditionalAnalysisError(propagatedType.elemen t, HintCode.UNDEFINED_OPERATOR, operator, [methodName, propagatedType.displayNam e]); 6143 _resolver.reportProxyConditionalErrorForToken(propagatedType.element, Hi ntCode.UNDEFINED_OPERATOR, operator, [methodName, propagatedType.displayName]);
6144 } 6144 }
6145 } 6145 }
6146 return null; 6146 return null;
6147 } 6147 }
6148 6148
6149 @override 6149 @override
6150 Object visitPropertyAccess(PropertyAccess node) { 6150 Object visitPropertyAccess(PropertyAccess node) {
6151 Expression target = node.realTarget; 6151 Expression target = node.realTarget;
6152 if (target is SuperExpression && !_isSuperInValidContext(target)) { 6152 if (target is SuperExpression && !_isSuperInValidContext(target)) {
6153 return null; 6153 return null;
(...skipping 2879 matching lines...) Expand 10 before | Expand all | Expand 10 after
9033 AnalysisErrorListener _errorListener; 9033 AnalysisErrorListener _errorListener;
9034 9034
9035 /** 9035 /**
9036 * The name of the function used as an entry point. 9036 * The name of the function used as an entry point.
9037 */ 9037 */
9038 static String ENTRY_POINT_NAME = "main"; 9038 static String ENTRY_POINT_NAME = "main";
9039 9039
9040 /** 9040 /**
9041 * Initialize a newly created library element builder. 9041 * Initialize a newly created library element builder.
9042 * 9042 *
9043 * @param resolver the resolver for which the element model is being built 9043 * @param analysisContext the analysis context in which the element model will be built
9044 * @param errorListener the listener to which errors will be reported
9044 */ 9045 */
9045 LibraryElementBuilder(LibraryResolver resolver) { 9046 LibraryElementBuilder(InternalAnalysisContext analysisContext, AnalysisErrorLi stener errorListener) {
9046 this._analysisContext = resolver.analysisContext; 9047 this._analysisContext = analysisContext;
9047 this._errorListener = resolver.errorListener; 9048 this._errorListener = errorListener;
9048 } 9049 }
9049 9050
9050 /** 9051 /**
9051 * Build the library element for the given library. 9052 * Build the library element for the given library.
9052 * 9053 *
9053 * @param library the library for which an element model is to be built 9054 * @param library the library for which an element model is to be built
9054 * @return the library element that was built 9055 * @return the library element that was built
9055 * @throws AnalysisException if the analysis could not be performed 9056 * @throws AnalysisException if the analysis could not be performed
9056 */ 9057 */
9057 LibraryElementImpl buildLibrary(Library library) { 9058 LibraryElementImpl buildLibrary(Library library) {
(...skipping 18 matching lines...) Expand all
9076 if (libraryNameNode == null) { 9077 if (libraryNameNode == null) {
9077 libraryNameNode = directive.name; 9078 libraryNameNode = directive.name;
9078 directivesToResolve.add(directive); 9079 directivesToResolve.add(directive);
9079 } 9080 }
9080 } else if (directive is PartDirective) { 9081 } else if (directive is PartDirective) {
9081 PartDirective partDirective = directive; 9082 PartDirective partDirective = directive;
9082 StringLiteral partUri = partDirective.uri; 9083 StringLiteral partUri = partDirective.uri;
9083 Source partSource = library.getSource(partDirective); 9084 Source partSource = library.getSource(partDirective);
9084 if (_analysisContext.exists(partSource)) { 9085 if (_analysisContext.exists(partSource)) {
9085 hasPartDirective = true; 9086 hasPartDirective = true;
9086 CompilationUnitElementImpl part = builder.buildCompilationUnit(partSou rce, library.getAST(partSource)); 9087 CompilationUnit partUnit = library.getAST(partSource);
9088 CompilationUnitElementImpl part = builder.buildCompilationUnit(partSou rce, partUnit);
9087 part.uriOffset = partUri.offset; 9089 part.uriOffset = partUri.offset;
9088 part.uriEnd = partUri.end; 9090 part.uriEnd = partUri.end;
9089 part.uri = library.getUri(partDirective); 9091 part.uri = library.getUri(partDirective);
9090 // 9092 //
9091 // Validate that the part contains a part-of directive with the same n ame as the library. 9093 // Validate that the part contains a part-of directive with the same n ame as the library.
9092 // 9094 //
9093 String partLibraryName = _getPartLibraryName(library, partSource, dire ctivesToResolve); 9095 String partLibraryName = _getPartLibraryName(partSource, partUnit, dir ectivesToResolve);
9094 if (partLibraryName == null) { 9096 if (partLibraryName == null) {
9095 _errorListener.onError(new AnalysisError.con2(librarySource, partUri .offset, partUri.length, CompileTimeErrorCode.PART_OF_NON_PART, [partUri.toSourc e()])); 9097 _errorListener.onError(new AnalysisError.con2(librarySource, partUri .offset, partUri.length, CompileTimeErrorCode.PART_OF_NON_PART, [partUri.toSourc e()]));
9096 } else if (libraryNameNode == null) { 9098 } else if (libraryNameNode == null) {
9099 } else if (libraryNameNode.name != partLibraryName) {
9100 _errorListener.onError(new AnalysisError.con2(librarySource, partUri .offset, partUri.length, StaticWarningCode.PART_OF_DIFFERENT_LIBRARY, [libraryNa meNode.name, partLibraryName]));
9101 }
9102 if (entryPoint == null) {
9103 entryPoint = _findEntryPoint(part);
9104 }
9105 directive.element = part;
9106 sourcedCompilationUnits.add(part);
9107 }
9108 }
9109 }
9110 if (hasPartDirective && libraryNameNode == null) {
9111 _errorListener.onError(new AnalysisError.con1(librarySource, ResolverError Code.MISSING_LIBRARY_DIRECTIVE_WITH_PART, []));
9112 }
9113 //
9114 // Create and populate the library element.
9115 //
9116 LibraryElementImpl libraryElement = new LibraryElementImpl(_analysisContext, libraryNameNode);
9117 libraryElement.definingCompilationUnit = definingCompilationUnitElement;
9118 if (entryPoint != null) {
9119 libraryElement.entryPoint = entryPoint;
9120 }
9121 int sourcedUnitCount = sourcedCompilationUnits.length;
9122 libraryElement.parts = new List.from(sourcedCompilationUnits);
9123 for (Directive directive in directivesToResolve) {
9124 directive.element = libraryElement;
9125 }
9126 library.libraryElement = libraryElement;
9127 if (sourcedUnitCount > 0) {
9128 _patchTopLevelAccessors(libraryElement);
9129 }
9130 return libraryElement;
9131 }
9132
9133 /**
9134 * Build the library element for the given library.
9135 *
9136 * @param library the library for which an element model is to be built
9137 * @return the library element that was built
9138 * @throws AnalysisException if the analysis could not be performed
9139 */
9140 LibraryElementImpl buildLibrary2(ResolvableLibrary library) {
9141 CompilationUnitBuilder builder = new CompilationUnitBuilder();
9142 Source librarySource = library.librarySource;
9143 CompilationUnit definingCompilationUnit = library.definingCompilationUnit;
9144 CompilationUnitElementImpl definingCompilationUnitElement = builder.buildCom pilationUnit(librarySource, definingCompilationUnit);
9145 NodeList<Directive> directives = definingCompilationUnit.directives;
9146 LibraryIdentifier libraryNameNode = null;
9147 bool hasPartDirective = false;
9148 FunctionElement entryPoint = _findEntryPoint(definingCompilationUnitElement) ;
9149 List<Directive> directivesToResolve = new List<Directive>();
9150 List<CompilationUnitElementImpl> sourcedCompilationUnits = new List<Compilat ionUnitElementImpl>();
9151 for (Directive directive in directives) {
9152 //
9153 // We do not build the elements representing the import and export directi ves at this point.
9154 // That is not done until we get to LibraryResolver.buildDirectiveModels() because we need the
9155 // LibraryElements for the referenced libraries, which might not exist at this point (due to
9156 // the possibility of circular references).
9157 //
9158 if (directive is LibraryDirective) {
9159 if (libraryNameNode == null) {
9160 libraryNameNode = directive.name;
9161 directivesToResolve.add(directive);
9162 }
9163 } else if (directive is PartDirective) {
9164 PartDirective partDirective = directive;
9165 StringLiteral partUri = partDirective.uri;
9166 Source partSource = partDirective.source;
9167 if (_analysisContext.exists(partSource)) {
9168 hasPartDirective = true;
9169 CompilationUnit partUnit = library.getAST(partSource);
9170 CompilationUnitElementImpl part = builder.buildCompilationUnit(partSou rce, partUnit);
9171 part.uriOffset = partUri.offset;
9172 part.uriEnd = partUri.end;
9173 part.uri = partDirective.uriContent;
9174 //
9175 // Validate that the part contains a part-of directive with the same n ame as the library.
9176 //
9177 String partLibraryName = _getPartLibraryName(partSource, partUnit, dir ectivesToResolve);
9178 if (partLibraryName == null) {
9179 _errorListener.onError(new AnalysisError.con2(librarySource, partUri .offset, partUri.length, CompileTimeErrorCode.PART_OF_NON_PART, [partUri.toSourc e()]));
9180 } else if (libraryNameNode == null) {
9097 } else if (libraryNameNode.name != partLibraryName) { 9181 } else if (libraryNameNode.name != partLibraryName) {
9098 _errorListener.onError(new AnalysisError.con2(librarySource, partUri .offset, partUri.length, StaticWarningCode.PART_OF_DIFFERENT_LIBRARY, [libraryNa meNode.name, partLibraryName])); 9182 _errorListener.onError(new AnalysisError.con2(librarySource, partUri .offset, partUri.length, StaticWarningCode.PART_OF_DIFFERENT_LIBRARY, [libraryNa meNode.name, partLibraryName]));
9099 } 9183 }
9100 if (entryPoint == null) { 9184 if (entryPoint == null) {
9101 entryPoint = _findEntryPoint(part); 9185 entryPoint = _findEntryPoint(part);
9102 } 9186 }
9103 directive.element = part; 9187 directive.element = part;
9104 sourcedCompilationUnits.add(part); 9188 sourcedCompilationUnits.add(part);
9105 } 9189 }
9106 } 9190 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
9163 return function; 9247 return function;
9164 } 9248 }
9165 } 9249 }
9166 return null; 9250 return null;
9167 } 9251 }
9168 9252
9169 /** 9253 /**
9170 * Return the name of the library that the given part is declared to be a part of, or `null` 9254 * Return the name of the library that the given part is declared to be a part of, or `null`
9171 * if the part does not contain a part-of directive. 9255 * if the part does not contain a part-of directive.
9172 * 9256 *
9173 * @param library the library containing the part
9174 * @param partSource the source representing the part 9257 * @param partSource the source representing the part
9258 * @param partUnit the AST structure of the part
9175 * @param directivesToResolve a list of directives that should be resolved to the library being 9259 * @param directivesToResolve a list of directives that should be resolved to the library being
9176 * built 9260 * built
9177 * @return the name of the library that the given part is declared to be a par t of 9261 * @return the name of the library that the given part is declared to be a par t of
9178 */ 9262 */
9179 String _getPartLibraryName(Library library, Source partSource, List<Directive> directivesToResolve) { 9263 String _getPartLibraryName(Source partSource, CompilationUnit partUnit, List<D irective> directivesToResolve) {
9180 try { 9264 for (Directive directive in partUnit.directives) {
9181 CompilationUnit partUnit = library.getAST(partSource); 9265 if (directive is PartOfDirective) {
9182 for (Directive directive in partUnit.directives) { 9266 directivesToResolve.add(directive);
9183 if (directive is PartOfDirective) { 9267 LibraryIdentifier libraryName = directive.libraryName;
9184 directivesToResolve.add(directive); 9268 if (libraryName != null) {
9185 LibraryIdentifier libraryName = directive.libraryName; 9269 return libraryName.name;
9186 if (libraryName != null) {
9187 return libraryName.name;
9188 }
9189 } 9270 }
9190 } 9271 }
9191 } on AnalysisException catch (exception) {
9192 } 9272 }
9193 return null; 9273 return null;
9194 } 9274 }
9195 9275
9196 /** 9276 /**
9197 * Look through all of the compilation units defined for the given library, lo oking for getters 9277 * Look through all of the compilation units defined for the given library, lo oking for getters
9198 * and setters that are defined in different compilation units but that have t he same names. If 9278 * and setters that are defined in different compilation units but that have t he same names. If
9199 * any are found, make sure that they have the same variable element. 9279 * any are found, make sure that they have the same variable element.
9200 * 9280 *
9201 * @param libraryElement the library defining the compilation units to be proc essed 9281 * @param libraryElement the library defining the compilation units to be proc essed
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
9645 } 9725 }
9646 } 9726 }
9647 9727
9648 /** 9728 /**
9649 * Build element models for all of the libraries in the current cycle. 9729 * Build element models for all of the libraries in the current cycle.
9650 * 9730 *
9651 * @throws AnalysisException if any of the element models cannot be built 9731 * @throws AnalysisException if any of the element models cannot be built
9652 */ 9732 */
9653 void _buildElementModels() { 9733 void _buildElementModels() {
9654 for (Library library in _librariesInCycles) { 9734 for (Library library in _librariesInCycles) {
9655 LibraryElementBuilder builder = new LibraryElementBuilder(this); 9735 LibraryElementBuilder builder = new LibraryElementBuilder(analysisContext, errorListener);
9656 LibraryElementImpl libraryElement = builder.buildLibrary(library); 9736 LibraryElementImpl libraryElement = builder.buildLibrary(library);
9657 library.libraryElement = libraryElement; 9737 library.libraryElement = libraryElement;
9658 } 9738 }
9659 } 9739 }
9660 9740
9661 /** 9741 /**
9662 * Resolve the type hierarchy across all of the types declared in the librarie s in the current 9742 * Resolve the type hierarchy across all of the types declared in the librarie s in the current
9663 * cycle. 9743 * cycle.
9664 * 9744 *
9665 * @throws AnalysisException if any of the type hierarchies could not be resol ved 9745 * @throws AnalysisException if any of the type hierarchies could not be resol ved
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
9942 String uriContent = uriLiteral.stringValue.trim(); 10022 String uriContent = uriLiteral.stringValue.trim();
9943 if (uriContent == null || uriContent.isEmpty) { 10023 if (uriContent == null || uriContent.isEmpty) {
9944 return null; 10024 return null;
9945 } 10025 }
9946 uriContent = Uri.encodeFull(uriContent); 10026 uriContent = Uri.encodeFull(uriContent);
9947 return analysisContext.sourceFactory.resolveUri(librarySource, uriContent); 10027 return analysisContext.sourceFactory.resolveUri(librarySource, uriContent);
9948 } 10028 }
9949 } 10029 }
9950 10030
9951 /** 10031 /**
10032 * Instances of the class `LibraryResolver` are used to resolve one or more mutu ally dependent
10033 * libraries within a single context.
10034 */
10035 class LibraryResolver2 {
10036 /**
10037 * The analysis context in which the libraries are being analyzed.
10038 */
10039 InternalAnalysisContext analysisContext;
10040
10041 /**
10042 * The listener to which analysis errors will be reported, this error listener is either
10043 * references [recordingErrorListener], or it unions the passed
10044 * [AnalysisErrorListener] with the [recordingErrorListener].
10045 */
10046 RecordingErrorListener _errorListener;
10047
10048 /**
10049 * A source object representing the core library (dart:core).
10050 */
10051 Source _coreLibrarySource;
10052
10053 /**
10054 * The object representing the core library.
10055 */
10056 ResolvableLibrary _coreLibrary;
10057
10058 /**
10059 * The object used to access the types from the core library.
10060 */
10061 TypeProvider _typeProvider;
10062
10063 /**
10064 * A table mapping library sources to the information being maintained for tho se libraries.
10065 */
10066 Map<Source, ResolvableLibrary> _libraryMap = new Map<Source, ResolvableLibrary >();
10067
10068 /**
10069 * A collection containing the libraries that are being resolved together.
10070 */
10071 List<ResolvableLibrary> _librariesInCycle;
10072
10073 /**
10074 * Initialize a newly created library resolver to resolve libraries within the given context.
10075 *
10076 * @param analysisContext the analysis context in which the library is being a nalyzed
10077 */
10078 LibraryResolver2(InternalAnalysisContext analysisContext) {
10079 this.analysisContext = analysisContext;
10080 this._errorListener = new RecordingErrorListener();
10081 _coreLibrarySource = analysisContext.sourceFactory.forUri(DartSdk.DART_CORE) ;
10082 }
10083
10084 /**
10085 * Return the listener to which analysis errors will be reported.
10086 *
10087 * @return the listener to which analysis errors will be reported
10088 */
10089 RecordingErrorListener get errorListener => _errorListener;
10090
10091 /**
10092 * Return an array containing information about all of the libraries that were resolved.
10093 *
10094 * @return an array containing the libraries that were resolved
10095 */
10096 List<ResolvableLibrary> get resolvedLibraries => _librariesInCycle;
10097
10098 /**
10099 * Resolve the library specified by the given source in the given context.
10100 *
10101 * Note that because Dart allows circular imports between libraries, it is pos sible that more than
10102 * one library will need to be resolved. In such cases the error listener can receive errors from
10103 * multiple libraries.
10104 *
10105 * @param librarySource the source specifying the defining compilation unit of the library to be
10106 * resolved
10107 * @param fullAnalysis `true` if a full analysis should be performed
10108 * @return the element representing the resolved library
10109 * @throws AnalysisException if the library could not be resolved for some rea son
10110 */
10111 LibraryElement resolveLibrary(Source librarySource, List<ResolvableLibrary> li brariesInCycle) {
10112 InstrumentationBuilder instrumentation = Instrumentation.builder2("dart.engi ne.LibraryResolver.resolveLibrary");
10113 try {
10114 instrumentation.data3("fullName", librarySource.fullName);
10115 //
10116 // Build the map of libraries that are known.
10117 //
10118 this._librariesInCycle = librariesInCycle;
10119 _libraryMap = _buildLibraryMap();
10120 ResolvableLibrary targetLibrary = _libraryMap[librarySource];
10121 _coreLibrary = _libraryMap[_coreLibrarySource];
10122 instrumentation.metric3("buildLibraryMap", "complete");
10123 //
10124 // Build the element models representing the libraries being resolved. Thi s is done in three
10125 // steps:
10126 //
10127 // 1. Build the basic element models without making any connections betwee n elements other than
10128 // the basic parent/child relationships. This includes building the ele ments representing the
10129 // libraries.
10130 // 2. Build the elements for the import and export directives. This requir es that we have the
10131 // elements built for the referenced libraries, but because of the poss ibility of circular
10132 // references needs to happen after all of the library elements have be en created.
10133 // 3. Build the rest of the type model by connecting superclasses, mixins, and interfaces. This
10134 // requires that we be able to compute the names visible in the librari es being resolved,
10135 // which in turn requires that we have resolved the import directives.
10136 //
10137 _buildElementModels();
10138 instrumentation.metric3("buildElementModels", "complete");
10139 LibraryElement coreElement = _coreLibrary.libraryElement;
10140 if (coreElement == null) {
10141 throw new AnalysisException.con1("Could not resolve dart:core");
10142 }
10143 _buildDirectiveModels();
10144 instrumentation.metric3("buildDirectiveModels", "complete");
10145 _typeProvider = new TypeProviderImpl(coreElement);
10146 _buildTypeHierarchies();
10147 instrumentation.metric3("buildTypeHierarchies", "complete");
10148 //
10149 // Perform resolution and type analysis.
10150 //
10151 // TODO(brianwilkerson) Decide whether we want to resolve all of the libra ries or whether we
10152 // want to only resolve the target library. The advantage to resolving eve rything is that we
10153 // have already done part of the work so we'll avoid duplicated effort. Th e disadvantage of
10154 // resolving everything is that we might do extra work that we don't reall y care about. Another
10155 // possibility is to add a parameter to this method and punt the decision to the clients.
10156 //
10157 //if (analyzeAll) {
10158 _resolveReferencesAndTypes();
10159 instrumentation.metric3("resolveReferencesAndTypes", "complete");
10160 //} else {
10161 // resolveReferencesAndTypes(targetLibrary);
10162 //}
10163 _performConstantEvaluation();
10164 instrumentation.metric3("performConstantEvaluation", "complete");
10165 instrumentation.metric2("librariesInCycles", librariesInCycle.length);
10166 for (ResolvableLibrary lib in librariesInCycle) {
10167 instrumentation.metric2("librariesInCycles-CompilationUnitSources-Size", lib.compilationUnitSources.length);
10168 }
10169 return targetLibrary.libraryElement;
10170 } finally {
10171 instrumentation.log();
10172 }
10173 }
10174
10175 /**
10176 * Build the element model representing the combinators declared by the given directive.
10177 *
10178 * @param directive the directive that declares the combinators
10179 * @return an array containing the import combinators that were built
10180 */
10181 List<NamespaceCombinator> _buildCombinators(NamespaceDirective directive) {
10182 List<NamespaceCombinator> combinators = new List<NamespaceCombinator>();
10183 for (Combinator combinator in directive.combinators) {
10184 if (combinator is HideCombinator) {
10185 HideElementCombinatorImpl hide = new HideElementCombinatorImpl();
10186 hide.hiddenNames = _getIdentifiers(combinator.hiddenNames);
10187 combinators.add(hide);
10188 } else {
10189 ShowElementCombinatorImpl show = new ShowElementCombinatorImpl();
10190 show.offset = combinator.offset;
10191 show.end = combinator.end;
10192 show.shownNames = _getIdentifiers((combinator as ShowCombinator).shownNa mes);
10193 combinators.add(show);
10194 }
10195 }
10196 return new List.from(combinators);
10197 }
10198
10199 /**
10200 * Every library now has a corresponding [LibraryElement], so it is now possib le to resolve
10201 * the import and export directives.
10202 *
10203 * @throws AnalysisException if the defining compilation unit for any of the l ibraries could not
10204 * be accessed
10205 */
10206 void _buildDirectiveModels() {
10207 for (ResolvableLibrary library in _librariesInCycle) {
10208 Map<String, PrefixElementImpl> nameToPrefixMap = new Map<String, PrefixEle mentImpl>();
10209 List<ImportElement> imports = new List<ImportElement>();
10210 List<ExportElement> exports = new List<ExportElement>();
10211 for (Directive directive in library.definingCompilationUnit.directives) {
10212 if (directive is ImportDirective) {
10213 ImportDirective importDirective = directive;
10214 Source importedSource = importDirective.source;
10215 if (importedSource != null && analysisContext.exists(importedSource)) {
10216 // The imported source will be null if the URI in the import directi ve was invalid.
10217 ResolvableLibrary importedLibrary = _libraryMap[importedSource];
10218 if (importedLibrary != null) {
10219 ImportElementImpl importElement = new ImportElementImpl(directive. offset);
10220 StringLiteral uriLiteral = importDirective.uri;
10221 if (uriLiteral != null) {
10222 importElement.uriOffset = uriLiteral.offset;
10223 importElement.uriEnd = uriLiteral.end;
10224 }
10225 importElement.uri = importDirective.uriContent;
10226 importElement.combinators = _buildCombinators(importDirective);
10227 LibraryElement importedLibraryElement = importedLibrary.libraryEle ment;
10228 if (importedLibraryElement != null) {
10229 importElement.importedLibrary = importedLibraryElement;
10230 }
10231 SimpleIdentifier prefixNode = directive.prefix;
10232 if (prefixNode != null) {
10233 importElement.prefixOffset = prefixNode.offset;
10234 String prefixName = prefixNode.name;
10235 PrefixElementImpl prefix = nameToPrefixMap[prefixName];
10236 if (prefix == null) {
10237 prefix = new PrefixElementImpl(prefixNode);
10238 nameToPrefixMap[prefixName] = prefix;
10239 }
10240 importElement.prefix = prefix;
10241 prefixNode.staticElement = prefix;
10242 }
10243 directive.element = importElement;
10244 imports.add(importElement);
10245 if (analysisContext.computeKindOf(importedSource) != SourceKind.LI BRARY) {
10246 _errorListener.onError(new AnalysisError.con2(library.librarySou rce, uriLiteral.offset, uriLiteral.length, CompileTimeErrorCode.IMPORT_OF_NON_LI BRARY, [uriLiteral.toSource()]));
10247 }
10248 }
10249 }
10250 } else if (directive is ExportDirective) {
10251 ExportDirective exportDirective = directive;
10252 Source exportedSource = exportDirective.source;
10253 if (exportedSource != null && analysisContext.exists(exportedSource)) {
10254 // The exported source will be null if the URI in the export directi ve was invalid.
10255 ResolvableLibrary exportedLibrary = _libraryMap[exportedSource];
10256 if (exportedLibrary != null) {
10257 ExportElementImpl exportElement = new ExportElementImpl();
10258 StringLiteral uriLiteral = exportDirective.uri;
10259 if (uriLiteral != null) {
10260 exportElement.uriOffset = uriLiteral.offset;
10261 exportElement.uriEnd = uriLiteral.end;
10262 }
10263 exportElement.uri = exportDirective.uriContent;
10264 exportElement.combinators = _buildCombinators(exportDirective);
10265 LibraryElement exportedLibraryElement = exportedLibrary.libraryEle ment;
10266 if (exportedLibraryElement != null) {
10267 exportElement.exportedLibrary = exportedLibraryElement;
10268 }
10269 directive.element = exportElement;
10270 exports.add(exportElement);
10271 if (analysisContext.computeKindOf(exportedSource) != SourceKind.LI BRARY) {
10272 _errorListener.onError(new AnalysisError.con2(library.librarySou rce, uriLiteral.offset, uriLiteral.length, CompileTimeErrorCode.EXPORT_OF_NON_LI BRARY, [uriLiteral.toSource()]));
10273 }
10274 }
10275 }
10276 }
10277 }
10278 Source librarySource = library.librarySource;
10279 if (!library.explicitlyImportsCore && _coreLibrarySource != librarySource) {
10280 ImportElementImpl importElement = new ImportElementImpl(-1);
10281 importElement.importedLibrary = _coreLibrary.libraryElement;
10282 importElement.synthetic = true;
10283 imports.add(importElement);
10284 }
10285 LibraryElementImpl libraryElement = library.libraryElement;
10286 libraryElement.imports = new List.from(imports);
10287 libraryElement.exports = new List.from(exports);
10288 if (libraryElement.entryPoint == null) {
10289 Namespace namespace = new NamespaceBuilder().createExportNamespaceForLib rary(libraryElement);
10290 Element element = namespace.get(LibraryElementBuilder.ENTRY_POINT_NAME);
10291 if (element is FunctionElement) {
10292 libraryElement.entryPoint = element;
10293 }
10294 }
10295 }
10296 }
10297
10298 /**
10299 * Build element models for all of the libraries in the current cycle.
10300 *
10301 * @throws AnalysisException if any of the element models cannot be built
10302 */
10303 void _buildElementModels() {
10304 for (ResolvableLibrary library in _librariesInCycle) {
10305 LibraryElementBuilder builder = new LibraryElementBuilder(analysisContext, errorListener);
10306 LibraryElementImpl libraryElement = builder.buildLibrary2(library);
10307 library.libraryElement = libraryElement;
10308 }
10309 }
10310
10311 Map<Source, ResolvableLibrary> _buildLibraryMap() {
10312 Map<Source, ResolvableLibrary> libraryMap = new Map<Source, ResolvableLibrar y>();
10313 int libraryCount = _librariesInCycle.length;
10314 for (int i = 0; i < libraryCount; i++) {
10315 ResolvableLibrary library = _librariesInCycle[i];
10316 library.errorListener = _errorListener;
10317 libraryMap[library.librarySource] = library;
10318 List<ResolvableLibrary> dependencies = library.importsAndExports;
10319 int dependencyCount = dependencies.length;
10320 for (int j = 0; j < dependencyCount; j++) {
10321 ResolvableLibrary dependency = dependencies[j];
10322 //dependency.setErrorListener(errorListener);
10323 libraryMap[dependency.librarySource] = dependency;
10324 }
10325 }
10326 return libraryMap;
10327 }
10328
10329 /**
10330 * Resolve the type hierarchy across all of the types declared in the librarie s in the current
10331 * cycle.
10332 *
10333 * @throws AnalysisException if any of the type hierarchies could not be resol ved
10334 */
10335 void _buildTypeHierarchies() {
10336 TimeCounter_TimeCounterHandle timeCounter = PerformanceStatistics.resolve.st art();
10337 try {
10338 for (ResolvableLibrary library in _librariesInCycle) {
10339 for (ResolvableCompilationUnit unit in library.resolvableCompilationUnit s) {
10340 Source source = unit.source;
10341 CompilationUnit ast = unit.compilationUnit;
10342 TypeResolverVisitor visitor = new TypeResolverVisitor.con4(library, so urce, _typeProvider);
10343 ast.accept(visitor);
10344 }
10345 }
10346 } finally {
10347 timeCounter.stop();
10348 }
10349 }
10350
10351 /**
10352 * Return an array containing the lexical identifiers associated with the node s in the given list.
10353 *
10354 * @param names the AST nodes representing the identifiers
10355 * @return the lexical identifiers associated with the nodes in the list
10356 */
10357 List<String> _getIdentifiers(NodeList<SimpleIdentifier> names) {
10358 int count = names.length;
10359 List<String> identifiers = new List<String>(count);
10360 for (int i = 0; i < count; i++) {
10361 identifiers[i] = names[i].name;
10362 }
10363 return identifiers;
10364 }
10365
10366 /**
10367 * Compute a value for all of the constants in the libraries being analyzed.
10368 */
10369 void _performConstantEvaluation() {
10370 TimeCounter_TimeCounterHandle timeCounter = PerformanceStatistics.resolve.st art();
10371 try {
10372 ConstantValueComputer computer = new ConstantValueComputer(_typeProvider);
10373 for (ResolvableLibrary library in _librariesInCycle) {
10374 for (ResolvableCompilationUnit unit in library.resolvableCompilationUnit s) {
10375 CompilationUnit ast = unit.compilationUnit;
10376 if (ast != null) {
10377 computer.add(ast);
10378 }
10379 }
10380 }
10381 computer.computeValues();
10382 } finally {
10383 timeCounter.stop();
10384 }
10385 }
10386
10387 /**
10388 * Resolve the identifiers and perform type analysis in the libraries in the c urrent cycle.
10389 *
10390 * @throws AnalysisException if any of the identifiers could not be resolved o r if any of the
10391 * libraries could not have their types analyzed
10392 */
10393 void _resolveReferencesAndTypes() {
10394 for (ResolvableLibrary library in _librariesInCycle) {
10395 _resolveReferencesAndTypesInLibrary(library);
10396 }
10397 }
10398
10399 /**
10400 * Resolve the identifiers and perform type analysis in the given library.
10401 *
10402 * @param library the library to be resolved
10403 * @throws AnalysisException if any of the identifiers could not be resolved o r if the types in
10404 * the library cannot be analyzed
10405 */
10406 void _resolveReferencesAndTypesInLibrary(ResolvableLibrary library) {
10407 TimeCounter_TimeCounterHandle timeCounter = PerformanceStatistics.resolve.st art();
10408 try {
10409 for (ResolvableCompilationUnit unit in library.resolvableCompilationUnits) {
10410 Source source = unit.source;
10411 CompilationUnit ast = unit.compilationUnit;
10412 ast.accept(new VariableResolverVisitor.con3(library, source, _typeProvid er));
10413 ResolverVisitor visitor = new ResolverVisitor.con4(library, source, _typ eProvider);
10414 ast.accept(visitor);
10415 for (ProxyConditionalAnalysisError conditionalCode in visitor.proxyCondi tionalAnalysisErrors) {
10416 if (conditionalCode.shouldIncludeErrorCode()) {
10417 visitor.reportError(conditionalCode.analysisError);
10418 }
10419 }
10420 }
10421 } finally {
10422 timeCounter.stop();
10423 }
10424 // Angular
10425 timeCounter = PerformanceStatistics.angular.start();
10426 try {
10427 for (ResolvableCompilationUnit unit in library.resolvableCompilationUnits) {
10428 Source source = unit.source;
10429 CompilationUnit ast = unit.compilationUnit;
10430 new AngularCompilationUnitBuilder(_errorListener, source, ast).build();
10431 }
10432 } finally {
10433 timeCounter.stop();
10434 }
10435 }
10436 }
10437
10438 /**
9952 * This class is used to replace uses of `HashMap<String, ExecutableElement>` wh ich are not as 10439 * This class is used to replace uses of `HashMap<String, ExecutableElement>` wh ich are not as
9953 * performant as this class. 10440 * performant as this class.
9954 */ 10441 */
9955 class MemberMap { 10442 class MemberMap {
9956 /** 10443 /**
9957 * The current size of this map. 10444 * The current size of this map.
9958 */ 10445 */
9959 int _size = 0; 10446 int _size = 0;
9960 10447
9961 /** 10448 /**
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
10151 */ 10638 */
10152 bool shouldIncludeErrorCode() { 10639 bool shouldIncludeErrorCode() {
10153 if (_enclosingElement is ClassElement) { 10640 if (_enclosingElement is ClassElement) {
10154 return !(_enclosingElement as ClassElement).isOrInheritsProxy; 10641 return !(_enclosingElement as ClassElement).isOrInheritsProxy;
10155 } 10642 }
10156 return true; 10643 return true;
10157 } 10644 }
10158 } 10645 }
10159 10646
10160 /** 10647 /**
10648 * Instances of the class `Library` represent the data about a single library du ring the
10649 * resolution of some (possibly different) library. They are not intended to be used except during
10650 * the resolution process.
10651 */
10652 class ResolvableLibrary {
10653 /**
10654 * The source specifying the defining compilation unit of this library.
10655 */
10656 Source librarySource;
10657
10658 /**
10659 * A list containing all of the libraries that are imported into this library.
10660 */
10661 List<ResolvableLibrary> _importedLibraries = _EMPTY_ARRAY;
10662
10663 /**
10664 * A flag indicating whether this library explicitly imports core.
10665 */
10666 bool explicitlyImportsCore = false;
10667
10668 /**
10669 * An array containing all of the libraries that are exported from this librar y.
10670 */
10671 List<ResolvableLibrary> _exportedLibraries = _EMPTY_ARRAY;
10672
10673 /**
10674 * An array containing the compilation units that comprise this library. The d efining compilation
10675 * unit is always first.
10676 */
10677 List<ResolvableCompilationUnit> _compilationUnits;
10678
10679 /**
10680 * The library element representing this library.
10681 */
10682 LibraryElementImpl _libraryElement;
10683
10684 /**
10685 * The listener to which analysis errors will be reported.
10686 */
10687 AnalysisErrorListener _errorListener;
10688
10689 /**
10690 * The inheritance manager which is used for member lookups in this library.
10691 */
10692 InheritanceManager _inheritanceManager;
10693
10694 /**
10695 * An empty array that can be used to initialize lists of libraries.
10696 */
10697 static List<ResolvableLibrary> _EMPTY_ARRAY = new List<ResolvableLibrary>(0);
10698
10699 /**
10700 * The library scope used when resolving elements within this library's compil ation units.
10701 */
10702 LibraryScope _libraryScope;
10703
10704 /**
10705 * Initialize a newly created data holder that can maintain the data associate d with a library.
10706 *
10707 * @param librarySource the source specifying the defining compilation unit of this library
10708 * @param errorListener the listener to which analysis errors will be reported
10709 */
10710 ResolvableLibrary(Source librarySource) {
10711 this.librarySource = librarySource;
10712 }
10713
10714 /**
10715 * Return the AST structure associated with the given source, or `null` if the source does
10716 * not represent a compilation unit that is included in this library.
10717 *
10718 * @param source the source representing the compilation unit whose AST is to be returned
10719 * @return the AST structure associated with the given source
10720 * @throws AnalysisException if an AST structure could not be created for the compilation unit
10721 */
10722 CompilationUnit getAST(Source source) {
10723 int count = _compilationUnits.length;
10724 for (int i = 0; i < count; i++) {
10725 if (_compilationUnits[i].source == source) {
10726 return _compilationUnits[i].compilationUnit;
10727 }
10728 }
10729 return null;
10730 }
10731
10732 /**
10733 * Return an array of the [CompilationUnit]s that make up the library. The fir st unit is
10734 * always the defining unit.
10735 *
10736 * @return an array of the [CompilationUnit]s that make up the library. The fi rst unit is
10737 * always the defining unit
10738 */
10739 List<CompilationUnit> get compilationUnits {
10740 int count = _compilationUnits.length;
10741 List<CompilationUnit> units = new List<CompilationUnit>(count);
10742 for (int i = 0; i < count; i++) {
10743 units[i] = _compilationUnits[i].compilationUnit;
10744 }
10745 return units;
10746 }
10747
10748 /**
10749 * Return an array containing the sources for the compilation units in this li brary, including the
10750 * defining compilation unit.
10751 *
10752 * @return the sources for the compilation units in this library
10753 */
10754 List<Source> get compilationUnitSources {
10755 int count = _compilationUnits.length;
10756 List<Source> sources = new List<Source>(count);
10757 for (int i = 0; i < count; i++) {
10758 sources[i] = _compilationUnits[i].source;
10759 }
10760 return sources;
10761 }
10762
10763 /**
10764 * Return the AST structure associated with the defining compilation unit for this library.
10765 *
10766 * @return the AST structure associated with the defining compilation unit for this library
10767 * @throws AnalysisException if an AST structure could not be created for the defining compilation
10768 * unit
10769 */
10770 CompilationUnit get definingCompilationUnit => _compilationUnits[0].compilatio nUnit;
10771
10772 /**
10773 * Return an array containing the libraries that are exported from this librar y.
10774 *
10775 * @return an array containing the libraries that are exported from this libra ry
10776 */
10777 List<ResolvableLibrary> get exports => _exportedLibraries;
10778
10779 /**
10780 * Return an array containing the libraries that are imported into this librar y.
10781 *
10782 * @return an array containing the libraries that are imported into this libra ry
10783 */
10784 List<ResolvableLibrary> get imports => _importedLibraries;
10785
10786 /**
10787 * Return an array containing the libraries that are either imported or export ed from this
10788 * library.
10789 *
10790 * @return the libraries that are either imported or exported from this librar y
10791 */
10792 List<ResolvableLibrary> get importsAndExports {
10793 Set<ResolvableLibrary> libraries = new Set<ResolvableLibrary>();
10794 for (ResolvableLibrary library in _importedLibraries) {
10795 libraries.add(library);
10796 }
10797 for (ResolvableLibrary library in _exportedLibraries) {
10798 libraries.add(library);
10799 }
10800 return new List.from(libraries);
10801 }
10802
10803 /**
10804 * Return the inheritance manager for this library.
10805 *
10806 * @return the inheritance manager for this library
10807 */
10808 InheritanceManager get inheritanceManager {
10809 if (_inheritanceManager == null) {
10810 return _inheritanceManager = new InheritanceManager(_libraryElement);
10811 }
10812 return _inheritanceManager;
10813 }
10814
10815 /**
10816 * Return the library element representing this library, creating it if necess ary.
10817 *
10818 * @return the library element representing this library
10819 */
10820 LibraryElementImpl get libraryElement => _libraryElement;
10821
10822 /**
10823 * Return the library scope used when resolving elements within this library's compilation units.
10824 *
10825 * @return the library scope used when resolving elements within this library' s compilation units
10826 */
10827 LibraryScope get libraryScope {
10828 if (_libraryScope == null) {
10829 _libraryScope = new LibraryScope(_libraryElement, _errorListener);
10830 }
10831 return _libraryScope;
10832 }
10833
10834 /**
10835 * Return the modification time associated with the given source.
10836 *
10837 * @param source the source representing the compilation unit whose modificati on time is to be
10838 * returned
10839 * @return the modification time associated with the given source
10840 * @throws AnalysisException if an AST structure could not be created for the compilation unit
10841 */
10842 int getModificationTime(Source source) {
10843 int count = _compilationUnits.length;
10844 for (int i = 0; i < count; i++) {
10845 if (source == _compilationUnits[i].source) {
10846 return _compilationUnits[i].modificationTime;
10847 }
10848 }
10849 return -1;
10850 }
10851
10852 /**
10853 * Return an array containing the compilation units that comprise this library . The defining
10854 * compilation unit is always first.
10855 *
10856 * @return the compilation units that comprise this library
10857 */
10858 List<ResolvableCompilationUnit> get resolvableCompilationUnits => _compilation Units;
10859
10860 /**
10861 * Set the compilation unit in this library to the given compilation units. Th e defining
10862 * compilation unit must be the first element of the array.
10863 *
10864 * @param units the compilation units in this library
10865 */
10866 void set resolvableCompilationUnits(List<ResolvableCompilationUnit> units) {
10867 _compilationUnits = units;
10868 }
10869
10870 /**
10871 * Set the listener to which analysis errors will be reported to be the given listener.
10872 *
10873 * @param errorListener the listener to which analysis errors will be reported
10874 */
10875 void set errorListener(AnalysisErrorListener errorListener) {
10876 this._errorListener = errorListener;
10877 }
10878
10879 /**
10880 * Set the libraries that are exported by this library to be those in the give n array.
10881 *
10882 * @param exportedLibraries the libraries that are exported by this library
10883 */
10884 void set exportedLibraries(List<ResolvableLibrary> exportedLibraries) {
10885 this._exportedLibraries = exportedLibraries;
10886 }
10887
10888 /**
10889 * Set the libraries that are imported into this library to be those in the gi ven array.
10890 *
10891 * @param importedLibraries the libraries that are imported into this library
10892 */
10893 void set importedLibraries(List<ResolvableLibrary> importedLibraries) {
10894 this._importedLibraries = importedLibraries;
10895 }
10896
10897 /**
10898 * Set the library element representing this library to the given library elem ent.
10899 *
10900 * @param libraryElement the library element representing this library
10901 */
10902 void set libraryElement(LibraryElementImpl libraryElement) {
10903 this._libraryElement = libraryElement;
10904 if (_inheritanceManager != null) {
10905 _inheritanceManager.libraryElement = libraryElement;
10906 }
10907 }
10908
10909 @override
10910 String toString() => librarySource.shortName;
10911 }
10912
10913 /**
10161 * Instances of the class `ResolverVisitor` are used to resolve the nodes within a single 10914 * Instances of the class `ResolverVisitor` are used to resolve the nodes within a single
10162 * compilation unit. 10915 * compilation unit.
10163 */ 10916 */
10164 class ResolverVisitor extends ScopedVisitor { 10917 class ResolverVisitor extends ScopedVisitor {
10165 /** 10918 /**
10166 * The manager for the inheritance mappings. 10919 * The manager for the inheritance mappings.
10167 */ 10920 */
10168 InheritanceManager _inheritanceManager; 10921 InheritanceManager _inheritanceManager;
10169 10922
10170 /** 10923 /**
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
10249 * @param errorListener the error listener that will be informed of any errors that are found 11002 * @param errorListener the error listener that will be informed of any errors that are found
10250 * during resolution 11003 * during resolution
10251 */ 11004 */
10252 ResolverVisitor.con3(LibraryElement definingLibrary, Source source, TypeProvid er typeProvider, Scope nameScope, AnalysisErrorListener errorListener) : super.c on3(definingLibrary, source, typeProvider, nameScope, errorListener) { 11005 ResolverVisitor.con3(LibraryElement definingLibrary, Source source, TypeProvid er typeProvider, Scope nameScope, AnalysisErrorListener errorListener) : super.c on3(definingLibrary, source, typeProvider, nameScope, errorListener) {
10253 this._inheritanceManager = new InheritanceManager(definingLibrary); 11006 this._inheritanceManager = new InheritanceManager(definingLibrary);
10254 this._elementResolver = new ElementResolver(this); 11007 this._elementResolver = new ElementResolver(this);
10255 this._typeAnalyzer = new StaticTypeAnalyzer(this); 11008 this._typeAnalyzer = new StaticTypeAnalyzer(this);
10256 } 11009 }
10257 11010
10258 /** 11011 /**
11012 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
11013 *
11014 * @param library the library containing the compilation unit being resolved
11015 * @param source the source representing the compilation unit being visited
11016 * @param typeProvider the object used to access the types from the core libra ry
11017 */
11018 ResolverVisitor.con4(ResolvableLibrary library, Source source, TypeProvider ty peProvider) : super.con4(library, source, typeProvider) {
11019 this._inheritanceManager = library.inheritanceManager;
11020 this._elementResolver = new ElementResolver(this);
11021 this._typeAnalyzer = new StaticTypeAnalyzer(this);
11022 }
11023
11024 /**
10259 * Return the object keeping track of which elements have had their types over ridden. 11025 * Return the object keeping track of which elements have had their types over ridden.
10260 * 11026 *
10261 * @return the object keeping track of which elements have had their types ove rridden 11027 * @return the object keeping track of which elements have had their types ove rridden
10262 */ 11028 */
10263 TypeOverrideManager get overrideManager => _overrideManager; 11029 TypeOverrideManager get overrideManager => _overrideManager;
10264 11030
10265 /** 11031 /**
10266 * Return the object keeping track of which elements have had their types prom oted. 11032 * Return the object keeping track of which elements have had their types prom oted.
10267 * 11033 *
10268 * @return the object keeping track of which elements have had their types pro moted 11034 * @return the object keeping track of which elements have had their types pro moted
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after
10985 } 11751 }
10986 11752
10987 /** 11753 /**
10988 * Report a conditional analysis error with the given error code and arguments . 11754 * Report a conditional analysis error with the given error code and arguments .
10989 * 11755 *
10990 * @param enclosingElement the enclosing element 11756 * @param enclosingElement the enclosing element
10991 * @param errorCode the error code of the error to be reported 11757 * @param errorCode the error code of the error to be reported
10992 * @param token the token specifying the location of the error 11758 * @param token the token specifying the location of the error
10993 * @param arguments the arguments to the error, used to compose the error mess age 11759 * @param arguments the arguments to the error, used to compose the error mess age
10994 */ 11760 */
10995 void reportErrorProxyConditionalAnalysisError(Element enclosingElement, ErrorC ode errorCode, sc.Token token, List<Object> arguments) { 11761 void reportProxyConditionalErrorForToken(Element enclosingElement, ErrorCode e rrorCode, sc.Token token, List<Object> arguments) {
10996 _proxyConditionalAnalysisErrors.add(new ProxyConditionalAnalysisError(enclos ingElement, new AnalysisError.con2(source, token.offset, token.length, errorCode , arguments))); 11762 _proxyConditionalAnalysisErrors.add(new ProxyConditionalAnalysisError(enclos ingElement, new AnalysisError.con2(source, token.offset, token.length, errorCode , arguments)));
10997 } 11763 }
10998 11764
10999 @override 11765 @override
11000 void visitForEachStatementInScope(ForEachStatement node) { 11766 void visitForEachStatementInScope(ForEachStatement node) {
11001 // 11767 //
11002 // We visit the iterator before the loop variable because the loop variable cannot be in scope 11768 // We visit the iterator before the loop variable because the loop variable cannot be in scope
11003 // while visiting the iterator. 11769 // while visiting the iterator.
11004 // 11770 //
11005 Expression iterator = node.iterator; 11771 Expression iterator = node.iterator;
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after
11546 */ 12312 */
11547 ScopedVisitor.con3(LibraryElement definingLibrary, Source source, TypeProvider typeProvider, Scope nameScope, AnalysisErrorListener errorListener) { 12313 ScopedVisitor.con3(LibraryElement definingLibrary, Source source, TypeProvider typeProvider, Scope nameScope, AnalysisErrorListener errorListener) {
11548 this._definingLibrary = definingLibrary; 12314 this._definingLibrary = definingLibrary;
11549 this.source = source; 12315 this.source = source;
11550 this._errorListener = errorListener; 12316 this._errorListener = errorListener;
11551 this._nameScope = nameScope; 12317 this._nameScope = nameScope;
11552 this.typeProvider = typeProvider; 12318 this.typeProvider = typeProvider;
11553 } 12319 }
11554 12320
11555 /** 12321 /**
12322 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
12323 *
12324 * @param library the library containing the compilation unit being resolved
12325 * @param source the source representing the compilation unit being visited
12326 * @param typeProvider the object used to access the types from the core libra ry
12327 */
12328 ScopedVisitor.con4(ResolvableLibrary library, Source source, TypeProvider type Provider) {
12329 this._definingLibrary = library.libraryElement;
12330 this.source = source;
12331 LibraryScope libraryScope = library.libraryScope;
12332 this._errorListener = libraryScope.errorListener;
12333 this._nameScope = libraryScope;
12334 this.typeProvider = typeProvider;
12335 }
12336
12337 /**
11556 * Return the library element for the library containing the compilation unit being resolved. 12338 * Return the library element for the library containing the compilation unit being resolved.
11557 * 12339 *
11558 * @return the library element for the library containing the compilation unit being resolved 12340 * @return the library element for the library containing the compilation unit being resolved
11559 */ 12341 */
11560 LibraryElement get definingLibrary => _definingLibrary; 12342 LibraryElement get definingLibrary => _definingLibrary;
11561 12343
11562 /** 12344 /**
11563 * Replaces the current [Scope] with the enclosing [Scope]. 12345 * Replaces the current [Scope] with the enclosing [Scope].
11564 * 12346 *
11565 * @return the enclosing [Scope]. 12347 * @return the enclosing [Scope].
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
11620 _nameScope = outerScope; 12402 _nameScope = outerScope;
11621 } 12403 }
11622 } else { 12404 } else {
11623 super.visitCatchClause(node); 12405 super.visitCatchClause(node);
11624 } 12406 }
11625 return null; 12407 return null;
11626 } 12408 }
11627 12409
11628 @override 12410 @override
11629 Object visitClassDeclaration(ClassDeclaration node) { 12411 Object visitClassDeclaration(ClassDeclaration node) {
12412 ClassElement classElement = node.element;
11630 Scope outerScope = _nameScope; 12413 Scope outerScope = _nameScope;
11631 try { 12414 try {
11632 _nameScope = new ClassScope(_nameScope, node.element); 12415 if (classElement == null) {
12416 AnalysisEngine.instance.logger.logInformation2("Missing element for cons tructor ${node.name.name} in ${definingLibrary.source.fullName}", new JavaExcept ion());
12417 } else {
12418 _nameScope = new ClassScope(_nameScope, classElement);
12419 }
11633 visitClassDeclarationInScope(node); 12420 visitClassDeclarationInScope(node);
11634 } finally { 12421 } finally {
11635 _nameScope = outerScope; 12422 _nameScope = outerScope;
11636 } 12423 }
11637 return null; 12424 return null;
11638 } 12425 }
11639 12426
11640 @override 12427 @override
11641 Object visitClassTypeAlias(ClassTypeAlias node) { 12428 Object visitClassTypeAlias(ClassTypeAlias node) {
11642 Scope outerScope = _nameScope; 12429 Scope outerScope = _nameScope;
11643 try { 12430 try {
11644 _nameScope = new ClassScope(_nameScope, node.element); 12431 _nameScope = new ClassScope(_nameScope, node.element);
11645 super.visitClassTypeAlias(node); 12432 super.visitClassTypeAlias(node);
11646 } finally { 12433 } finally {
11647 _nameScope = outerScope; 12434 _nameScope = outerScope;
11648 } 12435 }
11649 return null; 12436 return null;
11650 } 12437 }
11651 12438
11652 @override 12439 @override
11653 Object visitConstructorDeclaration(ConstructorDeclaration node) { 12440 Object visitConstructorDeclaration(ConstructorDeclaration node) {
12441 ConstructorElement constructorElement = node.element;
11654 Scope outerScope = _nameScope; 12442 Scope outerScope = _nameScope;
11655 try { 12443 try {
11656 _nameScope = new FunctionScope(_nameScope, node.element); 12444 if (constructorElement == null) {
12445 JavaStringBuilder builder = new JavaStringBuilder();
12446 builder.append("Missing element for constructor ");
12447 builder.append(node.returnType.name);
12448 if (node.name != null) {
12449 builder.append(".");
12450 builder.append(node.name.name);
12451 }
12452 builder.append(" in ");
12453 builder.append(definingLibrary.source.fullName);
12454 AnalysisEngine.instance.logger.logInformation2(builder.toString(), new J avaException());
12455 } else {
12456 _nameScope = new FunctionScope(_nameScope, constructorElement);
12457 }
11657 super.visitConstructorDeclaration(node); 12458 super.visitConstructorDeclaration(node);
11658 } finally { 12459 } finally {
11659 _nameScope = outerScope; 12460 _nameScope = outerScope;
11660 } 12461 }
11661 return null; 12462 return null;
11662 } 12463 }
11663 12464
11664 @override 12465 @override
11665 Object visitDeclaredIdentifier(DeclaredIdentifier node) { 12466 Object visitDeclaredIdentifier(DeclaredIdentifier node) {
11666 VariableElement element = node.element; 12467 VariableElement element = node.element;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
11722 visitForStatementInScope(node); 12523 visitForStatementInScope(node);
11723 } finally { 12524 } finally {
11724 _labelScope = outerLabelScope; 12525 _labelScope = outerLabelScope;
11725 _nameScope = outerNameScope; 12526 _nameScope = outerNameScope;
11726 } 12527 }
11727 return null; 12528 return null;
11728 } 12529 }
11729 12530
11730 @override 12531 @override
11731 Object visitFunctionDeclaration(FunctionDeclaration node) { 12532 Object visitFunctionDeclaration(FunctionDeclaration node) {
11732 ExecutableElement function = node.element; 12533 ExecutableElement functionElement = node.element;
11733 Scope outerScope = _nameScope; 12534 Scope outerScope = _nameScope;
11734 try { 12535 try {
11735 _nameScope = new FunctionScope(_nameScope, function); 12536 if (functionElement == null) {
12537 AnalysisEngine.instance.logger.logInformation2("Missing element for top- level function ${node.name.name} in ${definingLibrary.source.fullName}", new Jav aException());
12538 } else {
12539 _nameScope = new FunctionScope(_nameScope, functionElement);
12540 }
11736 super.visitFunctionDeclaration(node); 12541 super.visitFunctionDeclaration(node);
11737 } finally { 12542 } finally {
11738 _nameScope = outerScope; 12543 _nameScope = outerScope;
11739 } 12544 }
11740 if (function.enclosingElement is! CompilationUnitElement) { 12545 if (functionElement.enclosingElement is! CompilationUnitElement) {
11741 _nameScope.define(function); 12546 _nameScope.define(functionElement);
11742 } 12547 }
11743 return null; 12548 return null;
11744 } 12549 }
11745 12550
11746 @override 12551 @override
11747 Object visitFunctionExpression(FunctionExpression node) { 12552 Object visitFunctionExpression(FunctionExpression node) {
11748 if (node.parent is FunctionDeclaration) { 12553 if (node.parent is FunctionDeclaration) {
11749 // We have already created a function scope and don't need to do so again. 12554 // We have already created a function scope and don't need to do so again.
11750 super.visitFunctionExpression(node); 12555 super.visitFunctionExpression(node);
11751 } else { 12556 } else {
11752 Scope outerScope = _nameScope; 12557 Scope outerScope = _nameScope;
11753 try { 12558 try {
11754 ExecutableElement functionElement = node.element; 12559 ExecutableElement functionElement = node.element;
11755 if (functionElement == null) { 12560 if (functionElement == null) {
12561 JavaStringBuilder builder = new JavaStringBuilder();
12562 builder.append("Missing element for function ");
12563 AstNode parent = node.parent;
12564 while (parent != null) {
12565 if (parent is Declaration) {
12566 Element parentElement = (parent as Declaration).element;
12567 builder.append(parentElement == null ? "<unknown> " : ("${parentEl ement.name} "));
12568 }
12569 parent = parent.parent;
12570 }
12571 builder.append("in ");
12572 builder.append(definingLibrary.source.fullName);
12573 AnalysisEngine.instance.logger.logInformation2(builder.toString(), new JavaException());
11756 } else { 12574 } else {
11757 _nameScope = new FunctionScope(_nameScope, functionElement); 12575 _nameScope = new FunctionScope(_nameScope, functionElement);
11758 } 12576 }
11759 super.visitFunctionExpression(node); 12577 super.visitFunctionExpression(node);
11760 } finally { 12578 } finally {
11761 _nameScope = outerScope; 12579 _nameScope = outerScope;
11762 } 12580 }
11763 } 12581 }
11764 return null; 12582 return null;
11765 } 12583 }
(...skipping 26 matching lines...) Expand all
11792 } finally { 12610 } finally {
11793 _labelScope = outerScope; 12611 _labelScope = outerScope;
11794 } 12612 }
11795 return null; 12613 return null;
11796 } 12614 }
11797 12615
11798 @override 12616 @override
11799 Object visitMethodDeclaration(MethodDeclaration node) { 12617 Object visitMethodDeclaration(MethodDeclaration node) {
11800 Scope outerScope = _nameScope; 12618 Scope outerScope = _nameScope;
11801 try { 12619 try {
11802 _nameScope = new FunctionScope(_nameScope, node.element); 12620 ExecutableElement methodElement = node.element;
12621 if (methodElement == null) {
12622 AnalysisEngine.instance.logger.logInformation2("Missing element for meth od ${node.name.name} in ${definingLibrary.source.fullName}", new JavaException() );
12623 } else {
12624 _nameScope = new FunctionScope(_nameScope, methodElement);
12625 }
11803 super.visitMethodDeclaration(node); 12626 super.visitMethodDeclaration(node);
11804 } finally { 12627 } finally {
11805 _nameScope = outerScope; 12628 _nameScope = outerScope;
11806 } 12629 }
11807 return null; 12630 return null;
11808 } 12631 }
11809 12632
11810 @override 12633 @override
11811 Object visitSwitchCase(SwitchCase node) { 12634 Object visitSwitchCase(SwitchCase node) {
11812 node.expression.accept(this); 12635 node.expression.accept(this);
(...skipping 2781 matching lines...) Expand 10 before | Expand all | Expand 10 after
14594 * @param source the source representing the compilation unit containing the n ode being visited 15417 * @param source the source representing the compilation unit containing the n ode being visited
14595 * @param typeProvider the object used to access the types from the core libra ry 15418 * @param typeProvider the object used to access the types from the core libra ry
14596 * @param nameScope the scope used to resolve identifiers in the node that wil l first be visited 15419 * @param nameScope the scope used to resolve identifiers in the node that wil l first be visited
14597 * @param errorListener the error listener that will be informed of any errors that are found 15420 * @param errorListener the error listener that will be informed of any errors that are found
14598 * during resolution 15421 * during resolution
14599 */ 15422 */
14600 TypeResolverVisitor.con3(LibraryElement definingLibrary, Source source, TypePr ovider typeProvider, Scope nameScope, AnalysisErrorListener errorListener) : sup er.con3(definingLibrary, source, typeProvider, nameScope, errorListener) { 15423 TypeResolverVisitor.con3(LibraryElement definingLibrary, Source source, TypePr ovider typeProvider, Scope nameScope, AnalysisErrorListener errorListener) : sup er.con3(definingLibrary, source, typeProvider, nameScope, errorListener) {
14601 _dynamicType = typeProvider.dynamicType; 15424 _dynamicType = typeProvider.dynamicType;
14602 } 15425 }
14603 15426
15427 /**
15428 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
15429 *
15430 * @param library the library containing the compilation unit being resolved
15431 * @param source the source representing the compilation unit being visited
15432 * @param typeProvider the object used to access the types from the core libra ry
15433 */
15434 TypeResolverVisitor.con4(ResolvableLibrary library, Source source, TypeProvide r typeProvider) : super.con4(library, source, typeProvider) {
15435 _dynamicType = typeProvider.dynamicType;
15436 }
15437
14604 @override 15438 @override
14605 Object visitCatchClause(CatchClause node) { 15439 Object visitCatchClause(CatchClause node) {
14606 super.visitCatchClause(node); 15440 super.visitCatchClause(node);
14607 SimpleIdentifier exception = node.exceptionParameter; 15441 SimpleIdentifier exception = node.exceptionParameter;
14608 if (exception != null) { 15442 if (exception != null) {
14609 // If an 'on' clause is provided the type of the exception parameter is th e type in the 'on' 15443 // If an 'on' clause is provided the type of the exception parameter is th e type in the 'on'
14610 // clause. Otherwise, the type of the exception parameter is 'Object'. 15444 // clause. Otherwise, the type of the exception parameter is 'Object'.
14611 TypeName exceptionTypeName = node.exceptionType; 15445 TypeName exceptionTypeName = node.exceptionType;
14612 DartType exceptionType; 15446 DartType exceptionType;
14613 if (exceptionTypeName == null) { 15447 if (exceptionTypeName == null) {
(...skipping 1031 matching lines...) Expand 10 before | Expand all | Expand 10 after
15645 * 16479 *
15646 * @param definingLibrary the element for the library containing the node bein g visited 16480 * @param definingLibrary the element for the library containing the node bein g visited
15647 * @param source the source representing the compilation unit containing the n ode being visited 16481 * @param source the source representing the compilation unit containing the n ode being visited
15648 * @param typeProvider the object used to access the types from the core libra ry 16482 * @param typeProvider the object used to access the types from the core libra ry
15649 * @param nameScope the scope used to resolve identifiers in the node that wil l first be visited 16483 * @param nameScope the scope used to resolve identifiers in the node that wil l first be visited
15650 * @param errorListener the error listener that will be informed of any errors that are found 16484 * @param errorListener the error listener that will be informed of any errors that are found
15651 * during resolution 16485 * during resolution
15652 */ 16486 */
15653 VariableResolverVisitor.con2(LibraryElement definingLibrary, Source source, Ty peProvider typeProvider, Scope nameScope, AnalysisErrorListener errorListener) : super.con3(definingLibrary, source, typeProvider, nameScope, errorListener); 16487 VariableResolverVisitor.con2(LibraryElement definingLibrary, Source source, Ty peProvider typeProvider, Scope nameScope, AnalysisErrorListener errorListener) : super.con3(definingLibrary, source, typeProvider, nameScope, errorListener);
15654 16488
16489 /**
16490 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
16491 *
16492 * @param library the library containing the compilation unit being resolved
16493 * @param source the source representing the compilation unit being visited
16494 * @param typeProvider the object used to access the types from the core libra ry
16495 */
16496 VariableResolverVisitor.con3(ResolvableLibrary library, Source source, TypePro vider typeProvider) : super.con4(library, source, typeProvider);
16497
15655 @override 16498 @override
15656 Object visitFunctionDeclaration(FunctionDeclaration node) { 16499 Object visitFunctionDeclaration(FunctionDeclaration node) {
15657 ExecutableElement outerFunction = _enclosingFunction; 16500 ExecutableElement outerFunction = _enclosingFunction;
15658 try { 16501 try {
15659 _enclosingFunction = node.element; 16502 _enclosingFunction = node.element;
15660 return super.visitFunctionDeclaration(node); 16503 return super.visitFunctionDeclaration(node);
15661 } finally { 16504 } finally {
15662 _enclosingFunction = outerFunction; 16505 _enclosingFunction = outerFunction;
15663 } 16506 }
15664 } 16507 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
15736 * Instances of the class `ClassScope` implement the scope defined by a class. 16579 * Instances of the class `ClassScope` implement the scope defined by a class.
15737 */ 16580 */
15738 class ClassScope extends EnclosedScope { 16581 class ClassScope extends EnclosedScope {
15739 /** 16582 /**
15740 * Initialize a newly created scope enclosed within another scope. 16583 * Initialize a newly created scope enclosed within another scope.
15741 * 16584 *
15742 * @param enclosingScope the scope in which this scope is lexically enclosed 16585 * @param enclosingScope the scope in which this scope is lexically enclosed
15743 * @param typeElement the element representing the type represented by this sc ope 16586 * @param typeElement the element representing the type represented by this sc ope
15744 */ 16587 */
15745 ClassScope(Scope enclosingScope, ClassElement typeElement) : super(new Enclose dScope(enclosingScope)) { 16588 ClassScope(Scope enclosingScope, ClassElement typeElement) : super(new Enclose dScope(enclosingScope)) {
16589 if (typeElement == null) {
16590 throw new IllegalArgumentException("class element cannot be null");
16591 }
15746 _defineTypeParameters(typeElement); 16592 _defineTypeParameters(typeElement);
15747 _defineMembers(typeElement); 16593 _defineMembers(typeElement);
15748 } 16594 }
15749 16595
15750 @override 16596 @override
15751 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) { 16597 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) {
15752 if (existing is PropertyAccessorElement && duplicate is MethodElement) { 16598 if (existing is PropertyAccessorElement && duplicate is MethodElement) {
15753 if (existing.nameOffset < duplicate.nameOffset) { 16599 if (existing.nameOffset < duplicate.nameOffset) {
15754 return new AnalysisError.con2(duplicate.source, duplicate.nameOffset, du plicate.displayName.length, CompileTimeErrorCode.METHOD_AND_GETTER_WITH_SAME_NAM E, [existing.displayName]); 16600 return new AnalysisError.con2(duplicate.source, duplicate.nameOffset, du plicate.displayName.length, CompileTimeErrorCode.METHOD_AND_GETTER_WITH_SAME_NAM E, [existing.displayName]);
15755 } else { 16601 } else {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
15864 16710
15865 bool _parametersDefined = false; 16711 bool _parametersDefined = false;
15866 16712
15867 /** 16713 /**
15868 * Initialize a newly created scope enclosed within another scope. 16714 * Initialize a newly created scope enclosed within another scope.
15869 * 16715 *
15870 * @param enclosingScope the scope in which this scope is lexically enclosed 16716 * @param enclosingScope the scope in which this scope is lexically enclosed
15871 * @param functionElement the element representing the type represented by thi s scope 16717 * @param functionElement the element representing the type represented by thi s scope
15872 */ 16718 */
15873 FunctionScope(Scope enclosingScope, ExecutableElement functionElement) : super (new EnclosedScope(enclosingScope)) { 16719 FunctionScope(Scope enclosingScope, ExecutableElement functionElement) : super (new EnclosedScope(enclosingScope)) {
16720 if (functionElement == null) {
16721 throw new IllegalArgumentException("function element cannot be null");
16722 }
15874 this._functionElement = functionElement; 16723 this._functionElement = functionElement;
15875 } 16724 }
15876 16725
15877 /** 16726 /**
15878 * Define the parameters for the given function in the scope that encloses thi s function. 16727 * Define the parameters for the given function in the scope that encloses thi s function.
15879 */ 16728 */
15880 void defineParameters() { 16729 void defineParameters() {
15881 if (_parametersDefined) { 16730 if (_parametersDefined) {
15882 return; 16731 return;
15883 } 16732 }
(...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after
16765 Scope _scopeForAstNode(AstNode node) { 17614 Scope _scopeForAstNode(AstNode node) {
16766 if (node is CompilationUnit) { 17615 if (node is CompilationUnit) {
16767 return _scopeForCompilationUnit(node); 17616 return _scopeForCompilationUnit(node);
16768 } 17617 }
16769 AstNode parent = node.parent; 17618 AstNode parent = node.parent;
16770 if (parent == null) { 17619 if (parent == null) {
16771 throw new AnalysisException.con1("Cannot create scope: node is not part of a CompilationUnit"); 17620 throw new AnalysisException.con1("Cannot create scope: node is not part of a CompilationUnit");
16772 } 17621 }
16773 Scope scope = _scopeForAstNode(parent); 17622 Scope scope = _scopeForAstNode(parent);
16774 if (node is ClassDeclaration) { 17623 if (node is ClassDeclaration) {
16775 scope = new ClassScope(scope, node.element); 17624 ClassElement element = node.element;
17625 if (element == null) {
17626 throw new AnalysisException.con1("Cannot build a scope for an unresolved class");
17627 }
17628 scope = new ClassScope(scope, element);
16776 } else if (node is ClassTypeAlias) { 17629 } else if (node is ClassTypeAlias) {
16777 scope = new ClassScope(scope, node.element); 17630 ClassElement element = node.element;
17631 if (element == null) {
17632 throw new AnalysisException.con1("Cannot build a scope for an unresolved class type alias");
17633 }
17634 scope = new ClassScope(scope, element);
16778 } else if (node is ConstructorDeclaration) { 17635 } else if (node is ConstructorDeclaration) {
16779 FunctionScope functionScope = new FunctionScope(scope, node.element); 17636 ConstructorElement element = node.element;
17637 if (element == null) {
17638 throw new AnalysisException.con1("Cannot build a scope for an unresolved constructor");
17639 }
17640 FunctionScope functionScope = new FunctionScope(scope, element);
16780 functionScope.defineParameters(); 17641 functionScope.defineParameters();
16781 scope = functionScope; 17642 scope = functionScope;
16782 } else if (node is FunctionDeclaration) { 17643 } else if (node is FunctionDeclaration) {
16783 FunctionScope functionScope = new FunctionScope(scope, node.element); 17644 ExecutableElement element = node.element;
17645 if (element == null) {
17646 throw new AnalysisException.con1("Cannot build a scope for an unresolved function");
17647 }
17648 FunctionScope functionScope = new FunctionScope(scope, element);
16784 functionScope.defineParameters(); 17649 functionScope.defineParameters();
16785 scope = functionScope; 17650 scope = functionScope;
16786 } else if (node is FunctionTypeAlias) { 17651 } else if (node is FunctionTypeAlias) {
16787 scope = new FunctionTypeScope(scope, node.element); 17652 scope = new FunctionTypeScope(scope, node.element);
16788 } else if (node is MethodDeclaration) { 17653 } else if (node is MethodDeclaration) {
16789 FunctionScope functionScope = new FunctionScope(scope, node.element); 17654 ExecutableElement element = node.element;
17655 if (element == null) {
17656 throw new AnalysisException.con1("Cannot build a scope for an unresolved method");
17657 }
17658 FunctionScope functionScope = new FunctionScope(scope, element);
16790 functionScope.defineParameters(); 17659 functionScope.defineParameters();
16791 scope = functionScope; 17660 scope = functionScope;
16792 } 17661 }
16793 return scope; 17662 return scope;
16794 } 17663 }
16795 17664
16796 Scope _scopeForCompilationUnit(CompilationUnit node) { 17665 Scope _scopeForCompilationUnit(CompilationUnit node) {
16797 CompilationUnitElement unitElement = node.element; 17666 CompilationUnitElement unitElement = node.element;
16798 if (unitElement == null) { 17667 if (unitElement == null) {
16799 throw new AnalysisException.con1("Cannot create scope: compilation unit is not resolved"); 17668 throw new AnalysisException.con1("Cannot create scope: compilation unit is not resolved");
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after
17500 } finally { 18369 } finally {
17501 _isInNativeClass = false; 18370 _isInNativeClass = false;
17502 _initialFieldElementsMap = null; 18371 _initialFieldElementsMap = null;
17503 _enclosingClass = outerClass; 18372 _enclosingClass = outerClass;
17504 } 18373 }
17505 } 18374 }
17506 18375
17507 @override 18376 @override
17508 Object visitClassTypeAlias(ClassTypeAlias node) { 18377 Object visitClassTypeAlias(ClassTypeAlias node) {
17509 _checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_ID ENTIFIER_AS_TYPEDEF_NAME); 18378 _checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_ID ENTIFIER_AS_TYPEDEF_NAME);
18379 _checkForExtendsDisallowedClassInTypeAlias(node);
18380 _checkForImplementsDisallowedClass(node.implementsClause);
17510 _checkForAllMixinErrorCodes(node.withClause); 18381 _checkForAllMixinErrorCodes(node.withClause);
17511 ClassElement outerClassElement = _enclosingClass; 18382 ClassElement outerClassElement = _enclosingClass;
17512 try { 18383 try {
17513 _enclosingClass = node.element; 18384 _enclosingClass = node.element;
17514 _checkForRecursiveInterfaceInheritance(node.element); 18385 _checkForRecursiveInterfaceInheritance(node.element);
17515 _checkForTypeAliasCannotReferenceItself_mixin(node); 18386 _checkForTypeAliasCannotReferenceItself_mixin(node);
17516 } finally { 18387 } finally {
17517 _enclosingClass = outerClassElement; 18388 _enclosingClass = outerClassElement;
17518 } 18389 }
17519 return super.visitClassTypeAlias(node); 18390 return super.visitClassTypeAlias(node);
(...skipping 2214 matching lines...) Expand 10 before | Expand all | Expand 10 after
19734 * @see CompileTimeErrorCode#EXTENDS_DISALLOWED_CLASS 20605 * @see CompileTimeErrorCode#EXTENDS_DISALLOWED_CLASS
19735 */ 20606 */
19736 bool _checkForExtendsDisallowedClass(ExtendsClause node) { 20607 bool _checkForExtendsDisallowedClass(ExtendsClause node) {
19737 if (node == null) { 20608 if (node == null) {
19738 return false; 20609 return false;
19739 } 20610 }
19740 return _checkForExtendsOrImplementsDisallowedClass(node.superclass, CompileT imeErrorCode.EXTENDS_DISALLOWED_CLASS); 20611 return _checkForExtendsOrImplementsDisallowedClass(node.superclass, CompileT imeErrorCode.EXTENDS_DISALLOWED_CLASS);
19741 } 20612 }
19742 20613
19743 /** 20614 /**
20615 * This verifies that the passed type alias does not extend classes such as nu m or String.
20616 *
20617 * @param node the extends clause to test
20618 * @return `true` if and only if an error code is generated on the passed node
20619 * @see CompileTimeErrorCode#EXTENDS_DISALLOWED_CLASS
20620 */
20621 bool _checkForExtendsDisallowedClassInTypeAlias(ClassTypeAlias node) {
20622 if (node == null) {
20623 return false;
20624 }
20625 return _checkForExtendsOrImplementsDisallowedClass(node.superclass, CompileT imeErrorCode.EXTENDS_DISALLOWED_CLASS);
20626 }
20627
20628 /**
19744 * This verifies that the passed type name does not extend or implement classe s such as 'num' or 20629 * This verifies that the passed type name does not extend or implement classe s such as 'num' or
19745 * 'String'. 20630 * 'String'.
19746 * 20631 *
19747 * @param node the type name to test 20632 * @param node the type name to test
19748 * @return `true` if and only if an error code is generated on the passed node 20633 * @return `true` if and only if an error code is generated on the passed node
19749 * @see #checkForExtendsDisallowedClass(ExtendsClause) 20634 * @see #checkForExtendsDisallowedClass(ExtendsClause)
19750 * @see #checkForImplementsDisallowedClass(ImplementsClause) 20635 * @see #checkForImplementsDisallowedClass(ImplementsClause)
19751 * @see CompileTimeErrorCode#EXTENDS_DISALLOWED_CLASS 20636 * @see CompileTimeErrorCode#EXTENDS_DISALLOWED_CLASS
19752 * @see CompileTimeErrorCode#IMPLEMENTS_DISALLOWED_CLASS 20637 * @see CompileTimeErrorCode#IMPLEMENTS_DISALLOWED_CLASS
19753 */ 20638 */
(...skipping 2401 matching lines...) Expand 10 before | Expand all | Expand 10 after
22155 this.message = message; 23040 this.message = message;
22156 this.correction9 = correction; 23041 this.correction9 = correction;
22157 } 23042 }
22158 23043
22159 @override 23044 @override
22160 String get correction => correction9; 23045 String get correction => correction9;
22161 23046
22162 @override 23047 @override
22163 ErrorSeverity get errorSeverity => type.severity; 23048 ErrorSeverity get errorSeverity => type.severity;
22164 } 23049 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698