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

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

Issue 1008583002: Fix hints (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 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 library engine.resolver; 5 library engine.resolver;
6 6
7 import "dart:math" as math; 7 import "dart:math" as math;
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:analyzer/src/generated/utilities_collection.dart'; 10 import 'package:analyzer/src/generated/utilities_collection.dart';
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 } 233 }
234 String rhsNameStr = typeName.name.name; 234 String rhsNameStr = typeName.name.name;
235 // if x is dynamic 235 // if x is dynamic
236 if (rhsType.isDynamic && rhsNameStr == sc.Keyword.DYNAMIC.syntax) { 236 if (rhsType.isDynamic && rhsNameStr == sc.Keyword.DYNAMIC.syntax) {
237 if (node.notOperator == null) { 237 if (node.notOperator == null) {
238 // the is case 238 // the is case
239 _errorReporter.reportErrorForNode( 239 _errorReporter.reportErrorForNode(
240 HintCode.UNNECESSARY_TYPE_CHECK_TRUE, node); 240 HintCode.UNNECESSARY_TYPE_CHECK_TRUE, node);
241 } else { 241 } else {
242 // the is not case 242 // the is not case
243 _errorReporter 243 _errorReporter.reportErrorForNode(
244 .reportErrorForNode(HintCode.UNNECESSARY_TYPE_CHECK_FALSE, node); 244 HintCode.UNNECESSARY_TYPE_CHECK_FALSE, node);
245 } 245 }
246 return true; 246 return true;
247 } 247 }
248 Element rhsElement = rhsType.element; 248 Element rhsElement = rhsType.element;
249 LibraryElement libraryElement = 249 LibraryElement libraryElement =
250 rhsElement != null ? rhsElement.library : null; 250 rhsElement != null ? rhsElement.library : null;
251 if (libraryElement != null && libraryElement.isDartCore) { 251 if (libraryElement != null && libraryElement.isDartCore) {
252 // if x is Object or null is Null 252 // if x is Object or null is Null
253 if (rhsType.isObject || 253 if (rhsType.isObject ||
254 (expression is NullLiteral && rhsNameStr == _NULL_TYPE_NAME)) { 254 (expression is NullLiteral && rhsNameStr == _NULL_TYPE_NAME)) {
255 if (node.notOperator == null) { 255 if (node.notOperator == null) {
256 // the is case 256 // the is case
257 _errorReporter.reportErrorForNode( 257 _errorReporter.reportErrorForNode(
258 HintCode.UNNECESSARY_TYPE_CHECK_TRUE, node); 258 HintCode.UNNECESSARY_TYPE_CHECK_TRUE, node);
259 } else { 259 } else {
260 // the is not case 260 // the is not case
261 _errorReporter 261 _errorReporter.reportErrorForNode(
262 .reportErrorForNode(HintCode.UNNECESSARY_TYPE_CHECK_FALSE, node); 262 HintCode.UNNECESSARY_TYPE_CHECK_FALSE, node);
263 } 263 }
264 return true; 264 return true;
265 } else if (rhsNameStr == _NULL_TYPE_NAME) { 265 } else if (rhsNameStr == _NULL_TYPE_NAME) {
266 if (node.notOperator == null) { 266 if (node.notOperator == null) {
267 // the is case 267 // the is case
268 _errorReporter.reportErrorForNode(HintCode.TYPE_CHECK_IS_NULL, node); 268 _errorReporter.reportErrorForNode(HintCode.TYPE_CHECK_IS_NULL, node);
269 } else { 269 } else {
270 // the is not case 270 // the is not case
271 _errorReporter 271 _errorReporter.reportErrorForNode(
272 .reportErrorForNode(HintCode.TYPE_CHECK_IS_NOT_NULL, node); 272 HintCode.TYPE_CHECK_IS_NOT_NULL, node);
273 } 273 }
274 return true; 274 return true;
275 } 275 }
276 } 276 }
277 return false; 277 return false;
278 } 278 }
279 279
280 /** 280 /**
281 * This verifies that the passed expression can be assigned to its correspondi ng parameters. 281 * This verifies that the passed expression can be assigned to its correspondi ng parameters.
282 * 282 *
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 * See [CompileTimeErrorCode.IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION]. 535 * See [CompileTimeErrorCode.IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION].
536 */ 536 */
537 bool _checkForLoadLibraryFunction( 537 bool _checkForLoadLibraryFunction(
538 ImportDirective node, ImportElement importElement) { 538 ImportDirective node, ImportElement importElement) {
539 LibraryElement importedLibrary = importElement.importedLibrary; 539 LibraryElement importedLibrary = importElement.importedLibrary;
540 if (importedLibrary == null) { 540 if (importedLibrary == null) {
541 return false; 541 return false;
542 } 542 }
543 if (importedLibrary.hasLoadLibraryFunction) { 543 if (importedLibrary.hasLoadLibraryFunction) {
544 _errorReporter.reportErrorForNode( 544 _errorReporter.reportErrorForNode(
545 HintCode.IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION, node, [ 545 HintCode.IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION, node,
546 importedLibrary.name 546 [importedLibrary.name]);
547 ]);
548 return true; 547 return true;
549 } 548 }
550 return false; 549 return false;
551 } 550 }
552 551
553 /** 552 /**
554 * Generate a hint for functions or methods that have a return type, but do no t have a return 553 * Generate a hint for functions or methods that have a return type, but do no t have a return
555 * statement on all branches. At the end of blocks with no return, Dart implic itly returns 554 * statement on all branches. At the end of blocks with no return, Dart implic itly returns
556 * `null`, avoiding these implicit returns is considered a best practice. 555 * `null`, avoiding these implicit returns is considered a best practice.
557 * 556 *
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 } 736 }
738 _defineMembers(typeElement); 737 _defineMembers(typeElement);
739 } 738 }
740 739
741 @override 740 @override
742 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) { 741 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) {
743 if (existing is PropertyAccessorElement && duplicate is MethodElement) { 742 if (existing is PropertyAccessorElement && duplicate is MethodElement) {
744 if (existing.nameOffset < duplicate.nameOffset) { 743 if (existing.nameOffset < duplicate.nameOffset) {
745 return new AnalysisError.con2(duplicate.source, duplicate.nameOffset, 744 return new AnalysisError.con2(duplicate.source, duplicate.nameOffset,
746 duplicate.displayName.length, 745 duplicate.displayName.length,
747 CompileTimeErrorCode.METHOD_AND_GETTER_WITH_SAME_NAME, [ 746 CompileTimeErrorCode.METHOD_AND_GETTER_WITH_SAME_NAME,
748 existing.displayName 747 [existing.displayName]);
749 ]);
750 } else { 748 } else {
751 return new AnalysisError.con2(existing.source, existing.nameOffset, 749 return new AnalysisError.con2(existing.source, existing.nameOffset,
752 existing.displayName.length, 750 existing.displayName.length,
753 CompileTimeErrorCode.GETTER_AND_METHOD_WITH_SAME_NAME, [ 751 CompileTimeErrorCode.GETTER_AND_METHOD_WITH_SAME_NAME,
754 existing.displayName 752 [existing.displayName]);
755 ]);
756 } 753 }
757 } 754 }
758 return super.getErrorForDuplicate(existing, duplicate); 755 return super.getErrorForDuplicate(existing, duplicate);
759 } 756 }
760 757
761 /** 758 /**
762 * Define the instance members defined by the class. 759 * Define the instance members defined by the class.
763 * 760 *
764 * @param typeElement the element representing the type represented by this sc ope 761 * @param typeElement the element representing the type represented by this sc ope
765 */ 762 */
(...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after
1518 _getConstantBooleanValue(conditionExpression); 1515 _getConstantBooleanValue(conditionExpression);
1519 if (result != null) { 1516 if (result != null) {
1520 if (result.value.isTrue) { 1517 if (result.value.isTrue) {
1521 // report error on else block: true ? 1 : !2! 1518 // report error on else block: true ? 1 : !2!
1522 _errorReporter.reportErrorForNode( 1519 _errorReporter.reportErrorForNode(
1523 HintCode.DEAD_CODE, node.elseExpression); 1520 HintCode.DEAD_CODE, node.elseExpression);
1524 _safelyVisit(node.thenExpression); 1521 _safelyVisit(node.thenExpression);
1525 return null; 1522 return null;
1526 } else { 1523 } else {
1527 // report error on if block: false ? !1! : 2 1524 // report error on if block: false ? !1! : 2
1528 _errorReporter 1525 _errorReporter.reportErrorForNode(
1529 .reportErrorForNode(HintCode.DEAD_CODE, node.thenExpression); 1526 HintCode.DEAD_CODE, node.thenExpression);
1530 _safelyVisit(node.elseExpression); 1527 _safelyVisit(node.elseExpression);
1531 return null; 1528 return null;
1532 } 1529 }
1533 } 1530 }
1534 } 1531 }
1535 return super.visitConditionalExpression(node); 1532 return super.visitConditionalExpression(node);
1536 } 1533 }
1537 1534
1538 @override 1535 @override
1539 Object visitIfStatement(IfStatement node) { 1536 Object visitIfStatement(IfStatement node) {
1540 Expression conditionExpression = node.condition; 1537 Expression conditionExpression = node.condition;
1541 _safelyVisit(conditionExpression); 1538 _safelyVisit(conditionExpression);
1542 if (!_isDebugConstant(conditionExpression)) { 1539 if (!_isDebugConstant(conditionExpression)) {
1543 EvaluationResultImpl result = 1540 EvaluationResultImpl result =
1544 _getConstantBooleanValue(conditionExpression); 1541 _getConstantBooleanValue(conditionExpression);
1545 if (result != null) { 1542 if (result != null) {
1546 if (result.value.isTrue) { 1543 if (result.value.isTrue) {
1547 // report error on else block: if(true) {} else {!} 1544 // report error on else block: if(true) {} else {!}
1548 Statement elseStatement = node.elseStatement; 1545 Statement elseStatement = node.elseStatement;
1549 if (elseStatement != null) { 1546 if (elseStatement != null) {
1550 _errorReporter.reportErrorForNode( 1547 _errorReporter.reportErrorForNode(
1551 HintCode.DEAD_CODE, elseStatement); 1548 HintCode.DEAD_CODE, elseStatement);
1552 _safelyVisit(node.thenStatement); 1549 _safelyVisit(node.thenStatement);
1553 return null; 1550 return null;
1554 } 1551 }
1555 } else { 1552 } else {
1556 // report error on if block: if (false) {!} else {} 1553 // report error on if block: if (false) {!} else {}
1557 _errorReporter 1554 _errorReporter.reportErrorForNode(
1558 .reportErrorForNode(HintCode.DEAD_CODE, node.thenStatement); 1555 HintCode.DEAD_CODE, node.thenStatement);
1559 _safelyVisit(node.elseStatement); 1556 _safelyVisit(node.elseStatement);
1560 return null; 1557 return null;
1561 } 1558 }
1562 } 1559 }
1563 } 1560 }
1564 return super.visitIfStatement(node); 1561 return super.visitIfStatement(node);
1565 } 1562 }
1566 1563
1567 @override 1564 @override
1568 Object visitSwitchCase(SwitchCase node) { 1565 Object visitSwitchCase(SwitchCase node) {
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
1734 bool _isDebugConstant(Expression expression) { 1731 bool _isDebugConstant(Expression expression) {
1735 Element element = null; 1732 Element element = null;
1736 if (expression is Identifier) { 1733 if (expression is Identifier) {
1737 Identifier identifier = expression; 1734 Identifier identifier = expression;
1738 element = identifier.staticElement; 1735 element = identifier.staticElement;
1739 } else if (expression is PropertyAccess) { 1736 } else if (expression is PropertyAccess) {
1740 PropertyAccess propertyAccess = expression; 1737 PropertyAccess propertyAccess = expression;
1741 element = propertyAccess.propertyName.staticElement; 1738 element = propertyAccess.propertyName.staticElement;
1742 } 1739 }
1743 if (element is PropertyAccessorElement) { 1740 if (element is PropertyAccessorElement) {
1744 PropertyAccessorElement pae = element as PropertyAccessorElement; 1741 PropertyInducingElement variable = element.variable;
1745 PropertyInducingElement variable = pae.variable;
1746 return variable != null && variable.isConst; 1742 return variable != null && variable.isConst;
1747 } 1743 }
1748 return false; 1744 return false;
1749 } 1745 }
1750 1746
1751 /** 1747 /**
1752 * If the given node is not `null`, visit this instance of the dead code verif ier. 1748 * If the given node is not `null`, visit this instance of the dead code verif ier.
1753 * 1749 *
1754 * @param node the node to be visited 1750 * @param node the node to be visited
1755 */ 1751 */
(...skipping 1351 matching lines...) Expand 10 before | Expand all | Expand 10 after
3107 FunctionElementImpl initializer = 3103 FunctionElementImpl initializer =
3108 new FunctionElementImpl.forOffset(node.initializer.beginToken.offset); 3104 new FunctionElementImpl.forOffset(node.initializer.beginToken.offset);
3109 initializer.functions = holder.functions; 3105 initializer.functions = holder.functions;
3110 initializer.labels = holder.labels; 3106 initializer.labels = holder.labels;
3111 initializer.localVariables = holder.localVariables; 3107 initializer.localVariables = holder.localVariables;
3112 initializer.synthetic = true; 3108 initializer.synthetic = true;
3113 element.initializer = initializer; 3109 element.initializer = initializer;
3114 holder.validate(); 3110 holder.validate();
3115 } 3111 }
3116 if (element is PropertyInducingElementImpl) { 3112 if (element is PropertyInducingElementImpl) {
3117 PropertyInducingElementImpl variable =
3118 element as PropertyInducingElementImpl;
3119 if (_inFieldContext) { 3113 if (_inFieldContext) {
3120 (variable as FieldElementImpl).static = 3114 (element as FieldElementImpl).static =
3121 (node.parent.parent as FieldDeclaration).isStatic; 3115 (node.parent.parent as FieldDeclaration).isStatic;
3122 } 3116 }
3123 PropertyAccessorElementImpl getter = 3117 PropertyAccessorElementImpl getter =
3124 new PropertyAccessorElementImpl.forVariable(variable); 3118 new PropertyAccessorElementImpl.forVariable(element);
3125 getter.getter = true; 3119 getter.getter = true;
3126 _currentHolder.addAccessor(getter); 3120 _currentHolder.addAccessor(getter);
3127 variable.getter = getter; 3121 element.getter = getter;
3128 if (!isConst && !isFinal) { 3122 if (!isConst && !isFinal) {
3129 PropertyAccessorElementImpl setter = 3123 PropertyAccessorElementImpl setter =
3130 new PropertyAccessorElementImpl.forVariable(variable); 3124 new PropertyAccessorElementImpl.forVariable(element);
3131 setter.setter = true; 3125 setter.setter = true;
3132 ParameterElementImpl parameter = 3126 ParameterElementImpl parameter =
3133 new ParameterElementImpl("_${variable.name}", variable.nameOffset); 3127 new ParameterElementImpl("_${element.name}", element.nameOffset);
3134 parameter.synthetic = true; 3128 parameter.synthetic = true;
3135 parameter.parameterKind = ParameterKind.REQUIRED; 3129 parameter.parameterKind = ParameterKind.REQUIRED;
3136 setter.parameters = <ParameterElement>[parameter]; 3130 setter.parameters = <ParameterElement>[parameter];
3137 _currentHolder.addAccessor(setter); 3131 _currentHolder.addAccessor(setter);
3138 variable.setter = setter; 3132 element.setter = setter;
3139 } 3133 }
3140 } 3134 }
3141 return null; 3135 return null;
3142 } 3136 }
3143 3137
3144 /** 3138 /**
3145 * Build the table mapping field names to field elements for the fields define d in the current 3139 * Build the table mapping field names to field elements for the fields define d in the current
3146 * class. 3140 * class.
3147 * 3141 *
3148 * @param fields the field elements defined in the current class 3142 * @param fields the field elements defined in the current class
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
3200 * Return the body of the function that contains the given parameter, or `null ` if no 3194 * Return the body of the function that contains the given parameter, or `null ` if no
3201 * function body could be found. 3195 * function body could be found.
3202 * 3196 *
3203 * @param node the parameter contained in the function whose body is to be ret urned 3197 * @param node the parameter contained in the function whose body is to be ret urned
3204 * @return the body of the function that contains the given parameter 3198 * @return the body of the function that contains the given parameter
3205 */ 3199 */
3206 FunctionBody _getFunctionBody(FormalParameter node) { 3200 FunctionBody _getFunctionBody(FormalParameter node) {
3207 AstNode parent = node.parent; 3201 AstNode parent = node.parent;
3208 while (parent != null) { 3202 while (parent != null) {
3209 if (parent is ConstructorDeclaration) { 3203 if (parent is ConstructorDeclaration) {
3210 return (parent as ConstructorDeclaration).body; 3204 return parent.body;
3211 } else if (parent is FunctionExpression) { 3205 } else if (parent is FunctionExpression) {
3212 return (parent as FunctionExpression).body; 3206 return parent.body;
3213 } else if (parent is MethodDeclaration) { 3207 } else if (parent is MethodDeclaration) {
3214 return (parent as MethodDeclaration).body; 3208 return parent.body;
3215 } 3209 }
3216 parent = parent.parent; 3210 parent = parent.parent;
3217 } 3211 }
3218 return null; 3212 return null;
3219 } 3213 }
3220 3214
3221 /** 3215 /**
3222 * Sets the visible source range for formal parameter. 3216 * Sets the visible source range for formal parameter.
3223 */ 3217 */
3224 void _setParameterVisibleRange( 3218 void _setParameterVisibleRange(
(...skipping 1509 matching lines...) Expand 10 before | Expand all | Expand 10 after
4734 // can report the problem. 4728 // can report the problem.
4735 parseUriWithException(scriptSourcePath); 4729 parseUriWithException(scriptSourcePath);
4736 Source scriptSource = 4730 Source scriptSource =
4737 _context.sourceFactory.resolveUri(htmlSource, scriptSourcePath); 4731 _context.sourceFactory.resolveUri(htmlSource, scriptSourcePath);
4738 script.scriptSource = scriptSource; 4732 script.scriptSource = scriptSource;
4739 if (!_context.exists(scriptSource)) { 4733 if (!_context.exists(scriptSource)) {
4740 _reportValueError(HtmlWarningCode.URI_DOES_NOT_EXIST, 4734 _reportValueError(HtmlWarningCode.URI_DOES_NOT_EXIST,
4741 scriptAttribute, [scriptSourcePath]); 4735 scriptAttribute, [scriptSourcePath]);
4742 } 4736 }
4743 } on URISyntaxException catch (exception) { 4737 } on URISyntaxException catch (exception) {
4744 _reportValueError(HtmlWarningCode.INVALID_URI, scriptAttribute, [ 4738 _reportValueError(HtmlWarningCode.INVALID_URI, scriptAttribute,
4745 scriptSourcePath 4739 [scriptSourcePath]);
4746 ]);
4747 } 4740 }
4748 } 4741 }
4749 node.scriptElement = script; 4742 node.scriptElement = script;
4750 _scripts.add(script); 4743 _scripts.add(script);
4751 } 4744 }
4752 } finally { 4745 } finally {
4753 _parentNodes.remove(node); 4746 _parentNodes.remove(node);
4754 } 4747 }
4755 return null; 4748 return null;
4756 } 4749 }
(...skipping 2633 matching lines...) Expand 10 before | Expand all | Expand 10 after
7390 _definingLibrary.context, foundElement, element); 7383 _definingLibrary.context, foundElement, element);
7391 } 7384 }
7392 } 7385 }
7393 } 7386 }
7394 if (foundElement is MultiplyDefinedElementImpl) { 7387 if (foundElement is MultiplyDefinedElementImpl) {
7395 foundElement = _removeSdkElements( 7388 foundElement = _removeSdkElements(
7396 identifier, name, foundElement as MultiplyDefinedElementImpl); 7389 identifier, name, foundElement as MultiplyDefinedElementImpl);
7397 } 7390 }
7398 if (foundElement is MultiplyDefinedElementImpl) { 7391 if (foundElement is MultiplyDefinedElementImpl) {
7399 String foundEltName = foundElement.displayName; 7392 String foundEltName = foundElement.displayName;
7400 List<Element> conflictingMembers = 7393 List<Element> conflictingMembers = foundElement.conflictingElements;
7401 (foundElement as MultiplyDefinedElementImpl).conflictingElements;
7402 int count = conflictingMembers.length; 7394 int count = conflictingMembers.length;
7403 List<String> libraryNames = new List<String>(count); 7395 List<String> libraryNames = new List<String>(count);
7404 for (int i = 0; i < count; i++) { 7396 for (int i = 0; i < count; i++) {
7405 libraryNames[i] = _getLibraryName(conflictingMembers[i]); 7397 libraryNames[i] = _getLibraryName(conflictingMembers[i]);
7406 } 7398 }
7407 libraryNames.sort(); 7399 libraryNames.sort();
7408 errorListener.onError(new AnalysisError.con2(getSource(identifier), 7400 errorListener.onError(new AnalysisError.con2(getSource(identifier),
7409 identifier.offset, identifier.length, 7401 identifier.offset, identifier.length,
7410 StaticWarningCode.AMBIGUOUS_IMPORT, [ 7402 StaticWarningCode.AMBIGUOUS_IMPORT, [
7411 foundEltName, 7403 foundEltName,
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
7978 exportedLibrary.libraryElement; 7970 exportedLibrary.libraryElement;
7979 if (exportedLibraryElement != null) { 7971 if (exportedLibraryElement != null) {
7980 exportElement.exportedLibrary = exportedLibraryElement; 7972 exportElement.exportedLibrary = exportedLibraryElement;
7981 } 7973 }
7982 directive.element = exportElement; 7974 directive.element = exportElement;
7983 exports.add(exportElement); 7975 exports.add(exportElement);
7984 if (analysisContext.computeKindOf(exportedSource) != 7976 if (analysisContext.computeKindOf(exportedSource) !=
7985 SourceKind.LIBRARY) { 7977 SourceKind.LIBRARY) {
7986 _errorListener.onError(new AnalysisError.con2( 7978 _errorListener.onError(new AnalysisError.con2(
7987 library.librarySource, uriLiteral.offset, uriLiteral.length, 7979 library.librarySource, uriLiteral.offset, uriLiteral.length,
7988 CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY, [ 7980 CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY,
7989 uriLiteral.toSource() 7981 [uriLiteral.toSource()]));
7990 ]));
7991 } 7982 }
7992 } 7983 }
7993 } 7984 }
7994 } 7985 }
7995 } 7986 }
7996 Source librarySource = library.librarySource; 7987 Source librarySource = library.librarySource;
7997 if (!library.explicitlyImportsCore && 7988 if (!library.explicitlyImportsCore &&
7998 _coreLibrarySource != librarySource) { 7989 _coreLibrarySource != librarySource) {
7999 ImportElementImpl importElement = new ImportElementImpl(-1); 7990 ImportElementImpl importElement = new ImportElementImpl(-1);
8000 importElement.importedLibrary = _coreLibrary.libraryElement; 7991 importElement.importedLibrary = _coreLibrary.libraryElement;
(...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after
8685 exportedLibrary.libraryElement; 8676 exportedLibrary.libraryElement;
8686 if (exportedLibraryElement != null) { 8677 if (exportedLibraryElement != null) {
8687 exportElement.exportedLibrary = exportedLibraryElement; 8678 exportElement.exportedLibrary = exportedLibraryElement;
8688 } 8679 }
8689 directive.element = exportElement; 8680 directive.element = exportElement;
8690 exports.add(exportElement); 8681 exports.add(exportElement);
8691 if (analysisContext.computeKindOf(exportedSource) != 8682 if (analysisContext.computeKindOf(exportedSource) !=
8692 SourceKind.LIBRARY) { 8683 SourceKind.LIBRARY) {
8693 _errorListener.onError(new AnalysisError.con2( 8684 _errorListener.onError(new AnalysisError.con2(
8694 library.librarySource, uriLiteral.offset, uriLiteral.length, 8685 library.librarySource, uriLiteral.offset, uriLiteral.length,
8695 CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY, [ 8686 CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY,
8696 uriLiteral.toSource() 8687 [uriLiteral.toSource()]));
8697 ]));
8698 } 8688 }
8699 } 8689 }
8700 } 8690 }
8701 } 8691 }
8702 } 8692 }
8703 Source librarySource = library.librarySource; 8693 Source librarySource = library.librarySource;
8704 if (!library.explicitlyImportsCore && 8694 if (!library.explicitlyImportsCore &&
8705 _coreLibrarySource != librarySource) { 8695 _coreLibrarySource != librarySource) {
8706 ImportElementImpl importElement = new ImportElementImpl(-1); 8696 ImportElementImpl importElement = new ImportElementImpl(-1);
8707 importElement.importedLibrary = _coreLibrary.libraryElement; 8697 importElement.importedLibrary = _coreLibrary.libraryElement;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
8761 */ 8751 */
8762 void _buildImplicitConstructors() { 8752 void _buildImplicitConstructors() {
8763 PerformanceStatistics.resolve.makeCurrentWhile(() { 8753 PerformanceStatistics.resolve.makeCurrentWhile(() {
8764 ImplicitConstructorComputer computer = 8754 ImplicitConstructorComputer computer =
8765 new ImplicitConstructorComputer(_typeProvider); 8755 new ImplicitConstructorComputer(_typeProvider);
8766 for (ResolvableLibrary library in _librariesInCycle) { 8756 for (ResolvableLibrary library in _librariesInCycle) {
8767 for (ResolvableCompilationUnit unit 8757 for (ResolvableCompilationUnit unit
8768 in library.resolvableCompilationUnits) { 8758 in library.resolvableCompilationUnits) {
8769 Source source = unit.source; 8759 Source source = unit.source;
8770 CompilationUnit ast = unit.compilationUnit; 8760 CompilationUnit ast = unit.compilationUnit;
8771 computer 8761 computer.add(
8772 .add(ast, source, library.libraryElement, library.libraryScope); 8762 ast, source, library.libraryElement, library.libraryScope);
8773 } 8763 }
8774 } 8764 }
8775 computer.compute(); 8765 computer.compute();
8776 }); 8766 });
8777 } 8767 }
8778 8768
8779 HashMap<Source, ResolvableLibrary> _buildLibraryMap() { 8769 HashMap<Source, ResolvableLibrary> _buildLibraryMap() {
8780 HashMap<Source, ResolvableLibrary> libraryMap = 8770 HashMap<Source, ResolvableLibrary> libraryMap =
8781 new HashMap<Source, ResolvableLibrary>(); 8771 new HashMap<Source, ResolvableLibrary>();
8782 int libraryCount = _librariesInCycle.length; 8772 int libraryCount = _librariesInCycle.length;
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
9018 // synthetic accessor 9008 // synthetic accessor
9019 int offset = duplicate.nameOffset; 9009 int offset = duplicate.nameOffset;
9020 if (duplicate is PropertyAccessorElement) { 9010 if (duplicate is PropertyAccessorElement) {
9021 PropertyAccessorElement accessor = duplicate; 9011 PropertyAccessorElement accessor = duplicate;
9022 if (accessor.isSynthetic) { 9012 if (accessor.isSynthetic) {
9023 offset = accessor.variable.nameOffset; 9013 offset = accessor.variable.nameOffset;
9024 } 9014 }
9025 } 9015 }
9026 return new AnalysisError.con2(duplicate.source, offset, 9016 return new AnalysisError.con2(duplicate.source, offset,
9027 duplicate.displayName.length, 9017 duplicate.displayName.length,
9028 CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER, [ 9018 CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER,
9029 existing.displayName 9019 [existing.displayName]);
9030 ]);
9031 } 9020 }
9032 return super.getErrorForDuplicate(existing, duplicate); 9021 return super.getErrorForDuplicate(existing, duplicate);
9033 } 9022 }
9034 9023
9035 /** 9024 /**
9036 * Add to this scope all of the public top-level names that are defined in the given compilation 9025 * Add to this scope all of the public top-level names that are defined in the given compilation
9037 * unit. 9026 * unit.
9038 * 9027 *
9039 * @param compilationUnit the compilation unit defining the top-level names to be added to this 9028 * @param compilationUnit the compilation unit defining the top-level names to be added to this
9040 * scope 9029 * scope
(...skipping 1278 matching lines...) Expand 10 before | Expand all | Expand 10 after
10319 VariableElement getOverridablePropagatedElement(Expression expression) { 10308 VariableElement getOverridablePropagatedElement(Expression expression) {
10320 Element element = null; 10309 Element element = null;
10321 if (expression is SimpleIdentifier) { 10310 if (expression is SimpleIdentifier) {
10322 element = expression.propagatedElement; 10311 element = expression.propagatedElement;
10323 } else if (expression is PrefixedIdentifier) { 10312 } else if (expression is PrefixedIdentifier) {
10324 element = expression.propagatedElement; 10313 element = expression.propagatedElement;
10325 } else if (expression is PropertyAccess) { 10314 } else if (expression is PropertyAccess) {
10326 element = expression.propertyName.propagatedElement; 10315 element = expression.propertyName.propagatedElement;
10327 } 10316 }
10328 if (element is VariableElement) { 10317 if (element is VariableElement) {
10329 return element as VariableElement; 10318 return element;
10330 } 10319 }
10331 return null; 10320 return null;
10332 } 10321 }
10333 10322
10334 /** 10323 /**
10335 * Return the static element associated with the given expression whose type c an be overridden, or 10324 * Return the static element associated with the given expression whose type c an be overridden, or
10336 * `null` if there is no element whose type can be overridden. 10325 * `null` if there is no element whose type can be overridden.
10337 * 10326 *
10338 * @param expression the expression with which the element is associated 10327 * @param expression the expression with which the element is associated
10339 * @return the element associated with the given expression 10328 * @return the element associated with the given expression
10340 */ 10329 */
10341 VariableElement getOverridableStaticElement(Expression expression) { 10330 VariableElement getOverridableStaticElement(Expression expression) {
10342 Element element = null; 10331 Element element = null;
10343 if (expression is SimpleIdentifier) { 10332 if (expression is SimpleIdentifier) {
10344 element = expression.staticElement; 10333 element = expression.staticElement;
10345 } else if (expression is PrefixedIdentifier) { 10334 } else if (expression is PrefixedIdentifier) {
10346 element = expression.staticElement; 10335 element = expression.staticElement;
10347 } else if (expression is PropertyAccess) { 10336 } else if (expression is PropertyAccess) {
10348 element = expression.propertyName.staticElement; 10337 element = expression.propertyName.staticElement;
10349 } 10338 }
10350 if (element is VariableElement) { 10339 if (element is VariableElement) {
10351 return element as VariableElement; 10340 return element;
10352 } 10341 }
10353 return null; 10342 return null;
10354 } 10343 }
10355 10344
10356 /** 10345 /**
10357 * Return the static element associated with the given expression whose type c an be promoted, or 10346 * Return the static element associated with the given expression whose type c an be promoted, or
10358 * `null` if there is no element whose type can be promoted. 10347 * `null` if there is no element whose type can be promoted.
10359 * 10348 *
10360 * @param expression the expression with which the element is associated 10349 * @param expression the expression with which the element is associated
10361 * @return the element associated with the given expression 10350 * @return the element associated with the given expression
(...skipping 1891 matching lines...) Expand 10 before | Expand all | Expand 10 after
12253 } else { 12242 } else {
12254 Scope outerScope = _nameScope; 12243 Scope outerScope = _nameScope;
12255 try { 12244 try {
12256 ExecutableElement functionElement = node.element; 12245 ExecutableElement functionElement = node.element;
12257 if (functionElement == null) { 12246 if (functionElement == null) {
12258 StringBuffer buffer = new StringBuffer(); 12247 StringBuffer buffer = new StringBuffer();
12259 buffer.write("Missing element for function "); 12248 buffer.write("Missing element for function ");
12260 AstNode parent = node.parent; 12249 AstNode parent = node.parent;
12261 while (parent != null) { 12250 while (parent != null) {
12262 if (parent is Declaration) { 12251 if (parent is Declaration) {
12263 Element parentElement = (parent as Declaration).element; 12252 Element parentElement = parent.element;
12264 buffer.write(parentElement == null 12253 buffer.write(parentElement == null
12265 ? "<unknown> " 12254 ? "<unknown> "
12266 : "${parentElement.name} "); 12255 : "${parentElement.name} ");
12267 } 12256 }
12268 parent = parent.parent; 12257 parent = parent.parent;
12269 } 12258 }
12270 buffer.write("in "); 12259 buffer.write("in ");
12271 buffer.write(definingLibrary.source.fullName); 12260 buffer.write(definingLibrary.source.fullName);
12272 AnalysisEngine.instance.logger.logInformation(buffer.toString(), 12261 AnalysisEngine.instance.logger.logInformation(buffer.toString(),
12273 new CaughtException(new AnalysisException(), null)); 12262 new CaughtException(new AnalysisException(), null));
(...skipping 1752 matching lines...) Expand 10 before | Expand all | Expand 10 after
14026 (parent.parent as InstanceCreationExpression).isConst) { 14015 (parent.parent as InstanceCreationExpression).isConst) {
14027 // If, if this is a const expression, then generate a 14016 // If, if this is a const expression, then generate a
14028 // CompileTimeErrorCode.CONST_WITH_NON_TYPE error. 14017 // CompileTimeErrorCode.CONST_WITH_NON_TYPE error.
14029 reportErrorForNode(CompileTimeErrorCode.CONST_WITH_NON_TYPE, 14018 reportErrorForNode(CompileTimeErrorCode.CONST_WITH_NON_TYPE,
14030 prefixedIdentifier.identifier, 14019 prefixedIdentifier.identifier,
14031 [prefixedIdentifier.identifier.name]); 14020 [prefixedIdentifier.identifier.name]);
14032 } else { 14021 } else {
14033 // Else, if this expression is a new expression, report a 14022 // Else, if this expression is a new expression, report a
14034 // NEW_WITH_NON_TYPE warning. 14023 // NEW_WITH_NON_TYPE warning.
14035 reportErrorForNode(StaticWarningCode.NEW_WITH_NON_TYPE, 14024 reportErrorForNode(StaticWarningCode.NEW_WITH_NON_TYPE,
14036 prefixedIdentifier.identifier, [ 14025 prefixedIdentifier.identifier,
14037 prefixedIdentifier.identifier.name 14026 [prefixedIdentifier.identifier.name]);
14038 ]);
14039 } 14027 }
14040 _setElement(prefix, element); 14028 _setElement(prefix, element);
14041 return null; 14029 return null;
14042 } else if (element != null) { 14030 } else if (element != null) {
14043 // 14031 //
14044 // Rewrite the constructor name. The parser, when it sees a 14032 // Rewrite the constructor name. The parser, when it sees a
14045 // constructor named "a.b", cannot tell whether "a" is a prefix and 14033 // constructor named "a.b", cannot tell whether "a" is a prefix and
14046 // "b" is a class name, or whether "a" is a class name and "b" is a 14034 // "b" is a class name, or whether "a" is a class name and "b" is a
14047 // constructor name. It arbitrarily chooses the former, but in this 14035 // constructor name. It arbitrarily chooses the former, but in this
14048 // case was wrong. 14036 // case was wrong.
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
14127 } else { 14115 } else {
14128 _setElement(typeName, _dynamicType.element); 14116 _setElement(typeName, _dynamicType.element);
14129 } 14117 }
14130 typeName.staticType = _undefinedType; 14118 typeName.staticType = _undefinedType;
14131 node.type = _undefinedType; 14119 node.type = _undefinedType;
14132 return null; 14120 return null;
14133 } 14121 }
14134 DartType type = null; 14122 DartType type = null;
14135 if (element is ClassElement) { 14123 if (element is ClassElement) {
14136 _setElement(typeName, element); 14124 _setElement(typeName, element);
14137 type = (element as ClassElement).type; 14125 type = element.type;
14138 } else if (element is FunctionTypeAliasElement) { 14126 } else if (element is FunctionTypeAliasElement) {
14139 _setElement(typeName, element); 14127 _setElement(typeName, element);
14140 type = (element as FunctionTypeAliasElement).type; 14128 type = element.type;
14141 } else if (element is TypeParameterElement) { 14129 } else if (element is TypeParameterElement) {
14142 _setElement(typeName, element); 14130 _setElement(typeName, element);
14143 type = (element as TypeParameterElement).type; 14131 type = element.type;
14144 if (argumentList != null) { 14132 if (argumentList != null) {
14145 // Type parameters cannot have type arguments. 14133 // Type parameters cannot have type arguments.
14146 // TODO(brianwilkerson) Report this error. 14134 // TODO(brianwilkerson) Report this error.
14147 // resolver.reportError(ResolverErrorCode.?, keyType); 14135 // resolver.reportError(ResolverErrorCode.?, keyType);
14148 } 14136 }
14149 } else if (element is MultiplyDefinedElement) { 14137 } else if (element is MultiplyDefinedElement) {
14150 List<Element> elements = 14138 List<Element> elements = element.conflictingElements;
14151 (element as MultiplyDefinedElement).conflictingElements;
14152 type = _getTypeWhenMultiplyDefined(elements); 14139 type = _getTypeWhenMultiplyDefined(elements);
14153 if (type != null) { 14140 if (type != null) {
14154 node.type = type; 14141 node.type = type;
14155 } 14142 }
14156 } else { 14143 } else {
14157 // The name does not represent a type. 14144 // The name does not represent a type.
14158 RedirectingConstructorKind redirectingConstructorKind; 14145 RedirectingConstructorKind redirectingConstructorKind;
14159 if (_isTypeNameInCatchClause(node)) { 14146 if (_isTypeNameInCatchClause(node)) {
14160 reportErrorForNode(StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE, typeName, 14147 reportErrorForNode(StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE, typeName,
14161 [typeName.name]); 14148 [typeName.name]);
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
14377 * 14364 *
14378 * @param node the type name with the wrong number of type arguments 14365 * @param node the type name with the wrong number of type arguments
14379 * @return the error code that should be used to report that the wrong number of type arguments 14366 * @return the error code that should be used to report that the wrong number of type arguments
14380 * were provided 14367 * were provided
14381 */ 14368 */
14382 ErrorCode _getInvalidTypeParametersErrorCode(TypeName node) { 14369 ErrorCode _getInvalidTypeParametersErrorCode(TypeName node) {
14383 AstNode parent = node.parent; 14370 AstNode parent = node.parent;
14384 if (parent is ConstructorName) { 14371 if (parent is ConstructorName) {
14385 parent = parent.parent; 14372 parent = parent.parent;
14386 if (parent is InstanceCreationExpression) { 14373 if (parent is InstanceCreationExpression) {
14387 if ((parent as InstanceCreationExpression).isConst) { 14374 if (parent.isConst) {
14388 return CompileTimeErrorCode.CONST_WITH_INVALID_TYPE_PARAMETERS; 14375 return CompileTimeErrorCode.CONST_WITH_INVALID_TYPE_PARAMETERS;
14389 } else { 14376 } else {
14390 return StaticWarningCode.NEW_WITH_INVALID_TYPE_PARAMETERS; 14377 return StaticWarningCode.NEW_WITH_INVALID_TYPE_PARAMETERS;
14391 } 14378 }
14392 } 14379 }
14393 } 14380 }
14394 return StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS; 14381 return StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS;
14395 } 14382 }
14396 14383
14397 /** 14384 /**
14398 * Checks if the given type name is the target in a redirected constructor. 14385 * Checks if the given type name is the target in a redirected constructor.
14399 * 14386 *
14400 * @param typeName the type name to analyze 14387 * @param typeName the type name to analyze
14401 * @return some [RedirectingConstructorKind] if the given type name is used as the type in a 14388 * @return some [RedirectingConstructorKind] if the given type name is used as the type in a
14402 * redirected constructor, or `null` otherwise 14389 * redirected constructor, or `null` otherwise
14403 */ 14390 */
14404 RedirectingConstructorKind _getRedirectingConstructorKind(TypeName typeName) { 14391 RedirectingConstructorKind _getRedirectingConstructorKind(TypeName typeName) {
14405 AstNode parent = typeName.parent; 14392 AstNode parent = typeName.parent;
14406 if (parent is ConstructorName) { 14393 if (parent is ConstructorName) {
14407 ConstructorName constructorName = parent as ConstructorName; 14394 ConstructorName constructorName = parent as ConstructorName;
14408 parent = constructorName.parent; 14395 parent = constructorName.parent;
14409 if (parent is ConstructorDeclaration) { 14396 if (parent is ConstructorDeclaration) {
14410 ConstructorDeclaration constructorDeclaration = 14397 if (identical(parent.redirectedConstructor, constructorName)) {
14411 parent as ConstructorDeclaration; 14398 if (parent.constKeyword != null) {
14412 if (identical(
14413 constructorDeclaration.redirectedConstructor, constructorName)) {
14414 if (constructorDeclaration.constKeyword != null) {
14415 return RedirectingConstructorKind.CONST; 14399 return RedirectingConstructorKind.CONST;
14416 } 14400 }
14417 return RedirectingConstructorKind.NORMAL; 14401 return RedirectingConstructorKind.NORMAL;
14418 } 14402 }
14419 } 14403 }
14420 } 14404 }
14421 return null; 14405 return null;
14422 } 14406 }
14423 14407
14424 /** 14408 /**
(...skipping 970 matching lines...) Expand 10 before | Expand all | Expand 10 after
15395 * library. 15379 * library.
15396 */ 15380 */
15397 final HashSet<String> members = new HashSet<String>(); 15381 final HashSet<String> members = new HashSet<String>();
15398 15382
15399 /** 15383 /**
15400 * Names of resolved or unresolved class members that are read in the 15384 * Names of resolved or unresolved class members that are read in the
15401 * library. 15385 * library.
15402 */ 15386 */
15403 final HashSet<String> readMembers = new HashSet<String>(); 15387 final HashSet<String> readMembers = new HashSet<String>();
15404 } 15388 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/parser.dart ('k') | pkg/analyzer/lib/src/generated/static_type_analyzer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698