| 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.base.Objects; | 8 import com.google.common.base.Objects; |
| 9 import com.google.dart.compiler.DartCompilerContext; | 9 import com.google.dart.compiler.DartCompilerContext; |
| 10 import com.google.dart.compiler.ErrorCode; | 10 import com.google.dart.compiler.ErrorCode; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 | 82 |
| 83 @Override | 83 @Override |
| 84 boolean isStaticContext() { | 84 boolean isStaticContext() { |
| 85 return isStatic; | 85 return isStatic; |
| 86 } | 86 } |
| 87 | 87 |
| 88 @Override | 88 @Override |
| 89 boolean isFactoryContext() { | 89 boolean isFactoryContext() { |
| 90 return isFactory; | 90 return isFactory; |
| 91 } | 91 } |
| 92 | 92 |
| 93 @Override | 93 @Override |
| 94 protected EnclosingElement getEnclosingElement() { | 94 protected EnclosingElement getEnclosingElement() { |
| 95 return enclosingElement; | 95 return enclosingElement; |
| 96 } | 96 } |
| 97 | 97 |
| 98 @Override | 98 @Override |
| 99 public Element visitClass(DartClass node) { | 99 public Element visitClass(DartClass node) { |
| 100 assert !ElementKind.of(currentHolder).equals(ElementKind.CLASS) : "nested
class?"; | 100 assert !ElementKind.of(currentHolder).equals(ElementKind.CLASS) : "nested
class?"; |
| 101 beginClassContext(node); | 101 beginClassContext(node); |
| 102 EnclosingElement previousEnclosingElement = enclosingElement; | 102 EnclosingElement previousEnclosingElement = enclosingElement; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 ResolutionContext previous = context; | 212 ResolutionContext previous = context; |
| 213 context = context.extend(element.getName()); | 213 context = context.extend(element.getName()); |
| 214 EnclosingElement previousEnclosingElement = enclosingElement; | 214 EnclosingElement previousEnclosingElement = enclosingElement; |
| 215 enclosingElement = element; | 215 enclosingElement = element; |
| 216 resolveFunction(method.getFunction(), element); | 216 resolveFunction(method.getFunction(), element); |
| 217 enclosingElement = previousEnclosingElement; | 217 enclosingElement = previousEnclosingElement; |
| 218 context = previous; | 218 context = previous; |
| 219 } | 219 } |
| 220 return null; | 220 return null; |
| 221 } | 221 } |
| 222 | 222 |
| 223 @Override | 223 @Override |
| 224 protected void resolveFunctionWithParameters(DartFunction node, MethodElemen
t element) { | 224 protected void resolveFunctionWithParameters(DartFunction node, MethodElemen
t element) { |
| 225 super.resolveFunctionWithParameters(node, element); | 225 super.resolveFunctionWithParameters(node, element); |
| 226 // Bind "formal initializers" to fields. | 226 // Bind "formal initializers" to fields. |
| 227 if (node.getParent() instanceof DartMethodDefinition) { | 227 if (node.getParent() instanceof DartMethodDefinition) { |
| 228 DartMethodDefinition method = (DartMethodDefinition) node.getParent(); | 228 DartMethodDefinition method = (DartMethodDefinition) node.getParent(); |
| 229 for (DartParameter parameter : node.getParameters()) { | 229 for (DartParameter parameter : node.getParameters()) { |
| 230 if (parameter.getQualifier() instanceof DartThisExpression) { | 230 if (parameter.getQualifier() instanceof DartThisExpression) { |
| 231 checkParameterInitializer(method, parameter); | 231 checkParameterInitializer(method, parameter); |
| 232 } | 232 } |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 if (modifiers.isStatic()) { | 572 if (modifiers.isStatic()) { |
| 573 resolutionError(method.getName(), ResolverErrorCode.FACTORY_CANNOT_BE_
STATIC); | 573 resolutionError(method.getName(), ResolverErrorCode.FACTORY_CANNOT_BE_
STATIC); |
| 574 } | 574 } |
| 575 if (modifiers.isAbstract()) { | 575 if (modifiers.isAbstract()) { |
| 576 resolutionError(method.getName(), ResolverErrorCode.FACTORY_CANNOT_BE_
ABSTRACT); | 576 resolutionError(method.getName(), ResolverErrorCode.FACTORY_CANNOT_BE_
ABSTRACT); |
| 577 } | 577 } |
| 578 | 578 |
| 579 if (modifiers.isConstant()) { | 579 if (modifiers.isConstant()) { |
| 580 // Allow const factory ... native ... ; type of constructors, used in
core libraries | 580 // Allow const factory ... native ... ; type of constructors, used in
core libraries |
| 581 DartBlock dartBlock = method.getFunction().getBody(); | 581 DartBlock dartBlock = method.getFunction().getBody(); |
| 582 if (dartBlock == null || !(dartBlock instanceof DartNativeBlock)) { | 582 if (dartBlock == null || !(dartBlock instanceof DartNativeBlock)) { |
| 583 resolutionError(method.getName(), ResolverErrorCode.FACTORY_CANNOT_B
E_CONST); | 583 resolutionError(method.getName(), ResolverErrorCode.FACTORY_CANNOT_B
E_CONST); |
| 584 } | 584 } |
| 585 } | 585 } |
| 586 } | 586 } |
| 587 // TODO(ngeoffray): Add more checks on the modifiers. For | 587 // TODO(ngeoffray): Add more checks on the modifiers. For |
| 588 // example const and missing body. | 588 // example const and missing body. |
| 589 } | 589 } |
| 590 | 590 |
| 591 private void checkConstructor(MethodElement element, DartMethodDefinition me
thod) { | 591 private void checkConstructor(MethodElement element, DartMethodDefinition me
thod) { |
| 592 if (Elements.isNonFactoryConstructor(element) && method.getFunction() != n
ull | 592 if (Elements.isNonFactoryConstructor(element) && method.getFunction() != n
ull |
| 593 && method.getFunction().getReturnTypeNode() != null) { | 593 && method.getFunction().getReturnTypeNode() != null) { |
| 594 resolutionError(method, ResolverErrorCode.CONSTRUCTOR_CANNOT_HAVE_RETURN
_TYPE); | 594 resolutionError(method.getFunction().getReturnTypeNode(), |
| 595 ResolverErrorCode.CONSTRUCTOR_CANNOT_HAVE_RETURN_TYPE); |
| 595 } | 596 } |
| 596 } | 597 } |
| 597 | 598 |
| 598 private void checkUniqueName(EnclosingElement holder, Element e) { | 599 private void checkUniqueName(EnclosingElement holder, Element e) { |
| 599 Element other = lookupElementByName(holder, e.getName(), e.getModifiers())
; | 600 Element other = lookupElementByName(holder, e.getName(), e.getModifiers())
; |
| 600 assert e != other : "forgot to call checkUniqueName() before adding to the
class?"; | 601 assert e != other : "forgot to call checkUniqueName() before adding to the
class?"; |
| 601 if (other != null) { | 602 if (other != null) { |
| 602 ElementKind eKind = ElementKind.of(e); | 603 ElementKind eKind = ElementKind.of(e); |
| 603 ElementKind oKind = ElementKind.of(other); | 604 ElementKind oKind = ElementKind.of(other); |
| 604 | 605 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 */ | 664 */ |
| 664 private void reportDuplicateDeclaration(ErrorCode errorCode, Element element
) { | 665 private void reportDuplicateDeclaration(ErrorCode errorCode, Element element
) { |
| 665 String name = | 666 String name = |
| 666 element instanceof MethodElement | 667 element instanceof MethodElement |
| 667 ? Elements.getRawMethodName((MethodElement) element) | 668 ? Elements.getRawMethodName((MethodElement) element) |
| 668 : element.getName(); | 669 : element.getName(); |
| 669 resolutionError(element.getNameLocation(), errorCode, name); | 670 resolutionError(element.getNameLocation(), errorCode, name); |
| 670 } | 671 } |
| 671 } | 672 } |
| 672 } | 673 } |
| OLD | NEW |