| 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 engine.resolver.element_resolver; | 5 library engine.resolver.element_resolver; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'error.dart'; | 9 import 'error.dart'; |
| 10 import 'scanner.dart' as sc; | 10 import 'scanner.dart' as sc; |
| (...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 870 if (element == null && identifier.inSetterContext()) { | 870 if (element == null && identifier.inSetterContext()) { |
| 871 element = _resolver.nameScope.lookup(new SyntheticIdentifier( | 871 element = _resolver.nameScope.lookup(new SyntheticIdentifier( |
| 872 "${node.name}=", node), | 872 "${node.name}=", node), |
| 873 _definingLibrary); | 873 _definingLibrary); |
| 874 } | 874 } |
| 875 if (element == null) { | 875 if (element == null) { |
| 876 if (identifier.inSetterContext()) { | 876 if (identifier.inSetterContext()) { |
| 877 _resolver.reportErrorForNode(StaticWarningCode.UNDEFINED_SETTER, ident
ifier, [identifier.name, prefixElement.name]); | 877 _resolver.reportErrorForNode(StaticWarningCode.UNDEFINED_SETTER, ident
ifier, [identifier.name, prefixElement.name]); |
| 878 } else if (node.parent is Annotation) { | 878 } else if (node.parent is Annotation) { |
| 879 Annotation annotation = node.parent as Annotation; | 879 Annotation annotation = node.parent as Annotation; |
| 880 _resolver.reportErrorForNode(CompileTimeErrorCode.INVALID_ANNOTATION,
annotation, []); | 880 _resolver.reportErrorForNode(CompileTimeErrorCode.INVALID_ANNOTATION,
annotation); |
| 881 return null; | 881 return null; |
| 882 } else { | 882 } else { |
| 883 _resolver.reportErrorForNode(StaticWarningCode.UNDEFINED_GETTER, ident
ifier, [identifier.name, prefixElement.name]); | 883 _resolver.reportErrorForNode(StaticWarningCode.UNDEFINED_GETTER, ident
ifier, [identifier.name, prefixElement.name]); |
| 884 } | 884 } |
| 885 return null; | 885 return null; |
| 886 } | 886 } |
| 887 if (element is PropertyAccessorElement && identifier.inSetterContext()) { | 887 if (element is PropertyAccessorElement && identifier.inSetterContext()) { |
| 888 PropertyInducingElement variable = (element as PropertyAccessorElement).
variable; | 888 PropertyInducingElement variable = (element as PropertyAccessorElement).
variable; |
| 889 if (variable != null) { | 889 if (variable != null) { |
| 890 PropertyAccessorElement setter = variable.setter; | 890 PropertyAccessorElement setter = variable.setter; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1008 node.staticElement = _dynamicType.element; | 1008 node.staticElement = _dynamicType.element; |
| 1009 node.staticType = _typeType; | 1009 node.staticType = _typeType; |
| 1010 return null; | 1010 return null; |
| 1011 } | 1011 } |
| 1012 // | 1012 // |
| 1013 // Otherwise, the node should be resolved. | 1013 // Otherwise, the node should be resolved. |
| 1014 // | 1014 // |
| 1015 Element element = _resolveSimpleIdentifier(node); | 1015 Element element = _resolveSimpleIdentifier(node); |
| 1016 ClassElement enclosingClass = _resolver.enclosingClass; | 1016 ClassElement enclosingClass = _resolver.enclosingClass; |
| 1017 if (_isFactoryConstructorReturnType(node) && !identical(element, enclosingCl
ass)) { | 1017 if (_isFactoryConstructorReturnType(node) && !identical(element, enclosingCl
ass)) { |
| 1018 _resolver.reportErrorForNode(CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT
_A_CLASS, node, []); | 1018 _resolver.reportErrorForNode(CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT
_A_CLASS, node); |
| 1019 } else if (_isConstructorReturnType(node) && !identical(element, enclosingCl
ass)) { | 1019 } else if (_isConstructorReturnType(node) && !identical(element, enclosingCl
ass)) { |
| 1020 _resolver.reportErrorForNode(CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME
, node, []); | 1020 _resolver.reportErrorForNode(CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME
, node); |
| 1021 element = null; | 1021 element = null; |
| 1022 } else if (element == null || (element is PrefixElement && !_isValidAsPrefix
(node))) { | 1022 } else if (element == null || (element is PrefixElement && !_isValidAsPrefix
(node))) { |
| 1023 // TODO(brianwilkerson) Recover from this error. | 1023 // TODO(brianwilkerson) Recover from this error. |
| 1024 if (_isConstructorReturnType(node)) { | 1024 if (_isConstructorReturnType(node)) { |
| 1025 _resolver.reportErrorForNode(CompileTimeErrorCode.INVALID_CONSTRUCTOR_NA
ME, node, []); | 1025 _resolver.reportErrorForNode(CompileTimeErrorCode.INVALID_CONSTRUCTOR_NA
ME, node); |
| 1026 } else if (node.parent is Annotation) { | 1026 } else if (node.parent is Annotation) { |
| 1027 Annotation annotation = node.parent as Annotation; | 1027 Annotation annotation = node.parent as Annotation; |
| 1028 _resolver.reportErrorForNode(CompileTimeErrorCode.INVALID_ANNOTATION, an
notation, []); | 1028 _resolver.reportErrorForNode(CompileTimeErrorCode.INVALID_ANNOTATION, an
notation); |
| 1029 } else { | 1029 } else { |
| 1030 _recordUndefinedNode(_resolver.enclosingClass, StaticWarningCode.UNDEFIN
ED_IDENTIFIER, node, [node.name]); | 1030 _recordUndefinedNode(_resolver.enclosingClass, StaticWarningCode.UNDEFIN
ED_IDENTIFIER, node, [node.name]); |
| 1031 } | 1031 } |
| 1032 } | 1032 } |
| 1033 node.staticElement = element; | 1033 node.staticElement = element; |
| 1034 if (node.inSetterContext() && node.inGetterContext() && enclosingClass != nu
ll) { | 1034 if (node.inSetterContext() && node.inGetterContext() && enclosingClass != nu
ll) { |
| 1035 InterfaceType enclosingType = enclosingClass.type; | 1035 InterfaceType enclosingType = enclosingClass.type; |
| 1036 AuxiliaryElements auxiliaryElements = new AuxiliaryElements(_lookUpGetter(
null, enclosingType, node.name), null); | 1036 AuxiliaryElements auxiliaryElements = new AuxiliaryElements(_lookUpGetter(
null, enclosingType, node.name), null); |
| 1037 node.auxiliaryElements = auxiliaryElements; | 1037 node.auxiliaryElements = auxiliaryElements; |
| 1038 } | 1038 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1081 List<ParameterElement> parameters = _resolveArgumentsToFunction(isInConstCon
structor, argumentList, element); | 1081 List<ParameterElement> parameters = _resolveArgumentsToFunction(isInConstCon
structor, argumentList, element); |
| 1082 if (parameters != null) { | 1082 if (parameters != null) { |
| 1083 argumentList.correspondingStaticParameters = parameters; | 1083 argumentList.correspondingStaticParameters = parameters; |
| 1084 } | 1084 } |
| 1085 return null; | 1085 return null; |
| 1086 } | 1086 } |
| 1087 | 1087 |
| 1088 @override | 1088 @override |
| 1089 Object visitSuperExpression(SuperExpression node) { | 1089 Object visitSuperExpression(SuperExpression node) { |
| 1090 if (!_isSuperInValidContext(node)) { | 1090 if (!_isSuperInValidContext(node)) { |
| 1091 _resolver.reportErrorForNode(CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT
, node, []); | 1091 _resolver.reportErrorForNode(CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT
, node); |
| 1092 } | 1092 } |
| 1093 return super.visitSuperExpression(node); | 1093 return super.visitSuperExpression(node); |
| 1094 } | 1094 } |
| 1095 | 1095 |
| 1096 @override | 1096 @override |
| 1097 Object visitTypeParameter(TypeParameter node) { | 1097 Object visitTypeParameter(TypeParameter node) { |
| 1098 _setMetadata(node.element, node); | 1098 _setMetadata(node.element, node); |
| 1099 return null; | 1099 return null; |
| 1100 } | 1100 } |
| 1101 | 1101 |
| (...skipping 1009 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2111 _resolveAnnotationElementGetter(annotation, getter); | 2111 _resolveAnnotationElementGetter(annotation, getter); |
| 2112 return; | 2112 return; |
| 2113 } | 2113 } |
| 2114 // prefix.Class.constructor(args) | 2114 // prefix.Class.constructor(args) |
| 2115 constructor = new InterfaceTypeImpl.con1(classElement).lookUpConstructor
(name3, _definingLibrary); | 2115 constructor = new InterfaceTypeImpl.con1(classElement).lookUpConstructor
(name3, _definingLibrary); |
| 2116 nameNode3.staticElement = constructor; | 2116 nameNode3.staticElement = constructor; |
| 2117 } | 2117 } |
| 2118 } | 2118 } |
| 2119 // we need constructor | 2119 // we need constructor |
| 2120 if (constructor == null) { | 2120 if (constructor == null) { |
| 2121 _resolver.reportErrorForNode(CompileTimeErrorCode.INVALID_ANNOTATION, anno
tation, []); | 2121 _resolver.reportErrorForNode(CompileTimeErrorCode.INVALID_ANNOTATION, anno
tation); |
| 2122 return; | 2122 return; |
| 2123 } | 2123 } |
| 2124 // record element | 2124 // record element |
| 2125 annotation.element = constructor; | 2125 annotation.element = constructor; |
| 2126 // resolve arguments | 2126 // resolve arguments |
| 2127 _resolveAnnotationConstructorInvocationArguments(annotation, constructor); | 2127 _resolveAnnotationConstructorInvocationArguments(annotation, constructor); |
| 2128 } | 2128 } |
| 2129 | 2129 |
| 2130 void _resolveAnnotationElementGetter(Annotation annotation, PropertyAccessorEl
ement accessorElement) { | 2130 void _resolveAnnotationElementGetter(Annotation annotation, PropertyAccessorEl
ement accessorElement) { |
| 2131 // accessor should be synthetic | 2131 // accessor should be synthetic |
| 2132 if (!accessorElement.isSynthetic) { | 2132 if (!accessorElement.isSynthetic) { |
| 2133 _resolver.reportErrorForNode(CompileTimeErrorCode.INVALID_ANNOTATION, anno
tation, []); | 2133 _resolver.reportErrorForNode(CompileTimeErrorCode.INVALID_ANNOTATION, anno
tation); |
| 2134 return; | 2134 return; |
| 2135 } | 2135 } |
| 2136 // variable should be constant | 2136 // variable should be constant |
| 2137 VariableElement variableElement = accessorElement.variable; | 2137 VariableElement variableElement = accessorElement.variable; |
| 2138 if (!variableElement.isConst) { | 2138 if (!variableElement.isConst) { |
| 2139 _resolver.reportErrorForNode(CompileTimeErrorCode.INVALID_ANNOTATION, anno
tation, []); | 2139 _resolver.reportErrorForNode(CompileTimeErrorCode.INVALID_ANNOTATION, anno
tation); |
| 2140 } | 2140 } |
| 2141 // OK | 2141 // OK |
| 2142 return; | 2142 return; |
| 2143 } | 2143 } |
| 2144 | 2144 |
| 2145 /** | 2145 /** |
| 2146 * Given a list of arguments and the element that will be invoked using those
argument, compute | 2146 * Given a list of arguments and the element that will be invoked using those
argument, compute |
| 2147 * the list of parameters that correspond to the list of arguments. Return the
parameters that | 2147 * the list of parameters that correspond to the list of arguments. Return the
parameters that |
| 2148 * correspond to the arguments, or `null` if no correspondence could be comput
ed. | 2148 * correspond to the arguments, or `null` if no correspondence could be comput
ed. |
| 2149 * | 2149 * |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2645 @override | 2645 @override |
| 2646 Element get propagatedElement => null; | 2646 Element get propagatedElement => null; |
| 2647 | 2647 |
| 2648 @override | 2648 @override |
| 2649 Element get staticElement => null; | 2649 Element get staticElement => null; |
| 2650 | 2650 |
| 2651 @override | 2651 @override |
| 2652 void visitChildren(AstVisitor visitor) { | 2652 void visitChildren(AstVisitor visitor) { |
| 2653 } | 2653 } |
| 2654 } | 2654 } |
| OLD | NEW |