| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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.Sets; | 8 import com.google.common.collect.Sets; |
| 9 import com.google.dart.compiler.DartCompilationPhase; | 9 import com.google.dart.compiler.DartCompilationPhase; |
| 10 import com.google.dart.compiler.DartCompilerContext; | 10 import com.google.dart.compiler.DartCompilerContext; |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 } | 413 } |
| 414 | 414 |
| 415 @Override | 415 @Override |
| 416 public Element visitVariableStatement(DartVariableStatement node) { | 416 public Element visitVariableStatement(DartVariableStatement node) { |
| 417 resolveVariableStatement(node, false); | 417 resolveVariableStatement(node, false); |
| 418 return null; | 418 return null; |
| 419 } | 419 } |
| 420 | 420 |
| 421 private void resolveVariableStatement(DartVariableStatement node, | 421 private void resolveVariableStatement(DartVariableStatement node, |
| 422 boolean isImplicitlyInitialized) { | 422 boolean isImplicitlyInitialized) { |
| 423 Type type = resolveType(node.getTypeNode(), inStaticContext(currentMethod
)); | 423 Type type = |
| 424 resolveType( |
| 425 node.getTypeNode(), |
| 426 inStaticContext(currentMethod), |
| 427 TypeErrorCode.NO_SUCH_TYPE); |
| 424 for (DartVariable variable : node.getVariables()) { | 428 for (DartVariable variable : node.getVariables()) { |
| 425 Elements.setType(resolveVariable(variable, node.getModifiers()), type); | 429 Elements.setType(resolveVariable(variable, node.getModifiers()), type); |
| 426 checkVariableStatement(node, variable, isImplicitlyInitialized); | 430 checkVariableStatement(node, variable, isImplicitlyInitialized); |
| 427 } | 431 } |
| 428 } | 432 } |
| 429 | 433 |
| 430 @Override | 434 @Override |
| 431 public Element visitLabel(DartLabel x) { | 435 public Element visitLabel(DartLabel x) { |
| 432 LabelElement previousLabel = currentLabel; | 436 LabelElement previousLabel = currentLabel; |
| 433 currentLabel = Elements.labelElement(x, x.getName(), innermostFunction); | 437 currentLabel = Elements.labelElement(x, x.getName(), innermostFunction); |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 } | 699 } |
| 696 | 700 |
| 697 // If we we haven't resolved the identifier, it will be normalized to | 701 // If we we haven't resolved the identifier, it will be normalized to |
| 698 // this.<identifier>. | 702 // this.<identifier>. |
| 699 | 703 |
| 700 return recordElement(x, element); | 704 return recordElement(x, element); |
| 701 } | 705 } |
| 702 | 706 |
| 703 @Override | 707 @Override |
| 704 public Element visitTypeNode(DartTypeNode x) { | 708 public Element visitTypeNode(DartTypeNode x) { |
| 705 return resolveType(x, inStaticContext(currentMethod)).getElement(); | 709 return resolveType(x, inStaticContext(currentMethod), ResolverErrorCode.NO
_SUCH_TYPE).getElement(); |
| 706 } | 710 } |
| 707 | 711 |
| 708 @Override | 712 @Override |
| 709 public Element visitPropertyAccess(DartPropertyAccess x) { | 713 public Element visitPropertyAccess(DartPropertyAccess x) { |
| 710 Element qualifier = resolveQualifier(x.getQualifier()); | 714 Element qualifier = resolveQualifier(x.getQualifier()); |
| 711 Element element = null; | 715 Element element = null; |
| 712 switch (ElementKind.of(qualifier)) { | 716 switch (ElementKind.of(qualifier)) { |
| 713 case CLASS: | 717 case CLASS: |
| 714 // Must be a static field. | 718 // Must be a static field. |
| 715 element = Elements.findElement(((ClassElement) qualifier), x.getProper
tyName()); | 719 element = Elements.findElement(((ClassElement) qualifier), x.getProper
tyName()); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 876 | 880 |
| 877 if (x.isConst()) { | 881 if (x.isConst()) { |
| 878 for (DartExpression arg : x.getArgs()) { | 882 for (DartExpression arg : x.getArgs()) { |
| 879 checkConstantExpression(arg); | 883 checkConstantExpression(arg); |
| 880 } | 884 } |
| 881 } | 885 } |
| 882 | 886 |
| 883 Element element = x.getConstructor().accept(getContext().new Selector() { | 887 Element element = x.getConstructor().accept(getContext().new Selector() { |
| 884 // Only 'new' expressions can have a type in a property access. | 888 // Only 'new' expressions can have a type in a property access. |
| 885 @Override public Element visitTypeNode(DartTypeNode type) { | 889 @Override public Element visitTypeNode(DartTypeNode type) { |
| 886 return recordType(type, resolveType(type, inStaticContext(currentMetho
d))); | 890 return recordType( |
| 891 type, |
| 892 resolveType(type, inStaticContext(currentMethod), ResolverErrorCod
e.NO_SUCH_TYPE)); |
| 887 } | 893 } |
| 888 | 894 |
| 889 @Override public Element visitPropertyAccess(DartPropertyAccess node) { | 895 @Override public Element visitPropertyAccess(DartPropertyAccess node) { |
| 890 Element element = node.getQualifier().accept(this); | 896 Element element = node.getQualifier().accept(this); |
| 891 if (ElementKind.of(element).equals(ElementKind.CLASS)) { | 897 if (ElementKind.of(element).equals(ElementKind.CLASS)) { |
| 892 return Elements.lookupConstructor(((ClassElement) element), node.get
PropertyName()); | 898 return Elements.lookupConstructor(((ClassElement) element), node.get
PropertyName()); |
| 893 } else { | 899 } else { |
| 894 return null; | 900 return null; |
| 895 } | 901 } |
| 896 } | 902 } |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1187 } | 1193 } |
| 1188 break; | 1194 break; |
| 1189 } | 1195 } |
| 1190 } | 1196 } |
| 1191 return null; | 1197 return null; |
| 1192 } | 1198 } |
| 1193 | 1199 |
| 1194 @Override | 1200 @Override |
| 1195 public Element visitMapLiteral(DartMapLiteral node) { | 1201 public Element visitMapLiteral(DartMapLiteral node) { |
| 1196 List<DartTypeNode> typeArgs = node.getTypeArguments(); | 1202 List<DartTypeNode> typeArgs = node.getTypeArguments(); |
| 1197 InterfaceType type = topLevelContext.instantiateParameterizedType( | 1203 InterfaceType type = |
| 1198 defaultLiteralMapType.getElement(), node, typeArgs, inStaticContext(curr
entMethod)); | 1204 topLevelContext.instantiateParameterizedType( |
| 1205 defaultLiteralMapType.getElement(), |
| 1206 node, |
| 1207 typeArgs, |
| 1208 inStaticContext(currentMethod), |
| 1209 ResolverErrorCode.NO_SUCH_TYPE); |
| 1199 // instantiateParametersType() will complain for wrong number of parameter
s (!=2) | 1210 // instantiateParametersType() will complain for wrong number of parameter
s (!=2) |
| 1200 recordType(node, type); | 1211 recordType(node, type); |
| 1201 visit(node.getEntries()); | 1212 visit(node.getEntries()); |
| 1202 return null; | 1213 return null; |
| 1203 } | 1214 } |
| 1204 | 1215 |
| 1205 @Override | 1216 @Override |
| 1206 public Element visitArrayLiteral(DartArrayLiteral node) { | 1217 public Element visitArrayLiteral(DartArrayLiteral node) { |
| 1207 List<DartTypeNode> typeArgs = node.getTypeArguments(); | 1218 List<DartTypeNode> typeArgs = node.getTypeArguments(); |
| 1208 InterfaceType type = topLevelContext.instantiateParameterizedType(rawArray
Type.getElement(), | 1219 InterfaceType type = |
| 1209 node, typeArgs, inStaticContext(currentMethod)); | 1220 topLevelContext.instantiateParameterizedType( |
| 1221 rawArrayType.getElement(), |
| 1222 node, |
| 1223 typeArgs, |
| 1224 inStaticContext(currentMethod), |
| 1225 ResolverErrorCode.NO_SUCH_TYPE); |
| 1210 // instantiateParametersType() will complain for wrong number of parameter
s (!=1) | 1226 // instantiateParametersType() will complain for wrong number of parameter
s (!=1) |
| 1211 recordType(node, type); | 1227 recordType(node, type); |
| 1212 visit(node.getExpressions()); | 1228 visit(node.getExpressions()); |
| 1213 return null; | 1229 return null; |
| 1214 } | 1230 } |
| 1215 | 1231 |
| 1216 private ConstructorElement checkIsConstructor(DartNewExpression source, Elem
ent element) { | 1232 private ConstructorElement checkIsConstructor(DartNewExpression source, Elem
ent element) { |
| 1217 if (!ElementKind.of(element).equals(ElementKind.CONSTRUCTOR)) { | 1233 if (!ElementKind.of(element).equals(ElementKind.CONSTRUCTOR)) { |
| 1218 if (!context.shouldWarnOnNoSuchType()) { | 1234 if (!context.shouldWarnOnNoSuchType()) { |
| 1219 onError(source.getConstructor(), ResolverErrorCode.NEW_EXPRESSION_NOT_
CONSTRUCTOR); | 1235 onError(source.getConstructor(), ResolverErrorCode.NEW_EXPRESSION_NOT_
CONSTRUCTOR); |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1392 ClassElement nextClass = (ClassElement) nextConstructorElement.getEnclos
ingElement(); | 1408 ClassElement nextClass = (ClassElement) nextConstructorElement.getEnclos
ingElement(); |
| 1393 ClassElement currentClass = (ClassElement) constructor.getEnclosingEleme
nt(); | 1409 ClassElement currentClass = (ClassElement) constructor.getEnclosingEleme
nt(); |
| 1394 if (nextClass.getName().equals(currentClass.getName())) { | 1410 if (nextClass.getName().equals(currentClass.getName())) { |
| 1395 return nextConstructorElement; | 1411 return nextConstructorElement; |
| 1396 } | 1412 } |
| 1397 } | 1413 } |
| 1398 } | 1414 } |
| 1399 return null; | 1415 return null; |
| 1400 } | 1416 } |
| 1401 } | 1417 } |
| OLD | NEW |