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

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

Issue 47543010: Issue 14580. Fix for Source in which problem is reported. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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/Scope.java
diff --git a/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/scope/Scope.java b/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/scope/Scope.java
index c0e3f97bf8eaff3450f59368734f478188e0de40..e98cee187119d476cd415520ae9bce585d052718 100644
--- a/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/scope/Scope.java
+++ b/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/scope/Scope.java
@@ -13,7 +13,10 @@
*/
package com.google.dart.engine.internal.scope;
+import com.google.dart.engine.ast.ASTNode;
+import com.google.dart.engine.ast.CompilationUnit;
import com.google.dart.engine.ast.Identifier;
+import com.google.dart.engine.element.CompilationUnitElement;
import com.google.dart.engine.element.Element;
import com.google.dart.engine.element.LibraryElement;
import com.google.dart.engine.element.MethodElement;
@@ -123,13 +126,6 @@ public abstract class Scope {
}
/**
- * Return the element representing the library in which this scope is enclosed.
- *
- * @return the element representing the library in which this scope is enclosed
- */
- protected abstract LibraryElement getDefiningLibrary();
-
- /**
* Return the error code to be used when reporting that a name being defined locally conflicts
* with another element of the same name in the local scope.
*
@@ -142,9 +138,6 @@ public abstract class Scope {
// the same name.
// TODO(jwren) There are 4 error codes for duplicate, but only 1 is being generated.
Source source = duplicate.getSource();
- if (source == null) {
- source = getSource();
- }
return new AnalysisError(
source,
duplicate.getNameOffset(),
@@ -161,13 +154,24 @@ public abstract class Scope {
protected abstract AnalysisErrorListener getErrorListener();
/**
- * Return the source object representing the compilation unit with which errors related to this
- * scope should be associated.
+ * Return the source that contains the given identifier, or the source associated with this scope
+ * if the source containing the identifier could not be determined.
*
- * @return the source object with which errors should be associated
- */
- protected Source getSource() {
- return getDefiningLibrary().getDefiningCompilationUnit().getSource();
+ * @param identifier the identifier whose source is to be returned
+ * @return the source that contains the given identifier
+ */
+ protected final Source getSource(ASTNode node) {
+ CompilationUnit unit = node.getAncestor(CompilationUnit.class);
+ if (unit != null) {
+ CompilationUnitElement element = unit.getElement();
+ if (element != null) {
+ Source source = element.getSource();
+ if (source != null) {
Brian Wilkerson 2013/10/29 20:52:00 Not sure why we're testing this, since the "else"
+ return source;
+ }
+ }
+ }
+ return null;
}
/**

Powered by Google App Engine
This is Rietveld 408576698