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..5b683f7e70b163820264a4aabb3cb9b1e4289428 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 |
| @@ -387,6 +387,7 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> { |
| } |
| } |
| checkForFinalNotInitialized(node); |
| + checkForInstanceStaticMembers(); |
| return super.visitClassDeclaration(node); |
| } finally { |
| initialFieldElementsMap = null; |
| @@ -636,12 +637,12 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> { |
| try { |
| enclosingFunction = node.getElement(); |
| SimpleIdentifier identifier = node.getName(); |
| - String methoName = ""; |
| + String methodName = ""; |
| if (identifier != null) { |
| - methoName = identifier.getName(); |
| + methodName = identifier.getName(); |
| } |
| if (node.isSetter() || node.isGetter()) { |
| - checkForMismatchedAccessorTypes(node, methoName); |
| + checkForMismatchedAccessorTypes(node, methodName); |
| checkForConflictingInstanceGetterAndSuperclassMember(node); |
| } |
| if (node.isGetter()) { |
| @@ -2695,6 +2696,61 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> { |
| } |
| /** |
| + * This verifies that the enclosing class does not have an instance member with the given name of |
| + * the static member. |
| + * |
| + * @param staticMember the static member to check conflict for |
| + * @return {@code true} if and only if an error code is generated on the passed node |
| + * @see CompileTimeErrorCode#INSTANCE_STATIC_MEMBER |
| + */ |
| + private boolean checkForInstanceStaticMember(ExecutableElement staticMember) { |
| + // prepare name |
| + String name = staticMember.getName(); |
| + if (name == null) { |
| + return false; |
| + } |
| + // try to find member |
| + ExecutableElement inheritedMember = inheritanceManager.lookupInheritance(enclosingClass, name); |
| + if (inheritedMember == null) { |
| + return false; |
| + } |
| + // OK, also static |
| + if (inheritedMember.isStatic()) { |
| + return false; |
| + } |
| + // report problem |
| + errorReporter.reportError( |
| + CompileTimeErrorCode.INSTANCE_STATIC_MEMBER, |
| + staticMember.getNameOffset(), |
| + name.length(), |
| + enclosingClass.getName(), |
| + name); |
| + return true; |
| + } |
| + |
| + /** |
| + * This verifies that the enclosing class does not have an instance member with the given name of |
| + * the static member. |
| + * |
| + * @return {@code true} if and only if an error code is generated on the passed node |
| + * @see CompileTimeErrorCode#INSTANCE_STATIC_MEMBER |
| + */ |
| + private boolean checkForInstanceStaticMembers() { |
|
Brian Wilkerson
2013/06/24 14:06:11
Do we need to do the inverse: check for instance m
scheglov
2013/06/24 17:35:48
I'm not sure what do you mean under "overridden st
|
| + boolean hasProblem = false; |
| + for (MethodElement method : enclosingClass.getMethods()) { |
| + if (method.isStatic()) { |
| + hasProblem |= checkForInstanceStaticMember(method); |
| + } |
| + } |
| + for (PropertyAccessorElement accessor : enclosingClass.getAccessors()) { |
| + if (accessor.isStatic()) { |
| + hasProblem |= checkForInstanceStaticMember(accessor); |
| + } |
| + } |
| + return hasProblem; |
| + } |
| + |
| + /** |
| * Given an assignment using a compound assignment operator, this verifies that the given |
| * assignment is valid. |
| * |
| @@ -3584,7 +3640,7 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> { |
| /** |
| * This checks if the passed constructor declaration has redirected constructor and references |
| - * itself directly or indirectly. TODO(scheglov) |
| + * itself directly or indirectly. |
| * |
| * @param node the constructor declaration to evaluate |
| * @return {@code true} if and only if an error code is generated on the passed node |