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

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

Issue 10583036: More support of library privacy for analyzer (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Commented out an offending test Created 8 years, 6 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
« no previous file with comments | « no previous file | compiler/java/com/google/dart/compiler/resolver/ResolverErrorCode.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/Resolver.java
diff --git a/compiler/java/com/google/dart/compiler/resolver/Resolver.java b/compiler/java/com/google/dart/compiler/resolver/Resolver.java
index 2cf871c3a6dfe46429419bb9d0f9838c49c3744f..1c9192eccce50f33697e097d33a4c0acae6552f8 100644
--- a/compiler/java/com/google/dart/compiler/resolver/Resolver.java
+++ b/compiler/java/com/google/dart/compiler/resolver/Resolver.java
@@ -1053,12 +1053,18 @@ public class Resolver {
onError(x, ResolverErrorCode.ILLEGAL_FIELD_ACCESS_FROM_STATIC,
name);
}
+ if (isIllegalPrivateAccess(x, enclosingElement, element, x.getName())) {
+ return null;
+ }
break;
case METHOD:
if (inStaticContext(currentMethod) && !inStaticContext(element)) {
onError(x, ResolverErrorCode.ILLEGAL_METHOD_ACCESS_FROM_STATIC,
name);
}
+ if (isIllegalPrivateAccess(x, enclosingElement, element, x.getName())) {
+ return null;
+ }
break;
case CLASS:
if (!isQualifier) {
@@ -1117,6 +1123,10 @@ public class Resolver {
case CLASS:
// Must be a static field.
element = Elements.findElement(((ClassElement) qualifier), x.getPropertyName());
+ if (isIllegalPrivateAccess(x.getName(), qualifier, element, x.getPropertyName())) {
+ // break;
+ return null;
+ }
switch (ElementKind.of(element)) {
case FIELD:
FieldElement field = (FieldElement) element;
@@ -1157,6 +1167,9 @@ public class Resolver {
break;
case SUPER:
+ if (isIllegalPrivateAccess(x.getName(), qualifier, element, x.getPropertyName())) {
+ return null;
+ }
ClassElement cls = ((SuperElement) qualifier).getClassElement();
Member member = cls.getType().lookupMember(x.getPropertyName());
if (member != null) {
@@ -1221,6 +1234,24 @@ public class Resolver {
return recordElement(x, element);
}
+ private boolean isIllegalPrivateAccess(DartNode diagnosticNode, Element qualifier,
+ Element element, String name) {
+ if (DartIdentifier.isPrivateName(name)) {
+ if (element == null) {
+ element = getContext().getScope().findElement(null, name);
+ }
+ if (element != null) {
+ Element enclosingLibrary = Elements.getLibraryElement(enclosingElement);
+ Element identifierEnclosingLibrary = Elements.getLibraryElement(element);
+ if (!enclosingLibrary.equals(identifierEnclosingLibrary)) {
+ onError(diagnosticNode, ResolverErrorCode.ILLEGAL_ACCESS_TO_PRIVATE, name);
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
private Element resolveQualifier(DartNode qualifier) {
return (qualifier instanceof DartIdentifier)
? resolveIdentifier((DartIdentifier) qualifier, true)
@@ -1243,6 +1274,11 @@ public class Resolver {
}
if (element == null || !element.getModifiers().isStatic()) {
diagnoseErrorInMethodInvocation(x, classElement, element);
+ } else {
+ if (isIllegalPrivateAccess(x.getFunctionName(), target, element,
+ x.getFunctionNameString())) {
+ break;
+ }
}
break;
}
@@ -1353,6 +1389,18 @@ public class Resolver {
element = new SyntheticDefaultConstructorElement(null, classElement, typeProvider);
}
break;
+ case CONSTRUCTOR:
+ if (enclosingElement != null) {
+ Element enclosingLibrary = Elements.getLibraryElement(enclosingElement);
+ Element constructorEnclosingLibrary = Elements.getLibraryElement(element);
+ if (element != null && DartIdentifier.isPrivateName(element.getName())
+ && !enclosingLibrary.equals(constructorEnclosingLibrary)) {
+ onError(x.getConstructor(), ResolverErrorCode.ILLEGAL_ACCESS_TO_PRIVATE,
+ element.getName());
+ return null;
+ }
+ }
+ break;
case TYPE_VARIABLE:
onError(x.getConstructor(), ResolverErrorCode.NEW_EXPRESSION_CANT_USE_TYPE_VAR);
return null;
« no previous file with comments | « no previous file | compiler/java/com/google/dart/compiler/resolver/ResolverErrorCode.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698