OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library analyzer.src.generated.resolver; | 5 library analyzer.src.generated.resolver; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
| 9 import 'package:analyzer/dart/element/element.dart'; |
| 10 import 'package:analyzer/dart/element/type.dart'; |
| 11 import 'package:analyzer/dart/element/visitor.dart'; |
| 12 import 'package:analyzer/src/dart/element/element.dart'; |
| 13 import 'package:analyzer/src/dart/element/member.dart'; |
| 14 import 'package:analyzer/src/dart/element/type.dart'; |
9 import 'package:analyzer/src/generated/ast.dart'; | 15 import 'package:analyzer/src/generated/ast.dart'; |
10 import 'package:analyzer/src/generated/constant.dart'; | 16 import 'package:analyzer/src/generated/constant.dart'; |
11 import 'package:analyzer/src/generated/element.dart'; | |
12 import 'package:analyzer/src/generated/element_resolver.dart'; | 17 import 'package:analyzer/src/generated/element_resolver.dart'; |
13 import 'package:analyzer/src/generated/engine.dart'; | 18 import 'package:analyzer/src/generated/engine.dart'; |
14 import 'package:analyzer/src/generated/error.dart'; | 19 import 'package:analyzer/src/generated/error.dart'; |
15 import 'package:analyzer/src/generated/error_verifier.dart'; | 20 import 'package:analyzer/src/generated/error_verifier.dart'; |
16 import 'package:analyzer/src/generated/java_core.dart'; | 21 import 'package:analyzer/src/generated/java_core.dart'; |
17 import 'package:analyzer/src/generated/java_engine.dart'; | 22 import 'package:analyzer/src/generated/java_engine.dart'; |
18 import 'package:analyzer/src/generated/scanner.dart'; | 23 import 'package:analyzer/src/generated/scanner.dart'; |
19 import 'package:analyzer/src/generated/source.dart'; | 24 import 'package:analyzer/src/generated/source.dart'; |
20 import 'package:analyzer/src/generated/static_type_analyzer.dart'; | 25 import 'package:analyzer/src/generated/static_type_analyzer.dart'; |
21 import 'package:analyzer/src/generated/type_system.dart'; | 26 import 'package:analyzer/src/generated/type_system.dart'; |
22 import 'package:analyzer/src/generated/utilities_dart.dart'; | 27 import 'package:analyzer/src/generated/utilities_dart.dart'; |
23 import 'package:analyzer/src/task/strong/info.dart' show InferredType, StaticInf
o; | 28 import 'package:analyzer/src/task/strong/info.dart' |
| 29 show InferredType, StaticInfo; |
24 | 30 |
25 export 'package:analyzer/src/generated/type_system.dart'; | 31 export 'package:analyzer/src/generated/type_system.dart'; |
26 | 32 |
27 /** | 33 /** |
28 * Instances of the class `BestPracticesVerifier` traverse an AST structure look
ing for | 34 * Instances of the class `BestPracticesVerifier` traverse an AST structure look
ing for |
29 * violations of Dart best practices. | 35 * violations of Dart best practices. |
30 */ | 36 */ |
31 class BestPracticesVerifier extends RecursiveAstVisitor<Object> { | 37 class BestPracticesVerifier extends RecursiveAstVisitor<Object> { |
32 // static String _HASHCODE_GETTER_NAME = "hashCode"; | 38 // static String _HASHCODE_GETTER_NAME = "hashCode"; |
33 | 39 |
(...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1126 | 1132 |
1127 @override | 1133 @override |
1128 Object visitListLiteral(ListLiteral node) { | 1134 Object visitListLiteral(ListLiteral node) { |
1129 super.visitListLiteral(node); | 1135 super.visitListLiteral(node); |
1130 if (node.constKeyword != null) { | 1136 if (node.constKeyword != null) { |
1131 DartObjectImpl result; | 1137 DartObjectImpl result; |
1132 for (Expression element in node.elements) { | 1138 for (Expression element in node.elements) { |
1133 result = | 1139 result = |
1134 _validate(element, CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT); | 1140 _validate(element, CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT); |
1135 if (result != null) { | 1141 if (result != null) { |
1136 _reportErrorIfFromDeferredLibrary(element, | 1142 _reportErrorIfFromDeferredLibrary( |
1137 CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT_FROM_DEFERRED_LIBRA
RY); | 1143 element, |
| 1144 CompileTimeErrorCode |
| 1145 .NON_CONSTANT_LIST_ELEMENT_FROM_DEFERRED_LIBRARY); |
1138 } | 1146 } |
1139 } | 1147 } |
1140 } | 1148 } |
1141 return null; | 1149 return null; |
1142 } | 1150 } |
1143 | 1151 |
1144 @override | 1152 @override |
1145 Object visitMapLiteral(MapLiteral node) { | 1153 Object visitMapLiteral(MapLiteral node) { |
1146 super.visitMapLiteral(node); | 1154 super.visitMapLiteral(node); |
1147 bool isConst = node.constKeyword != null; | 1155 bool isConst = node.constKeyword != null; |
1148 bool reportEqualKeys = true; | 1156 bool reportEqualKeys = true; |
1149 HashSet<DartObject> keys = new HashSet<DartObject>(); | 1157 HashSet<DartObject> keys = new HashSet<DartObject>(); |
1150 List<Expression> invalidKeys = new List<Expression>(); | 1158 List<Expression> invalidKeys = new List<Expression>(); |
1151 for (MapLiteralEntry entry in node.entries) { | 1159 for (MapLiteralEntry entry in node.entries) { |
1152 Expression key = entry.key; | 1160 Expression key = entry.key; |
1153 if (isConst) { | 1161 if (isConst) { |
1154 DartObjectImpl keyResult = | 1162 DartObjectImpl keyResult = |
1155 _validate(key, CompileTimeErrorCode.NON_CONSTANT_MAP_KEY); | 1163 _validate(key, CompileTimeErrorCode.NON_CONSTANT_MAP_KEY); |
1156 Expression valueExpression = entry.value; | 1164 Expression valueExpression = entry.value; |
1157 DartObjectImpl valueResult = _validate( | 1165 DartObjectImpl valueResult = _validate( |
1158 valueExpression, CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE); | 1166 valueExpression, CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE); |
1159 if (valueResult != null) { | 1167 if (valueResult != null) { |
1160 _reportErrorIfFromDeferredLibrary(valueExpression, | 1168 _reportErrorIfFromDeferredLibrary( |
1161 CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE_FROM_DEFERRED_LIBRARY)
; | 1169 valueExpression, |
| 1170 CompileTimeErrorCode |
| 1171 .NON_CONSTANT_MAP_VALUE_FROM_DEFERRED_LIBRARY); |
1162 } | 1172 } |
1163 if (keyResult != null) { | 1173 if (keyResult != null) { |
1164 _reportErrorIfFromDeferredLibrary(key, | 1174 _reportErrorIfFromDeferredLibrary(key, |
1165 CompileTimeErrorCode.NON_CONSTANT_MAP_KEY_FROM_DEFERRED_LIBRARY); | 1175 CompileTimeErrorCode.NON_CONSTANT_MAP_KEY_FROM_DEFERRED_LIBRARY); |
1166 if (keys.contains(keyResult)) { | 1176 if (keys.contains(keyResult)) { |
1167 invalidKeys.add(key); | 1177 invalidKeys.add(key); |
1168 } else { | 1178 } else { |
1169 keys.add(keyResult); | 1179 keys.add(keyResult); |
1170 } | 1180 } |
1171 DartType type = keyResult.type; | 1181 DartType type = keyResult.type; |
1172 if (_implementsEqualsWhenNotAllowed(type)) { | 1182 if (_implementsEqualsWhenNotAllowed(type)) { |
1173 _errorReporter.reportErrorForNode( | 1183 _errorReporter.reportErrorForNode( |
1174 CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMPLEMENTS_EQ
UALS, | 1184 CompileTimeErrorCode |
| 1185 .CONST_MAP_KEY_EXPRESSION_TYPE_IMPLEMENTS_EQUALS, |
1175 key, | 1186 key, |
1176 [type.displayName]); | 1187 [type.displayName]); |
1177 } | 1188 } |
1178 } | 1189 } |
1179 } else { | 1190 } else { |
1180 // Note: we throw the errors away because this isn't actually a const. | 1191 // Note: we throw the errors away because this isn't actually a const. |
1181 AnalysisErrorListener errorListener = | 1192 AnalysisErrorListener errorListener = |
1182 AnalysisErrorListener.NULL_LISTENER; | 1193 AnalysisErrorListener.NULL_LISTENER; |
1183 ErrorReporter subErrorReporter = | 1194 ErrorReporter subErrorReporter = |
1184 new ErrorReporter(errorListener, _errorReporter.source); | 1195 new ErrorReporter(errorListener, _errorReporter.source); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1221 NodeList<SwitchMember> switchMembers = node.members; | 1232 NodeList<SwitchMember> switchMembers = node.members; |
1222 bool foundError = false; | 1233 bool foundError = false; |
1223 DartType firstType = null; | 1234 DartType firstType = null; |
1224 for (SwitchMember switchMember in switchMembers) { | 1235 for (SwitchMember switchMember in switchMembers) { |
1225 if (switchMember is SwitchCase) { | 1236 if (switchMember is SwitchCase) { |
1226 SwitchCase switchCase = switchMember; | 1237 SwitchCase switchCase = switchMember; |
1227 Expression expression = switchCase.expression; | 1238 Expression expression = switchCase.expression; |
1228 DartObjectImpl caseResult = _validate( | 1239 DartObjectImpl caseResult = _validate( |
1229 expression, CompileTimeErrorCode.NON_CONSTANT_CASE_EXPRESSION); | 1240 expression, CompileTimeErrorCode.NON_CONSTANT_CASE_EXPRESSION); |
1230 if (caseResult != null) { | 1241 if (caseResult != null) { |
1231 _reportErrorIfFromDeferredLibrary(expression, | 1242 _reportErrorIfFromDeferredLibrary( |
1232 CompileTimeErrorCode.NON_CONSTANT_CASE_EXPRESSION_FROM_DEFERRED_LI
BRARY); | 1243 expression, |
| 1244 CompileTimeErrorCode |
| 1245 .NON_CONSTANT_CASE_EXPRESSION_FROM_DEFERRED_LIBRARY); |
1233 DartObject value = caseResult; | 1246 DartObject value = caseResult; |
1234 if (firstType == null) { | 1247 if (firstType == null) { |
1235 firstType = value.type; | 1248 firstType = value.type; |
1236 } else { | 1249 } else { |
1237 DartType nType = value.type; | 1250 DartType nType = value.type; |
1238 if (firstType != nType) { | 1251 if (firstType != nType) { |
1239 _errorReporter.reportErrorForNode( | 1252 _errorReporter.reportErrorForNode( |
1240 CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES, | 1253 CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES, |
1241 expression, | 1254 expression, |
1242 [expression.toSource(), firstType.displayName]); | 1255 [expression.toSource(), firstType.displayName]); |
(...skipping 19 matching lines...) Expand all Loading... |
1262 if (result == null) { | 1275 if (result == null) { |
1263 // Variables marked "const" should have had their values computed by | 1276 // Variables marked "const" should have had their values computed by |
1264 // ConstantValueComputer. Other variables will only have had their | 1277 // ConstantValueComputer. Other variables will only have had their |
1265 // values computed if the value was needed (e.g. final variables in a | 1278 // values computed if the value was needed (e.g. final variables in a |
1266 // class containing const constructors). | 1279 // class containing const constructors). |
1267 assert(!node.isConst); | 1280 assert(!node.isConst); |
1268 return null; | 1281 return null; |
1269 } | 1282 } |
1270 _reportErrors(result.errors, | 1283 _reportErrors(result.errors, |
1271 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE); | 1284 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE); |
1272 _reportErrorIfFromDeferredLibrary(initializer, | 1285 _reportErrorIfFromDeferredLibrary( |
1273 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE_FROM_DE
FERRED_LIBRARY); | 1286 initializer, |
| 1287 CompileTimeErrorCode |
| 1288 .CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE_FROM_DEFERRED_LIBRARY); |
1274 } | 1289 } |
1275 return null; | 1290 return null; |
1276 } | 1291 } |
1277 | 1292 |
1278 /** | 1293 /** |
1279 * This verifies that the passed switch statement does not have a case express
ion with the | 1294 * This verifies that the passed switch statement does not have a case express
ion with the |
1280 * operator '==' overridden. | 1295 * operator '==' overridden. |
1281 * | 1296 * |
1282 * @param node the switch statement to evaluate | 1297 * @param node the switch statement to evaluate |
1283 * @param type the common type of all 'case' expressions | 1298 * @param type the common type of all 'case' expressions |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1356 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION) || | 1371 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION) || |
1357 identical( | 1372 identical( |
1358 dataErrorCode, CompileTimeErrorCode.CONST_EVAL_THROWS_IDBZE) || | 1373 dataErrorCode, CompileTimeErrorCode.CONST_EVAL_THROWS_IDBZE) || |
1359 identical(dataErrorCode, | 1374 identical(dataErrorCode, |
1360 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING) || | 1375 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING) || |
1361 identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL) || | 1376 identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL) || |
1362 identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_INT) || | 1377 identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_INT) || |
1363 identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM) || | 1378 identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM) || |
1364 identical(dataErrorCode, | 1379 identical(dataErrorCode, |
1365 CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT) || | 1380 CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT) || |
1366 identical(dataErrorCode, | 1381 identical( |
1367 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMA
TCH) || | 1382 dataErrorCode, |
1368 identical(dataErrorCode, | 1383 CheckedModeCompileTimeErrorCode |
1369 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMA
TCH) || | 1384 .CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH) || |
| 1385 identical( |
| 1386 dataErrorCode, |
| 1387 CheckedModeCompileTimeErrorCode |
| 1388 .CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH) || |
1370 identical(dataErrorCode, | 1389 identical(dataErrorCode, |
1371 CheckedModeCompileTimeErrorCode.VARIABLE_TYPE_MISMATCH)) { | 1390 CheckedModeCompileTimeErrorCode.VARIABLE_TYPE_MISMATCH)) { |
1372 _errorReporter.reportError(data); | 1391 _errorReporter.reportError(data); |
1373 } else if (errorCode != null) { | 1392 } else if (errorCode != null) { |
1374 _errorReporter.reportError(new AnalysisError( | 1393 _errorReporter.reportError(new AnalysisError( |
1375 data.source, data.offset, data.length, errorCode)); | 1394 data.source, data.offset, data.length, errorCode)); |
1376 } | 1395 } |
1377 } | 1396 } |
1378 } | 1397 } |
1379 | 1398 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1456 DefaultFormalParameter defaultParameter = parameter; | 1475 DefaultFormalParameter defaultParameter = parameter; |
1457 Expression defaultValue = defaultParameter.defaultValue; | 1476 Expression defaultValue = defaultParameter.defaultValue; |
1458 DartObjectImpl result; | 1477 DartObjectImpl result; |
1459 if (defaultValue == null) { | 1478 if (defaultValue == null) { |
1460 result = | 1479 result = |
1461 new DartObjectImpl(_typeProvider.nullType, NullState.NULL_STATE); | 1480 new DartObjectImpl(_typeProvider.nullType, NullState.NULL_STATE); |
1462 } else { | 1481 } else { |
1463 result = _validate( | 1482 result = _validate( |
1464 defaultValue, CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE); | 1483 defaultValue, CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE); |
1465 if (result != null) { | 1484 if (result != null) { |
1466 _reportErrorIfFromDeferredLibrary(defaultValue, | 1485 _reportErrorIfFromDeferredLibrary( |
1467 CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE_FROM_DEFERRED_LI
BRARY); | 1486 defaultValue, |
| 1487 CompileTimeErrorCode |
| 1488 .NON_CONSTANT_DEFAULT_VALUE_FROM_DEFERRED_LIBRARY); |
1468 } | 1489 } |
1469 } | 1490 } |
1470 VariableElementImpl element = parameter.element as VariableElementImpl; | 1491 VariableElementImpl element = parameter.element as VariableElementImpl; |
1471 element.evaluationResult = new EvaluationResultImpl(result); | 1492 element.evaluationResult = new EvaluationResultImpl(result); |
1472 } | 1493 } |
1473 } | 1494 } |
1474 } | 1495 } |
1475 | 1496 |
1476 /** | 1497 /** |
1477 * Validates that the expressions of any field initializers in the class decla
ration are all | 1498 * Validates that the expressions of any field initializers in the class decla
ration are all |
(...skipping 19 matching lines...) Expand all Loading... |
1497 AnalysisErrorListener errorListener = | 1518 AnalysisErrorListener errorListener = |
1498 AnalysisErrorListener.NULL_LISTENER; | 1519 AnalysisErrorListener.NULL_LISTENER; |
1499 ErrorReporter subErrorReporter = | 1520 ErrorReporter subErrorReporter = |
1500 new ErrorReporter(errorListener, _errorReporter.source); | 1521 new ErrorReporter(errorListener, _errorReporter.source); |
1501 DartObjectImpl result = initializer.accept(new ConstantVisitor( | 1522 DartObjectImpl result = initializer.accept(new ConstantVisitor( |
1502 new ConstantEvaluationEngine(_typeProvider, declaredVariables, | 1523 new ConstantEvaluationEngine(_typeProvider, declaredVariables, |
1503 typeSystem: _typeSystem), | 1524 typeSystem: _typeSystem), |
1504 subErrorReporter)); | 1525 subErrorReporter)); |
1505 if (result == null) { | 1526 if (result == null) { |
1506 _errorReporter.reportErrorForNode( | 1527 _errorReporter.reportErrorForNode( |
1507 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_FIELD_INITIALIZE
D_BY_NON_CONST, | 1528 CompileTimeErrorCode |
| 1529 .CONST_CONSTRUCTOR_WITH_FIELD_INITIALIZED_BY_NON_CONST, |
1508 errorSite, | 1530 errorSite, |
1509 [variableDeclaration.name.name]); | 1531 [variableDeclaration.name.name]); |
1510 } | 1532 } |
1511 } | 1533 } |
1512 } | 1534 } |
1513 } | 1535 } |
1514 } | 1536 } |
1515 } | 1537 } |
1516 } | 1538 } |
1517 | 1539 |
1518 /** | 1540 /** |
1519 * Validates that the given expression is a compile time constant. | 1541 * Validates that the given expression is a compile time constant. |
1520 * | 1542 * |
1521 * @param parameterElements the elements of parameters of constant constructor
, they are | 1543 * @param parameterElements the elements of parameters of constant constructor
, they are |
1522 * considered as a valid potentially constant expressions | 1544 * considered as a valid potentially constant expressions |
1523 * @param expression the expression to validate | 1545 * @param expression the expression to validate |
1524 */ | 1546 */ |
1525 void _validateInitializerExpression( | 1547 void _validateInitializerExpression( |
1526 List<ParameterElement> parameterElements, Expression expression) { | 1548 List<ParameterElement> parameterElements, Expression expression) { |
1527 RecordingErrorListener errorListener = new RecordingErrorListener(); | 1549 RecordingErrorListener errorListener = new RecordingErrorListener(); |
1528 ErrorReporter subErrorReporter = | 1550 ErrorReporter subErrorReporter = |
1529 new ErrorReporter(errorListener, _errorReporter.source); | 1551 new ErrorReporter(errorListener, _errorReporter.source); |
1530 DartObjectImpl result = expression.accept( | 1552 DartObjectImpl result = expression.accept( |
1531 new _ConstantVerifier_validateInitializerExpression(_typeProvider, | 1553 new _ConstantVerifier_validateInitializerExpression(_typeProvider, |
1532 subErrorReporter, this, parameterElements, declaredVariables, | 1554 subErrorReporter, this, parameterElements, declaredVariables, |
1533 typeSystem: _typeSystem)); | 1555 typeSystem: _typeSystem)); |
1534 _reportErrors(errorListener.errors, | 1556 _reportErrors(errorListener.errors, |
1535 CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER); | 1557 CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER); |
1536 if (result != null) { | 1558 if (result != null) { |
1537 _reportErrorIfFromDeferredLibrary(expression, | 1559 _reportErrorIfFromDeferredLibrary( |
1538 CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER_FROM_DEFERRED_L
IBRARY); | 1560 expression, |
| 1561 CompileTimeErrorCode |
| 1562 .NON_CONSTANT_VALUE_IN_INITIALIZER_FROM_DEFERRED_LIBRARY); |
1539 } | 1563 } |
1540 } | 1564 } |
1541 | 1565 |
1542 /** | 1566 /** |
1543 * Validates that all of the arguments of a constructor initializer are compil
e time constants. | 1567 * Validates that all of the arguments of a constructor initializer are compil
e time constants. |
1544 * | 1568 * |
1545 * @param parameterElements the elements of parameters of constant constructor
, they are | 1569 * @param parameterElements the elements of parameters of constant constructor
, they are |
1546 * considered as a valid potentially constant expressions | 1570 * considered as a valid potentially constant expressions |
1547 * @param argumentList the argument list to validate | 1571 * @param argumentList the argument list to validate |
1548 */ | 1572 */ |
(...skipping 4117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5666 * @param classElt the class element to query | 5690 * @param classElt the class element to query |
5667 * @param memberName the name of the executable element to find and return | 5691 * @param memberName the name of the executable element to find and return |
5668 * @return the inherited executable element with the member name, or `null` if
no such | 5692 * @return the inherited executable element with the member name, or `null` if
no such |
5669 * member exists | 5693 * member exists |
5670 */ | 5694 */ |
5671 ExecutableElement lookupInheritance( | 5695 ExecutableElement lookupInheritance( |
5672 ClassElement classElt, String memberName) { | 5696 ClassElement classElt, String memberName) { |
5673 if (memberName == null || memberName.isEmpty) { | 5697 if (memberName == null || memberName.isEmpty) { |
5674 return null; | 5698 return null; |
5675 } | 5699 } |
5676 ExecutableElement executable = _computeClassChainLookupMap( | 5700 ExecutableElement executable = |
5677 classElt, new HashSet<ClassElement>()).get(memberName); | 5701 _computeClassChainLookupMap(classElt, new HashSet<ClassElement>()) |
| 5702 .get(memberName); |
5678 if (executable == null) { | 5703 if (executable == null) { |
5679 return _computeInterfaceLookupMap(classElt, new HashSet<ClassElement>()) | 5704 return _computeInterfaceLookupMap(classElt, new HashSet<ClassElement>()) |
5680 .get(memberName); | 5705 .get(memberName); |
5681 } | 5706 } |
5682 return executable; | 5707 return executable; |
5683 } | 5708 } |
5684 | 5709 |
5685 /** | 5710 /** |
5686 * Given some [ClassElement] and some member name, this returns the | 5711 * Given some [ClassElement] and some member name, this returns the |
5687 * [ExecutableElement] that the class either declares itself, or | 5712 * [ExecutableElement] that the class either declares itself, or |
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6322 } else { | 6347 } else { |
6323 // | 6348 // |
6324 // Example: class A inherits 2 methods named 'm'. | 6349 // Example: class A inherits 2 methods named 'm'. |
6325 // One has the function type '(int) -> dynamic' and one has the | 6350 // One has the function type '(int) -> dynamic' and one has the |
6326 // function type '(num) -> dynamic'. Since they are both a subtype | 6351 // function type '(num) -> dynamic'. Since they are both a subtype |
6327 // of the other, a synthetic function '(dynamic) -> dynamic' is | 6352 // of the other, a synthetic function '(dynamic) -> dynamic' is |
6328 // inherited. | 6353 // inherited. |
6329 // Tests: test_getMapOfMembersInheritedFromInterfaces_ | 6354 // Tests: test_getMapOfMembersInheritedFromInterfaces_ |
6330 // union_multipleSubtypes_* | 6355 // union_multipleSubtypes_* |
6331 // | 6356 // |
6332 List<ExecutableElement> elementArrayToMerge = new List< | 6357 List<ExecutableElement> elementArrayToMerge = |
6333 ExecutableElement>(subtypesOfAllOtherTypesIndexes.length); | 6358 new List<ExecutableElement>( |
| 6359 subtypesOfAllOtherTypesIndexes.length); |
6334 for (int i = 0; i < elementArrayToMerge.length; i++) { | 6360 for (int i = 0; i < elementArrayToMerge.length; i++) { |
6335 elementArrayToMerge[i] = | 6361 elementArrayToMerge[i] = |
6336 elements[subtypesOfAllOtherTypesIndexes[i]]; | 6362 elements[subtypesOfAllOtherTypesIndexes[i]]; |
6337 } | 6363 } |
6338 ExecutableElement mergedExecutableElement = | 6364 ExecutableElement mergedExecutableElement = |
6339 _computeMergedExecutableElement(elementArrayToMerge); | 6365 _computeMergedExecutableElement(elementArrayToMerge); |
6340 resultMap.put(key, mergedExecutableElement); | 6366 resultMap.put(key, mergedExecutableElement); |
6341 } | 6367 } |
6342 } | 6368 } |
6343 } else { | 6369 } else { |
6344 _reportError( | 6370 _reportError( |
6345 classElt, | 6371 classElt, |
6346 classElt.nameOffset, | 6372 classElt.nameOffset, |
6347 classElt.nameLength, | 6373 classElt.nameLength, |
6348 StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GETTER_AND_METHO
D, | 6374 StaticWarningCode |
| 6375 .INCONSISTENT_METHOD_INHERITANCE_GETTER_AND_METHOD, |
6349 [key]); | 6376 [key]); |
6350 } | 6377 } |
6351 } | 6378 } |
6352 }); | 6379 }); |
6353 return resultMap; | 6380 return resultMap; |
6354 } | 6381 } |
6355 | 6382 |
6356 /** | 6383 /** |
6357 * Loop through all of the members in some [MemberMap], performing type parame
ter | 6384 * Loop through all of the members in some [MemberMap], performing type parame
ter |
6358 * substitutions using a passed supertype. | 6385 * substitutions using a passed supertype. |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6485 * @param namedParameters the list of [String]s that are the named parameters | 6512 * @param namedParameters the list of [String]s that are the named parameters |
6486 * @return the created synthetic element | 6513 * @return the created synthetic element |
6487 */ | 6514 */ |
6488 static ExecutableElement _createSyntheticExecutableElement( | 6515 static ExecutableElement _createSyntheticExecutableElement( |
6489 List<ExecutableElement> elementArrayToMerge, | 6516 List<ExecutableElement> elementArrayToMerge, |
6490 String name, | 6517 String name, |
6491 int numOfRequiredParameters, | 6518 int numOfRequiredParameters, |
6492 int numOfPositionalParameters, | 6519 int numOfPositionalParameters, |
6493 List<String> namedParameters) { | 6520 List<String> namedParameters) { |
6494 DynamicTypeImpl dynamicType = DynamicTypeImpl.instance; | 6521 DynamicTypeImpl dynamicType = DynamicTypeImpl.instance; |
6495 SimpleIdentifier nameIdentifier = new SimpleIdentifier( | 6522 SimpleIdentifier nameIdentifier = |
6496 new StringToken(TokenType.IDENTIFIER, name, 0)); | 6523 new SimpleIdentifier(new StringToken(TokenType.IDENTIFIER, name, 0)); |
6497 ExecutableElementImpl executable; | 6524 ExecutableElementImpl executable; |
6498 if (elementArrayToMerge[0] is MethodElement) { | 6525 if (elementArrayToMerge[0] is MethodElement) { |
6499 MultiplyInheritedMethodElementImpl unionedMethod = | 6526 MultiplyInheritedMethodElementImpl unionedMethod = |
6500 new MultiplyInheritedMethodElementImpl(nameIdentifier); | 6527 new MultiplyInheritedMethodElementImpl(nameIdentifier); |
6501 unionedMethod.inheritedElements = elementArrayToMerge; | 6528 unionedMethod.inheritedElements = elementArrayToMerge; |
6502 executable = unionedMethod; | 6529 executable = unionedMethod; |
6503 } else { | 6530 } else { |
6504 MultiplyInheritedPropertyAccessorElementImpl unionedPropertyAccessor = | 6531 MultiplyInheritedPropertyAccessorElementImpl unionedPropertyAccessor = |
6505 new MultiplyInheritedPropertyAccessorElementImpl(nameIdentifier); | 6532 new MultiplyInheritedPropertyAccessorElementImpl(nameIdentifier); |
6506 unionedPropertyAccessor.getter = | 6533 unionedPropertyAccessor.getter = |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6575 } | 6602 } |
6576 | 6603 |
6577 /** | 6604 /** |
6578 * Given some [ExecutableElement] return the number of positional parameters. | 6605 * Given some [ExecutableElement] return the number of positional parameters. |
6579 * | 6606 * |
6580 * Note: by positional we mean [ParameterKind.REQUIRED] or [ParameterKind.POSI
TIONAL]. | 6607 * Note: by positional we mean [ParameterKind.REQUIRED] or [ParameterKind.POSI
TIONAL]. |
6581 */ | 6608 */ |
6582 static int _getNumOfPositionalParameters( | 6609 static int _getNumOfPositionalParameters( |
6583 ExecutableElement executableElement) => | 6610 ExecutableElement executableElement) => |
6584 _getNumOfParameters(executableElement, ParameterKind.REQUIRED) + | 6611 _getNumOfParameters(executableElement, ParameterKind.REQUIRED) + |
6585 _getNumOfParameters(executableElement, ParameterKind.POSITIONAL); | 6612 _getNumOfParameters(executableElement, ParameterKind.POSITIONAL); |
6586 | 6613 |
6587 /** | 6614 /** |
6588 * Given some [ExecutableElement] return the number of required parameters. | 6615 * Given some [ExecutableElement] return the number of required parameters. |
6589 */ | 6616 */ |
6590 static int _getNumOfRequiredParameters(ExecutableElement executableElement) => | 6617 static int _getNumOfRequiredParameters(ExecutableElement executableElement) => |
6591 _getNumOfParameters(executableElement, ParameterKind.REQUIRED); | 6618 _getNumOfParameters(executableElement, ParameterKind.REQUIRED); |
6592 | 6619 |
6593 /** | 6620 /** |
6594 * Given some [ExecutableElement] returns `true` if it is an abstract member o
f a | 6621 * Given some [ExecutableElement] returns `true` if it is an abstract member o
f a |
6595 * class. | 6622 * class. |
(...skipping 5529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12125 [typeName.name]); | 12152 [typeName.name]); |
12126 } else if (_isTypeNameInAsExpression(node)) { | 12153 } else if (_isTypeNameInAsExpression(node)) { |
12127 reportErrorForNode( | 12154 reportErrorForNode( |
12128 StaticWarningCode.CAST_TO_NON_TYPE, typeName, [typeName.name]); | 12155 StaticWarningCode.CAST_TO_NON_TYPE, typeName, [typeName.name]); |
12129 } else if (_isTypeNameInIsExpression(node)) { | 12156 } else if (_isTypeNameInIsExpression(node)) { |
12130 reportErrorForNode(StaticWarningCode.TYPE_TEST_WITH_UNDEFINED_NAME, | 12157 reportErrorForNode(StaticWarningCode.TYPE_TEST_WITH_UNDEFINED_NAME, |
12131 typeName, [typeName.name]); | 12158 typeName, [typeName.name]); |
12132 } else if ((redirectingConstructorKind = | 12159 } else if ((redirectingConstructorKind = |
12133 _getRedirectingConstructorKind(node)) != | 12160 _getRedirectingConstructorKind(node)) != |
12134 null) { | 12161 null) { |
12135 ErrorCode errorCode = (redirectingConstructorKind == | 12162 ErrorCode errorCode = |
12136 RedirectingConstructorKind.CONST | 12163 (redirectingConstructorKind == RedirectingConstructorKind.CONST |
12137 ? CompileTimeErrorCode.REDIRECT_TO_NON_CLASS | 12164 ? CompileTimeErrorCode.REDIRECT_TO_NON_CLASS |
12138 : StaticWarningCode.REDIRECT_TO_NON_CLASS); | 12165 : StaticWarningCode.REDIRECT_TO_NON_CLASS); |
12139 reportErrorForNode(errorCode, typeName, [typeName.name]); | 12166 reportErrorForNode(errorCode, typeName, [typeName.name]); |
12140 } else if (_isTypeNameInTypeArgumentList(node)) { | 12167 } else if (_isTypeNameInTypeArgumentList(node)) { |
12141 reportErrorForNode(StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT, | 12168 reportErrorForNode(StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT, |
12142 typeName, [typeName.name]); | 12169 typeName, [typeName.name]); |
12143 } else { | 12170 } else { |
12144 reportErrorForNode( | 12171 reportErrorForNode( |
12145 StaticWarningCode.UNDEFINED_CLASS, typeName, [typeName.name]); | 12172 StaticWarningCode.UNDEFINED_CLASS, typeName, [typeName.name]); |
12146 } | 12173 } |
12147 elementValid = false; | 12174 elementValid = false; |
12148 } | 12175 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12185 [typeName.name]); | 12212 [typeName.name]); |
12186 } else if (_isTypeNameInAsExpression(node)) { | 12213 } else if (_isTypeNameInAsExpression(node)) { |
12187 reportErrorForNode( | 12214 reportErrorForNode( |
12188 StaticWarningCode.CAST_TO_NON_TYPE, typeName, [typeName.name]); | 12215 StaticWarningCode.CAST_TO_NON_TYPE, typeName, [typeName.name]); |
12189 } else if (_isTypeNameInIsExpression(node)) { | 12216 } else if (_isTypeNameInIsExpression(node)) { |
12190 reportErrorForNode(StaticWarningCode.TYPE_TEST_WITH_NON_TYPE, typeName, | 12217 reportErrorForNode(StaticWarningCode.TYPE_TEST_WITH_NON_TYPE, typeName, |
12191 [typeName.name]); | 12218 [typeName.name]); |
12192 } else if ((redirectingConstructorKind = | 12219 } else if ((redirectingConstructorKind = |
12193 _getRedirectingConstructorKind(node)) != | 12220 _getRedirectingConstructorKind(node)) != |
12194 null) { | 12221 null) { |
12195 ErrorCode errorCode = (redirectingConstructorKind == | 12222 ErrorCode errorCode = |
12196 RedirectingConstructorKind.CONST | 12223 (redirectingConstructorKind == RedirectingConstructorKind.CONST |
12197 ? CompileTimeErrorCode.REDIRECT_TO_NON_CLASS | 12224 ? CompileTimeErrorCode.REDIRECT_TO_NON_CLASS |
12198 : StaticWarningCode.REDIRECT_TO_NON_CLASS); | 12225 : StaticWarningCode.REDIRECT_TO_NON_CLASS); |
12199 reportErrorForNode(errorCode, typeName, [typeName.name]); | 12226 reportErrorForNode(errorCode, typeName, [typeName.name]); |
12200 } else if (_isTypeNameInTypeArgumentList(node)) { | 12227 } else if (_isTypeNameInTypeArgumentList(node)) { |
12201 reportErrorForNode(StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT, | 12228 reportErrorForNode(StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT, |
12202 typeName, [typeName.name]); | 12229 typeName, [typeName.name]); |
12203 } else { | 12230 } else { |
12204 AstNode parent = typeName.parent; | 12231 AstNode parent = typeName.parent; |
12205 while (parent is TypeName) { | 12232 while (parent is TypeName) { |
12206 parent = parent.parent; | 12233 parent = parent.parent; |
12207 } | 12234 } |
12208 if (parent is ExtendsClause || | 12235 if (parent is ExtendsClause || |
(...skipping 1111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13320 nonFields.add(node); | 13347 nonFields.add(node); |
13321 return null; | 13348 return null; |
13322 } | 13349 } |
13323 | 13350 |
13324 @override | 13351 @override |
13325 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); | 13352 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); |
13326 | 13353 |
13327 @override | 13354 @override |
13328 Object visitWithClause(WithClause node) => null; | 13355 Object visitWithClause(WithClause node) => null; |
13329 } | 13356 } |
OLD | NEW |