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 7325b798ef5a4758ac8ad5b36c8c21a4c180d192..da7c156d409a7a0eefc44b7248c0d3cfd242e13b 100644 |
--- a/compiler/java/com/google/dart/compiler/resolver/Elements.java |
+++ b/compiler/java/com/google/dart/compiler/resolver/Elements.java |
@@ -36,6 +36,7 @@ import com.google.dart.compiler.type.InterfaceType; |
import com.google.dart.compiler.type.Type; |
import com.google.dart.compiler.type.TypeVariable; |
import com.google.dart.compiler.util.Paths; |
+import com.google.dart.compiler.util.apache.StringUtils; |
import java.io.File; |
import java.net.URI; |
@@ -605,6 +606,29 @@ static FieldElementImplementation fieldFromNode(DartField node, |
} |
return false; |
} |
+ |
+ /** |
+ * @return the {@link LibraryElement} which declares given {@link Element}. |
+ */ |
+ public static LibraryElement getDeclaringLibrary(Element element) { |
+ while (element != null) { |
+ if (element instanceof LibraryElement) { |
+ return (LibraryElement) element; |
+ } |
+ element = element.getEnclosingElement(); |
+ } |
+ return null; |
+ } |
+ |
+ /** |
+ * @return <code>true</code> if "element" is accessible in "scopeLibrary". |
+ */ |
+ public static boolean isAccessible(LibraryElement scopeLibrary, Element element) { |
+ if (element != null && StringUtils.startsWith(element.getName(), "_")) { |
+ return Objects.equal(scopeLibrary, getDeclaringLibrary(element)); |
+ } |
+ return true; |
+ } |
/** |
* Looks to see if the property access requires a getter. |