OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 package com.google.dart.compiler.resolver; | 5 package com.google.dart.compiler.resolver; |
6 | 6 |
7 import com.google.common.annotations.VisibleForTesting; | 7 import com.google.common.annotations.VisibleForTesting; |
8 import com.google.common.collect.Lists; | 8 import com.google.common.collect.Lists; |
9 import com.google.common.collect.Sets; | 9 import com.google.common.collect.Sets; |
10 import com.google.dart.compiler.DartCompilationPhase; | 10 import com.google.dart.compiler.DartCompilationPhase; |
(...skipping 1113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1124 element = scope.findElement(scope.getLibrary(), x.getPropertyName()); | 1124 element = scope.findElement(scope.getLibrary(), x.getPropertyName()); |
1125 if (element == null) { | 1125 if (element == null) { |
1126 onError(x, ResolverErrorCode.CANNOT_BE_RESOLVED_LIBRARY, | 1126 onError(x, ResolverErrorCode.CANNOT_BE_RESOLVED_LIBRARY, |
1127 x.getPropertyName(), qualifier.getName()); | 1127 x.getPropertyName(), qualifier.getName()); |
1128 } | 1128 } |
1129 break; | 1129 break; |
1130 | 1130 |
1131 default: | 1131 default: |
1132 break; | 1132 break; |
1133 } | 1133 } |
| 1134 if (x.getName() != null) { |
| 1135 recordElement(x.getName(), element); |
| 1136 } |
1134 return recordElement(x, element); | 1137 return recordElement(x, element); |
1135 } | 1138 } |
1136 | 1139 |
1137 private Element resolveQualifier(DartNode qualifier) { | 1140 private Element resolveQualifier(DartNode qualifier) { |
1138 return (qualifier instanceof DartIdentifier) | 1141 return (qualifier instanceof DartIdentifier) |
1139 ? resolveIdentifier((DartIdentifier) qualifier, true) | 1142 ? resolveIdentifier((DartIdentifier) qualifier, true) |
1140 : qualifier.accept(this); | 1143 : qualifier.accept(this); |
1141 } | 1144 } |
1142 | 1145 |
1143 @Override | 1146 @Override |
1144 public Element visitMethodInvocation(DartMethodInvocation x) { | 1147 public Element visitMethodInvocation(DartMethodInvocation x) { |
1145 Element target = resolveQualifier(x.getTarget()); | 1148 Element target = resolveQualifier(x.getTarget()); |
1146 Element element = null; | 1149 Element element = null; |
1147 | 1150 |
1148 switch (ElementKind.of(target)) { | 1151 switch (ElementKind.of(target)) { |
1149 case CLASS: { | 1152 case CLASS: { |
1150 // Must be a static method or field. | 1153 // Must be a static method or field. |
1151 ClassElement classElement = (ClassElement) target; | 1154 ClassElement classElement = (ClassElement) target; |
1152 element = Elements.lookupLocalMethod(classElement, x.getFunctionNameSt
ring()); | 1155 element = Elements.lookupLocalMethod(classElement, x.getFunctionNameSt
ring()); |
1153 if (element == null) { | 1156 if (element == null) { |
1154 element = Elements.lookupLocalField(classElement, x.getFunctionNameS
tring()); | 1157 element = Elements.lookupLocalField(classElement, x.getFunctionNameS
tring()); |
1155 } | 1158 } |
1156 if (element == null || !element.getModifiers().isStatic()) { | 1159 if (element == null || !element.getModifiers().isStatic()) { |
1157 diagnoseErrorInMethodInvocation(x, (ClassElement) target, element); | 1160 diagnoseErrorInMethodInvocation(x, classElement, element); |
1158 } | 1161 } |
1159 break; | 1162 break; |
1160 } | 1163 } |
1161 | 1164 |
1162 case SUPER: { | 1165 case SUPER: { |
1163 // Must be a superclass' method or field. | 1166 // Must be a superclass' method or field. |
1164 ClassElement classElement = ((SuperElement) target).getClassElement(); | 1167 ClassElement classElement = ((SuperElement) target).getClassElement(); |
1165 InterfaceType type = classElement.getType(); | 1168 InterfaceType type = classElement.getType(); |
1166 Member member = type.lookupMember(x.getFunctionNameString()); | 1169 Member member = type.lookupMember(x.getFunctionNameString()); |
1167 if (member != null) { | 1170 if (member != null) { |
1168 if (!member.getElement().getModifiers().isStatic()) { | 1171 if (!member.getElement().getModifiers().isStatic()) { |
1169 element = member.getElement(); | 1172 element = member.getElement(); |
1170 } | 1173 } |
1171 } | 1174 } |
1172 break; | 1175 break; |
1173 } | 1176 } |
1174 | 1177 |
1175 case LIBRARY: | 1178 case LIBRARY: |
1176 // Library prefix, lookup the element in the reference library. | 1179 // Library prefix, lookup the element in the reference library. |
1177 LibraryElement library = ((LibraryElement) target); | 1180 LibraryElement library = ((LibraryElement) target); |
1178 element = library.getScope().findElement(context.getScope().getLibrary
(), | 1181 element = library.getScope().findElement(context.getScope().getLibrary
(), |
1179 x.getFunctionNameString()); | 1182 x.getFunctionNameString()); |
1180 if (element == null) { | 1183 if (element == null) { |
1181 diagnoseErrorInMethodInvocation(x, null, null); | 1184 diagnoseErrorInMethodInvocation(x, library, null); |
1182 } else { | 1185 } else { |
1183 x.getFunctionName().setElement(element); | 1186 x.getFunctionName().setElement(element); |
1184 } | 1187 } |
1185 break; | 1188 break; |
1186 } | 1189 } |
1187 | 1190 |
1188 checkInvocationTarget(x, currentMethod, target); | 1191 checkInvocationTarget(x, currentMethod, target); |
1189 visit(x.getArguments()); | 1192 visit(x.getArguments()); |
1190 return recordElement(x, element); | 1193 return recordElement(x, element); |
1191 } | 1194 } |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1377 onError(x.getLabel(), ResolverErrorCode.CANNOT_RESOLVE_LABEL, | 1380 onError(x.getLabel(), ResolverErrorCode.CANNOT_RESOLVE_LABEL, |
1378 x.getTargetName()); | 1381 x.getTargetName()); |
1379 } else if (ElementKind.of(element).equals(ElementKind.LABEL)) { | 1382 } else if (ElementKind.of(element).equals(ElementKind.LABEL)) { |
1380 onError(x.getLabel(), ResolverErrorCode.CANNOT_ACCESS_OUTER_LABEL, | 1383 onError(x.getLabel(), ResolverErrorCode.CANNOT_ACCESS_OUTER_LABEL, |
1381 x.getTargetName()); | 1384 x.getTargetName()); |
1382 } else { | 1385 } else { |
1383 onError(x.getLabel(), ResolverErrorCode.NOT_A_LABEL, x.getTargetName()); | 1386 onError(x.getLabel(), ResolverErrorCode.NOT_A_LABEL, x.getTargetName()); |
1384 } | 1387 } |
1385 } | 1388 } |
1386 | 1389 |
1387 private void diagnoseErrorInMethodInvocation(DartMethodInvocation node, Clas
sElement klass, | 1390 private void diagnoseErrorInMethodInvocation(DartMethodInvocation node, Elem
ent classOrLibrary, |
1388 Element element) { | 1391 Element element) { |
1389 String name = node.getFunctionNameString(); | 1392 String name = node.getFunctionNameString(); |
1390 ElementKind kind = ElementKind.of(element); | 1393 ElementKind kind = ElementKind.of(element); |
1391 DartNode errorNode = node.getFunctionName(); | 1394 DartNode errorNode = node.getFunctionName(); |
1392 switch (kind) { | 1395 switch (kind) { |
1393 case NONE: | 1396 case NONE: |
1394 onError(errorNode, ResolverErrorCode.CANNOT_RESOLVE_METHOD, name); | 1397 switch (ElementKind.of(classOrLibrary)) { |
| 1398 case CLASS: |
| 1399 onError(errorNode, ResolverErrorCode.CANNOT_RESOLVE_METHOD_IN_CLAS
S, name, |
| 1400 classOrLibrary.getName()); |
| 1401 break; |
| 1402 case LIBRARY: |
| 1403 onError(errorNode, ResolverErrorCode.CANNOT_RESOLVE_METHOD_IN_LIBR
ARY, name, |
| 1404 classOrLibrary.getName()); |
| 1405 break; |
| 1406 default: |
| 1407 onError(errorNode, ResolverErrorCode.CANNOT_RESOLVE_METHOD, name); |
| 1408 } |
| 1409 |
1395 break; | 1410 break; |
1396 | 1411 |
1397 case CONSTRUCTOR: | 1412 case CONSTRUCTOR: |
1398 onError(errorNode, ResolverErrorCode.IS_A_CONSTRUCTOR, klass.getName()
, | 1413 onError(errorNode, ResolverErrorCode.IS_A_CONSTRUCTOR, classOrLibrary.
getName(), |
1399 name); | 1414 name); |
1400 break; | 1415 break; |
1401 | 1416 |
1402 case METHOD: { | 1417 case METHOD: { |
1403 assert !((MethodElement) element).getModifiers().isStatic(); | 1418 assert !((MethodElement) element).getModifiers().isStatic(); |
1404 onError(errorNode, ResolverErrorCode.IS_AN_INSTANCE_METHOD, | 1419 onError(errorNode, ResolverErrorCode.IS_AN_INSTANCE_METHOD, |
1405 klass.getName(), name); | 1420 classOrLibrary.getName(), name); |
1406 break; | 1421 break; |
1407 } | 1422 } |
1408 | 1423 |
1409 default: | 1424 default: |
1410 throw context.internalError(errorNode, "Unexpected kind of element: %s
", kind); | 1425 throw context.internalError(errorNode, "Unexpected kind of element: %s
", kind); |
1411 } | 1426 } |
1412 } | 1427 } |
1413 | 1428 |
1414 private void diagnoseErrorInUnqualifiedInvocation(DartUnqualifiedInvocation
node) { | 1429 private void diagnoseErrorInUnqualifiedInvocation(DartUnqualifiedInvocation
node) { |
1415 String name = node.getTarget().getName(); | 1430 String name = node.getTarget().getName(); |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1868 ClassElement nextClass = (ClassElement) nextConstructorElement.getEnclos
ingElement(); | 1883 ClassElement nextClass = (ClassElement) nextConstructorElement.getEnclos
ingElement(); |
1869 ClassElement currentClass = (ClassElement) constructor.getEnclosingEleme
nt(); | 1884 ClassElement currentClass = (ClassElement) constructor.getEnclosingEleme
nt(); |
1870 if (nextClass == currentClass) { | 1885 if (nextClass == currentClass) { |
1871 return (ConstructorNodeElement) nextConstructorElement; | 1886 return (ConstructorNodeElement) nextConstructorElement; |
1872 } | 1887 } |
1873 } | 1888 } |
1874 } | 1889 } |
1875 return null; | 1890 return null; |
1876 } | 1891 } |
1877 } | 1892 } |
OLD | NEW |