| 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 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 bool wasInAsync = _inAsync; | 644 bool wasInAsync = _inAsync; |
| 645 bool wasInGenerator = _inGenerator; | 645 bool wasInGenerator = _inGenerator; |
| 646 try { | 646 try { |
| 647 _inAsync = node.isAsynchronous; | 647 _inAsync = node.isAsynchronous; |
| 648 _inGenerator = node.isGenerator; | 648 _inGenerator = node.isGenerator; |
| 649 FunctionType functionType = | 649 FunctionType functionType = |
| 650 _enclosingFunction == null ? null : _enclosingFunction.type; | 650 _enclosingFunction == null ? null : _enclosingFunction.type; |
| 651 DartType expectedReturnType = functionType == null | 651 DartType expectedReturnType = functionType == null |
| 652 ? DynamicTypeImpl.instance | 652 ? DynamicTypeImpl.instance |
| 653 : functionType.returnType; | 653 : functionType.returnType; |
| 654 bool isSetterWithImplicitReturn = | 654 ExecutableElement function = _enclosingFunction; |
| 655 _enclosingFunction.hasImplicitReturnType && | 655 bool isSetterWithImplicitReturn = function.hasImplicitReturnType && |
| 656 _enclosingFunction is PropertyAccessorElement && | 656 function is PropertyAccessorElement && |
| 657 (_enclosingFunction as PropertyAccessorElement).isSetter; | 657 function.isSetter; |
| 658 if (!isSetterWithImplicitReturn) { | 658 if (!isSetterWithImplicitReturn) { |
| 659 _checkForReturnOfInvalidType(node.expression, expectedReturnType); | 659 _checkForReturnOfInvalidType(node.expression, expectedReturnType); |
| 660 } | 660 } |
| 661 return super.visitExpressionFunctionBody(node); | 661 return super.visitExpressionFunctionBody(node); |
| 662 } finally { | 662 } finally { |
| 663 _inAsync = wasInAsync; | 663 _inAsync = wasInAsync; |
| 664 _inGenerator = wasInGenerator; | 664 _inGenerator = wasInGenerator; |
| 665 } | 665 } |
| 666 } | 666 } |
| 667 | 667 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 817 | 817 |
| 818 @override | 818 @override |
| 819 Object visitInstanceCreationExpression(InstanceCreationExpression node) { | 819 Object visitInstanceCreationExpression(InstanceCreationExpression node) { |
| 820 bool wasInConstInstanceCreation = _isInConstInstanceCreation; | 820 bool wasInConstInstanceCreation = _isInConstInstanceCreation; |
| 821 _isInConstInstanceCreation = node.isConst; | 821 _isInConstInstanceCreation = node.isConst; |
| 822 try { | 822 try { |
| 823 ConstructorName constructorName = node.constructorName; | 823 ConstructorName constructorName = node.constructorName; |
| 824 TypeName typeName = constructorName.type; | 824 TypeName typeName = constructorName.type; |
| 825 DartType type = typeName.type; | 825 DartType type = typeName.type; |
| 826 if (type is InterfaceType) { | 826 if (type is InterfaceType) { |
| 827 InterfaceType interfaceType = type; | 827 _checkForConstOrNewWithAbstractClass(node, typeName, type); |
| 828 _checkForConstOrNewWithAbstractClass(node, typeName, interfaceType); | 828 _checkForConstOrNewWithEnum(node, typeName, type); |
| 829 _checkForConstOrNewWithEnum(node, typeName, interfaceType); | |
| 830 _checkForMissingRequiredParam( | 829 _checkForMissingRequiredParam( |
| 831 node.staticElement?.type, node.argumentList, node.constructorName); | 830 node.staticElement?.type, node.argumentList, node.constructorName); |
| 832 if (_isInConstInstanceCreation) { | 831 if (_isInConstInstanceCreation) { |
| 833 _checkForConstWithNonConst(node); | 832 _checkForConstWithNonConst(node); |
| 834 _checkForConstWithUndefinedConstructor( | 833 _checkForConstWithUndefinedConstructor( |
| 835 node, constructorName, typeName); | 834 node, constructorName, typeName); |
| 836 _checkForConstWithTypeParameters(typeName); | 835 _checkForConstWithTypeParameters(typeName); |
| 837 _checkForConstDeferredClass(node, constructorName, typeName); | 836 _checkForConstDeferredClass(node, constructorName, typeName); |
| 838 } else { | 837 } else { |
| 839 _checkForNewWithUndefinedConstructor(node, constructorName, typeName); | 838 _checkForNewWithUndefinedConstructor(node, constructorName, typeName); |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1236 if (_isInNativeClass) { | 1235 if (_isInNativeClass) { |
| 1237 return; | 1236 return; |
| 1238 } | 1237 } |
| 1239 | 1238 |
| 1240 HashMap<FieldElement, INIT_STATE> fieldElementsMap = | 1239 HashMap<FieldElement, INIT_STATE> fieldElementsMap = |
| 1241 new HashMap<FieldElement, INIT_STATE>.from(_initialFieldElementsMap); | 1240 new HashMap<FieldElement, INIT_STATE>.from(_initialFieldElementsMap); |
| 1242 // Visit all of the field formal parameters | 1241 // Visit all of the field formal parameters |
| 1243 NodeList<FormalParameter> formalParameters = | 1242 NodeList<FormalParameter> formalParameters = |
| 1244 constructor.parameters.parameters; | 1243 constructor.parameters.parameters; |
| 1245 for (FormalParameter formalParameter in formalParameters) { | 1244 for (FormalParameter formalParameter in formalParameters) { |
| 1246 FormalParameter parameter = formalParameter; | 1245 FormalParameter baseParameter(FormalParameter parameter) { |
| 1247 if (parameter is DefaultFormalParameter) { | 1246 if (parameter is DefaultFormalParameter) { |
| 1248 parameter = (parameter as DefaultFormalParameter).parameter; | 1247 return parameter.parameter; |
| 1248 } |
| 1249 return parameter; |
| 1249 } | 1250 } |
| 1251 FormalParameter parameter = baseParameter(formalParameter); |
| 1250 if (parameter is FieldFormalParameter) { | 1252 if (parameter is FieldFormalParameter) { |
| 1251 FieldElement fieldElement = | 1253 FieldElement fieldElement = |
| 1252 (parameter.element as FieldFormalParameterElementImpl).field; | 1254 (parameter.element as FieldFormalParameterElementImpl).field; |
| 1253 INIT_STATE state = fieldElementsMap[fieldElement]; | 1255 INIT_STATE state = fieldElementsMap[fieldElement]; |
| 1254 if (state == INIT_STATE.NOT_INIT) { | 1256 if (state == INIT_STATE.NOT_INIT) { |
| 1255 fieldElementsMap[fieldElement] = INIT_STATE.INIT_IN_FIELD_FORMAL; | 1257 fieldElementsMap[fieldElement] = INIT_STATE.INIT_IN_FIELD_FORMAL; |
| 1256 } else if (state == INIT_STATE.INIT_IN_DECLARATION) { | 1258 } else if (state == INIT_STATE.INIT_IN_DECLARATION) { |
| 1257 if (fieldElement.isFinal || fieldElement.isConst) { | 1259 if (fieldElement.isFinal || fieldElement.isConst) { |
| 1258 _errorReporter.reportErrorForNode( | 1260 _errorReporter.reportErrorForNode( |
| 1259 StaticWarningCode | 1261 StaticWarningCode |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1271 } | 1273 } |
| 1272 } | 1274 } |
| 1273 } | 1275 } |
| 1274 // Visit all of the initializers | 1276 // Visit all of the initializers |
| 1275 NodeList<ConstructorInitializer> initializers = constructor.initializers; | 1277 NodeList<ConstructorInitializer> initializers = constructor.initializers; |
| 1276 for (ConstructorInitializer constructorInitializer in initializers) { | 1278 for (ConstructorInitializer constructorInitializer in initializers) { |
| 1277 if (constructorInitializer is RedirectingConstructorInvocation) { | 1279 if (constructorInitializer is RedirectingConstructorInvocation) { |
| 1278 return; | 1280 return; |
| 1279 } | 1281 } |
| 1280 if (constructorInitializer is ConstructorFieldInitializer) { | 1282 if (constructorInitializer is ConstructorFieldInitializer) { |
| 1281 ConstructorFieldInitializer constructorFieldInitializer = | 1283 SimpleIdentifier fieldName = constructorInitializer.fieldName; |
| 1282 constructorInitializer; | |
| 1283 SimpleIdentifier fieldName = constructorFieldInitializer.fieldName; | |
| 1284 Element element = fieldName.staticElement; | 1284 Element element = fieldName.staticElement; |
| 1285 if (element is FieldElement) { | 1285 if (element is FieldElement) { |
| 1286 FieldElement fieldElement = element; | 1286 INIT_STATE state = fieldElementsMap[element]; |
| 1287 INIT_STATE state = fieldElementsMap[fieldElement]; | |
| 1288 if (state == INIT_STATE.NOT_INIT) { | 1287 if (state == INIT_STATE.NOT_INIT) { |
| 1289 fieldElementsMap[fieldElement] = INIT_STATE.INIT_IN_INITIALIZERS; | 1288 fieldElementsMap[element] = INIT_STATE.INIT_IN_INITIALIZERS; |
| 1290 } else if (state == INIT_STATE.INIT_IN_DECLARATION) { | 1289 } else if (state == INIT_STATE.INIT_IN_DECLARATION) { |
| 1291 if (fieldElement.isFinal || fieldElement.isConst) { | 1290 if (element.isFinal || element.isConst) { |
| 1292 _errorReporter.reportErrorForNode( | 1291 _errorReporter.reportErrorForNode( |
| 1293 StaticWarningCode | 1292 StaticWarningCode |
| 1294 .FIELD_INITIALIZED_IN_INITIALIZER_AND_DECLARATION, | 1293 .FIELD_INITIALIZED_IN_INITIALIZER_AND_DECLARATION, |
| 1295 fieldName); | 1294 fieldName); |
| 1296 } | 1295 } |
| 1297 } else if (state == INIT_STATE.INIT_IN_FIELD_FORMAL) { | 1296 } else if (state == INIT_STATE.INIT_IN_FIELD_FORMAL) { |
| 1298 _errorReporter.reportErrorForNode( | 1297 _errorReporter.reportErrorForNode( |
| 1299 CompileTimeErrorCode | 1298 CompileTimeErrorCode |
| 1300 .FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER, | 1299 .FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER, |
| 1301 fieldName); | 1300 fieldName); |
| 1302 } else if (state == INIT_STATE.INIT_IN_INITIALIZERS) { | 1301 } else if (state == INIT_STATE.INIT_IN_INITIALIZERS) { |
| 1303 _errorReporter.reportErrorForNode( | 1302 _errorReporter.reportErrorForNode( |
| 1304 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS, | 1303 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS, |
| 1305 fieldName, | 1304 fieldName, |
| 1306 [fieldElement.displayName]); | 1305 [element.displayName]); |
| 1307 } | 1306 } |
| 1308 } | 1307 } |
| 1309 } | 1308 } |
| 1310 } | 1309 } |
| 1311 // Prepare a list of not initialized fields. | 1310 // Prepare a list of not initialized fields. |
| 1312 List<FieldElement> notInitFinalFields = <FieldElement>[]; | 1311 List<FieldElement> notInitFinalFields = <FieldElement>[]; |
| 1313 fieldElementsMap.forEach((FieldElement fieldElement, INIT_STATE state) { | 1312 fieldElementsMap.forEach((FieldElement fieldElement, INIT_STATE state) { |
| 1314 if (state == INIT_STATE.NOT_INIT) { | 1313 if (state == INIT_STATE.NOT_INIT) { |
| 1315 if (fieldElement.isFinal) { | 1314 if (fieldElement.isFinal) { |
| 1316 notInitFinalFields.add(fieldElement); | 1315 notInitFinalFields.add(fieldElement); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1376 */ | 1375 */ |
| 1377 bool _checkForAllInvalidOverrideErrorCodes( | 1376 bool _checkForAllInvalidOverrideErrorCodes( |
| 1378 ExecutableElement executableElement, | 1377 ExecutableElement executableElement, |
| 1379 ExecutableElement overriddenExecutable, | 1378 ExecutableElement overriddenExecutable, |
| 1380 List<ParameterElement> parameters, | 1379 List<ParameterElement> parameters, |
| 1381 List<AstNode> parameterLocations, | 1380 List<AstNode> parameterLocations, |
| 1382 SimpleIdentifier errorNameTarget) { | 1381 SimpleIdentifier errorNameTarget) { |
| 1383 bool isGetter = false; | 1382 bool isGetter = false; |
| 1384 bool isSetter = false; | 1383 bool isSetter = false; |
| 1385 if (executableElement is PropertyAccessorElement) { | 1384 if (executableElement is PropertyAccessorElement) { |
| 1386 PropertyAccessorElement accessorElement = executableElement; | 1385 isGetter = executableElement.isGetter; |
| 1387 isGetter = accessorElement.isGetter; | 1386 isSetter = executableElement.isSetter; |
| 1388 isSetter = accessorElement.isSetter; | |
| 1389 } | 1387 } |
| 1390 String executableElementName = executableElement.name; | 1388 String executableElementName = executableElement.name; |
| 1391 FunctionType overridingFT = executableElement.type; | 1389 FunctionType overridingFT = executableElement.type; |
| 1392 FunctionType overriddenFT = overriddenExecutable.type; | 1390 FunctionType overriddenFT = overriddenExecutable.type; |
| 1393 InterfaceType enclosingType = _enclosingClass.type; | 1391 InterfaceType enclosingType = _enclosingClass.type; |
| 1394 overriddenFT = | 1392 overriddenFT = |
| 1395 _inheritanceManager.substituteTypeArgumentsInMemberFromInheritance( | 1393 _inheritanceManager.substituteTypeArgumentsInMemberFromInheritance( |
| 1396 overriddenFT, executableElementName, enclosingType); | 1394 overriddenFT, executableElementName, enclosingType); |
| 1397 if (overridingFT == null || overriddenFT == null) { | 1395 if (overridingFT == null || overriddenFT == null) { |
| 1398 return false; | 1396 return false; |
| (...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2137 void _checkForAssignmentToFinal(Expression expression) { | 2135 void _checkForAssignmentToFinal(Expression expression) { |
| 2138 // prepare element | 2136 // prepare element |
| 2139 Element element = null; | 2137 Element element = null; |
| 2140 AstNode highlightedNode = expression; | 2138 AstNode highlightedNode = expression; |
| 2141 if (expression is Identifier) { | 2139 if (expression is Identifier) { |
| 2142 element = expression.staticElement; | 2140 element = expression.staticElement; |
| 2143 if (expression is PrefixedIdentifier) { | 2141 if (expression is PrefixedIdentifier) { |
| 2144 highlightedNode = expression.identifier; | 2142 highlightedNode = expression.identifier; |
| 2145 } | 2143 } |
| 2146 } else if (expression is PropertyAccess) { | 2144 } else if (expression is PropertyAccess) { |
| 2147 PropertyAccess propertyAccess = expression; | 2145 element = expression.propertyName.staticElement; |
| 2148 element = propertyAccess.propertyName.staticElement; | 2146 highlightedNode = expression.propertyName; |
| 2149 highlightedNode = propertyAccess.propertyName; | |
| 2150 } | 2147 } |
| 2151 // check if element is assignable | 2148 // check if element is assignable |
| 2152 if (element is PropertyAccessorElement) { | 2149 Element toVariable(Element element) { |
| 2153 PropertyAccessorElement accessor = element as PropertyAccessorElement; | 2150 return element is PropertyAccessorElement ? element.variable : element; |
| 2154 element = accessor.variable; | |
| 2155 } | 2151 } |
| 2152 element = toVariable(element); |
| 2156 if (element is VariableElement) { | 2153 if (element is VariableElement) { |
| 2157 if (element.isConst) { | 2154 if (element.isConst) { |
| 2158 _errorReporter.reportErrorForNode( | 2155 _errorReporter.reportErrorForNode( |
| 2159 StaticWarningCode.ASSIGNMENT_TO_CONST, expression); | 2156 StaticWarningCode.ASSIGNMENT_TO_CONST, expression); |
| 2160 } else if (element.isFinal) { | 2157 } else if (element.isFinal) { |
| 2161 if (element is FieldElementImpl && | 2158 if (element is FieldElementImpl && |
| 2162 element.setter == null && | 2159 element.setter == null && |
| 2163 element.isSynthetic) { | 2160 element.isSynthetic) { |
| 2164 _errorReporter.reportErrorForNode( | 2161 _errorReporter.reportErrorForNode( |
| 2165 StaticWarningCode.ASSIGNMENT_TO_FINAL_NO_SETTER, | 2162 StaticWarningCode.ASSIGNMENT_TO_FINAL_NO_SETTER, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2206 * 'return' or 'throw'. | 2203 * 'return' or 'throw'. |
| 2207 * | 2204 * |
| 2208 * see [StaticWarningCode.CASE_BLOCK_NOT_TERMINATED]. | 2205 * see [StaticWarningCode.CASE_BLOCK_NOT_TERMINATED]. |
| 2209 */ | 2206 */ |
| 2210 void _checkForCaseBlockNotTerminated(SwitchCase switchCase) { | 2207 void _checkForCaseBlockNotTerminated(SwitchCase switchCase) { |
| 2211 NodeList<Statement> statements = switchCase.statements; | 2208 NodeList<Statement> statements = switchCase.statements; |
| 2212 if (statements.isEmpty) { | 2209 if (statements.isEmpty) { |
| 2213 // fall-through without statements at all | 2210 // fall-through without statements at all |
| 2214 AstNode parent = switchCase.parent; | 2211 AstNode parent = switchCase.parent; |
| 2215 if (parent is SwitchStatement) { | 2212 if (parent is SwitchStatement) { |
| 2216 SwitchStatement switchStatement = parent; | 2213 NodeList<SwitchMember> members = parent.members; |
| 2217 NodeList<SwitchMember> members = switchStatement.members; | |
| 2218 int index = members.indexOf(switchCase); | 2214 int index = members.indexOf(switchCase); |
| 2219 if (index != -1 && index < members.length - 1) { | 2215 if (index != -1 && index < members.length - 1) { |
| 2220 return; | 2216 return; |
| 2221 } | 2217 } |
| 2222 } | 2218 } |
| 2223 // no other switch member after this one | 2219 // no other switch member after this one |
| 2224 } else { | 2220 } else { |
| 2225 Statement statement = statements[statements.length - 1]; | 2221 Statement statement = statements[statements.length - 1]; |
| 2226 // terminated with statement | 2222 // terminated with statement |
| 2227 if (statement is BreakStatement || | 2223 if (statement is BreakStatement || |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2476 NodeList<ClassMember> classMembers = declaration.members; | 2472 NodeList<ClassMember> classMembers = declaration.members; |
| 2477 if (classMembers.isEmpty) { | 2473 if (classMembers.isEmpty) { |
| 2478 return; | 2474 return; |
| 2479 } | 2475 } |
| 2480 // Create a HashMap to track conflicting members, and then loop through | 2476 // Create a HashMap to track conflicting members, and then loop through |
| 2481 // members in the class to construct the HashMap, at the same time, | 2477 // members in the class to construct the HashMap, at the same time, |
| 2482 // look for violations. Don't add members if they are part of a conflict, | 2478 // look for violations. Don't add members if they are part of a conflict, |
| 2483 // this prevents multiple warnings for one issue. | 2479 // this prevents multiple warnings for one issue. |
| 2484 HashMap<String, ClassMember> memberHashMap = | 2480 HashMap<String, ClassMember> memberHashMap = |
| 2485 new HashMap<String, ClassMember>(); | 2481 new HashMap<String, ClassMember>(); |
| 2486 for (ClassMember classMember in classMembers) { | 2482 for (ClassMember member in classMembers) { |
| 2487 if (classMember is MethodDeclaration) { | 2483 if (member is MethodDeclaration) { |
| 2488 MethodDeclaration method = classMember; | 2484 if (member.isStatic) { |
| 2489 if (method.isStatic) { | |
| 2490 continue; | 2485 continue; |
| 2491 } | 2486 } |
| 2492 // prepare name | 2487 // prepare name |
| 2493 SimpleIdentifier name = method.name; | 2488 SimpleIdentifier name = member.name; |
| 2494 if (name == null) { | 2489 if (name == null) { |
| 2495 continue; | 2490 continue; |
| 2496 } | 2491 } |
| 2497 bool addThisMemberToTheMap = true; | 2492 bool addThisMemberToTheMap = true; |
| 2498 bool isGetter = method.isGetter; | 2493 bool isGetter = member.isGetter; |
| 2499 bool isSetter = method.isSetter; | 2494 bool isSetter = member.isSetter; |
| 2500 bool isOperator = method.isOperator; | 2495 bool isOperator = member.isOperator; |
| 2501 bool isMethod = !isGetter && !isSetter && !isOperator; | 2496 bool isMethod = !isGetter && !isSetter && !isOperator; |
| 2502 // Do lookups in the enclosing class (and the inherited member) if the | 2497 // Do lookups in the enclosing class (and the inherited member) if the |
| 2503 // member is a method or a setter for | 2498 // member is a method or a setter for |
| 2504 // StaticWarningCode.CONFLICTING_INSTANCE_METHOD_SETTER warning. | 2499 // StaticWarningCode.CONFLICTING_INSTANCE_METHOD_SETTER warning. |
| 2505 if (isMethod) { | 2500 if (isMethod) { |
| 2506 String setterName = "${name.name}="; | 2501 String setterName = "${name.name}="; |
| 2507 Element enclosingElementOfSetter = null; | 2502 Element enclosingElementOfSetter = null; |
| 2508 ClassMember conflictingSetter = memberHashMap[setterName]; | 2503 ClassMember conflictingSetter = memberHashMap[setterName]; |
| 2509 if (conflictingSetter != null) { | 2504 if (conflictingSetter != null) { |
| 2510 enclosingElementOfSetter = | 2505 enclosingElementOfSetter = |
| (...skipping 23 matching lines...) Expand all Loading... |
| 2534 !conflictingMethod.isGetter) { | 2529 !conflictingMethod.isGetter) { |
| 2535 _errorReporter.reportErrorForNode( | 2530 _errorReporter.reportErrorForNode( |
| 2536 StaticWarningCode.CONFLICTING_INSTANCE_METHOD_SETTER2, | 2531 StaticWarningCode.CONFLICTING_INSTANCE_METHOD_SETTER2, |
| 2537 name, | 2532 name, |
| 2538 [_enclosingClass.displayName, name.name]); | 2533 [_enclosingClass.displayName, name.name]); |
| 2539 addThisMemberToTheMap = false; | 2534 addThisMemberToTheMap = false; |
| 2540 } | 2535 } |
| 2541 } | 2536 } |
| 2542 // Finally, add this member into the HashMap. | 2537 // Finally, add this member into the HashMap. |
| 2543 if (addThisMemberToTheMap) { | 2538 if (addThisMemberToTheMap) { |
| 2544 if (method.isSetter) { | 2539 if (member.isSetter) { |
| 2545 memberHashMap["${name.name}="] = method; | 2540 memberHashMap["${name.name}="] = member; |
| 2546 } else { | 2541 } else { |
| 2547 memberHashMap[name.name] = method; | 2542 memberHashMap[name.name] = member; |
| 2548 } | 2543 } |
| 2549 } | 2544 } |
| 2550 } | 2545 } |
| 2551 } | 2546 } |
| 2552 } | 2547 } |
| 2553 | 2548 |
| 2554 /** | 2549 /** |
| 2555 * Verify that the enclosing class does not have an instance member with the | 2550 * Verify that the enclosing class does not have an instance member with the |
| 2556 * same name as the given static [method] declaration. | 2551 * same name as the given static [method] declaration. |
| 2557 * | 2552 * |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2689 // check for mixins | 2684 // check for mixins |
| 2690 if (_enclosingClass.mixins.length != 0) { | 2685 if (_enclosingClass.mixins.length != 0) { |
| 2691 _errorReporter.reportErrorForNode( | 2686 _errorReporter.reportErrorForNode( |
| 2692 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_MIXIN, | 2687 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_MIXIN, |
| 2693 constructor.returnType); | 2688 constructor.returnType); |
| 2694 return; | 2689 return; |
| 2695 } | 2690 } |
| 2696 // try to find and check super constructor invocation | 2691 // try to find and check super constructor invocation |
| 2697 for (ConstructorInitializer initializer in constructor.initializers) { | 2692 for (ConstructorInitializer initializer in constructor.initializers) { |
| 2698 if (initializer is SuperConstructorInvocation) { | 2693 if (initializer is SuperConstructorInvocation) { |
| 2699 SuperConstructorInvocation superInvocation = initializer; | 2694 ConstructorElement element = initializer.staticElement; |
| 2700 ConstructorElement element = superInvocation.staticElement; | |
| 2701 if (element == null || element.isConst) { | 2695 if (element == null || element.isConst) { |
| 2702 return; | 2696 return; |
| 2703 } | 2697 } |
| 2704 _errorReporter.reportErrorForNode( | 2698 _errorReporter.reportErrorForNode( |
| 2705 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER, | 2699 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER, |
| 2706 superInvocation, | 2700 initializer, |
| 2707 [element.enclosingElement.displayName]); | 2701 [element.enclosingElement.displayName]); |
| 2708 return; | 2702 return; |
| 2709 } | 2703 } |
| 2710 } | 2704 } |
| 2711 // no explicit super constructor invocation, check default constructor | 2705 // no explicit super constructor invocation, check default constructor |
| 2712 InterfaceType supertype = _enclosingClass.supertype; | 2706 InterfaceType supertype = _enclosingClass.supertype; |
| 2713 if (supertype == null) { | 2707 if (supertype == null) { |
| 2714 return; | 2708 return; |
| 2715 } | 2709 } |
| 2716 if (supertype.isObject) { | 2710 if (supertype.isObject) { |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2932 | 2926 |
| 2933 /** | 2927 /** |
| 2934 * Verify that there are no default parameters in the given function type | 2928 * Verify that there are no default parameters in the given function type |
| 2935 * [alias]. | 2929 * [alias]. |
| 2936 * | 2930 * |
| 2937 * See [CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPE_ALIAS]. | 2931 * See [CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPE_ALIAS]. |
| 2938 */ | 2932 */ |
| 2939 void _checkForDefaultValueInFunctionTypeAlias(FunctionTypeAlias alias) { | 2933 void _checkForDefaultValueInFunctionTypeAlias(FunctionTypeAlias alias) { |
| 2940 FormalParameterList formalParameterList = alias.parameters; | 2934 FormalParameterList formalParameterList = alias.parameters; |
| 2941 NodeList<FormalParameter> parameters = formalParameterList.parameters; | 2935 NodeList<FormalParameter> parameters = formalParameterList.parameters; |
| 2942 for (FormalParameter formalParameter in parameters) { | 2936 for (FormalParameter parameter in parameters) { |
| 2943 if (formalParameter is DefaultFormalParameter) { | 2937 if (parameter is DefaultFormalParameter) { |
| 2944 DefaultFormalParameter defaultFormalParameter = formalParameter; | 2938 if (parameter.defaultValue != null) { |
| 2945 if (defaultFormalParameter.defaultValue != null) { | |
| 2946 _errorReporter.reportErrorForNode( | 2939 _errorReporter.reportErrorForNode( |
| 2947 CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPE_ALIAS, alias); | 2940 CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPE_ALIAS, alias); |
| 2948 } | 2941 } |
| 2949 } | 2942 } |
| 2950 } | 2943 } |
| 2951 } | 2944 } |
| 2952 | 2945 |
| 2953 /** | 2946 /** |
| 2954 * Verify that the given default formal [parameter] is not part of a function | 2947 * Verify that the given default formal [parameter] is not part of a function |
| 2955 * typed parameter. | 2948 * typed parameter. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2980 */ | 2973 */ |
| 2981 void _checkForDeferredPrefixCollisions(CompilationUnit unit) { | 2974 void _checkForDeferredPrefixCollisions(CompilationUnit unit) { |
| 2982 NodeList<Directive> directives = unit.directives; | 2975 NodeList<Directive> directives = unit.directives; |
| 2983 int count = directives.length; | 2976 int count = directives.length; |
| 2984 if (count > 0) { | 2977 if (count > 0) { |
| 2985 HashMap<PrefixElement, List<ImportDirective>> prefixToDirectivesMap = | 2978 HashMap<PrefixElement, List<ImportDirective>> prefixToDirectivesMap = |
| 2986 new HashMap<PrefixElement, List<ImportDirective>>(); | 2979 new HashMap<PrefixElement, List<ImportDirective>>(); |
| 2987 for (int i = 0; i < count; i++) { | 2980 for (int i = 0; i < count; i++) { |
| 2988 Directive directive = directives[i]; | 2981 Directive directive = directives[i]; |
| 2989 if (directive is ImportDirective) { | 2982 if (directive is ImportDirective) { |
| 2990 ImportDirective importDirective = directive; | 2983 SimpleIdentifier prefix = directive.prefix; |
| 2991 SimpleIdentifier prefix = importDirective.prefix; | |
| 2992 if (prefix != null) { | 2984 if (prefix != null) { |
| 2993 Element element = prefix.staticElement; | 2985 Element element = prefix.staticElement; |
| 2994 if (element is PrefixElement) { | 2986 if (element is PrefixElement) { |
| 2995 PrefixElement prefixElement = element; | 2987 List<ImportDirective> elements = prefixToDirectivesMap[element]; |
| 2996 List<ImportDirective> elements = | |
| 2997 prefixToDirectivesMap[prefixElement]; | |
| 2998 if (elements == null) { | 2988 if (elements == null) { |
| 2999 elements = new List<ImportDirective>(); | 2989 elements = new List<ImportDirective>(); |
| 3000 prefixToDirectivesMap[prefixElement] = elements; | 2990 prefixToDirectivesMap[element] = elements; |
| 3001 } | 2991 } |
| 3002 elements.add(importDirective); | 2992 elements.add(directive); |
| 3003 } | 2993 } |
| 3004 } | 2994 } |
| 3005 } | 2995 } |
| 3006 } | 2996 } |
| 3007 for (List<ImportDirective> imports in prefixToDirectivesMap.values) { | 2997 for (List<ImportDirective> imports in prefixToDirectivesMap.values) { |
| 3008 _checkDeferredPrefixCollision(imports); | 2998 _checkDeferredPrefixCollision(imports); |
| 3009 } | 2999 } |
| 3010 } | 3000 } |
| 3011 } | 3001 } |
| 3012 | 3002 |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3558 if (enclosingElement is! ClassElement) { | 3548 if (enclosingElement is! ClassElement) { |
| 3559 return; | 3549 return; |
| 3560 } | 3550 } |
| 3561 // comment | 3551 // comment |
| 3562 AstNode parent = identifier.parent; | 3552 AstNode parent = identifier.parent; |
| 3563 if (parent is CommentReference) { | 3553 if (parent is CommentReference) { |
| 3564 return; | 3554 return; |
| 3565 } | 3555 } |
| 3566 // qualified method invocation | 3556 // qualified method invocation |
| 3567 if (parent is MethodInvocation) { | 3557 if (parent is MethodInvocation) { |
| 3568 MethodInvocation invocation = parent; | 3558 if (identical(parent.methodName, identifier) && |
| 3569 if (identical(invocation.methodName, identifier) && | 3559 parent.realTarget != null) { |
| 3570 invocation.realTarget != null) { | |
| 3571 return; | 3560 return; |
| 3572 } | 3561 } |
| 3573 } | 3562 } |
| 3574 // qualified property access | 3563 // qualified property access |
| 3575 if (parent is PropertyAccess) { | 3564 if (parent is PropertyAccess) { |
| 3576 PropertyAccess access = parent; | 3565 if (identical(parent.propertyName, identifier) && |
| 3577 if (identical(access.propertyName, identifier) && | 3566 parent.realTarget != null) { |
| 3578 access.realTarget != null) { | |
| 3579 return; | 3567 return; |
| 3580 } | 3568 } |
| 3581 } | 3569 } |
| 3582 if (parent is PrefixedIdentifier) { | 3570 if (parent is PrefixedIdentifier) { |
| 3583 PrefixedIdentifier prefixed = parent; | 3571 if (identical(parent.identifier, identifier)) { |
| 3584 if (identical(prefixed.identifier, identifier)) { | |
| 3585 return; | 3572 return; |
| 3586 } | 3573 } |
| 3587 } | 3574 } |
| 3588 | 3575 |
| 3589 if (_isInStaticMethod) { | 3576 if (_isInStaticMethod) { |
| 3590 _errorReporter.reportErrorForNode( | 3577 _errorReporter.reportErrorForNode( |
| 3591 CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_STATIC, identifier); | 3578 CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_STATIC, identifier); |
| 3592 } else if (_isInFactory) { | 3579 } else if (_isInFactory) { |
| 3593 _errorReporter.reportErrorForNode( | 3580 _errorReporter.reportErrorForNode( |
| 3594 CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_FACTORY, identifier); | 3581 CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_FACTORY, identifier); |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3929 | 3916 |
| 3930 /** | 3917 /** |
| 3931 * Check the given [initializer] to ensure that the field being initialized is | 3918 * Check the given [initializer] to ensure that the field being initialized is |
| 3932 * a valid field. The [fieldName] is the field name from the | 3919 * a valid field. The [fieldName] is the field name from the |
| 3933 * [ConstructorFieldInitializer]. The [staticElement] is the static element | 3920 * [ConstructorFieldInitializer]. The [staticElement] is the static element |
| 3934 * from the name in the [ConstructorFieldInitializer]. | 3921 * from the name in the [ConstructorFieldInitializer]. |
| 3935 */ | 3922 */ |
| 3936 void _checkForInvalidField(ConstructorFieldInitializer initializer, | 3923 void _checkForInvalidField(ConstructorFieldInitializer initializer, |
| 3937 SimpleIdentifier fieldName, Element staticElement) { | 3924 SimpleIdentifier fieldName, Element staticElement) { |
| 3938 if (staticElement is FieldElement) { | 3925 if (staticElement is FieldElement) { |
| 3939 FieldElement fieldElement = staticElement; | 3926 if (staticElement.isSynthetic) { |
| 3940 if (fieldElement.isSynthetic) { | |
| 3941 _errorReporter.reportErrorForNode( | 3927 _errorReporter.reportErrorForNode( |
| 3942 CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTENT_FIELD, | 3928 CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTENT_FIELD, |
| 3943 initializer, | 3929 initializer, |
| 3944 [fieldName]); | 3930 [fieldName]); |
| 3945 } else if (fieldElement.isStatic) { | 3931 } else if (staticElement.isStatic) { |
| 3946 _errorReporter.reportErrorForNode( | 3932 _errorReporter.reportErrorForNode( |
| 3947 CompileTimeErrorCode.INITIALIZER_FOR_STATIC_FIELD, | 3933 CompileTimeErrorCode.INITIALIZER_FOR_STATIC_FIELD, |
| 3948 initializer, | 3934 initializer, |
| 3949 [fieldName]); | 3935 [fieldName]); |
| 3950 } | 3936 } |
| 3951 } else { | 3937 } else { |
| 3952 _errorReporter.reportErrorForNode( | 3938 _errorReporter.reportErrorForNode( |
| 3953 CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTENT_FIELD, | 3939 CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTENT_FIELD, |
| 3954 initializer, | 3940 initializer, |
| 3955 [fieldName]); | 3941 [fieldName]); |
| (...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4607 // class. | 4593 // class. |
| 4608 int missingOverridesSize = missingOverrides.length; | 4594 int missingOverridesSize = missingOverrides.length; |
| 4609 if (missingOverridesSize == 0) { | 4595 if (missingOverridesSize == 0) { |
| 4610 return; | 4596 return; |
| 4611 } | 4597 } |
| 4612 List<ExecutableElement> missingOverridesArray = | 4598 List<ExecutableElement> missingOverridesArray = |
| 4613 new List.from(missingOverrides); | 4599 new List.from(missingOverrides); |
| 4614 List<String> stringMembersArrayListSet = new List<String>(); | 4600 List<String> stringMembersArrayListSet = new List<String>(); |
| 4615 for (int i = 0; i < missingOverridesArray.length; i++) { | 4601 for (int i = 0; i < missingOverridesArray.length; i++) { |
| 4616 String newStrMember; | 4602 String newStrMember; |
| 4617 Element enclosingElement = missingOverridesArray[i].enclosingElement; | 4603 ExecutableElement element = missingOverridesArray[i]; |
| 4604 Element enclosingElement = element.enclosingElement; |
| 4618 String prefix = StringUtilities.EMPTY; | 4605 String prefix = StringUtilities.EMPTY; |
| 4619 if (missingOverridesArray[i] is PropertyAccessorElement) { | 4606 if (element is PropertyAccessorElement) { |
| 4620 PropertyAccessorElement propertyAccessorElement = | 4607 if (element.isGetter) { |
| 4621 missingOverridesArray[i] as PropertyAccessorElement; | |
| 4622 if (propertyAccessorElement.isGetter) { | |
| 4623 prefix = _GETTER_SPACE; | 4608 prefix = _GETTER_SPACE; |
| 4624 // "getter " | 4609 // "getter " |
| 4625 } else { | 4610 } else { |
| 4626 prefix = _SETTER_SPACE; | 4611 prefix = _SETTER_SPACE; |
| 4627 // "setter " | 4612 // "setter " |
| 4628 } | 4613 } |
| 4629 } | 4614 } |
| 4630 if (enclosingElement != null) { | 4615 if (enclosingElement != null) { |
| 4631 newStrMember = | 4616 newStrMember = |
| 4632 "$prefix'${enclosingElement.displayName}.${missingOverridesArray[i].
displayName}'"; | 4617 "$prefix'${enclosingElement.displayName}.${element.displayName}'"; |
| 4633 } else { | 4618 } else { |
| 4634 newStrMember = "$prefix'${missingOverridesArray[i].displayName}'"; | 4619 newStrMember = "$prefix'${element.displayName}'"; |
| 4635 } | 4620 } |
| 4636 stringMembersArrayListSet.add(newStrMember); | 4621 stringMembersArrayListSet.add(newStrMember); |
| 4637 } | 4622 } |
| 4638 List<String> stringMembersArray = new List.from(stringMembersArrayListSet); | 4623 List<String> stringMembersArray = new List.from(stringMembersArrayListSet); |
| 4639 stringMembersArray.sort(); | 4624 stringMembersArray.sort(); |
| 4640 AnalysisErrorWithProperties analysisError; | 4625 AnalysisErrorWithProperties analysisError; |
| 4641 if (stringMembersArray.length == 1) { | 4626 if (stringMembersArray.length == 1) { |
| 4642 analysisError = _errorReporter.newErrorWithProperties( | 4627 analysisError = _errorReporter.newErrorWithProperties( |
| 4643 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE, | 4628 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE, |
| 4644 classNameNode, | 4629 classNameNode, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4706 */ | 4691 */ |
| 4707 void _checkForNonBoolExpression(AssertStatement statement) { | 4692 void _checkForNonBoolExpression(AssertStatement statement) { |
| 4708 Expression expression = statement.condition; | 4693 Expression expression = statement.condition; |
| 4709 DartType type = getStaticType(expression); | 4694 DartType type = getStaticType(expression); |
| 4710 if (type is InterfaceType) { | 4695 if (type is InterfaceType) { |
| 4711 if (!_typeSystem.isAssignableTo(type, _boolType)) { | 4696 if (!_typeSystem.isAssignableTo(type, _boolType)) { |
| 4712 _errorReporter.reportErrorForNode( | 4697 _errorReporter.reportErrorForNode( |
| 4713 StaticTypeWarningCode.NON_BOOL_EXPRESSION, expression); | 4698 StaticTypeWarningCode.NON_BOOL_EXPRESSION, expression); |
| 4714 } | 4699 } |
| 4715 } else if (type is FunctionType) { | 4700 } else if (type is FunctionType) { |
| 4716 FunctionType functionType = type; | 4701 if (type.typeArguments.length == 0 && |
| 4717 if (functionType.typeArguments.length == 0 && | 4702 !_typeSystem.isAssignableTo(type.returnType, _boolType)) { |
| 4718 !_typeSystem.isAssignableTo(functionType.returnType, _boolType)) { | |
| 4719 _errorReporter.reportErrorForNode( | 4703 _errorReporter.reportErrorForNode( |
| 4720 StaticTypeWarningCode.NON_BOOL_EXPRESSION, expression); | 4704 StaticTypeWarningCode.NON_BOOL_EXPRESSION, expression); |
| 4721 } | 4705 } |
| 4722 } | 4706 } |
| 4723 } | 4707 } |
| 4724 | 4708 |
| 4725 /** | 4709 /** |
| 4726 * Checks to ensure that the given [expression] is assignable to bool. | 4710 * Checks to ensure that the given [expression] is assignable to bool. |
| 4727 * | 4711 * |
| 4728 * See [StaticTypeWarningCode.NON_BOOL_NEGATION_EXPRESSION]. | 4712 * See [StaticTypeWarningCode.NON_BOOL_NEGATION_EXPRESSION]. |
| (...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5416 if (element is FieldFormalParameterElement) { | 5400 if (element is FieldFormalParameterElement) { |
| 5417 FieldElement fieldElement = element.field; | 5401 FieldElement fieldElement = element.field; |
| 5418 if (fieldElement == null || fieldElement.isSynthetic) { | 5402 if (fieldElement == null || fieldElement.isSynthetic) { |
| 5419 _errorReporter.reportErrorForNode( | 5403 _errorReporter.reportErrorForNode( |
| 5420 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD, | 5404 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD, |
| 5421 parameter, | 5405 parameter, |
| 5422 [parameter.identifier.name]); | 5406 [parameter.identifier.name]); |
| 5423 } else { | 5407 } else { |
| 5424 ParameterElement parameterElement = parameter.element; | 5408 ParameterElement parameterElement = parameter.element; |
| 5425 if (parameterElement is FieldFormalParameterElementImpl) { | 5409 if (parameterElement is FieldFormalParameterElementImpl) { |
| 5426 FieldFormalParameterElementImpl fieldFormal = parameterElement; | 5410 DartType declaredType = parameterElement.type; |
| 5427 DartType declaredType = fieldFormal.type; | |
| 5428 DartType fieldType = fieldElement.type; | 5411 DartType fieldType = fieldElement.type; |
| 5429 if (fieldElement.isSynthetic) { | 5412 if (fieldElement.isSynthetic) { |
| 5430 _errorReporter.reportErrorForNode( | 5413 _errorReporter.reportErrorForNode( |
| 5431 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD, | 5414 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD, |
| 5432 parameter, | 5415 parameter, |
| 5433 [parameter.identifier.name]); | 5416 [parameter.identifier.name]); |
| 5434 } else if (fieldElement.isStatic) { | 5417 } else if (fieldElement.isStatic) { |
| 5435 _errorReporter.reportErrorForNode( | 5418 _errorReporter.reportErrorForNode( |
| 5436 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_STATIC_FIELD, | 5419 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_STATIC_FIELD, |
| 5437 parameter, | 5420 parameter, |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5827 ClassElement definingClass = | 5810 ClassElement definingClass = |
| 5828 method.getAncestor((Element element) => element is ClassElement); | 5811 method.getAncestor((Element element) => element is ClassElement); |
| 5829 return definingClass != null && !definingClass.type.isObject; | 5812 return definingClass != null && !definingClass.type.isObject; |
| 5830 } | 5813 } |
| 5831 | 5814 |
| 5832 /** | 5815 /** |
| 5833 * Return `true` if the given [constructor] redirects to itself, directly or | 5816 * Return `true` if the given [constructor] redirects to itself, directly or |
| 5834 * indirectly. | 5817 * indirectly. |
| 5835 */ | 5818 */ |
| 5836 bool _hasRedirectingFactoryConstructorCycle(ConstructorElement constructor) { | 5819 bool _hasRedirectingFactoryConstructorCycle(ConstructorElement constructor) { |
| 5820 ConstructorElement nonMember(ConstructorElement constructor) { |
| 5821 return constructor is ConstructorMember |
| 5822 ? constructor.baseElement |
| 5823 : constructor; |
| 5824 } |
| 5825 |
| 5837 Set<ConstructorElement> constructors = new HashSet<ConstructorElement>(); | 5826 Set<ConstructorElement> constructors = new HashSet<ConstructorElement>(); |
| 5838 ConstructorElement current = constructor; | 5827 ConstructorElement current = constructor; |
| 5839 while (current != null) { | 5828 while (current != null) { |
| 5840 if (constructors.contains(current)) { | 5829 if (constructors.contains(current)) { |
| 5841 return identical(current, constructor); | 5830 return identical(current, constructor); |
| 5842 } | 5831 } |
| 5843 constructors.add(current); | 5832 constructors.add(current); |
| 5844 current = current.redirectedConstructor; | 5833 current = nonMember(current.redirectedConstructor); |
| 5845 if (current is ConstructorMember) { | |
| 5846 current = (current as ConstructorMember).baseElement; | |
| 5847 } | |
| 5848 } | 5834 } |
| 5849 return false; | 5835 return false; |
| 5850 } | 5836 } |
| 5851 | 5837 |
| 5852 /** | 5838 /** |
| 5853 * Return `true` if the given [element] has direct or indirect reference to | 5839 * Return `true` if the given [element] has direct or indirect reference to |
| 5854 * itself from anywhere except a class element or type parameter bounds. | 5840 * itself from anywhere except a class element or type parameter bounds. |
| 5855 */ | 5841 */ |
| 5856 bool _hasTypedefSelfReference(Element element) { | 5842 bool _hasTypedefSelfReference(Element element) { |
| 5857 Set<Element> checked = new HashSet<Element>(); | 5843 Set<Element> checked = new HashSet<Element>(); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5923 return true; | 5909 return true; |
| 5924 } | 5910 } |
| 5925 List<InterfaceType> mixins = classElement.mixins; | 5911 List<InterfaceType> mixins = classElement.mixins; |
| 5926 for (int i = 0; i < mixins.length && foundElt == null; i++) { | 5912 for (int i = 0; i < mixins.length && foundElt == null; i++) { |
| 5927 foundElt = mixins[i].getMethod(executableName); | 5913 foundElt = mixins[i].getMethod(executableName); |
| 5928 } | 5914 } |
| 5929 if (foundElt != null && !(foundElt as MethodElement).isAbstract) { | 5915 if (foundElt != null && !(foundElt as MethodElement).isAbstract) { |
| 5930 return true; | 5916 return true; |
| 5931 } | 5917 } |
| 5932 } else if (executableElement is PropertyAccessorElement) { | 5918 } else if (executableElement is PropertyAccessorElement) { |
| 5933 PropertyAccessorElement propertyAccessorElement = executableElement; | 5919 if (executableElement.isGetter) { |
| 5934 if (propertyAccessorElement.isGetter) { | |
| 5935 foundElt = classElement.getGetter(executableName); | 5920 foundElt = classElement.getGetter(executableName); |
| 5936 } | 5921 } |
| 5937 if (foundElt == null && propertyAccessorElement.isSetter) { | 5922 if (foundElt == null && executableElement.isSetter) { |
| 5938 foundElt = classElement.getSetter(executableName); | 5923 foundElt = classElement.getSetter(executableName); |
| 5939 } | 5924 } |
| 5940 if (foundElt != null && | 5925 if (foundElt != null && |
| 5941 !(foundElt as PropertyAccessorElement).isAbstract) { | 5926 !(foundElt as PropertyAccessorElement).isAbstract) { |
| 5942 return true; | 5927 return true; |
| 5943 } | 5928 } |
| 5944 List<InterfaceType> mixins = classElement.mixins; | 5929 List<InterfaceType> mixins = classElement.mixins; |
| 5945 for (int i = 0; i < mixins.length && foundElt == null; i++) { | 5930 for (int i = 0; i < mixins.length && foundElt == null; i++) { |
| 5946 foundElt = mixins[i].getGetter(executableName); | 5931 foundElt = mixins[i].getGetter(executableName); |
| 5947 if (foundElt == null) { | 5932 if (foundElt == null) { |
| 5948 foundElt = mixins[i].getSetter(executableName); | 5933 foundElt = mixins[i].getSetter(executableName); |
| 5949 } | 5934 } |
| 5950 } | 5935 } |
| 5951 if (foundElt != null && | 5936 if (foundElt != null && |
| 5952 !(foundElt as PropertyAccessorElement).isAbstract) { | 5937 !(foundElt as PropertyAccessorElement).isAbstract) { |
| 5953 return true; | 5938 return true; |
| 5954 } | 5939 } |
| 5955 } | 5940 } |
| 5956 return false; | 5941 return false; |
| 5957 } | 5942 } |
| 5958 | 5943 |
| 5959 /** | 5944 /** |
| 5960 * Return `true` if the given 'this' [expression] is in a valid context. | 5945 * Return `true` if the given 'this' [expression] is in a valid context. |
| 5961 */ | 5946 */ |
| 5962 bool _isThisInValidContext(ThisExpression expression) { | 5947 bool _isThisInValidContext(ThisExpression expression) { |
| 5963 for (AstNode node = expression.parent; node != null; node = node.parent) { | 5948 for (AstNode node = expression.parent; node != null; node = node.parent) { |
| 5964 if (node is CompilationUnit) { | 5949 if (node is CompilationUnit) { |
| 5965 return false; | 5950 return false; |
| 5966 } | 5951 } else if (node is ConstructorDeclaration) { |
| 5967 if (node is ConstructorDeclaration) { | |
| 5968 return node.factoryKeyword == null; | 5952 return node.factoryKeyword == null; |
| 5969 } | 5953 } else if (node is ConstructorInitializer) { |
| 5970 if (node is ConstructorInitializer) { | |
| 5971 return false; | 5954 return false; |
| 5972 } | 5955 } else if (node is MethodDeclaration) { |
| 5973 if (node is MethodDeclaration) { | |
| 5974 return !node.isStatic; | 5956 return !node.isStatic; |
| 5975 } | 5957 } |
| 5976 } | 5958 } |
| 5977 return false; | 5959 return false; |
| 5978 } | 5960 } |
| 5979 | 5961 |
| 5980 /** | 5962 /** |
| 5981 * Return `true` if the given [identifier] is in a location where it is | 5963 * Return `true` if the given [identifier] is in a location where it is |
| 5982 * allowed to resolve to a static member of a supertype. | 5964 * allowed to resolve to a static member of a supertype. |
| 5983 */ | 5965 */ |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6147 } | 6129 } |
| 6148 | 6130 |
| 6149 void _addTypeToCheck(DartType type) { | 6131 void _addTypeToCheck(DartType type) { |
| 6150 if (type == null) { | 6132 if (type == null) { |
| 6151 return; | 6133 return; |
| 6152 } | 6134 } |
| 6153 // schedule for checking | 6135 // schedule for checking |
| 6154 toCheck.add(type.element); | 6136 toCheck.add(type.element); |
| 6155 // type arguments | 6137 // type arguments |
| 6156 if (type is InterfaceType) { | 6138 if (type is InterfaceType) { |
| 6157 InterfaceType interfaceType = type; | 6139 for (DartType typeArgument in type.typeArguments) { |
| 6158 for (DartType typeArgument in interfaceType.typeArguments) { | |
| 6159 _addTypeToCheck(typeArgument); | 6140 _addTypeToCheck(typeArgument); |
| 6160 } | 6141 } |
| 6161 } | 6142 } |
| 6162 } | 6143 } |
| 6163 } | 6144 } |
| 6164 | 6145 |
| 6165 /** | 6146 /** |
| 6166 * Recursively visits an AST, looking for method invocations. | 6147 * Recursively visits an AST, looking for method invocations. |
| 6167 */ | 6148 */ |
| 6168 class _InvocationCollector extends RecursiveAstVisitor { | 6149 class _InvocationCollector extends RecursiveAstVisitor { |
| 6169 final List<String> superCalls = <String>[]; | 6150 final List<String> superCalls = <String>[]; |
| 6170 | 6151 |
| 6171 @override | 6152 @override |
| 6172 visitMethodInvocation(MethodInvocation node) { | 6153 visitMethodInvocation(MethodInvocation node) { |
| 6173 if (node.target is SuperExpression) { | 6154 if (node.target is SuperExpression) { |
| 6174 superCalls.add(node.methodName.name); | 6155 superCalls.add(node.methodName.name); |
| 6175 } | 6156 } |
| 6176 } | 6157 } |
| 6177 } | 6158 } |
| OLD | NEW |