Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1243)

Unified Diff: editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/verifier/ErrorVerifier.java

Issue 14704011: Report CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 fd7ad6e3b7bf2b2150a60c9d9b37a6df8a6e2fbf..5357e9a377c1ec21157369058839a94af124abf3 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
@@ -255,6 +255,7 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
checkForBuiltInIdentifierAsName(
node.getName(),
CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_NAME);
+ checkForMemberWithClassName();
// initialize initialFieldElementsMap
ClassElement classElement = node.getElement();
if (classElement != null) {
@@ -1414,6 +1415,37 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
}
/**
+ * This verifies that the {@link #enclosingClass} does not define members with the same name as
+ * the enclosing class.
+ *
+ * @return {@code true} if and only if an error code is generated on the passed node
+ * @see CompileTimeErrorCode#MEMBER_WITH_CLASS_NAME
+ */
+ private boolean checkForMemberWithClassName() {
+ if (enclosingClass == null) {
+ return false;
+ }
+ String className = enclosingClass.getName();
+ if (className == null) {
+ return false;
+ }
+ boolean problemReported = false;
+ // check accessors
+ for (PropertyAccessorElement accessor : enclosingClass.getAccessors()) {
+ if (className.equals(accessor.getName())) {
+ errorReporter.reportError(
+ CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME,
+ accessor.getNameOffset(),
+ className.length());
+ problemReported = true;
+ }
+ }
+ // don't check methods, they would be constructors
+ // done
+ return problemReported;
+ }
+
+ /**
* Checks to ensure that native function bodies can only in SDK code.
*
* @param node the native function body to test

Powered by Google App Engine
This is Rietveld 408576698