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

Unified Diff: compiler/java/com/google/dart/compiler/resolver/Elements.java

Issue 11410076: Issue 6711. Fix for NPE in resolver. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month 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
« no previous file with comments | « no previous file | compiler/java/com/google/dart/compiler/resolver/Resolver.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiler/java/com/google/dart/compiler/resolver/Elements.java
diff --git a/compiler/java/com/google/dart/compiler/resolver/Elements.java b/compiler/java/com/google/dart/compiler/resolver/Elements.java
index 06a2078c5b3bec7ff30ee5329f87ef4e607cad48..5fadc578d3218d1d457df7b0012f2b4d76d0b144 100644
--- a/compiler/java/com/google/dart/compiler/resolver/Elements.java
+++ b/compiler/java/com/google/dart/compiler/resolver/Elements.java
@@ -92,13 +92,26 @@ public class Elements {
}
public static LibraryElement getLibraryElement(Element element) {
- do {
- if (ElementKind.of(element).equals(ElementKind.LIBRARY)) {
- break;
+ while (element != null) {
+ if (ElementKind.of(element) == ElementKind.LIBRARY) {
+ return (LibraryElement) element;
}
- element = element.getEnclosingElement();
- } while (element != null && element.getEnclosingElement() != element);
- return (LibraryElement) element;
+ EnclosingElement enclosingElement = element.getEnclosingElement();
+ if (enclosingElement == element) {
+ return null;
+ }
+ element = enclosingElement;
+ };
+ return null;
+ }
+
+ /**
+ * @return <code>true</code> if "a" and "b" are declared in the same {@link LibraryElement}.
+ */
+ public static boolean areSameLibrary(Element a, Element b) {
+ LibraryElement aLibrary = getLibraryElement(a);
+ LibraryElement bLibrary = getLibraryElement(b);
+ return Objects.equal(aLibrary, bLibrary);
}
@VisibleForTesting
« no previous file with comments | « no previous file | compiler/java/com/google/dart/compiler/resolver/Resolver.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698