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

Unified Diff: editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/scope/EnclosedScope.java

Issue 22846005: Report StaticWarningCode.UNDEFINED_IDENTIFIER when name is hidden, but not defined yet in block. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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/scope/EnclosedScope.java
diff --git a/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/scope/EnclosedScope.java b/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/scope/EnclosedScope.java
index 1824161621361266572b9a33b98f8749a0e21ee7..449c83b13c3a841047a45900a4ee0e55e5c8523f 100644
--- a/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/scope/EnclosedScope.java
+++ b/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/scope/EnclosedScope.java
@@ -18,6 +18,9 @@ import com.google.dart.engine.element.Element;
import com.google.dart.engine.element.LibraryElement;
import com.google.dart.engine.error.AnalysisErrorListener;
+import java.util.HashSet;
+import java.util.Set;
+
/**
* Instances of the class {@code EnclosedScope} implement a scope that is lexically enclosed in
* another scope.
@@ -31,6 +34,13 @@ public class EnclosedScope extends Scope {
private Scope enclosingScope;
/**
+ * A set of names that will be defined in this scope, but right now are not defined. However
+ * according to the scoping rules these names are hidden, even if they were defined in an outer
+ * scope.
+ */
+ private Set<String> hiddenNames = new HashSet<String>();
+
+ /**
* Initialize a newly created scope enclosed within another scope.
*
* @param enclosingScope the scope in which this scope is lexically enclosed
@@ -50,6 +60,21 @@ public class EnclosedScope extends Scope {
}
/**
+ * Hides the name of the given element in this scope. If there is already an element with the
+ * given name defined in an outer scope, then it will become unavailable.
+ *
+ * @param element the element to be hidden in this scope
+ */
+ public void hide(Element element) {
+ if (element != null) {
+ String name = element.getName();
+ if (name != null && !name.isEmpty()) {
+ hiddenNames.add(name);
+ }
+ }
+ }
+
+ /**
* Return the scope in which this scope is lexically enclosed.
*
* @return the scope in which this scope is lexically enclosed
@@ -64,6 +89,9 @@ public class EnclosedScope extends Scope {
if (element != null) {
return element;
}
+ if (hiddenNames.contains(name)) {
+ return null;
+ }
return enclosingScope.lookup(identifier, name, referencingLibrary);
}
}

Powered by Google App Engine
This is Rietveld 408576698