| 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.element_resolver; | 5 library analyzer.src.generated.element_resolver; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/ast/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
| (...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 return null; | 606 return null; |
| 607 } | 607 } |
| 608 Element staticElement; | 608 Element staticElement; |
| 609 Element propagatedElement; | 609 Element propagatedElement; |
| 610 if (target == null) { | 610 if (target == null) { |
| 611 staticElement = _resolveInvokedElement(methodName); | 611 staticElement = _resolveInvokedElement(methodName); |
| 612 propagatedElement = null; | 612 propagatedElement = null; |
| 613 } else if (methodName.name == FunctionElement.LOAD_LIBRARY_NAME && | 613 } else if (methodName.name == FunctionElement.LOAD_LIBRARY_NAME && |
| 614 _isDeferredPrefix(target)) { | 614 _isDeferredPrefix(target)) { |
| 615 if (node.operator.type == TokenType.QUESTION_PERIOD) { | 615 if (node.operator.type == TokenType.QUESTION_PERIOD) { |
| 616 _resolver.reportErrorForNode( | 616 _resolver.errorReporter.reportErrorForNode( |
| 617 CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT, | 617 CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT, |
| 618 target, | 618 target, |
| 619 [(target as SimpleIdentifier).name]); | 619 [(target as SimpleIdentifier).name]); |
| 620 } | 620 } |
| 621 LibraryElement importedLibrary = _getImportedLibrary(target); | 621 LibraryElement importedLibrary = _getImportedLibrary(target); |
| 622 FunctionElement loadLibraryFunction = importedLibrary.loadLibraryFunction; | 622 FunctionElement loadLibraryFunction = importedLibrary.loadLibraryFunction; |
| 623 methodName.staticElement = loadLibraryFunction; | 623 methodName.staticElement = loadLibraryFunction; |
| 624 node.staticInvokeType = loadLibraryFunction.type; | 624 node.staticInvokeType = loadLibraryFunction.type; |
| 625 return null; | 625 return null; |
| 626 } else { | 626 } else { |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 generatedWithTypePropagation = true; | 742 generatedWithTypePropagation = true; |
| 743 } | 743 } |
| 744 if (errorCode == null) { | 744 if (errorCode == null) { |
| 745 return null; | 745 return null; |
| 746 } | 746 } |
| 747 if (identical( | 747 if (identical( |
| 748 errorCode, StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION) || | 748 errorCode, StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION) || |
| 749 identical(errorCode, | 749 identical(errorCode, |
| 750 CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT) || | 750 CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT) || |
| 751 identical(errorCode, StaticTypeWarningCode.UNDEFINED_FUNCTION)) { | 751 identical(errorCode, StaticTypeWarningCode.UNDEFINED_FUNCTION)) { |
| 752 _resolver.reportErrorForNode(errorCode, methodName, [methodName.name]); | 752 _resolver.errorReporter |
| 753 .reportErrorForNode(errorCode, methodName, [methodName.name]); |
| 753 } else if (identical(errorCode, StaticTypeWarningCode.UNDEFINED_METHOD)) { | 754 } else if (identical(errorCode, StaticTypeWarningCode.UNDEFINED_METHOD)) { |
| 754 String targetTypeName; | 755 String targetTypeName; |
| 755 if (target == null) { | 756 if (target == null) { |
| 756 ClassElement enclosingClass = _resolver.enclosingClass; | 757 ClassElement enclosingClass = _resolver.enclosingClass; |
| 757 targetTypeName = enclosingClass.displayName; | 758 targetTypeName = enclosingClass.displayName; |
| 758 ErrorCode proxyErrorCode = (generatedWithTypePropagation | 759 ErrorCode proxyErrorCode = (generatedWithTypePropagation |
| 759 ? HintCode.UNDEFINED_METHOD | 760 ? HintCode.UNDEFINED_METHOD |
| 760 : StaticTypeWarningCode.UNDEFINED_METHOD); | 761 : StaticTypeWarningCode.UNDEFINED_METHOD); |
| 761 _recordUndefinedNode(_resolver.enclosingClass, proxyErrorCode, | 762 _recordUndefinedNode(_resolver.enclosingClass, proxyErrorCode, |
| 762 methodName, [methodName.name, targetTypeName]); | 763 methodName, [methodName.name, targetTypeName]); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 // Generate the type name. | 811 // Generate the type name. |
| 811 // The error code will never be generated via type propagation | 812 // The error code will never be generated via type propagation |
| 812 DartType getSuperType(DartType type) { | 813 DartType getSuperType(DartType type) { |
| 813 if (type is InterfaceType && !type.isObject) { | 814 if (type is InterfaceType && !type.isObject) { |
| 814 return type.superclass; | 815 return type.superclass; |
| 815 } | 816 } |
| 816 return type; | 817 return type; |
| 817 } | 818 } |
| 818 DartType targetType = getSuperType(_getStaticType(target)); | 819 DartType targetType = getSuperType(_getStaticType(target)); |
| 819 String targetTypeName = targetType?.name; | 820 String targetTypeName = targetType?.name; |
| 820 _resolver.reportErrorForNode(StaticTypeWarningCode.UNDEFINED_SUPER_METHOD, | 821 _resolver.errorReporter.reportErrorForNode( |
| 821 methodName, [methodName.name, targetTypeName]); | 822 StaticTypeWarningCode.UNDEFINED_SUPER_METHOD, |
| 823 methodName, |
| 824 [methodName.name, targetTypeName]); |
| 822 } | 825 } |
| 823 return null; | 826 return null; |
| 824 } | 827 } |
| 825 | 828 |
| 826 @override | 829 @override |
| 827 Object visitPartDirective(PartDirective node) { | 830 Object visitPartDirective(PartDirective node) { |
| 828 resolveMetadata(node); | 831 resolveMetadata(node); |
| 829 return null; | 832 return null; |
| 830 } | 833 } |
| 831 | 834 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 885 Element element = _resolver.nameScope.lookup(node, _definingLibrary); | 888 Element element = _resolver.nameScope.lookup(node, _definingLibrary); |
| 886 if (element == null && identifier.inSetterContext()) { | 889 if (element == null && identifier.inSetterContext()) { |
| 887 Identifier setterName = new PrefixedIdentifierImpl.temp( | 890 Identifier setterName = new PrefixedIdentifierImpl.temp( |
| 888 node.prefix, | 891 node.prefix, |
| 889 new SimpleIdentifierImpl(new StringToken(TokenType.STRING, | 892 new SimpleIdentifierImpl(new StringToken(TokenType.STRING, |
| 890 "${node.identifier.name}=", node.identifier.offset - 1))); | 893 "${node.identifier.name}=", node.identifier.offset - 1))); |
| 891 element = _resolver.nameScope.lookup(setterName, _definingLibrary); | 894 element = _resolver.nameScope.lookup(setterName, _definingLibrary); |
| 892 } | 895 } |
| 893 if (element == null) { | 896 if (element == null) { |
| 894 if (identifier.inSetterContext()) { | 897 if (identifier.inSetterContext()) { |
| 895 _resolver.reportErrorForNode(StaticWarningCode.UNDEFINED_SETTER, | 898 _resolver.errorReporter.reportErrorForNode( |
| 896 identifier, [identifier.name, prefixElement.name]); | 899 StaticWarningCode.UNDEFINED_SETTER, |
| 900 identifier, |
| 901 [identifier.name, prefixElement.name]); |
| 897 return null; | 902 return null; |
| 898 } | 903 } |
| 899 AstNode parent = node.parent; | 904 AstNode parent = node.parent; |
| 900 if (parent is Annotation) { | 905 if (parent is Annotation) { |
| 901 _resolver.reportErrorForNode( | 906 _resolver.errorReporter.reportErrorForNode( |
| 902 CompileTimeErrorCode.INVALID_ANNOTATION, parent); | 907 CompileTimeErrorCode.INVALID_ANNOTATION, parent); |
| 903 } else { | 908 } else { |
| 904 _resolver.reportErrorForNode(StaticWarningCode.UNDEFINED_GETTER, | 909 _resolver.errorReporter.reportErrorForNode( |
| 905 identifier, [identifier.name, prefixElement.name]); | 910 StaticWarningCode.UNDEFINED_GETTER, |
| 911 identifier, |
| 912 [identifier.name, prefixElement.name]); |
| 906 } | 913 } |
| 907 return null; | 914 return null; |
| 908 } | 915 } |
| 909 Element accessor = element; | 916 Element accessor = element; |
| 910 if (accessor is PropertyAccessorElement && identifier.inSetterContext()) { | 917 if (accessor is PropertyAccessorElement && identifier.inSetterContext()) { |
| 911 PropertyInducingElement variable = accessor.variable; | 918 PropertyInducingElement variable = accessor.variable; |
| 912 if (variable != null) { | 919 if (variable != null) { |
| 913 PropertyAccessorElement setter = variable.setter; | 920 PropertyAccessorElement setter = variable.setter; |
| 914 if (setter != null) { | 921 if (setter != null) { |
| 915 element = setter; | 922 element = setter; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1070 node.staticType = _typeType; | 1077 node.staticType = _typeType; |
| 1071 return null; | 1078 return null; |
| 1072 } | 1079 } |
| 1073 // | 1080 // |
| 1074 // Otherwise, the node should be resolved. | 1081 // Otherwise, the node should be resolved. |
| 1075 // | 1082 // |
| 1076 Element element = _resolveSimpleIdentifier(node); | 1083 Element element = _resolveSimpleIdentifier(node); |
| 1077 ClassElement enclosingClass = _resolver.enclosingClass; | 1084 ClassElement enclosingClass = _resolver.enclosingClass; |
| 1078 if (_isFactoryConstructorReturnType(node) && | 1085 if (_isFactoryConstructorReturnType(node) && |
| 1079 !identical(element, enclosingClass)) { | 1086 !identical(element, enclosingClass)) { |
| 1080 _resolver.reportErrorForNode( | 1087 _resolver.errorReporter.reportErrorForNode( |
| 1081 CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLASS, node); | 1088 CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLASS, node); |
| 1082 } else if (_isConstructorReturnType(node) && | 1089 } else if (_isConstructorReturnType(node) && |
| 1083 !identical(element, enclosingClass)) { | 1090 !identical(element, enclosingClass)) { |
| 1084 _resolver.reportErrorForNode( | 1091 _resolver.errorReporter.reportErrorForNode( |
| 1085 CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME, node); | 1092 CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME, node); |
| 1086 element = null; | 1093 element = null; |
| 1087 } else if (element == null || | 1094 } else if (element == null || |
| 1088 (element is PrefixElement && !_isValidAsPrefix(node))) { | 1095 (element is PrefixElement && !_isValidAsPrefix(node))) { |
| 1089 // TODO(brianwilkerson) Recover from this error. | 1096 // TODO(brianwilkerson) Recover from this error. |
| 1090 if (_isConstructorReturnType(node)) { | 1097 if (_isConstructorReturnType(node)) { |
| 1091 _resolver.reportErrorForNode( | 1098 _resolver.errorReporter.reportErrorForNode( |
| 1092 CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME, node); | 1099 CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME, node); |
| 1093 } else { | 1100 } else { |
| 1094 if (parent is Annotation) { | 1101 if (parent is Annotation) { |
| 1095 _resolver.reportErrorForNode( | 1102 _resolver.errorReporter.reportErrorForNode( |
| 1096 CompileTimeErrorCode.INVALID_ANNOTATION, parent); | 1103 CompileTimeErrorCode.INVALID_ANNOTATION, parent); |
| 1097 } else if (element != null) { | 1104 } else if (element != null) { |
| 1098 _resolver.reportErrorForNode( | 1105 _resolver.errorReporter.reportErrorForNode( |
| 1099 CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT, | 1106 CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT, |
| 1100 node, | 1107 node, |
| 1101 [element.name]); | 1108 [element.name]); |
| 1102 } else { | 1109 } else { |
| 1103 _recordUndefinedNode(_resolver.enclosingClass, | 1110 _recordUndefinedNode(_resolver.enclosingClass, |
| 1104 StaticWarningCode.UNDEFINED_IDENTIFIER, node, [node.name]); | 1111 StaticWarningCode.UNDEFINED_IDENTIFIER, node, [node.name]); |
| 1105 } | 1112 } |
| 1106 } | 1113 } |
| 1107 } | 1114 } |
| 1108 node.staticElement = element; | 1115 node.staticElement = element; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1137 return null; | 1144 return null; |
| 1138 } | 1145 } |
| 1139 SimpleIdentifier name = node.constructorName; | 1146 SimpleIdentifier name = node.constructorName; |
| 1140 String superName = name != null ? name.name : null; | 1147 String superName = name != null ? name.name : null; |
| 1141 ConstructorElement element = | 1148 ConstructorElement element = |
| 1142 superType.lookUpConstructor(superName, _definingLibrary); | 1149 superType.lookUpConstructor(superName, _definingLibrary); |
| 1143 if (element == null || | 1150 if (element == null || |
| 1144 (!enclosingClass.doesMixinLackConstructors && | 1151 (!enclosingClass.doesMixinLackConstructors && |
| 1145 !enclosingClass.isSuperConstructorAccessible(element))) { | 1152 !enclosingClass.isSuperConstructorAccessible(element))) { |
| 1146 if (name != null) { | 1153 if (name != null) { |
| 1147 _resolver.reportErrorForNode( | 1154 _resolver.errorReporter.reportErrorForNode( |
| 1148 CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER, | 1155 CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER, |
| 1149 node, | 1156 node, |
| 1150 [superType.displayName, name]); | 1157 [superType.displayName, name]); |
| 1151 } else { | 1158 } else { |
| 1152 _resolver.reportErrorForNode( | 1159 _resolver.errorReporter.reportErrorForNode( |
| 1153 CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT, | 1160 CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT, |
| 1154 node, | 1161 node, |
| 1155 [superType.displayName]); | 1162 [superType.displayName]); |
| 1156 } | 1163 } |
| 1157 return null; | 1164 return null; |
| 1158 } else { | 1165 } else { |
| 1159 if (element.isFactory) { | 1166 if (element.isFactory) { |
| 1160 _resolver.reportErrorForNode( | 1167 _resolver.errorReporter.reportErrorForNode( |
| 1161 CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR, node, [element]); | 1168 CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR, node, [element]); |
| 1162 } | 1169 } |
| 1163 } | 1170 } |
| 1164 if (name != null) { | 1171 if (name != null) { |
| 1165 name.staticElement = element; | 1172 name.staticElement = element; |
| 1166 } | 1173 } |
| 1167 node.staticElement = element; | 1174 node.staticElement = element; |
| 1168 ArgumentList argumentList = node.argumentList; | 1175 ArgumentList argumentList = node.argumentList; |
| 1169 List<ParameterElement> parameters = _resolveArgumentsToFunction( | 1176 List<ParameterElement> parameters = _resolveArgumentsToFunction( |
| 1170 isInConstConstructor, argumentList, element); | 1177 isInConstConstructor, argumentList, element); |
| 1171 if (parameters != null) { | 1178 if (parameters != null) { |
| 1172 argumentList.correspondingStaticParameters = parameters; | 1179 argumentList.correspondingStaticParameters = parameters; |
| 1173 } | 1180 } |
| 1174 return null; | 1181 return null; |
| 1175 } | 1182 } |
| 1176 | 1183 |
| 1177 @override | 1184 @override |
| 1178 Object visitSuperExpression(SuperExpression node) { | 1185 Object visitSuperExpression(SuperExpression node) { |
| 1179 if (!_isSuperInValidContext(node)) { | 1186 if (!_isSuperInValidContext(node)) { |
| 1180 _resolver.reportErrorForNode( | 1187 _resolver.errorReporter.reportErrorForNode( |
| 1181 CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT, node); | 1188 CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT, node); |
| 1182 } | 1189 } |
| 1183 return super.visitSuperExpression(node); | 1190 return super.visitSuperExpression(node); |
| 1184 } | 1191 } |
| 1185 | 1192 |
| 1186 @override | 1193 @override |
| 1187 Object visitTypeParameter(TypeParameter node) { | 1194 Object visitTypeParameter(TypeParameter node) { |
| 1188 resolveMetadata(node); | 1195 resolveMetadata(node); |
| 1189 return null; | 1196 return null; |
| 1190 } | 1197 } |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1519 * Check for a generic method & apply type arguments if any were passed. | 1526 * Check for a generic method & apply type arguments if any were passed. |
| 1520 */ | 1527 */ |
| 1521 DartType _instantiateGenericMethod( | 1528 DartType _instantiateGenericMethod( |
| 1522 DartType invokeType, TypeArgumentList typeArguments, AstNode node) { | 1529 DartType invokeType, TypeArgumentList typeArguments, AstNode node) { |
| 1523 // TODO(jmesserly): support generic "call" methods on InterfaceType. | 1530 // TODO(jmesserly): support generic "call" methods on InterfaceType. |
| 1524 if (invokeType is FunctionType) { | 1531 if (invokeType is FunctionType) { |
| 1525 List<TypeParameterElement> parameters = invokeType.typeFormals; | 1532 List<TypeParameterElement> parameters = invokeType.typeFormals; |
| 1526 | 1533 |
| 1527 NodeList<TypeName> arguments = typeArguments?.arguments; | 1534 NodeList<TypeName> arguments = typeArguments?.arguments; |
| 1528 if (arguments != null && arguments.length != parameters.length) { | 1535 if (arguments != null && arguments.length != parameters.length) { |
| 1529 _resolver.reportErrorForNode( | 1536 _resolver.errorReporter.reportErrorForNode( |
| 1530 StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS, | 1537 StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS, |
| 1531 node, | 1538 node, |
| 1532 [invokeType, parameters.length, arguments?.length ?? 0]); | 1539 [invokeType, parameters.length, arguments?.length ?? 0]); |
| 1533 | 1540 |
| 1534 // Wrong number of type arguments. Ignore them. | 1541 // Wrong number of type arguments. Ignore them. |
| 1535 arguments = null; | 1542 arguments = null; |
| 1536 } | 1543 } |
| 1537 if (parameters.isNotEmpty) { | 1544 if (parameters.isNotEmpty) { |
| 1538 if (arguments == null) { | 1545 if (arguments == null) { |
| 1539 return _resolver.typeSystem.instantiateToBounds(invokeType); | 1546 return _resolver.typeSystem.instantiateToBounds(invokeType); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1628 */ | 1635 */ |
| 1629 AstNode _lookupBreakOrContinueTarget( | 1636 AstNode _lookupBreakOrContinueTarget( |
| 1630 AstNode parentNode, SimpleIdentifier labelNode, bool isContinue) { | 1637 AstNode parentNode, SimpleIdentifier labelNode, bool isContinue) { |
| 1631 if (labelNode == null) { | 1638 if (labelNode == null) { |
| 1632 return _resolver.implicitLabelScope.getTarget(isContinue); | 1639 return _resolver.implicitLabelScope.getTarget(isContinue); |
| 1633 } else { | 1640 } else { |
| 1634 LabelScope labelScope = _resolver.labelScope; | 1641 LabelScope labelScope = _resolver.labelScope; |
| 1635 if (labelScope == null) { | 1642 if (labelScope == null) { |
| 1636 // There are no labels in scope, so by definition the label is | 1643 // There are no labels in scope, so by definition the label is |
| 1637 // undefined. | 1644 // undefined. |
| 1638 _resolver.reportErrorForNode( | 1645 _resolver.errorReporter.reportErrorForNode( |
| 1639 CompileTimeErrorCode.LABEL_UNDEFINED, labelNode, [labelNode.name]); | 1646 CompileTimeErrorCode.LABEL_UNDEFINED, labelNode, [labelNode.name]); |
| 1640 return null; | 1647 return null; |
| 1641 } | 1648 } |
| 1642 LabelScope definingScope = labelScope.lookup(labelNode.name); | 1649 LabelScope definingScope = labelScope.lookup(labelNode.name); |
| 1643 if (definingScope == null) { | 1650 if (definingScope == null) { |
| 1644 // No definition of the given label name could be found in any | 1651 // No definition of the given label name could be found in any |
| 1645 // enclosing scope. | 1652 // enclosing scope. |
| 1646 _resolver.reportErrorForNode( | 1653 _resolver.errorReporter.reportErrorForNode( |
| 1647 CompileTimeErrorCode.LABEL_UNDEFINED, labelNode, [labelNode.name]); | 1654 CompileTimeErrorCode.LABEL_UNDEFINED, labelNode, [labelNode.name]); |
| 1648 return null; | 1655 return null; |
| 1649 } | 1656 } |
| 1650 // The target has been found. | 1657 // The target has been found. |
| 1651 labelNode.staticElement = definingScope.element; | 1658 labelNode.staticElement = definingScope.element; |
| 1652 ExecutableElement labelContainer = definingScope.element | 1659 ExecutableElement labelContainer = definingScope.element |
| 1653 .getAncestor((element) => element is ExecutableElement); | 1660 .getAncestor((element) => element is ExecutableElement); |
| 1654 if (!identical(labelContainer, _resolver.enclosingFunction)) { | 1661 if (!identical(labelContainer, _resolver.enclosingFunction)) { |
| 1655 _resolver.reportErrorForNode(CompileTimeErrorCode.LABEL_IN_OUTER_SCOPE, | 1662 _resolver.errorReporter.reportErrorForNode( |
| 1656 labelNode, [labelNode.name]); | 1663 CompileTimeErrorCode.LABEL_IN_OUTER_SCOPE, |
| 1664 labelNode, |
| 1665 [labelNode.name]); |
| 1657 } | 1666 } |
| 1658 return definingScope.node; | 1667 return definingScope.node; |
| 1659 } | 1668 } |
| 1660 } | 1669 } |
| 1661 | 1670 |
| 1662 /** | 1671 /** |
| 1663 * Look up the getter with the given [getterName] in the given [type]. Return | 1672 * Look up the getter with the given [getterName] in the given [type]. Return |
| 1664 * the element representing the getter that was found, or `null` if there is | 1673 * the element representing the getter that was found, or `null` if there is |
| 1665 * no getter with the given name. The [target] is the target of the | 1674 * no getter with the given name. The [target] is the target of the |
| 1666 * invocation, or `null` if there is no target. | 1675 * invocation, or `null` if there is no target. |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1808 * Record that the given [node] is undefined, causing an error to be reported | 1817 * Record that the given [node] is undefined, causing an error to be reported |
| 1809 * if appropriate. The [declaringElement] is the element inside which no | 1818 * if appropriate. The [declaringElement] is the element inside which no |
| 1810 * declaration was found. If this element is a proxy, no error will be | 1819 * declaration was found. If this element is a proxy, no error will be |
| 1811 * reported. If null, then an error will always be reported. The [errorCode] | 1820 * reported. If null, then an error will always be reported. The [errorCode] |
| 1812 * is the error code to report. The [arguments] are the arguments to the error | 1821 * is the error code to report. The [arguments] are the arguments to the error |
| 1813 * message. | 1822 * message. |
| 1814 */ | 1823 */ |
| 1815 void _recordUndefinedNode(Element declaringElement, ErrorCode errorCode, | 1824 void _recordUndefinedNode(Element declaringElement, ErrorCode errorCode, |
| 1816 AstNode node, List<Object> arguments) { | 1825 AstNode node, List<Object> arguments) { |
| 1817 if (_doesntHaveProxy(declaringElement)) { | 1826 if (_doesntHaveProxy(declaringElement)) { |
| 1818 _resolver.reportErrorForNode(errorCode, node, arguments); | 1827 _resolver.errorReporter.reportErrorForNode(errorCode, node, arguments); |
| 1819 } | 1828 } |
| 1820 } | 1829 } |
| 1821 | 1830 |
| 1822 /** | 1831 /** |
| 1823 * Record that the given [offset]/[length] is undefined, causing an error to | 1832 * Record that the given [offset]/[length] is undefined, causing an error to |
| 1824 * be reported if appropriate. The [declaringElement] is the element inside | 1833 * be reported if appropriate. The [declaringElement] is the element inside |
| 1825 * which no declaration was found. If this element is a proxy, no error will | 1834 * which no declaration was found. If this element is a proxy, no error will |
| 1826 * be reported. If null, then an error will always be reported. The | 1835 * be reported. If null, then an error will always be reported. The |
| 1827 * [errorCode] is the error code to report. The [arguments] are arguments to | 1836 * [errorCode] is the error code to report. The [arguments] are arguments to |
| 1828 * the error message. | 1837 * the error message. |
| 1829 */ | 1838 */ |
| 1830 void _recordUndefinedOffset(Element declaringElement, ErrorCode errorCode, | 1839 void _recordUndefinedOffset(Element declaringElement, ErrorCode errorCode, |
| 1831 int offset, int length, List<Object> arguments) { | 1840 int offset, int length, List<Object> arguments) { |
| 1832 if (_doesntHaveProxy(declaringElement)) { | 1841 if (_doesntHaveProxy(declaringElement)) { |
| 1833 _resolver.reportErrorForOffset(errorCode, offset, length, arguments); | 1842 _resolver.errorReporter |
| 1843 .reportErrorForOffset(errorCode, offset, length, arguments); |
| 1834 } | 1844 } |
| 1835 } | 1845 } |
| 1836 | 1846 |
| 1837 /** | 1847 /** |
| 1838 * Record that the given [token] is undefined, causing an error to be reported | 1848 * Record that the given [token] is undefined, causing an error to be reported |
| 1839 * if appropriate. The [declaringElement] is the element inside which no | 1849 * if appropriate. The [declaringElement] is the element inside which no |
| 1840 * declaration was found. If this element is a proxy, no error will be | 1850 * declaration was found. If this element is a proxy, no error will be |
| 1841 * reported. If null, then an error will always be reported. The [errorCode] | 1851 * reported. If null, then an error will always be reported. The [errorCode] |
| 1842 * is the error code to report. The [arguments] are arguments to the error | 1852 * is the error code to report. The [arguments] are arguments to the error |
| 1843 * message. | 1853 * message. |
| 1844 */ | 1854 */ |
| 1845 void _recordUndefinedToken(Element declaringElement, ErrorCode errorCode, | 1855 void _recordUndefinedToken(Element declaringElement, ErrorCode errorCode, |
| 1846 Token token, List<Object> arguments) { | 1856 Token token, List<Object> arguments) { |
| 1847 if (_doesntHaveProxy(declaringElement)) { | 1857 if (_doesntHaveProxy(declaringElement)) { |
| 1848 _resolver.reportErrorForToken(errorCode, token, arguments); | 1858 _resolver.errorReporter.reportErrorForToken(errorCode, token, arguments); |
| 1849 } | 1859 } |
| 1850 } | 1860 } |
| 1851 | 1861 |
| 1852 void _resolveAnnotationConstructorInvocationArguments( | 1862 void _resolveAnnotationConstructorInvocationArguments( |
| 1853 Annotation annotation, ConstructorElement constructor) { | 1863 Annotation annotation, ConstructorElement constructor) { |
| 1854 ArgumentList argumentList = annotation.arguments; | 1864 ArgumentList argumentList = annotation.arguments; |
| 1855 // error will be reported in ConstantVerifier | 1865 // error will be reported in ConstantVerifier |
| 1856 if (argumentList == null) { | 1866 if (argumentList == null) { |
| 1857 return; | 1867 return; |
| 1858 } | 1868 } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1944 return; | 1954 return; |
| 1945 } | 1955 } |
| 1946 // prefix.Class.constructor(args) | 1956 // prefix.Class.constructor(args) |
| 1947 constructor = new InterfaceTypeImpl(element2) | 1957 constructor = new InterfaceTypeImpl(element2) |
| 1948 .lookUpConstructor(name3, _definingLibrary); | 1958 .lookUpConstructor(name3, _definingLibrary); |
| 1949 nameNode3.staticElement = constructor; | 1959 nameNode3.staticElement = constructor; |
| 1950 } | 1960 } |
| 1951 } | 1961 } |
| 1952 // we need constructor | 1962 // we need constructor |
| 1953 if (constructor == null) { | 1963 if (constructor == null) { |
| 1954 _resolver.reportErrorForNode( | 1964 _resolver.errorReporter.reportErrorForNode( |
| 1955 CompileTimeErrorCode.INVALID_ANNOTATION, annotation); | 1965 CompileTimeErrorCode.INVALID_ANNOTATION, annotation); |
| 1956 return; | 1966 return; |
| 1957 } | 1967 } |
| 1958 // record element | 1968 // record element |
| 1959 annotation.element = constructor; | 1969 annotation.element = constructor; |
| 1960 // resolve arguments | 1970 // resolve arguments |
| 1961 _resolveAnnotationConstructorInvocationArguments(annotation, constructor); | 1971 _resolveAnnotationConstructorInvocationArguments(annotation, constructor); |
| 1962 } | 1972 } |
| 1963 | 1973 |
| 1964 void _resolveAnnotationElementGetter( | 1974 void _resolveAnnotationElementGetter( |
| 1965 Annotation annotation, PropertyAccessorElement accessorElement) { | 1975 Annotation annotation, PropertyAccessorElement accessorElement) { |
| 1966 // accessor should be synthetic | 1976 // accessor should be synthetic |
| 1967 if (!accessorElement.isSynthetic) { | 1977 if (!accessorElement.isSynthetic) { |
| 1968 _resolver.reportErrorForNode( | 1978 _resolver.errorReporter.reportErrorForNode( |
| 1969 CompileTimeErrorCode.INVALID_ANNOTATION, annotation); | 1979 CompileTimeErrorCode.INVALID_ANNOTATION, annotation); |
| 1970 return; | 1980 return; |
| 1971 } | 1981 } |
| 1972 // variable should be constant | 1982 // variable should be constant |
| 1973 VariableElement variableElement = accessorElement.variable; | 1983 VariableElement variableElement = accessorElement.variable; |
| 1974 if (!variableElement.isConst) { | 1984 if (!variableElement.isConst) { |
| 1975 _resolver.reportErrorForNode( | 1985 _resolver.errorReporter.reportErrorForNode( |
| 1976 CompileTimeErrorCode.INVALID_ANNOTATION, annotation); | 1986 CompileTimeErrorCode.INVALID_ANNOTATION, annotation); |
| 1977 } | 1987 } |
| 1978 // no arguments | 1988 // no arguments |
| 1979 if (annotation.arguments != null) { | 1989 if (annotation.arguments != null) { |
| 1980 _resolver.reportErrorForNode( | 1990 _resolver.errorReporter.reportErrorForNode( |
| 1981 CompileTimeErrorCode.ANNOTATION_WITH_NON_CLASS, | 1991 CompileTimeErrorCode.ANNOTATION_WITH_NON_CLASS, |
| 1982 annotation.name, | 1992 annotation.name, |
| 1983 [annotation.name]); | 1993 [annotation.name]); |
| 1984 } | 1994 } |
| 1985 // OK | 1995 // OK |
| 1986 return; | 1996 return; |
| 1987 } | 1997 } |
| 1988 | 1998 |
| 1989 /** | 1999 /** |
| 1990 * Given an [argumentList] and the [executableElement] that will be invoked | 2000 * Given an [argumentList] and the [executableElement] that will be invoked |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2010 * will be invoked using those arguments, compute the list of parameters that | 2020 * will be invoked using those arguments, compute the list of parameters that |
| 2011 * correspond to the list of arguments. An error will be reported if any of | 2021 * correspond to the list of arguments. An error will be reported if any of |
| 2012 * the arguments cannot be matched to a parameter. The flag [reportAsError] | 2022 * the arguments cannot be matched to a parameter. The flag [reportAsError] |
| 2013 * should be `true` if a compile-time error should be reported; or `false` if | 2023 * should be `true` if a compile-time error should be reported; or `false` if |
| 2014 * a compile-time warning should be reported. Return the parameters that | 2024 * a compile-time warning should be reported. Return the parameters that |
| 2015 * correspond to the arguments. | 2025 * correspond to the arguments. |
| 2016 */ | 2026 */ |
| 2017 List<ParameterElement> _resolveArgumentsToParameters(bool reportAsError, | 2027 List<ParameterElement> _resolveArgumentsToParameters(bool reportAsError, |
| 2018 ArgumentList argumentList, List<ParameterElement> parameters) { | 2028 ArgumentList argumentList, List<ParameterElement> parameters) { |
| 2019 return ResolverVisitor.resolveArgumentsToParameters( | 2029 return ResolverVisitor.resolveArgumentsToParameters( |
| 2020 argumentList, parameters, _resolver.reportErrorForNode, | 2030 argumentList, parameters, _resolver.errorReporter.reportErrorForNode, |
| 2021 reportAsError: reportAsError); | 2031 reportAsError: reportAsError); |
| 2022 } | 2032 } |
| 2023 | 2033 |
| 2024 void _resolveBinaryExpression(BinaryExpression node, String methodName) { | 2034 void _resolveBinaryExpression(BinaryExpression node, String methodName) { |
| 2025 Expression leftOperand = node.leftOperand; | 2035 Expression leftOperand = node.leftOperand; |
| 2026 if (leftOperand != null) { | 2036 if (leftOperand != null) { |
| 2027 DartType staticType = _getStaticType(leftOperand); | 2037 DartType staticType = _getStaticType(leftOperand); |
| 2028 MethodElement staticMethod = | 2038 MethodElement staticMethod = |
| 2029 _lookUpMethod(leftOperand, staticType, methodName); | 2039 _lookUpMethod(leftOperand, staticType, methodName); |
| 2030 node.staticElement = staticMethod; | 2040 node.staticElement = staticMethod; |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2176 // | 2186 // |
| 2177 // TODO (collinsn): need to add union type support here too, in the | 2187 // TODO (collinsn): need to add union type support here too, in the |
| 2178 // style of [lookUpMethod]. | 2188 // style of [lookUpMethod]. |
| 2179 element = _lookUpGetter(target, targetType, methodName.name); | 2189 element = _lookUpGetter(target, targetType, methodName.name); |
| 2180 } | 2190 } |
| 2181 return element; | 2191 return element; |
| 2182 } else if (target is SimpleIdentifier) { | 2192 } else if (target is SimpleIdentifier) { |
| 2183 Element targetElement = target.staticElement; | 2193 Element targetElement = target.staticElement; |
| 2184 if (targetElement is PrefixElement) { | 2194 if (targetElement is PrefixElement) { |
| 2185 if (isConditional) { | 2195 if (isConditional) { |
| 2186 _resolver.reportErrorForNode( | 2196 _resolver.errorReporter.reportErrorForNode( |
| 2187 CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT, | 2197 CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT, |
| 2188 target, | 2198 target, |
| 2189 [target.name]); | 2199 [target.name]); |
| 2190 } | 2200 } |
| 2191 // | 2201 // |
| 2192 // Look to see whether the name of the method is really part of a | 2202 // Look to see whether the name of the method is really part of a |
| 2193 // prefixed identifier for an imported top-level function or top-level | 2203 // prefixed identifier for an imported top-level function or top-level |
| 2194 // getter that returns a function. | 2204 // getter that returns a function. |
| 2195 // | 2205 // |
| 2196 Identifier functionName = | 2206 Identifier functionName = |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2299 if (!_enableStrictCallChecks && | 2309 if (!_enableStrictCallChecks && |
| 2300 targetType != null && | 2310 targetType != null && |
| 2301 targetType.isDartCoreFunction && | 2311 targetType.isDartCoreFunction && |
| 2302 propertyName.name == FunctionElement.CALL_METHOD_NAME) { | 2312 propertyName.name == FunctionElement.CALL_METHOD_NAME) { |
| 2303 // TODO(brianwilkerson) Can we ever resolve the function being | 2313 // TODO(brianwilkerson) Can we ever resolve the function being |
| 2304 // invoked? | 2314 // invoked? |
| 2305 // resolveArgumentsToParameters(node.getArgumentList(), invokedFuncti
on); | 2315 // resolveArgumentsToParameters(node.getArgumentList(), invokedFuncti
on); |
| 2306 return; | 2316 return; |
| 2307 } else if (staticOrPropagatedEnclosingElt.isEnum && | 2317 } else if (staticOrPropagatedEnclosingElt.isEnum && |
| 2308 propertyName.name == "_name") { | 2318 propertyName.name == "_name") { |
| 2309 _resolver.reportErrorForNode( | 2319 _resolver.errorReporter.reportErrorForNode( |
| 2310 CompileTimeErrorCode.ACCESS_PRIVATE_ENUM_FIELD, | 2320 CompileTimeErrorCode.ACCESS_PRIVATE_ENUM_FIELD, |
| 2311 propertyName, | 2321 propertyName, |
| 2312 [propertyName.name]); | 2322 [propertyName.name]); |
| 2313 return; | 2323 return; |
| 2314 } | 2324 } |
| 2315 } | 2325 } |
| 2316 } | 2326 } |
| 2317 Element declaringElement = | 2327 Element declaringElement = |
| 2318 staticType.isVoid ? null : staticOrPropagatedEnclosingElt; | 2328 staticType.isVoid ? null : staticOrPropagatedEnclosingElt; |
| 2319 if (propertyName.inSetterContext()) { | 2329 if (propertyName.inSetterContext()) { |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2578 | 2588 |
| 2579 @override | 2589 @override |
| 2580 Element get staticElement => null; | 2590 Element get staticElement => null; |
| 2581 | 2591 |
| 2582 @override | 2592 @override |
| 2583 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => null; | 2593 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => null; |
| 2584 | 2594 |
| 2585 @override | 2595 @override |
| 2586 void visitChildren(AstVisitor visitor) {} | 2596 void visitChildren(AstVisitor visitor) {} |
| 2587 } | 2597 } |
| OLD | NEW |