Chromium Code Reviews| Index: editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/verifier/ErrorVerifier.java |
| diff --git a/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/verifier/ErrorVerifier.java b/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/verifier/ErrorVerifier.java |
| index 0bc7718b4cdad3d59b5b8251b830ab37c9e4e765..43b2e7bd246816b78a83565fb998c4da0078fa34 100644 |
| --- a/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/verifier/ErrorVerifier.java |
| +++ b/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/verifier/ErrorVerifier.java |
| @@ -24,6 +24,7 @@ import com.google.dart.engine.ast.CatchClause; |
| import com.google.dart.engine.ast.ClassDeclaration; |
| import com.google.dart.engine.ast.ClassMember; |
| import com.google.dart.engine.ast.ClassTypeAlias; |
| +import com.google.dart.engine.ast.CommentReference; |
| import com.google.dart.engine.ast.CompilationUnit; |
| import com.google.dart.engine.ast.ConditionalExpression; |
| import com.google.dart.engine.ast.ConstructorDeclaration; |
| @@ -230,6 +231,11 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> { |
| private boolean isInConstructorInitializer; |
| /** |
| + * This is set to {@code true} iff the visitor is currently visiting a static method. |
| + */ |
| + private boolean isInStaticMethod; |
| + |
| + /** |
| * This is set to {@code true} iff the visitor is currently visiting code in the SDK. |
| */ |
| private boolean isInSystemLibrary; |
| @@ -634,6 +640,7 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> { |
| public Void visitMethodDeclaration(MethodDeclaration node) { |
| ExecutableElement previousFunction = enclosingFunction; |
| try { |
| + isInStaticMethod = node.isStatic(); |
| enclosingFunction = node.getElement(); |
| SimpleIdentifier identifier = node.getName(); |
| String methoName = ""; |
| @@ -660,6 +667,7 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> { |
| return super.visitMethodDeclaration(node); |
| } finally { |
| enclosingFunction = previousFunction; |
| + isInStaticMethod = false; |
| } |
| } |
| @@ -2516,9 +2524,10 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> { |
| * @param node the simple identifier to test |
| * @return {@code true} if and only if an error code is generated on the passed node |
| * @see CompileTimeErrorCode#IMPLICIT_THIS_REFERENCE_IN_INITIALIZER |
| + * @see CompileTimeErrorCode#INSTANCE_MEMBER_ACCESS_FROM_STATIC TODO(scheglov) rename thid method |
| */ |
| private boolean checkForImplicitThisReferenceInInitializer(SimpleIdentifier node) { |
| - if (!isInConstructorInitializer) { |
| + if (!isInConstructorInitializer && !isInStaticMethod) { |
|
Brian Wilkerson
2013/06/24 15:14:49
What about references in a static field initialize
scheglov
2013/06/24 16:21:29
I will add TODO.
|
| return false; |
| } |
| // prepare element |
| @@ -2536,8 +2545,12 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> { |
| if (!(enclosingElement instanceof ClassElement)) { |
| return false; |
| } |
| - // qualified method invocation |
| + // comment |
| ASTNode parent = node.getParent(); |
| + if (parent instanceof CommentReference) { |
| + return false; |
| + } |
| + // qualified method invocation |
| if (parent instanceof MethodInvocation) { |
| MethodInvocation invocation = (MethodInvocation) parent; |
| if (invocation.getMethodName() == node && invocation.getRealTarget() != null) { |
| @@ -2560,7 +2573,11 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> { |
| } |
| } |
| // report problem |
| - errorReporter.reportError(CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER, node); |
| + if (isInConstructorInitializer) { |
| + errorReporter.reportError(CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER, node); |
| + } else if (isInStaticMethod) { |
| + errorReporter.reportError(CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_STATIC, node); |
| + } |
| return true; |
| } |