--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java Tue Mar 15 13:48:30 2016 -0700
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java Thu Mar 17 19:04:28 2016 +0000
@@ -93,10 +93,13 @@
JCDiagnostic.Factory diags;
public final boolean allowMethodHandles;
public final boolean allowFunctionalInterfaceMostSpecific;
+ public final boolean allowModules;
public final boolean checkVarargsAccessAfterResolution;
private final boolean compactMethodDiags;
final EnumSet<VerboseResolutionMode> verboseResolutionMode;
+ private final boolean checkModuleAccess;
+
WriteableScope polymorphicSignatureScope;
protected Resolve(Context context) {
@@ -130,6 +133,12 @@
polymorphicSignatureScope = WriteableScope.create(syms.noSymbol);
inapplicableMethodException = new InapplicableMethodException(diags);
+
+ allowModules = source.allowModules();
+
+ // The following is required, for now, to support building
+ // Swing beaninfo via javadoc.
+ checkModuleAccess = !options.isSet("noModules");
}
/** error symbols, which are returned when resolution fails
@@ -309,8 +318,19 @@
env.toplevel.packge == c.packge();
break;
default: // error recovery
+ isAccessible = true;
+ break;
case PUBLIC:
isAccessible = true;
+ if (allowModules && checkModuleAccess) {
+ ModuleSymbol currModule = env.toplevel.modle;
+ currModule.complete();
+ PackageSymbol p = c.packge();
+ isAccessible =
+ (currModule == p.modle) || currModule.visiblePackages.get(p.fullname) == p || p == syms.rootPackage;
+ } else {
+ isAccessible = true;
+ }
break;
case PROTECTED:
isAccessible =
@@ -1947,16 +1967,27 @@
*/
Symbol loadClass(Env<AttrContext> env, Name name) {
try {
- ClassSymbol c = finder.loadClass(name);
+ ClassSymbol c = finder.loadClass(env.toplevel.modle, name);
return isAccessible(env, c) ? c : new AccessError(c);
} catch (ClassFinder.BadClassFile err) {
throw err;
} catch (CompletionFailure ex) {
+ //even if a class cannot be found in the current module and packages in modules it depends on that
+ //are exported for any or this module, the class may exist internally in some of these modules,
+ //or may exist in a module on which this module does not depend. Provide better diagnostic in
+ //such cases by looking for the class in any module:
+ for (ModuleSymbol ms : syms.getAllModules()) {
+ //do not load currently unloaded classes, to avoid too eager completion of random things in other modules:
+ ClassSymbol clazz = syms.getClass(ms, name);
+
+ if (clazz != null) {
+ return new AccessError(clazz);
+ }
+ }
return typeNotFound;
}
}
-
/**
* Find a type declared in a scope (not inherited). Return null
* if none is found.
@@ -2157,7 +2188,7 @@
}
if (kind.contains(KindSelector.PCK))
- return syms.enterPackage(name);
+ return syms.lookupPackage(env.toplevel.modle, name);
else return bestSoFar;
}
@@ -2173,7 +2204,7 @@
Symbol bestSoFar = typeNotFound;
PackageSymbol pack = null;
if (kind.contains(KindSelector.PCK)) {
- pack = syms.enterPackage(fullname);
+ pack = syms.lookupPackage(env.toplevel.modle, fullname);
if (pack.exists()) return pack;
}
if (kind.contains(KindSelector.TYP)) {
@@ -3920,9 +3951,15 @@
else if ((sym.flags() & PUBLIC) != 0
|| (env != null && this.site != null
&& !isAccessible(env, this.site))) {
- return diags.create(dkind, log.currentSource(),
- pos, "not.def.access.class.intf.cant.access",
- sym, sym.location());
+ if (sym.owner.kind == PCK) {
+ return diags.create(dkind, log.currentSource(),
+ pos, "not.def.access.package.cant.access",
+ sym, sym.location());
+ } else {
+ return diags.create(dkind, log.currentSource(),
+ pos, "not.def.access.class.intf.cant.access",
+ sym, sym.location());
+ }
}
else if ((sym.flags() & (PRIVATE | PROTECTED)) != 0) {
return diags.create(dkind, log.currentSource(),
@@ -3935,6 +3972,18 @@
pos, "not.def.public.cant.access", sym, sym.location());
}
}
+
+ private String toString(Type type) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(type);
+ if (type != null) {
+ sb.append("[tsym:").append(type.tsym);
+ if (type.tsym != null)
+ sb.append("packge:").append(type.tsym.packge());
+ sb.append("]");
+ }
+ return sb.toString();
+ }
}
/**