| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library analyzer.src.generated.error_verifier; | 5 library analyzer.src.generated.error_verifier; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import "dart:math" as math; | 8 import "dart:math" as math; |
| 9 | 9 |
| 10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 StaticTypeWarningCode.NON_BOOL_OPERAND, [lexeme]); | 380 StaticTypeWarningCode.NON_BOOL_OPERAND, [lexeme]); |
| 381 _checkForAssignability(node.rightOperand, _boolType, | 381 _checkForAssignability(node.rightOperand, _boolType, |
| 382 StaticTypeWarningCode.NON_BOOL_OPERAND, [lexeme]); | 382 StaticTypeWarningCode.NON_BOOL_OPERAND, [lexeme]); |
| 383 } else { | 383 } else { |
| 384 _checkForArgumentTypeNotAssignableForArgument(node.rightOperand); | 384 _checkForArgumentTypeNotAssignableForArgument(node.rightOperand); |
| 385 } | 385 } |
| 386 return super.visitBinaryExpression(node); | 386 return super.visitBinaryExpression(node); |
| 387 } | 387 } |
| 388 | 388 |
| 389 @override | 389 @override |
| 390 Object visitBlock(Block node) { |
| 391 _checkDuplicateDeclarationInStatements(node.statements); |
| 392 return super.visitBlock(node); |
| 393 } |
| 394 |
| 395 @override |
| 390 Object visitBlockFunctionBody(BlockFunctionBody node) { | 396 Object visitBlockFunctionBody(BlockFunctionBody node) { |
| 391 bool wasInAsync = _inAsync; | 397 bool wasInAsync = _inAsync; |
| 392 bool wasInGenerator = _inGenerator; | 398 bool wasInGenerator = _inGenerator; |
| 393 bool previousHasReturnWithoutValue = _hasReturnWithoutValue; | 399 bool previousHasReturnWithoutValue = _hasReturnWithoutValue; |
| 394 _hasReturnWithoutValue = false; | 400 _hasReturnWithoutValue = false; |
| 395 List<ReturnStatement> previousReturnsWith = _returnsWith; | 401 List<ReturnStatement> previousReturnsWith = _returnsWith; |
| 396 List<ReturnStatement> previousReturnsWithout = _returnsWithout; | 402 List<ReturnStatement> previousReturnsWithout = _returnsWithout; |
| 397 try { | 403 try { |
| 398 _inAsync = node.isAsynchronous; | 404 _inAsync = node.isAsynchronous; |
| 399 _inGenerator = node.isGenerator; | 405 _inGenerator = node.isGenerator; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 419 if (labelElement is LabelElementImpl && labelElement.isOnSwitchMember) { | 425 if (labelElement is LabelElementImpl && labelElement.isOnSwitchMember) { |
| 420 _errorReporter.reportErrorForNode( | 426 _errorReporter.reportErrorForNode( |
| 421 ResolverErrorCode.BREAK_LABEL_ON_SWITCH_MEMBER, labelNode); | 427 ResolverErrorCode.BREAK_LABEL_ON_SWITCH_MEMBER, labelNode); |
| 422 } | 428 } |
| 423 } | 429 } |
| 424 return null; | 430 return null; |
| 425 } | 431 } |
| 426 | 432 |
| 427 @override | 433 @override |
| 428 Object visitCatchClause(CatchClause node) { | 434 Object visitCatchClause(CatchClause node) { |
| 435 _checkDuplicateDefinitionInCatchClause(node); |
| 429 bool previousIsInCatchClause = _isInCatchClause; | 436 bool previousIsInCatchClause = _isInCatchClause; |
| 430 try { | 437 try { |
| 431 _isInCatchClause = true; | 438 _isInCatchClause = true; |
| 432 _checkForTypeAnnotationDeferredClass(node.exceptionType); | 439 _checkForTypeAnnotationDeferredClass(node.exceptionType); |
| 433 return super.visitCatchClause(node); | 440 return super.visitCatchClause(node); |
| 434 } finally { | 441 } finally { |
| 435 _isInCatchClause = previousIsInCatchClause; | 442 _isInCatchClause = previousIsInCatchClause; |
| 436 } | 443 } |
| 437 } | 444 } |
| 438 | 445 |
| 439 @override | 446 @override |
| 440 Object visitClassDeclaration(ClassDeclaration node) { | 447 Object visitClassDeclaration(ClassDeclaration node) { |
| 441 ClassElementImpl outerClass = _enclosingClass; | 448 ClassElementImpl outerClass = _enclosingClass; |
| 442 try { | 449 try { |
| 443 _isInNativeClass = node.nativeClause != null; | 450 _isInNativeClass = node.nativeClause != null; |
| 444 _enclosingClass = AbstractClassElementImpl.getImpl(node.element); | 451 _enclosingClass = AbstractClassElementImpl.getImpl(node.element); |
| 445 ExtendsClause extendsClause = node.extendsClause; | 452 _checkDuplicateClassMembers(node); |
| 446 ImplementsClause implementsClause = node.implementsClause; | |
| 447 WithClause withClause = node.withClause; | |
| 448 _checkForBuiltInIdentifierAsName( | 453 _checkForBuiltInIdentifierAsName( |
| 449 node.name, CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_NAME); | 454 node.name, CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_NAME); |
| 450 _checkForMemberWithClassName(); | 455 _checkForMemberWithClassName(); |
| 451 _checkForNoDefaultSuperConstructorImplicit(node); | 456 _checkForNoDefaultSuperConstructorImplicit(node); |
| 452 _checkForConflictingTypeVariableErrorCodes(node); | 457 _checkForConflictingTypeVariableErrorCodes(node); |
| 458 ExtendsClause extendsClause = node.extendsClause; |
| 459 ImplementsClause implementsClause = node.implementsClause; |
| 460 WithClause withClause = node.withClause; |
| 453 // Only do error checks on the clause nodes if there is a non-null clause | 461 // Only do error checks on the clause nodes if there is a non-null clause |
| 454 if (implementsClause != null || | 462 if (implementsClause != null || |
| 455 extendsClause != null || | 463 extendsClause != null || |
| 456 withClause != null) { | 464 withClause != null) { |
| 457 // Only check for all of the inheritance logic around clauses if there | 465 // Only check for all of the inheritance logic around clauses if there |
| 458 // isn't an error code such as "Cannot extend double" already on the | 466 // isn't an error code such as "Cannot extend double" already on the |
| 459 // class. | 467 // class. |
| 460 if (!_checkForImplementsDisallowedClass(implementsClause) && | 468 if (!_checkForImplementsDisallowedClass(implementsClause) && |
| 461 !_checkForExtendsDisallowedClass(extendsClause) && | 469 !_checkForExtendsDisallowedClass(extendsClause) && |
| 462 !_checkForAllMixinErrorCodes(withClause)) { | 470 !_checkForAllMixinErrorCodes(withClause)) { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 _isInComment = true; | 545 _isInComment = true; |
| 538 try { | 546 try { |
| 539 return super.visitComment(node); | 547 return super.visitComment(node); |
| 540 } finally { | 548 } finally { |
| 541 _isInComment = false; | 549 _isInComment = false; |
| 542 } | 550 } |
| 543 } | 551 } |
| 544 | 552 |
| 545 @override | 553 @override |
| 546 Object visitCompilationUnit(CompilationUnit node) { | 554 Object visitCompilationUnit(CompilationUnit node) { |
| 555 _checkDuplicateUnitMembers(node); |
| 547 _checkForDeferredPrefixCollisions(node); | 556 _checkForDeferredPrefixCollisions(node); |
| 548 return super.visitCompilationUnit(node); | 557 return super.visitCompilationUnit(node); |
| 549 } | 558 } |
| 550 | 559 |
| 551 @override | 560 @override |
| 552 Object visitConditionalExpression(ConditionalExpression node) { | 561 Object visitConditionalExpression(ConditionalExpression node) { |
| 553 _checkForNonBoolCondition(node.condition); | 562 _checkForNonBoolCondition(node.condition); |
| 554 return super.visitConditionalExpression(node); | 563 return super.visitConditionalExpression(node); |
| 555 } | 564 } |
| 556 | 565 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 Object visitDoStatement(DoStatement node) { | 635 Object visitDoStatement(DoStatement node) { |
| 627 _checkForNonBoolCondition(node.condition); | 636 _checkForNonBoolCondition(node.condition); |
| 628 return super.visitDoStatement(node); | 637 return super.visitDoStatement(node); |
| 629 } | 638 } |
| 630 | 639 |
| 631 @override | 640 @override |
| 632 Object visitEnumDeclaration(EnumDeclaration node) { | 641 Object visitEnumDeclaration(EnumDeclaration node) { |
| 633 ClassElement outerEnum = _enclosingEnum; | 642 ClassElement outerEnum = _enclosingEnum; |
| 634 try { | 643 try { |
| 635 _enclosingEnum = node.element; | 644 _enclosingEnum = node.element; |
| 645 _checkDuplicateEnumMembers(node); |
| 636 return super.visitEnumDeclaration(node); | 646 return super.visitEnumDeclaration(node); |
| 637 } finally { | 647 } finally { |
| 638 _enclosingEnum = outerEnum; | 648 _enclosingEnum = outerEnum; |
| 639 } | 649 } |
| 640 } | 650 } |
| 641 | 651 |
| 642 @override | 652 @override |
| 643 Object visitExportDirective(ExportDirective node) { | 653 Object visitExportDirective(ExportDirective node) { |
| 644 ExportElement exportElement = node.element; | 654 ExportElement exportElement = node.element; |
| 645 if (exportElement != null) { | 655 if (exportElement != null) { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 return super.visitFieldFormalParameter(node); | 722 return super.visitFieldFormalParameter(node); |
| 713 } | 723 } |
| 714 | 724 |
| 715 @override | 725 @override |
| 716 Object visitForEachStatement(ForEachStatement node) { | 726 Object visitForEachStatement(ForEachStatement node) { |
| 717 _checkForInIterable(node); | 727 _checkForInIterable(node); |
| 718 return super.visitForEachStatement(node); | 728 return super.visitForEachStatement(node); |
| 719 } | 729 } |
| 720 | 730 |
| 721 @override | 731 @override |
| 732 Object visitFormalParameterList(FormalParameterList node) { |
| 733 _checkDuplicateDefinitionInParameterList(node); |
| 734 return super.visitFormalParameterList(node); |
| 735 } |
| 736 |
| 737 @override |
| 722 Object visitForStatement(ForStatement node) { | 738 Object visitForStatement(ForStatement node) { |
| 723 if (node.condition != null) { | 739 if (node.condition != null) { |
| 724 _checkForNonBoolCondition(node.condition); | 740 _checkForNonBoolCondition(node.condition); |
| 725 } | 741 } |
| 742 if (node.variables != null) { |
| 743 _checkDuplicateVariables(node.variables); |
| 744 } |
| 726 return super.visitForStatement(node); | 745 return super.visitForStatement(node); |
| 727 } | 746 } |
| 728 | 747 |
| 729 @override | 748 @override |
| 730 Object visitFunctionDeclaration(FunctionDeclaration node) { | 749 Object visitFunctionDeclaration(FunctionDeclaration node) { |
| 731 ExecutableElement outerFunction = _enclosingFunction; | 750 ExecutableElement outerFunction = _enclosingFunction; |
| 732 try { | 751 try { |
| 733 SimpleIdentifier identifier = node.name; | 752 SimpleIdentifier identifier = node.name; |
| 734 String methodName = ""; | 753 String methodName = ""; |
| 735 if (identifier != null) { | 754 if (identifier != null) { |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1103 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) { | 1122 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) { |
| 1104 _isInConstructorInitializer = true; | 1123 _isInConstructorInitializer = true; |
| 1105 try { | 1124 try { |
| 1106 return super.visitSuperConstructorInvocation(node); | 1125 return super.visitSuperConstructorInvocation(node); |
| 1107 } finally { | 1126 } finally { |
| 1108 _isInConstructorInitializer = false; | 1127 _isInConstructorInitializer = false; |
| 1109 } | 1128 } |
| 1110 } | 1129 } |
| 1111 | 1130 |
| 1112 @override | 1131 @override |
| 1132 Object visitSwitchCase(SwitchCase node) { |
| 1133 _checkDuplicateDeclarationInStatements(node.statements); |
| 1134 return super.visitSwitchCase(node); |
| 1135 } |
| 1136 |
| 1137 @override |
| 1138 Object visitSwitchDefault(SwitchDefault node) { |
| 1139 _checkDuplicateDeclarationInStatements(node.statements); |
| 1140 return super.visitSwitchDefault(node); |
| 1141 } |
| 1142 |
| 1143 @override |
| 1113 Object visitSwitchStatement(SwitchStatement node) { | 1144 Object visitSwitchStatement(SwitchStatement node) { |
| 1114 _checkForSwitchExpressionNotAssignable(node); | 1145 _checkForSwitchExpressionNotAssignable(node); |
| 1115 _checkForCaseBlocksNotTerminated(node); | 1146 _checkForCaseBlocksNotTerminated(node); |
| 1116 _checkForMissingEnumConstantInSwitch(node); | 1147 _checkForMissingEnumConstantInSwitch(node); |
| 1117 return super.visitSwitchStatement(node); | 1148 return super.visitSwitchStatement(node); |
| 1118 } | 1149 } |
| 1119 | 1150 |
| 1120 @override | 1151 @override |
| 1121 Object visitThisExpression(ThisExpression node) { | 1152 Object visitThisExpression(ThisExpression node) { |
| 1122 _checkForInvalidReferenceToThis(node); | 1153 _checkForInvalidReferenceToThis(node); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1155 Object visitTypeParameter(TypeParameter node) { | 1186 Object visitTypeParameter(TypeParameter node) { |
| 1156 _checkForBuiltInIdentifierAsName(node.name, | 1187 _checkForBuiltInIdentifierAsName(node.name, |
| 1157 CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME); | 1188 CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME); |
| 1158 _checkForTypeParameterSupertypeOfItsBound(node); | 1189 _checkForTypeParameterSupertypeOfItsBound(node); |
| 1159 _checkForTypeAnnotationDeferredClass(node.bound); | 1190 _checkForTypeAnnotationDeferredClass(node.bound); |
| 1160 _checkForImplicitDynamicType(node.bound); | 1191 _checkForImplicitDynamicType(node.bound); |
| 1161 return super.visitTypeParameter(node); | 1192 return super.visitTypeParameter(node); |
| 1162 } | 1193 } |
| 1163 | 1194 |
| 1164 @override | 1195 @override |
| 1196 Object visitTypeParameterList(TypeParameterList node) { |
| 1197 _checkDuplicateDefinitionInTypeParameterList(node); |
| 1198 return super.visitTypeParameterList(node); |
| 1199 } |
| 1200 |
| 1201 @override |
| 1165 Object visitVariableDeclaration(VariableDeclaration node) { | 1202 Object visitVariableDeclaration(VariableDeclaration node) { |
| 1166 SimpleIdentifier nameNode = node.name; | 1203 SimpleIdentifier nameNode = node.name; |
| 1167 Expression initializerNode = node.initializer; | 1204 Expression initializerNode = node.initializer; |
| 1168 // do checks | 1205 // do checks |
| 1169 _checkForInvalidAssignment(nameNode, initializerNode); | 1206 _checkForInvalidAssignment(nameNode, initializerNode); |
| 1170 _checkForImplicitDynamicIdentifier(node, nameNode); | 1207 _checkForImplicitDynamicIdentifier(node, nameNode); |
| 1171 // visit name | 1208 // visit name |
| 1172 nameNode.accept(this); | 1209 nameNode.accept(this); |
| 1173 // visit initializer | 1210 // visit initializer |
| 1174 String name = nameNode.name; | 1211 String name = nameNode.name; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1252 Token deferredToken = directives[i].deferredKeyword; | 1289 Token deferredToken = directives[i].deferredKeyword; |
| 1253 if (deferredToken != null) { | 1290 if (deferredToken != null) { |
| 1254 _errorReporter.reportErrorForToken( | 1291 _errorReporter.reportErrorForToken( |
| 1255 CompileTimeErrorCode.SHARED_DEFERRED_PREFIX, deferredToken); | 1292 CompileTimeErrorCode.SHARED_DEFERRED_PREFIX, deferredToken); |
| 1256 } | 1293 } |
| 1257 } | 1294 } |
| 1258 } | 1295 } |
| 1259 } | 1296 } |
| 1260 | 1297 |
| 1261 /** | 1298 /** |
| 1299 * Check that there are no members with the same name. |
| 1300 */ |
| 1301 void _checkDuplicateClassMembers(ClassDeclaration node) { |
| 1302 Map<String, Element> definedNames = new HashMap<String, Element>(); |
| 1303 Set<String> visitedFields = new HashSet<String>(); |
| 1304 for (ClassMember member in node.members) { |
| 1305 // We ignore constructors because they are checked in the method |
| 1306 // _checkForConflictingConstructorNameAndMember. |
| 1307 if (member is FieldDeclaration) { |
| 1308 for (VariableDeclaration field in member.fields.variables) { |
| 1309 SimpleIdentifier identifier = field.name; |
| 1310 _checkDuplicateIdentifier(definedNames, identifier); |
| 1311 String name = identifier.name; |
| 1312 if (!field.isFinal && |
| 1313 !field.isConst && |
| 1314 !visitedFields.contains(name)) { |
| 1315 _checkDuplicateIdentifier(definedNames, identifier, |
| 1316 implicitSetter: true); |
| 1317 } |
| 1318 visitedFields.add(name); |
| 1319 } |
| 1320 } else if (member is MethodDeclaration) { |
| 1321 _checkDuplicateIdentifier(definedNames, member.name); |
| 1322 } |
| 1323 } |
| 1324 } |
| 1325 |
| 1326 /** |
| 1327 * Check that all of the parameters have unique names. |
| 1328 */ |
| 1329 void _checkDuplicateDeclarationInStatements(List<Statement> statements) { |
| 1330 Map<String, Element> definedNames = new HashMap<String, Element>(); |
| 1331 for (Statement statement in statements) { |
| 1332 if (statement is VariableDeclarationStatement) { |
| 1333 for (VariableDeclaration variable in statement.variables.variables) { |
| 1334 _checkDuplicateIdentifier(definedNames, variable.name); |
| 1335 } |
| 1336 } else if (statement is FunctionDeclarationStatement) { |
| 1337 _checkDuplicateIdentifier( |
| 1338 definedNames, statement.functionDeclaration.name); |
| 1339 } |
| 1340 } |
| 1341 } |
| 1342 |
| 1343 /** |
| 1344 * Check that the exception and stack trace parameters have different names. |
| 1345 */ |
| 1346 void _checkDuplicateDefinitionInCatchClause(CatchClause node) { |
| 1347 SimpleIdentifier exceptionParameter = node.exceptionParameter; |
| 1348 SimpleIdentifier stackTraceParameter = node.stackTraceParameter; |
| 1349 if (exceptionParameter != null && stackTraceParameter != null) { |
| 1350 String exceptionName = exceptionParameter.name; |
| 1351 if (exceptionName == stackTraceParameter.name) { |
| 1352 _errorReporter.reportErrorForNode( |
| 1353 CompileTimeErrorCode.DUPLICATE_DEFINITION, |
| 1354 stackTraceParameter, |
| 1355 [exceptionName]); |
| 1356 } |
| 1357 } |
| 1358 } |
| 1359 |
| 1360 /** |
| 1361 * Check that all of the parameters have unique names. |
| 1362 */ |
| 1363 void _checkDuplicateDefinitionInParameterList(FormalParameterList node) { |
| 1364 Map<String, Element> definedNames = new HashMap<String, Element>(); |
| 1365 for (FormalParameter parameter in node.parameters) { |
| 1366 _checkDuplicateIdentifier(definedNames, parameter.identifier); |
| 1367 } |
| 1368 } |
| 1369 |
| 1370 /** |
| 1371 * Check that all of the parameters have unique names. |
| 1372 */ |
| 1373 void _checkDuplicateDefinitionInTypeParameterList(TypeParameterList node) { |
| 1374 Map<String, Element> definedNames = new HashMap<String, Element>(); |
| 1375 for (TypeParameter parameter in node.typeParameters) { |
| 1376 _checkDuplicateIdentifier(definedNames, parameter.name); |
| 1377 } |
| 1378 } |
| 1379 |
| 1380 /** |
| 1381 * Check that there are no members with the same name. |
| 1382 */ |
| 1383 void _checkDuplicateEnumMembers(EnumDeclaration node) { |
| 1384 Map<String, Element> definedNames = new HashMap<String, Element>(); |
| 1385 ClassElement element = node.element; |
| 1386 String indexName = 'index'; |
| 1387 String valuesName = 'values'; |
| 1388 definedNames[indexName] = element.getField(indexName); |
| 1389 definedNames[valuesName] = element.getField(valuesName); |
| 1390 for (EnumConstantDeclaration constant in node.constants) { |
| 1391 _checkDuplicateIdentifier(definedNames, constant.name); |
| 1392 } |
| 1393 } |
| 1394 |
| 1395 /** |
| 1396 * Check whether the given [identifier] is already in the set of |
| 1397 * [definedNames], and produce an error if it is. If [implicitSetter] is |
| 1398 * `true`, then the identifier represents the definition of a setter. |
| 1399 */ |
| 1400 void _checkDuplicateIdentifier( |
| 1401 Map<String, Element> definedNames, SimpleIdentifier identifier, |
| 1402 {bool implicitSetter: false}) { |
| 1403 ErrorCode getError(Element previous, Element current) { |
| 1404 if (previous is MethodElement && current is PropertyAccessorElement) { |
| 1405 if (current.isGetter) { |
| 1406 return CompileTimeErrorCode.GETTER_AND_METHOD_WITH_SAME_NAME; |
| 1407 } |
| 1408 } else if (previous is PropertyAccessorElement && |
| 1409 current is MethodElement) { |
| 1410 if (previous.isGetter) { |
| 1411 return CompileTimeErrorCode.METHOD_AND_GETTER_WITH_SAME_NAME; |
| 1412 } |
| 1413 } else if (previous is PrefixElement) { |
| 1414 return CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER; |
| 1415 } |
| 1416 return CompileTimeErrorCode.DUPLICATE_DEFINITION; |
| 1417 } |
| 1418 |
| 1419 Element current = identifier.staticElement; |
| 1420 String name = identifier.name; |
| 1421 if (current is PropertyAccessorElement && current.isSetter) { |
| 1422 name += '='; |
| 1423 } else if (current is MethodElement && current.isOperator && name == '-') { |
| 1424 if (current.parameters.length == 0) { |
| 1425 name = 'unary-'; |
| 1426 } |
| 1427 } else if (implicitSetter) { |
| 1428 name += '='; |
| 1429 } |
| 1430 Element previous = definedNames[name]; |
| 1431 if (previous != null) { |
| 1432 _errorReporter |
| 1433 .reportErrorForNode(getError(previous, current), identifier, [name]); |
| 1434 } else { |
| 1435 definedNames[name] = identifier.staticElement; |
| 1436 } |
| 1437 } |
| 1438 |
| 1439 /** |
| 1440 * Check that there are no members with the same name. |
| 1441 */ |
| 1442 void _checkDuplicateUnitMembers(CompilationUnit node) { |
| 1443 Map<String, Element> definedNames = new HashMap<String, Element>(); |
| 1444 void addWithoutChecking(CompilationUnitElement element) { |
| 1445 for (PropertyAccessorElement accessor in element.accessors) { |
| 1446 String name = accessor.name; |
| 1447 if (accessor.isSetter) { |
| 1448 name += '='; |
| 1449 } |
| 1450 definedNames[name] = accessor; |
| 1451 } |
| 1452 for (ClassElement type in element.enums) { |
| 1453 definedNames[type.name] = type; |
| 1454 } |
| 1455 for (FunctionElement function in element.functions) { |
| 1456 definedNames[function.name] = function; |
| 1457 } |
| 1458 for (FunctionTypeAliasElement alias in element.functionTypeAliases) { |
| 1459 definedNames[alias.name] = alias; |
| 1460 } |
| 1461 for (TopLevelVariableElement variable in element.topLevelVariables) { |
| 1462 definedNames[variable.name] = variable; |
| 1463 if (!variable.isFinal && !variable.isConst) { |
| 1464 definedNames[variable.name + '='] = variable; |
| 1465 } |
| 1466 } |
| 1467 for (ClassElement type in element.types) { |
| 1468 definedNames[type.name] = type; |
| 1469 } |
| 1470 } |
| 1471 |
| 1472 for (ImportElement importElement in _currentLibrary.imports) { |
| 1473 PrefixElement prefix = importElement.prefix; |
| 1474 if (prefix != null) { |
| 1475 definedNames[prefix.name] = prefix; |
| 1476 } |
| 1477 } |
| 1478 CompilationUnitElement element = node.element; |
| 1479 if (element != _currentLibrary.definingCompilationUnit) { |
| 1480 addWithoutChecking(_currentLibrary.definingCompilationUnit); |
| 1481 for (CompilationUnitElement part in _currentLibrary.parts) { |
| 1482 if (element == part) { |
| 1483 break; |
| 1484 } |
| 1485 addWithoutChecking(part); |
| 1486 } |
| 1487 } |
| 1488 for (CompilationUnitMember member in node.declarations) { |
| 1489 if (member is NamedCompilationUnitMember) { |
| 1490 _checkDuplicateIdentifier(definedNames, member.name); |
| 1491 } else if (member is TopLevelVariableDeclaration) { |
| 1492 for (VariableDeclaration variable in member.variables.variables) { |
| 1493 _checkDuplicateIdentifier(definedNames, variable.name); |
| 1494 if (!variable.isFinal && !variable.isConst) { |
| 1495 _checkDuplicateIdentifier(definedNames, variable.name, |
| 1496 implicitSetter: true); |
| 1497 } |
| 1498 } |
| 1499 } |
| 1500 } |
| 1501 } |
| 1502 |
| 1503 /** |
| 1504 * Check that the given list of variable declarations does not define multiple |
| 1505 * variables of the same name. |
| 1506 */ |
| 1507 void _checkDuplicateVariables(VariableDeclarationList node) { |
| 1508 Map<String, Element> definedNames = new HashMap<String, Element>(); |
| 1509 for (VariableDeclaration variable in node.variables) { |
| 1510 _checkDuplicateIdentifier(definedNames, variable.name); |
| 1511 } |
| 1512 } |
| 1513 |
| 1514 /** |
| 1262 * Verify that the given list of [typeArguments] contains exactly two | 1515 * Verify that the given list of [typeArguments] contains exactly two |
| 1263 * elements. | 1516 * elements. |
| 1264 * | 1517 * |
| 1265 * See [StaticTypeWarningCode.EXPECTED_TWO_MAP_TYPE_ARGUMENTS]. | 1518 * See [StaticTypeWarningCode.EXPECTED_TWO_MAP_TYPE_ARGUMENTS]. |
| 1266 */ | 1519 */ |
| 1267 void _checkExpectedTwoMapTypeArguments(TypeArgumentList typeArguments) { | 1520 void _checkExpectedTwoMapTypeArguments(TypeArgumentList typeArguments) { |
| 1268 int num = typeArguments.arguments.length; | 1521 int num = typeArguments.arguments.length; |
| 1269 if (num != 2) { | 1522 if (num != 2) { |
| 1270 _errorReporter.reportErrorForNode( | 1523 _errorReporter.reportErrorForNode( |
| 1271 StaticTypeWarningCode.EXPECTED_TWO_MAP_TYPE_ARGUMENTS, | 1524 StaticTypeWarningCode.EXPECTED_TWO_MAP_TYPE_ARGUMENTS, |
| (...skipping 5197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6469 class _InvocationCollector extends RecursiveAstVisitor { | 6722 class _InvocationCollector extends RecursiveAstVisitor { |
| 6470 final List<String> superCalls = <String>[]; | 6723 final List<String> superCalls = <String>[]; |
| 6471 | 6724 |
| 6472 @override | 6725 @override |
| 6473 visitMethodInvocation(MethodInvocation node) { | 6726 visitMethodInvocation(MethodInvocation node) { |
| 6474 if (node.target is SuperExpression) { | 6727 if (node.target is SuperExpression) { |
| 6475 superCalls.add(node.methodName.name); | 6728 superCalls.add(node.methodName.name); |
| 6476 } | 6729 } |
| 6477 } | 6730 } |
| 6478 } | 6731 } |
| OLD | NEW |