OLD | NEW |
1 // This code was auto-generated, is not intended to be edited, and is subject to | 1 // This code was auto-generated, is not intended to be edited, and is subject to |
2 // significant change. Please see the README file for more information. | 2 // significant change. Please see the README file for more information. |
3 library engine.resolver; | 3 library engine.resolver; |
4 import 'dart:collection'; | 4 import 'dart:collection'; |
5 import 'java_core.dart'; | 5 import 'java_core.dart'; |
6 import 'java_engine.dart'; | 6 import 'java_engine.dart'; |
7 import 'instrumentation.dart'; | 7 import 'instrumentation.dart'; |
8 import 'source.dart'; | 8 import 'source.dart'; |
9 import 'error.dart'; | 9 import 'error.dart'; |
10 import 'scanner.dart' as sc; | 10 import 'scanner.dart' as sc; |
(...skipping 3505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3516 * itself recursively | 3516 * itself recursively |
3517 * @return a mapping between the set of all string names of the members inheri
ted from the passed{@link ClassElement} interface hierarchy, and the associated
{@link ExecutableElement} | 3517 * @return a mapping between the set of all string names of the members inheri
ted from the passed{@link ClassElement} interface hierarchy, and the associated
{@link ExecutableElement} |
3518 */ | 3518 */ |
3519 Map<String, ExecutableElement> computeInterfaceLookupMap(ClassElement classElt
, Set<ClassElement> visitedInterfaces) { | 3519 Map<String, ExecutableElement> computeInterfaceLookupMap(ClassElement classElt
, Set<ClassElement> visitedInterfaces) { |
3520 Map<String, ExecutableElement> resultMap = _interfaceLookup[classElt]; | 3520 Map<String, ExecutableElement> resultMap = _interfaceLookup[classElt]; |
3521 if (resultMap != null) { | 3521 if (resultMap != null) { |
3522 return resultMap; | 3522 return resultMap; |
3523 } else { | 3523 } else { |
3524 resultMap = new Map<String, ExecutableElement>(); | 3524 resultMap = new Map<String, ExecutableElement>(); |
3525 } | 3525 } |
| 3526 InterfaceType supertype2 = classElt.supertype; |
| 3527 ClassElement superclassElement = supertype2 != null ? supertype2.element : n
ull; |
3526 List<InterfaceType> interfaces2 = classElt.interfaces; | 3528 List<InterfaceType> interfaces2 = classElt.interfaces; |
3527 if (interfaces2.length == 0) { | 3529 if (superclassElement == null || interfaces2.length == 0) { |
3528 _interfaceLookup[classElt] = resultMap; | 3530 _interfaceLookup[classElt] = resultMap; |
3529 return resultMap; | 3531 return resultMap; |
3530 } | 3532 } |
3531 List<Map<String, ExecutableElement>> lookupMaps = new List<Map<String, Execu
tableElement>>(); | 3533 List<Map<String, ExecutableElement>> lookupMaps = new List<Map<String, Execu
tableElement>>(); |
| 3534 if (superclassElement != null) { |
| 3535 if (!visitedInterfaces.contains(superclassElement)) { |
| 3536 try { |
| 3537 javaSetAdd(visitedInterfaces, superclassElement); |
| 3538 lookupMaps.add(computeInterfaceLookupMap(superclassElement, visitedInt
erfaces)); |
| 3539 } finally { |
| 3540 visitedInterfaces.remove(superclassElement); |
| 3541 } |
| 3542 } else { |
| 3543 Map<String, ExecutableElement> map = _interfaceLookup[classElt]; |
| 3544 if (map != null) { |
| 3545 lookupMaps.add(map); |
| 3546 } else { |
| 3547 _interfaceLookup[superclassElement] = resultMap; |
| 3548 return resultMap; |
| 3549 } |
| 3550 } |
| 3551 } |
3532 for (InterfaceType interfaceType in interfaces2) { | 3552 for (InterfaceType interfaceType in interfaces2) { |
3533 ClassElement interfaceElement = interfaceType.element; | 3553 ClassElement interfaceElement = interfaceType.element; |
3534 if (interfaceElement != null) { | 3554 if (interfaceElement != null) { |
3535 if (!visitedInterfaces.contains(interfaceElement)) { | 3555 if (!visitedInterfaces.contains(interfaceElement)) { |
3536 javaSetAdd(visitedInterfaces, interfaceElement); | 3556 try { |
3537 lookupMaps.add(computeInterfaceLookupMap(interfaceElement, visitedInte
rfaces)); | 3557 javaSetAdd(visitedInterfaces, interfaceElement); |
| 3558 lookupMaps.add(computeInterfaceLookupMap(interfaceElement, visitedIn
terfaces)); |
| 3559 } finally { |
| 3560 visitedInterfaces.remove(interfaceElement); |
| 3561 } |
3538 } else { | 3562 } else { |
3539 Map<String, ExecutableElement> map = _interfaceLookup[classElt]; | 3563 Map<String, ExecutableElement> map = _interfaceLookup[classElt]; |
3540 if (map != null) { | 3564 if (map != null) { |
3541 lookupMaps.add(map); | 3565 lookupMaps.add(map); |
3542 } else { | 3566 } else { |
3543 _interfaceLookup[interfaceElement] = resultMap; | 3567 _interfaceLookup[interfaceElement] = resultMap; |
3544 return resultMap; | 3568 return resultMap; |
3545 } | 3569 } |
3546 } | 3570 } |
3547 } | 3571 } |
3548 } | 3572 } |
3549 if (lookupMaps.length == 0) { | 3573 if (lookupMaps.length == 0) { |
3550 _interfaceLookup[classElt] = resultMap; | 3574 _interfaceLookup[classElt] = resultMap; |
3551 return resultMap; | 3575 return resultMap; |
3552 } | 3576 } |
3553 Map<String, Set<ExecutableElement>> unionMap = new Map<String, Set<Executabl
eElement>>(); | 3577 Map<String, Set<ExecutableElement>> unionMap = new Map<String, Set<Executabl
eElement>>(); |
3554 for (Map<String, ExecutableElement> lookupMap in lookupMaps) { | 3578 for (Map<String, ExecutableElement> lookupMap in lookupMaps) { |
3555 for (MapEntry<String, ExecutableElement> entry in getMapEntrySet(lookupMap
)) { | 3579 for (MapEntry<String, ExecutableElement> entry in getMapEntrySet(lookupMap
)) { |
3556 String key = entry.getKey(); | 3580 String key = entry.getKey(); |
3557 if (!unionMap.containsKey(key)) { | 3581 if (!unionMap.containsKey(key)) { |
3558 Set<ExecutableElement> set = new Set<ExecutableElement>(); | 3582 Set<ExecutableElement> set = new Set<ExecutableElement>(); |
3559 javaSetAdd(set, entry.getValue()); | 3583 javaSetAdd(set, entry.getValue()); |
3560 unionMap[key] = set; | 3584 unionMap[key] = set; |
3561 } else { | 3585 } else { |
3562 javaSetAdd(unionMap[key], entry.getValue()); | 3586 javaSetAdd(unionMap[key], entry.getValue()); |
3563 } | 3587 } |
3564 } | 3588 } |
3565 } | 3589 } |
| 3590 if (superclassElement != null) { |
| 3591 List<MethodElement> methods2 = superclassElement.methods; |
| 3592 for (MethodElement method in methods2) { |
| 3593 if (method.isAccessibleIn(_library) && !method.isStatic()) { |
| 3594 String key = method.name; |
| 3595 if (!unionMap.containsKey(key)) { |
| 3596 Set<ExecutableElement> set = new Set<ExecutableElement>(); |
| 3597 javaSetAdd(set, method); |
| 3598 unionMap[key] = set; |
| 3599 } else { |
| 3600 javaSetAdd(unionMap[key], method); |
| 3601 } |
| 3602 } |
| 3603 } |
| 3604 List<PropertyAccessorElement> accessors2 = superclassElement.accessors; |
| 3605 for (PropertyAccessorElement accessor in accessors2) { |
| 3606 if (accessor.isAccessibleIn(_library) && !accessor.isStatic()) { |
| 3607 String key = accessor.name; |
| 3608 if (!unionMap.containsKey(key)) { |
| 3609 Set<ExecutableElement> set = new Set<ExecutableElement>(); |
| 3610 javaSetAdd(set, accessor); |
| 3611 unionMap[key] = set; |
| 3612 } else { |
| 3613 javaSetAdd(unionMap[key], accessor); |
| 3614 } |
| 3615 } |
| 3616 } |
| 3617 } |
3566 for (InterfaceType interfaceType in interfaces2) { | 3618 for (InterfaceType interfaceType in interfaces2) { |
3567 ClassElement interfaceElement = interfaceType.element; | 3619 ClassElement interfaceElement = interfaceType.element; |
3568 if (interfaceElement != null) { | 3620 if (interfaceElement != null) { |
3569 List<MethodElement> methods2 = interfaceElement.methods; | 3621 List<MethodElement> methods3 = interfaceElement.methods; |
3570 for (MethodElement method in methods2) { | 3622 for (MethodElement method in methods3) { |
3571 if (method.isAccessibleIn(_library) && !method.isStatic()) { | 3623 if (method.isAccessibleIn(_library) && !method.isStatic()) { |
3572 String key = method.name; | 3624 String key = method.name; |
3573 if (!unionMap.containsKey(key)) { | 3625 if (!unionMap.containsKey(key)) { |
3574 Set<ExecutableElement> set = new Set<ExecutableElement>(); | 3626 Set<ExecutableElement> set = new Set<ExecutableElement>(); |
3575 javaSetAdd(set, method); | 3627 javaSetAdd(set, method); |
3576 unionMap[key] = set; | 3628 unionMap[key] = set; |
3577 } else { | 3629 } else { |
3578 javaSetAdd(unionMap[key], method); | 3630 javaSetAdd(unionMap[key], method); |
3579 } | 3631 } |
3580 } | 3632 } |
3581 } | 3633 } |
3582 List<PropertyAccessorElement> accessors2 = interfaceElement.accessors; | 3634 List<PropertyAccessorElement> accessors3 = interfaceElement.accessors; |
3583 for (PropertyAccessorElement accessor in accessors2) { | 3635 for (PropertyAccessorElement accessor in accessors3) { |
3584 if (accessor.isAccessibleIn(_library) && !accessor.isStatic()) { | 3636 if (accessor.isAccessibleIn(_library) && !accessor.isStatic()) { |
3585 String key = accessor.name; | 3637 String key = accessor.name; |
3586 if (!unionMap.containsKey(key)) { | 3638 if (!unionMap.containsKey(key)) { |
3587 Set<ExecutableElement> set = new Set<ExecutableElement>(); | 3639 Set<ExecutableElement> set = new Set<ExecutableElement>(); |
3588 javaSetAdd(set, accessor); | 3640 javaSetAdd(set, accessor); |
3589 unionMap[key] = set; | 3641 unionMap[key] = set; |
3590 } else { | 3642 } else { |
3591 javaSetAdd(unionMap[key], accessor); | 3643 javaSetAdd(unionMap[key], accessor); |
3592 } | 3644 } |
3593 } | 3645 } |
(...skipping 22 matching lines...) Expand all Loading... |
3616 allGetters = false; | 3668 allGetters = false; |
3617 allSetters = false; | 3669 allSetters = false; |
3618 } | 3670 } |
3619 } | 3671 } |
3620 if (allMethods || allGetters || allSetters) { | 3672 if (allMethods || allGetters || allSetters) { |
3621 List<ExecutableElement> elements = new List.from(set); | 3673 List<ExecutableElement> elements = new List.from(set); |
3622 List<FunctionType> executableElementTypes = new List<FunctionType>(num
OfEltsWithMatchingNames); | 3674 List<FunctionType> executableElementTypes = new List<FunctionType>(num
OfEltsWithMatchingNames); |
3623 for (int i = 0; i < numOfEltsWithMatchingNames; i++) { | 3675 for (int i = 0; i < numOfEltsWithMatchingNames; i++) { |
3624 executableElementTypes[i] = elements[i].type; | 3676 executableElementTypes[i] = elements[i].type; |
3625 } | 3677 } |
3626 bool foundSubtypeOfAllTypes = true; | 3678 bool foundSubtypeOfAllTypes = false; |
3627 for (int i = 0; i < numOfEltsWithMatchingNames; i++) { | 3679 for (int i = 0; i < numOfEltsWithMatchingNames; i++) { |
3628 FunctionType subtype = executableElementTypes[i]; | 3680 FunctionType subtype = executableElementTypes[i]; |
3629 if (subtype == null) { | 3681 if (subtype == null) { |
3630 continue; | 3682 continue; |
3631 } | 3683 } |
3632 bool subtypeOfAllTypes = true; | 3684 bool subtypeOfAllTypes = true; |
3633 for (int j = 0; j < numOfEltsWithMatchingNames && subtypeOfAllTypes;
j++) { | 3685 for (int j = 0; j < numOfEltsWithMatchingNames && subtypeOfAllTypes;
j++) { |
3634 if (i != j) { | 3686 if (i != j) { |
3635 if (!subtype.isSubtypeOf(executableElementTypes[j])) { | 3687 if (!subtype.isSubtypeOf(executableElementTypes[j])) { |
3636 subtypeOfAllTypes = false; | 3688 subtypeOfAllTypes = false; |
3637 foundSubtypeOfAllTypes = false; | |
3638 break; | 3689 break; |
3639 } | 3690 } |
3640 } | 3691 } |
3641 } | 3692 } |
3642 if (subtypeOfAllTypes) { | 3693 if (subtypeOfAllTypes) { |
| 3694 foundSubtypeOfAllTypes = true; |
3643 resultMap[key] = elements[i]; | 3695 resultMap[key] = elements[i]; |
3644 break; | 3696 break; |
3645 } | 3697 } |
3646 } | 3698 } |
3647 if (!foundSubtypeOfAllTypes) { | 3699 if (!foundSubtypeOfAllTypes) { |
3648 reportError(classElt, classElt.nameOffset, classElt.displayName.leng
th, StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE, [key]); | 3700 reportError(classElt, classElt.nameOffset, classElt.displayName.leng
th, StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE, [key]); |
3649 } | 3701 } |
3650 } else { | 3702 } else { |
3651 if (!allMethods && !allGetters) { | 3703 if (!allMethods && !allGetters) { |
3652 reportError(classElt, classElt.nameOffset, classElt.displayName.leng
th, StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GETTER_AND_METHOD, [key]); | 3704 reportError(classElt, classElt.nameOffset, classElt.displayName.leng
th, StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GETTER_AND_METHOD, [key]); |
(...skipping 4309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7962 reportError(StaticWarningCode.NEW_WITH_NON_TYPE, typeNameSimple, [type
Name]); | 8014 reportError(StaticWarningCode.NEW_WITH_NON_TYPE, typeNameSimple, [type
Name]); |
7963 elementValid = false; | 8015 elementValid = false; |
7964 } | 8016 } |
7965 } | 8017 } |
7966 } | 8018 } |
7967 if (elementValid && element == null) { | 8019 if (elementValid && element == null) { |
7968 SimpleIdentifier typeNameSimple = getTypeSimpleIdentifier(typeName); | 8020 SimpleIdentifier typeNameSimple = getTypeSimpleIdentifier(typeName); |
7969 if (typeNameSimple.name == "boolean") { | 8021 if (typeNameSimple.name == "boolean") { |
7970 reportError(StaticWarningCode.UNDEFINED_CLASS_BOOLEAN, typeNameSimple, [
]); | 8022 reportError(StaticWarningCode.UNDEFINED_CLASS_BOOLEAN, typeNameSimple, [
]); |
7971 } else if (isTypeNameInCatchClause(node)) { | 8023 } else if (isTypeNameInCatchClause(node)) { |
7972 reportError(StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE, node, [node]); | 8024 reportError(StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE, typeName, [typeN
ame.name]); |
| 8025 } else if (isTypeNameInAsExpression(node)) { |
| 8026 reportError(StaticWarningCode.CAST_TO_NON_TYPE, typeName, [typeName.name
]); |
| 8027 } else if (isTypeNameInIsExpression(node)) { |
| 8028 reportError(StaticWarningCode.TYPE_TEST_NON_TYPE, typeName, [typeName.na
me]); |
7973 } else { | 8029 } else { |
7974 reportError(StaticWarningCode.UNDEFINED_CLASS, typeNameSimple, [typeName
Simple.name]); | 8030 reportError(StaticWarningCode.UNDEFINED_CLASS, typeName, [typeName.name]
); |
7975 } | 8031 } |
7976 elementValid = false; | 8032 elementValid = false; |
7977 } | 8033 } |
7978 if (!elementValid) { | 8034 if (!elementValid) { |
7979 setElement(typeName, _dynamicType.element); | 8035 setElement(typeName, _dynamicType.element); |
7980 typeName.staticType = _dynamicType; | 8036 typeName.staticType = _dynamicType; |
7981 node.type = _dynamicType; | 8037 node.type = _dynamicType; |
7982 return null; | 8038 return null; |
7983 } | 8039 } |
7984 Type2 type = null; | 8040 Type2 type = null; |
7985 if (element is ClassElement) { | 8041 if (element is ClassElement) { |
7986 setElement(typeName, element); | 8042 setElement(typeName, element); |
7987 type = ((element as ClassElement)).type; | 8043 type = ((element as ClassElement)).type; |
7988 } else if (element is FunctionTypeAliasElement) { | 8044 } else if (element is FunctionTypeAliasElement) { |
7989 setElement(typeName, element); | 8045 setElement(typeName, element); |
7990 type = ((element as FunctionTypeAliasElement)).type; | 8046 type = ((element as FunctionTypeAliasElement)).type; |
7991 } else if (element is TypeVariableElement) { | 8047 } else if (element is TypeVariableElement) { |
7992 setElement(typeName, element); | 8048 setElement(typeName, element); |
7993 type = ((element as TypeVariableElement)).type; | 8049 type = ((element as TypeVariableElement)).type; |
7994 if (argumentList != null) { | 8050 if (argumentList != null) { |
7995 } | 8051 } |
7996 } else if (element is MultiplyDefinedElement) { | 8052 } else if (element is MultiplyDefinedElement) { |
7997 List<Element> elements = ((element as MultiplyDefinedElement)).conflicting
Elements; | 8053 List<Element> elements = ((element as MultiplyDefinedElement)).conflicting
Elements; |
7998 type = getType(elements); | 8054 type = getType(elements); |
7999 if (type != null) { | 8055 if (type != null) { |
8000 node.type = type; | 8056 node.type = type; |
8001 } | 8057 } |
8002 } else { | 8058 } else { |
8003 if (isTypeNameInCatchClause(node)) { | 8059 if (isTypeNameInCatchClause(node)) { |
8004 reportError(StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE, node, [node]); | 8060 reportError(StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE, typeName, [typeN
ame.name]); |
| 8061 } else if (isTypeNameInAsExpression(node)) { |
| 8062 reportError(StaticWarningCode.CAST_TO_NON_TYPE, typeName, [typeName.name
]); |
| 8063 } else if (isTypeNameInIsExpression(node)) { |
| 8064 reportError(StaticWarningCode.TYPE_TEST_NON_TYPE, typeName, [typeName.na
me]); |
8005 } | 8065 } |
8006 setElement(typeName, _dynamicType.element); | 8066 setElement(typeName, _dynamicType.element); |
8007 typeName.staticType = _dynamicType; | 8067 typeName.staticType = _dynamicType; |
8008 node.type = _dynamicType; | 8068 node.type = _dynamicType; |
8009 return null; | 8069 return null; |
8010 } | 8070 } |
8011 if (argumentList != null) { | 8071 if (argumentList != null) { |
8012 NodeList<TypeName> arguments2 = argumentList.arguments; | 8072 NodeList<TypeName> arguments2 = argumentList.arguments; |
8013 int argumentCount = arguments2.length; | 8073 int argumentCount = arguments2.length; |
8014 List<Type2> parameters = getTypeArguments(type); | 8074 List<Type2> parameters = getTypeArguments(type); |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8194 */ | 8254 */ |
8195 SimpleIdentifier getTypeSimpleIdentifier(Identifier typeName) { | 8255 SimpleIdentifier getTypeSimpleIdentifier(Identifier typeName) { |
8196 if (typeName is SimpleIdentifier) { | 8256 if (typeName is SimpleIdentifier) { |
8197 return typeName as SimpleIdentifier; | 8257 return typeName as SimpleIdentifier; |
8198 } else { | 8258 } else { |
8199 return ((typeName as PrefixedIdentifier)).identifier; | 8259 return ((typeName as PrefixedIdentifier)).identifier; |
8200 } | 8260 } |
8201 } | 8261 } |
8202 | 8262 |
8203 /** | 8263 /** |
8204 * Checks if the given type name is used as the exception type in the catch cl
ause. | 8264 * Checks if the given type name is used as the type in an as expression. |
8205 * @param typeName the type name to analyzer | 8265 * @param typeName the type name to analyzer |
8206 * @return {@code true} if the given type name is used as the exception type i
n the catch clause. | 8266 * @return {@code true} if the given type name is used as the type in an as ex
pression |
| 8267 */ |
| 8268 bool isTypeNameInAsExpression(TypeName typeName) { |
| 8269 ASTNode parent2 = typeName.parent; |
| 8270 if (parent2 is AsExpression) { |
| 8271 AsExpression asExpression = parent2 as AsExpression; |
| 8272 return identical(asExpression.type, typeName); |
| 8273 } |
| 8274 return false; |
| 8275 } |
| 8276 |
| 8277 /** |
| 8278 * Checks if the given type name is used as the exception type in a catch clau
se. |
| 8279 * @param typeName the type name to analyzer |
| 8280 * @return {@code true} if the given type name is used as the exception type i
n a catch clause |
8207 */ | 8281 */ |
8208 bool isTypeNameInCatchClause(TypeName typeName) { | 8282 bool isTypeNameInCatchClause(TypeName typeName) { |
8209 ASTNode parent2 = typeName.parent; | 8283 ASTNode parent2 = typeName.parent; |
8210 if (parent2 is CatchClause) { | 8284 if (parent2 is CatchClause) { |
8211 CatchClause catchClause = parent2 as CatchClause; | 8285 CatchClause catchClause = parent2 as CatchClause; |
8212 return identical(catchClause.exceptionType, typeName); | 8286 return identical(catchClause.exceptionType, typeName); |
8213 } | 8287 } |
8214 return false; | 8288 return false; |
8215 } | 8289 } |
8216 | 8290 |
8217 /** | 8291 /** |
8218 * Checks if the given type name is used as the type in the instance creation
expression. | 8292 * Checks if the given type name is used as the type in an instance creation e
xpression. |
8219 * @param typeName the type name to analyzer | 8293 * @param typeName the type name to analyzer |
8220 * @return {@code true} if the given type name is used as the type in the inst
ance creation | 8294 * @return {@code true} if the given type name is used as the type in an insta
nce creation |
8221 * expression | 8295 * expression |
8222 */ | 8296 */ |
8223 bool isTypeNameInInstanceCreationExpression(TypeName typeName) { | 8297 bool isTypeNameInInstanceCreationExpression(TypeName typeName) { |
8224 ASTNode parent2 = typeName.parent; | 8298 ASTNode parent2 = typeName.parent; |
8225 if (parent2 is ConstructorName && parent2.parent is InstanceCreationExpressi
on) { | 8299 if (parent2 is ConstructorName && parent2.parent is InstanceCreationExpressi
on) { |
8226 ConstructorName constructorName = parent2 as ConstructorName; | 8300 ConstructorName constructorName = parent2 as ConstructorName; |
8227 return constructorName != null && identical(constructorName.type, typeName
); | 8301 return constructorName != null && identical(constructorName.type, typeName
); |
8228 } | 8302 } |
8229 return false; | 8303 return false; |
8230 } | 8304 } |
8231 | 8305 |
8232 /** | 8306 /** |
| 8307 * Checks if the given type name is used as the type in an is expression. |
| 8308 * @param typeName the type name to analyzer |
| 8309 * @return {@code true} if the given type name is used as the type in an is ex
pression |
| 8310 */ |
| 8311 bool isTypeNameInIsExpression(TypeName typeName) { |
| 8312 ASTNode parent2 = typeName.parent; |
| 8313 if (parent2 is IsExpression) { |
| 8314 IsExpression isExpression = parent2 as IsExpression; |
| 8315 return identical(isExpression.type, typeName); |
| 8316 } |
| 8317 return false; |
| 8318 } |
| 8319 |
| 8320 /** |
8233 * Record that the static type of the given node is the given type. | 8321 * Record that the static type of the given node is the given type. |
8234 * @param expression the node whose type is to be recorded | 8322 * @param expression the node whose type is to be recorded |
8235 * @param type the static type of the node | 8323 * @param type the static type of the node |
8236 */ | 8324 */ |
8237 Object recordType(Expression expression, Type2 type) { | 8325 Object recordType(Expression expression, Type2 type) { |
8238 if (type == null) { | 8326 if (type == null) { |
8239 expression.staticType = _dynamicType; | 8327 expression.staticType = _dynamicType; |
8240 } else { | 8328 } else { |
8241 expression.staticType = type; | 8329 expression.staticType = type; |
8242 } | 8330 } |
(...skipping 1548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9791 Object visitDoStatement(DoStatement node) { | 9879 Object visitDoStatement(DoStatement node) { |
9792 checkForNonBoolCondition(node.condition); | 9880 checkForNonBoolCondition(node.condition); |
9793 return super.visitDoStatement(node); | 9881 return super.visitDoStatement(node); |
9794 } | 9882 } |
9795 Object visitExportDirective(ExportDirective node) { | 9883 Object visitExportDirective(ExportDirective node) { |
9796 checkForAmbiguousExport(node); | 9884 checkForAmbiguousExport(node); |
9797 checkForExportDuplicateLibraryName(node); | 9885 checkForExportDuplicateLibraryName(node); |
9798 checkForExportInternalLibrary(node); | 9886 checkForExportInternalLibrary(node); |
9799 return super.visitExportDirective(node); | 9887 return super.visitExportDirective(node); |
9800 } | 9888 } |
| 9889 Object visitFieldDeclaration(FieldDeclaration node) { |
| 9890 if (!node.isStatic()) { |
| 9891 VariableDeclarationList variables = node.fields; |
| 9892 if (variables.isConst()) { |
| 9893 _errorReporter.reportError4(CompileTimeErrorCode.CONST_INSTANCE_FIELD, v
ariables.keyword, []); |
| 9894 } |
| 9895 } |
| 9896 return super.visitFieldDeclaration(node); |
| 9897 } |
9801 Object visitFieldFormalParameter(FieldFormalParameter node) { | 9898 Object visitFieldFormalParameter(FieldFormalParameter node) { |
9802 checkForConstFormalParameter(node); | 9899 checkForConstFormalParameter(node); |
9803 checkForFieldInitializingFormalRedirectingConstructor(node); | 9900 checkForFieldInitializingFormalRedirectingConstructor(node); |
9804 return super.visitFieldFormalParameter(node); | 9901 return super.visitFieldFormalParameter(node); |
9805 } | 9902 } |
9806 Object visitFunctionDeclaration(FunctionDeclaration node) { | 9903 Object visitFunctionDeclaration(FunctionDeclaration node) { |
9807 ExecutableElement outerFunction = _enclosingFunction; | 9904 ExecutableElement outerFunction = _enclosingFunction; |
9808 try { | 9905 try { |
9809 SimpleIdentifier identifier = node.name; | 9906 SimpleIdentifier identifier = node.name; |
9810 String methoName = ""; | 9907 String methoName = ""; |
(...skipping 1382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11193 * @param node the class declaration to test | 11290 * @param node the class declaration to test |
11194 * @return {@code true} if and only if an error code is generated on the passe
d node | 11291 * @return {@code true} if and only if an error code is generated on the passe
d node |
11195 * @see CompileTimeErrorCode#FINAL_NOT_INITIALIZED | 11292 * @see CompileTimeErrorCode#FINAL_NOT_INITIALIZED |
11196 */ | 11293 */ |
11197 bool checkForFinalNotInitialized2(VariableDeclarationList node) { | 11294 bool checkForFinalNotInitialized2(VariableDeclarationList node) { |
11198 bool foundError = false; | 11295 bool foundError = false; |
11199 if (!node.isSynthetic() && (node.isConst() || node.isFinal())) { | 11296 if (!node.isSynthetic() && (node.isConst() || node.isFinal())) { |
11200 NodeList<VariableDeclaration> variables2 = node.variables; | 11297 NodeList<VariableDeclaration> variables2 = node.variables; |
11201 for (VariableDeclaration variable in variables2) { | 11298 for (VariableDeclaration variable in variables2) { |
11202 if (variable.initializer == null) { | 11299 if (variable.initializer == null) { |
11203 _errorReporter.reportError2(CompileTimeErrorCode.FINAL_NOT_INITIALIZED
, variable, [variable.name.name]); | 11300 _errorReporter.reportError2(StaticWarningCode.FINAL_NOT_INITIALIZED, v
ariable, [variable.name.name]); |
11204 foundError = true; | 11301 foundError = true; |
11205 } | 11302 } |
11206 } | 11303 } |
11207 } | 11304 } |
11208 return foundError; | 11305 return foundError; |
11209 } | 11306 } |
11210 | 11307 |
11211 /** | 11308 /** |
11212 * This verifies that the passed implements clause does not implement classes
such as 'num' or | 11309 * This verifies that the passed implements clause does not implement classes
such as 'num' or |
11213 * 'String'. | 11310 * 'String'. |
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11721 if (!accessorsInEnclosingClass.contains(accessorName)) { | 11818 if (!accessorsInEnclosingClass.contains(accessorName)) { |
11722 javaSetAdd(missingOverrides, executableElt); | 11819 javaSetAdd(missingOverrides, executableElt); |
11723 } | 11820 } |
11724 } | 11821 } |
11725 } | 11822 } |
11726 int missingOverridesSize = missingOverrides.length; | 11823 int missingOverridesSize = missingOverrides.length; |
11727 if (missingOverridesSize == 0) { | 11824 if (missingOverridesSize == 0) { |
11728 return false; | 11825 return false; |
11729 } | 11826 } |
11730 List<ExecutableElement> missingOverridesArray = new List.from(missingOverrid
es); | 11827 List<ExecutableElement> missingOverridesArray = new List.from(missingOverrid
es); |
| 11828 List<String> stringTypeArray = new List<String>(Math.min(missingOverridesSiz
e, 4)); |
| 11829 String GET = "get "; |
| 11830 String SET = "set "; |
| 11831 for (int i = 0; i < stringTypeArray.length; i++) { |
| 11832 stringTypeArray[i] = StringUtilities.EMPTY; |
| 11833 if (missingOverridesArray[i] is PropertyAccessorElement) { |
| 11834 stringTypeArray[i] = ((missingOverridesArray[i] as PropertyAccessorEleme
nt)).isGetter() ? GET : SET; |
| 11835 } |
| 11836 } |
11731 if (missingOverridesSize == 1) { | 11837 if (missingOverridesSize == 1) { |
11732 _errorReporter.reportError2(StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_
ABSTRACT_MEMBER_ONE, node.name, [missingOverridesArray[0].enclosingElement.displ
ayName, missingOverridesArray[0].displayName]); | 11838 _errorReporter.reportError2(StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_
ABSTRACT_MEMBER_ONE, node.name, [stringTypeArray[0], missingOverridesArray[0].en
closingElement.displayName, missingOverridesArray[0].displayName]); |
11733 } else if (missingOverridesSize == 2) { | 11839 } else if (missingOverridesSize == 2) { |
11734 _errorReporter.reportError2(StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_
ABSTRACT_MEMBER_TWO, node.name, [missingOverridesArray[0].enclosingElement.displ
ayName, missingOverridesArray[0].displayName, missingOverridesArray[1].enclosing
Element.displayName, missingOverridesArray[1].displayName]); | 11840 _errorReporter.reportError2(StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_
ABSTRACT_MEMBER_TWO, node.name, [stringTypeArray[0], missingOverridesArray[0].en
closingElement.displayName, missingOverridesArray[0].displayName, stringTypeArra
y[1], missingOverridesArray[1].enclosingElement.displayName, missingOverridesArr
ay[1].displayName]); |
11735 } else if (missingOverridesSize == 3) { | 11841 } else if (missingOverridesSize == 3) { |
11736 _errorReporter.reportError2(StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_
ABSTRACT_MEMBER_THREE, node.name, [missingOverridesArray[0].enclosingElement.dis
playName, missingOverridesArray[0].displayName, missingOverridesArray[1].enclosi
ngElement.displayName, missingOverridesArray[1].displayName, missingOverridesArr
ay[2].enclosingElement.displayName, missingOverridesArray[2].displayName]); | 11842 _errorReporter.reportError2(StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_
ABSTRACT_MEMBER_THREE, node.name, [stringTypeArray[0], missingOverridesArray[0].
enclosingElement.displayName, missingOverridesArray[0].displayName, stringTypeAr
ray[1], missingOverridesArray[1].enclosingElement.displayName, missingOverridesA
rray[1].displayName, stringTypeArray[2], missingOverridesArray[2].enclosingEleme
nt.displayName, missingOverridesArray[2].displayName]); |
11737 } else if (missingOverridesSize == 4) { | 11843 } else if (missingOverridesSize == 4) { |
11738 _errorReporter.reportError2(StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_
ABSTRACT_MEMBER_FOUR, node.name, [missingOverridesArray[0].enclosingElement.disp
layName, missingOverridesArray[0].displayName, missingOverridesArray[1].enclosin
gElement.displayName, missingOverridesArray[1].displayName, missingOverridesArra
y[2].enclosingElement.displayName, missingOverridesArray[2].displayName, missing
OverridesArray[3].enclosingElement.displayName, missingOverridesArray[3].display
Name]); | 11844 _errorReporter.reportError2(StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_
ABSTRACT_MEMBER_FOUR, node.name, [stringTypeArray[0], missingOverridesArray[0].e
nclosingElement.displayName, missingOverridesArray[0].displayName, stringTypeArr
ay[1], missingOverridesArray[1].enclosingElement.displayName, missingOverridesAr
ray[1].displayName, stringTypeArray[2], missingOverridesArray[2].enclosingElemen
t.displayName, missingOverridesArray[2].displayName, stringTypeArray[3], missing
OverridesArray[3].enclosingElement.displayName, missingOverridesArray[3].display
Name]); |
11739 } else { | 11845 } else { |
11740 _errorReporter.reportError2(StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_
ABSTRACT_MEMBER_FIVE_PLUS, node.name, [missingOverridesArray[0].enclosingElement
.displayName, missingOverridesArray[0].displayName, missingOverridesArray[1].enc
losingElement.displayName, missingOverridesArray[1].displayName, missingOverride
sArray[2].enclosingElement.displayName, missingOverridesArray[2].displayName, mi
ssingOverridesArray[3].enclosingElement.displayName, missingOverridesArray[3].di
splayName, missingOverridesArray.length - 4]); | 11846 _errorReporter.reportError2(StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_
ABSTRACT_MEMBER_FIVE_PLUS, node.name, [stringTypeArray[0], missingOverridesArray
[0].enclosingElement.displayName, missingOverridesArray[0].displayName, stringTy
peArray[1], missingOverridesArray[1].enclosingElement.displayName, missingOverri
desArray[1].displayName, stringTypeArray[2], missingOverridesArray[2].enclosingE
lement.displayName, missingOverridesArray[2].displayName, stringTypeArray[3], mi
ssingOverridesArray[3].enclosingElement.displayName, missingOverridesArray[3].di
splayName, missingOverridesArray.length - 4]); |
11741 } | 11847 } |
11742 return true; | 11848 return true; |
11743 } | 11849 } |
11744 | 11850 |
11745 /** | 11851 /** |
11746 * Checks to ensure that the expressions that need to be of type bool, are. Ot
herwise an error is | 11852 * Checks to ensure that the expressions that need to be of type bool, are. Ot
herwise an error is |
11747 * reported on the expression. | 11853 * reported on the expression. |
11748 * @param condition the conditional expression to test | 11854 * @param condition the conditional expression to test |
11749 * @return {@code true} if and only if an error code is generated on the passe
d node | 11855 * @return {@code true} if and only if an error code is generated on the passe
d node |
11750 * @see StaticTypeWarningCode#NON_BOOL_CONDITION | 11856 * @see StaticTypeWarningCode#NON_BOOL_CONDITION |
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12238 _errorReporter.reportError2(StaticTypeWarningCode.TYPE_ARGUMENT_NOT_
MATCHING_BOUNDS, argTypeName, [argTypeName.name, boundingElts[i].displayName]); | 12344 _errorReporter.reportError2(StaticTypeWarningCode.TYPE_ARGUMENT_NOT_
MATCHING_BOUNDS, argTypeName, [argTypeName.name, boundingElts[i].displayName]); |
12239 return true; | 12345 return true; |
12240 } | 12346 } |
12241 } | 12347 } |
12242 } | 12348 } |
12243 } | 12349 } |
12244 return false; | 12350 return false; |
12245 } | 12351 } |
12246 | 12352 |
12247 /** | 12353 /** |
12248 * This checks that if the passed generative constructor has no explicit super
constructor | 12354 * This checks that if the passed generative constructor has neither an explic
it super constructor |
12249 * invocation, then super class has the default generative constructor. | 12355 * invocation nor a redirecting constructor invocation, that the superclass ha
s a default |
| 12356 * generative constructor. |
12250 * @param node the constructor declaration to evaluate | 12357 * @param node the constructor declaration to evaluate |
12251 * @return {@code true} if and only if an error code is generated on the passe
d node | 12358 * @return {@code true} if and only if an error code is generated on the passe
d node |
12252 * @see CompileTimeErrorCode#UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT | 12359 * @see CompileTimeErrorCode#UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT |
12253 * @see CompileTimeErrorCode#NON_GENERATIVE_CONSTRUCTOR | 12360 * @see CompileTimeErrorCode#NON_GENERATIVE_CONSTRUCTOR |
12254 */ | 12361 */ |
12255 bool checkForUndefinedConstructorInInitializerImplicit(ConstructorDeclaration
node) { | 12362 bool checkForUndefinedConstructorInInitializerImplicit(ConstructorDeclaration
node) { |
12256 if (node.factoryKeyword != null) { | 12363 if (node.factoryKeyword != null) { |
12257 return false; | 12364 return false; |
12258 } | 12365 } |
| 12366 for (ConstructorInitializer constructorInitializer in node.initializers) { |
| 12367 if (constructorInitializer is SuperConstructorInvocation || constructorIni
tializer is RedirectingConstructorInvocation) { |
| 12368 return false; |
| 12369 } |
| 12370 } |
12259 if (_enclosingClass == null) { | 12371 if (_enclosingClass == null) { |
12260 return false; | 12372 return false; |
12261 } | 12373 } |
12262 InterfaceType superType = _enclosingClass.supertype; | 12374 InterfaceType superType = _enclosingClass.supertype; |
12263 if (superType == null) { | 12375 if (superType == null) { |
12264 return false; | 12376 return false; |
12265 } | 12377 } |
12266 ClassElement superElement = superType.element; | 12378 ClassElement superElement = superType.element; |
12267 for (ConstructorInitializer constructorInitializer in node.initializers) { | |
12268 if (constructorInitializer is SuperConstructorInvocation) { | |
12269 return false; | |
12270 } | |
12271 } | |
12272 ConstructorElement superDefaultConstructor = superElement.unnamedConstructor
; | 12379 ConstructorElement superDefaultConstructor = superElement.unnamedConstructor
; |
12273 if (superDefaultConstructor != null) { | 12380 if (superDefaultConstructor != null) { |
12274 if (superDefaultConstructor.isFactory()) { | 12381 if (superDefaultConstructor.isFactory()) { |
12275 _errorReporter.reportError2(CompileTimeErrorCode.NON_GENERATIVE_CONSTRUC
TOR, node.returnType, [superDefaultConstructor]); | 12382 _errorReporter.reportError2(CompileTimeErrorCode.NON_GENERATIVE_CONSTRUC
TOR, node.returnType, [superDefaultConstructor]); |
12276 return true; | 12383 return true; |
12277 } | 12384 } |
12278 return false; | 12385 return false; |
12279 } | 12386 } |
12280 _errorReporter.reportError2(CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_IN
ITIALIZER_DEFAULT, node.returnType, [superElement.name]); | 12387 _errorReporter.reportError2(CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_IN
ITIALIZER_DEFAULT, node.returnType, [superElement.name]); |
12281 return true; | 12388 return true; |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12478 static final List<INIT_STATE> values = [NOT_INIT, INIT_IN_DECLARATION, INIT_IN
_FIELD_FORMAL, INIT_IN_DEFAULT_VALUE, INIT_IN_INITIALIZERS]; | 12585 static final List<INIT_STATE> values = [NOT_INIT, INIT_IN_DECLARATION, INIT_IN
_FIELD_FORMAL, INIT_IN_DEFAULT_VALUE, INIT_IN_INITIALIZERS]; |
12479 | 12586 |
12480 /// The name of this enum constant, as declared in the enum declaration. | 12587 /// The name of this enum constant, as declared in the enum declaration. |
12481 final String name; | 12588 final String name; |
12482 | 12589 |
12483 /// The position in the enum declaration. | 12590 /// The position in the enum declaration. |
12484 final int ordinal; | 12591 final int ordinal; |
12485 INIT_STATE(this.name, this.ordinal) { | 12592 INIT_STATE(this.name, this.ordinal) { |
12486 } | 12593 } |
12487 int compareTo(INIT_STATE other) => ordinal - other.ordinal; | 12594 int compareTo(INIT_STATE other) => ordinal - other.ordinal; |
| 12595 int get hashCode => ordinal; |
12488 String toString() => name; | 12596 String toString() => name; |
12489 } | 12597 } |
12490 /** | 12598 /** |
12491 * Instances of the class {@code PubVerifier} traverse an AST structure looking
for deviations from | 12599 * Instances of the class {@code PubVerifier} traverse an AST structure looking
for deviations from |
12492 * pub best practices. | 12600 * pub best practices. |
12493 */ | 12601 */ |
12494 class PubVerifier extends RecursiveASTVisitor<Object> { | 12602 class PubVerifier extends RecursiveASTVisitor<Object> { |
12495 | 12603 |
12496 /** | 12604 /** |
12497 * The error reporter by which errors will be reported. | 12605 * The error reporter by which errors will be reported. |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12614 * @param message the message template used to create the message to be displa
yed for the error | 12722 * @param message the message template used to create the message to be displa
yed for the error |
12615 */ | 12723 */ |
12616 ResolverErrorCode(this.name, this.ordinal, ErrorType type, String message) { | 12724 ResolverErrorCode(this.name, this.ordinal, ErrorType type, String message) { |
12617 this._type = type; | 12725 this._type = type; |
12618 this._message = message; | 12726 this._message = message; |
12619 } | 12727 } |
12620 ErrorSeverity get errorSeverity => _type.severity; | 12728 ErrorSeverity get errorSeverity => _type.severity; |
12621 String get message => _message; | 12729 String get message => _message; |
12622 ErrorType get type => _type; | 12730 ErrorType get type => _type; |
12623 int compareTo(ResolverErrorCode other) => ordinal - other.ordinal; | 12731 int compareTo(ResolverErrorCode other) => ordinal - other.ordinal; |
| 12732 int get hashCode => ordinal; |
12624 String toString() => name; | 12733 String toString() => name; |
12625 } | 12734 } |
OLD | NEW |