Chromium Code Reviews| Index: editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/verifier/ConstantVerifier.java |
| diff --git a/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/verifier/ConstantVerifier.java b/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/verifier/ConstantVerifier.java |
| index cb1127f6ca90647bd32804ac535ffefcbcff4e5e..48d07e64625618d65329ca204d7011927497b8a4 100644 |
| --- a/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/verifier/ConstantVerifier.java |
| +++ b/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/verifier/ConstantVerifier.java |
| @@ -30,6 +30,8 @@ import com.google.dart.engine.ast.MapLiteralEntry; |
| import com.google.dart.engine.ast.MethodDeclaration; |
| import com.google.dart.engine.ast.NamedExpression; |
| import com.google.dart.engine.ast.NodeList; |
| +import com.google.dart.engine.ast.PrefixedIdentifier; |
| +import com.google.dart.engine.ast.PropertyAccess; |
| import com.google.dart.engine.ast.RedirectingConstructorInvocation; |
| import com.google.dart.engine.ast.SimpleIdentifier; |
| import com.google.dart.engine.ast.SuperConstructorInvocation; |
| @@ -74,6 +76,24 @@ import java.util.HashSet; |
| */ |
| public class ConstantVerifier extends RecursiveAstVisitor<Void> { |
| /** |
| + * Given some {@link Expression} return {@true} if it is a reference into a deferred library. |
| + * <p> |
| + * Do we have some place to more static AstNode utilities such as this method? |
| + * |
| + * @param expression some {@link Expression} |
| + * @return return {@true} if the expression is a reference into a deferred library |
| + */ |
| + private static boolean isDeferredLibraryReference(Expression expression) { |
|
Brian Wilkerson
2014/04/29 23:01:52
Does this method need to handle nested references,
jwren
2014/04/30 22:42:14
No.
Support and tests have now been added.
On 20
|
| + if (expression instanceof PropertyAccess) { |
| + PropertyAccess propertyAccess = (PropertyAccess) expression; |
| + return isDeferredLibraryReference(propertyAccess.getRealTarget()); |
| + } else if (expression instanceof PrefixedIdentifier) { |
| + return ((PrefixedIdentifier) expression).isDeferred(); |
| + } |
| + return false; |
| + } |
| + |
| + /** |
| * The error reporter by which errors will be reported. |
| */ |
| private ErrorReporter errorReporter; |
| @@ -126,13 +146,17 @@ public class ConstantVerifier extends RecursiveAstVisitor<Void> { |
| ConstructorElement constructorElement = (ConstructorElement) element; |
| // should 'const' constructor |
| if (!constructorElement.isConst()) { |
| - errorReporter.reportErrorForNode(CompileTimeErrorCode.NON_CONSTANT_ANNOTATION_CONSTRUCTOR, node); |
| + errorReporter.reportErrorForNode( |
| + CompileTimeErrorCode.NON_CONSTANT_ANNOTATION_CONSTRUCTOR, |
| + node); |
| return null; |
| } |
| // should have arguments |
| ArgumentList argumentList = node.getArguments(); |
| if (argumentList == null) { |
| - errorReporter.reportErrorForNode(CompileTimeErrorCode.NO_ANNOTATION_CONSTRUCTOR_ARGUMENTS, node); |
| + errorReporter.reportErrorForNode( |
| + CompileTimeErrorCode.NO_ANNOTATION_CONSTRUCTOR_ARGUMENTS, |
| + node); |
| return null; |
| } |
| // arguments should be constants |
| @@ -249,6 +273,10 @@ public class ConstantVerifier extends RecursiveAstVisitor<Void> { |
| element.setEvaluationResult(result); |
| } else if (result instanceof ErrorResult) { |
| reportErrors(result, CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE); |
| + } else if (result instanceof ValidResult && isDeferredLibraryReference(initializer)) { |
| + errorReporter.reportErrorForNode( |
| + CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE_FROM_DEFERRED_LIBRARY, |
| + initializer); |
| } |
| } |
| return null; |
| @@ -331,6 +359,11 @@ public class ConstantVerifier extends RecursiveAstVisitor<Void> { |
| CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE); |
| VariableElementImpl element = (VariableElementImpl) parameter.getElement(); |
| element.setEvaluationResult(result); |
| + if (result instanceof ValidResult && isDeferredLibraryReference(defaultValue)) { |
| + errorReporter.reportErrorForNode( |
| + CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE_FROM_DEFERRED_LIBRARY, |
| + defaultValue); |
| + } |
| } |
| } |
| } |