8154956: Module system implementation refresh (4/2016)

Co-authored-by: Jan Lahoda <jan.lahoda@oracle.com>
Reviewed-by: jjg, mchung, alanb
This commit is contained in:
Jonathan Gibbons 2016-05-03 09:11:12 +01:00 committed by Alan Bateman
parent 8c52468e73
commit 64261477b1
33 changed files with 328 additions and 298 deletions

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -48,6 +48,13 @@ import com.sun.tools.javac.util.DefinedBy;
import com.sun.tools.javac.util.DefinedBy.Api; import com.sun.tools.javac.util.DefinedBy.Api;
import com.sun.tools.javac.util.Log; import com.sun.tools.javac.util.Log;
/*
* This code must be run in a context that provides
* access to the following javac internal packages:
* com.sun.tools.javac.api
* com.sun.tools.javac.tree
* com.sun.tools.javac.util
*/
public class CodingRulesAnalyzerPlugin implements Plugin { public class CodingRulesAnalyzerPlugin implements Plugin {
protected Log log; protected Log log;
@ -55,11 +62,6 @@ public class CodingRulesAnalyzerPlugin implements Plugin {
@DefinedBy(Api.COMPILER_TREE) @DefinedBy(Api.COMPILER_TREE)
public void init(JavacTask task, String... args) { public void init(JavacTask task, String... args) {
addExports("jdk.compiler",
"com.sun.tools.javac.api",
"com.sun.tools.javac.code",
"com.sun.tools.javac.tree",
"com.sun.tools.javac.util");
BasicJavacTask impl = (BasicJavacTask)task; BasicJavacTask impl = (BasicJavacTask)task;
Context context = impl.getContext(); Context context = impl.getContext();
log = Log.instance(context); log = Log.instance(context);

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,8 +25,10 @@ package crules;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import com.sun.source.util.JavacTask; import com.sun.source.util.JavacTask;
import com.sun.source.util.TaskEvent.Kind; import com.sun.source.util.TaskEvent.Kind;
@ -48,16 +50,8 @@ public class MutableFieldsAnalyzer extends AbstractCodingRulesAnalyzer {
} }
private boolean ignoreField(String className, String field) { private boolean ignoreField(String className, String field) {
List<String> currentFieldsToIgnore = Set<String> fieldsToIgnore = classFieldsToIgnoreMap.get(className);
classFieldsToIgnoreMap.get(className); return (fieldsToIgnore) != null && fieldsToIgnore.contains(field);
if (currentFieldsToIgnore != null) {
for (String fieldToIgnore : currentFieldsToIgnore) {
if (field.equals(fieldToIgnore)) {
return true;
}
}
}
return false;
} }
class MutableFieldsVisitor extends TreeScanner { class MutableFieldsVisitor extends TreeScanner {
@ -89,34 +83,29 @@ public class MutableFieldsAnalyzer extends AbstractCodingRulesAnalyzer {
private static final String packageToCheck = "com.sun.tools.javac"; private static final String packageToCheck = "com.sun.tools.javac";
private static final Map<String, List<String>> classFieldsToIgnoreMap = private static final Map<String, Set<String>> classFieldsToIgnoreMap =
new HashMap<>(); new HashMap<>();
private static void ignoreFields(String className, String... fieldNames) {
classFieldsToIgnoreMap.put(className, new HashSet<>(Arrays.asList(fieldNames)));
};
static { static {
classFieldsToIgnoreMap. ignoreFields("com.sun.tools.javac.util.JCDiagnostic", "fragmentFormatter");
put("com.sun.tools.javac.util.JCDiagnostic", ignoreFields("com.sun.tools.javac.util.JavacMessages", "defaultBundle", "defaultMessages");
Arrays.asList("fragmentFormatter")); ignoreFields("com.sun.tools.javac.file.JRTIndex", "sharedInstance");
classFieldsToIgnoreMap. ignoreFields("com.sun.tools.javac.main.JavaCompiler", "versionRB");
put("com.sun.tools.javac.util.JavacMessages", ignoreFields("com.sun.tools.javac.code.Type", "moreInfo");
Arrays.asList("defaultBundle", "defaultMessages")); ignoreFields("com.sun.tools.javac.util.SharedNameTable", "freelist");
classFieldsToIgnoreMap. ignoreFields("com.sun.tools.javac.util.Log", "useRawMessages");
put("com.sun.tools.javac.file.ZipFileIndexCache", ignoreFields("com.sun.tools.javac.util.ModuleWrappers$ModuleFinderHelper",
Arrays.asList("sharedInstance")); "moduleFinderInterface", "ofMethod", "emptyMethod");
classFieldsToIgnoreMap. ignoreFields("com.sun.tools.javac.util.ModuleWrappers$ConfigurationHelper",
put("com.sun.tools.javac.file.JRTIndex", "configurationClass", "resolveRequiresAndUsesMethod");
Arrays.asList("sharedInstance")); ignoreFields("com.sun.tools.javac.util.ModuleWrappers$LayerHelper",
classFieldsToIgnoreMap. "layerClass", "bootMethod", "defineModulesWithOneLoaderMethod", "configurationMethod");
put("com.sun.tools.javac.main.JavaCompiler", ignoreFields("com.sun.tools.javac.util.ModuleHelper",
Arrays.asList("versionRB")); "addExportsMethod", "getUnnamedModuleMethod", "getModuleMethod");
classFieldsToIgnoreMap.
put("com.sun.tools.javac.code.Type",
Arrays.asList("moreInfo"));
classFieldsToIgnoreMap.
put("com.sun.tools.javac.util.SharedNameTable",
Arrays.asList("freelist"));
classFieldsToIgnoreMap.
put("com.sun.tools.javac.util.Log",
Arrays.asList("useRawMessages"));
} }
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -49,11 +49,21 @@ public interface Elements {
/** /**
* Returns a package given its fully qualified name. * Returns a package given its fully qualified name.
* *
* @param name fully qualified package name, or "" for an unnamed package * @param name fully qualified package name, or an empty string for an unnamed package
* @return the named package, or {@code null} if it cannot be found * @return the named package, or {@code null} if it cannot be found
*/ */
PackageElement getPackageElement(CharSequence name); PackageElement getPackageElement(CharSequence name);
/**
* Returns a package given its fully qualified name, as seen from the given module.
*
* @param name fully qualified package name, or an empty string for an unnamed package
* @param module module relative to which the lookup should happen
* @return the named package, or {@code null} if it cannot be found
* @since 9
*/
PackageElement getPackageElement(ModuleElement module, CharSequence name);
/** /**
* Returns a type element given its canonical name. * Returns a type element given its canonical name.
* *
@ -62,6 +72,16 @@ public interface Elements {
*/ */
TypeElement getTypeElement(CharSequence name); TypeElement getTypeElement(CharSequence name);
/**
* Returns a type element given its canonical name, as seen from the given module.
*
* @param name the canonical name
* @param module module relative to which the lookup should happen
* @return the named type element, or {@code null} if it cannot be found
* @since 9
*/
TypeElement getTypeElement(ModuleElement module, CharSequence name);
/** /**
* Returns a module element given its fully qualified name. * Returns a module element given its fully qualified name.
* *

View file

@ -960,12 +960,12 @@ public abstract class Symbol extends AnnoConstruct implements Element {
return n; return n;
} }
@Override @Override @DefinedBy(Api.LANGUAGE_MODEL)
public <R, P> R accept(ElementVisitor<R, P> v, P p) { public <R, P> R accept(ElementVisitor<R, P> v, P p) {
return v.visitModule(this, p); return v.visitModule(this, p);
} }
@Override @Override @DefinedBy(Api.LANGUAGE_MODEL)
public List<Symbol> getEnclosedElements() { public List<Symbol> getEnclosedElements() {
List<Symbol> list = List.nil(); List<Symbol> list = List.nil();
for (Symbol sym : enclosedPackages) { for (Symbol sym : enclosedPackages) {

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -1588,17 +1588,17 @@ public abstract class Type extends AnnoConstruct implements TypeMirror {
return v.visitModuleType(this, s); return v.visitModuleType(this, s);
} }
@Override @Override @DefinedBy(Api.LANGUAGE_MODEL)
public String toString() { public String toString() {
return tsym.getQualifiedName().toString(); return tsym.getQualifiedName().toString();
} }
@Override @Override @DefinedBy(Api.LANGUAGE_MODEL)
public TypeKind getKind() { public TypeKind getKind() {
return TypeKind.MODULE; return TypeKind.MODULE;
} }
@Override @Override @DefinedBy(Api.LANGUAGE_MODEL)
public <R, P> R accept(TypeVisitor<R, P> v, P p) { public <R, P> R accept(TypeVisitor<R, P> v, P p) {
return v.visitNoType(this, p); return v.visitNoType(this, p);
} }

View file

@ -131,6 +131,9 @@ public class Modules extends JCTree.Visitor {
private final String moduleOverride; private final String moduleOverride;
private final Name java_se;
private final Name java_;
ModuleSymbol defaultModule; ModuleSymbol defaultModule;
private final String addExportsOpt; private final String addExportsOpt;
@ -173,6 +176,9 @@ public class Modules extends JCTree.Visitor {
JNIWriter jniWriter = JNIWriter.instance(context); JNIWriter jniWriter = JNIWriter.instance(context);
jniWriter.multiModuleMode = multiModuleMode; jniWriter.multiModuleMode = multiModuleMode;
java_se = names.fromString("java.se");
java_ = names.fromString("java.");
addExportsOpt = options.get(Option.XADDEXPORTS); addExportsOpt = options.get(Option.XADDEXPORTS);
addReadsOpt = options.get(Option.XADDREADS); addReadsOpt = options.get(Option.XADDREADS);
addModsOpt = options.get(Option.ADDMODS); addModsOpt = options.get(Option.ADDMODS);
@ -761,17 +767,17 @@ public class Modules extends JCTree.Visitor {
private void checkForCorrectness() { private void checkForCorrectness() {
for (Directive.ProvidesDirective provides : allProvides) { for (Directive.ProvidesDirective provides : allProvides) {
JCProvides tree = directiveToTreeMap.get(provides); JCProvides tree = directiveToTreeMap.get(provides);
/** The implementation must be defined in the same module as the provides directive /* The implementation must be defined in the same module as the provides directive
* (else, error) * (else, error)
*/ */
PackageSymbol implementationDefiningPackage = provides.impl.packge(); PackageSymbol implementationDefiningPackage = provides.impl.packge();
if (implementationDefiningPackage.modle != msym) { if (implementationDefiningPackage.modle != msym) {
log.error(tree.pos(), Errors.ServiceImplementationNotInRightModule(implementationDefiningPackage.modle)); log.error(tree.pos(), Errors.ServiceImplementationNotInRightModule(implementationDefiningPackage.modle));
} }
/** There is no inherent requirement that module that provides a service should actually /* There is no inherent requirement that module that provides a service should actually
* use it itself. However, it is a pointless declaration if the service package is not * use it itself. However, it is a pointless declaration if the service package is not
* exported and there is no uses for the service. * exported and there is no uses for the service.
*/ */
PackageSymbol interfaceDeclaringPackage = provides.service.packge(); PackageSymbol interfaceDeclaringPackage = provides.service.packge();
boolean isInterfaceDeclaredInCurrentModule = interfaceDeclaringPackage.modle == msym; boolean isInterfaceDeclaredInCurrentModule = interfaceDeclaringPackage.modle == msym;
@ -826,8 +832,22 @@ public class Modules extends JCTree.Visitor {
Set<ModuleSymbol> enabledRoot = new LinkedHashSet<>(); Set<ModuleSymbol> enabledRoot = new LinkedHashSet<>();
if (rootModules.contains(syms.unnamedModule)) { if (rootModules.contains(syms.unnamedModule)) {
for (ModuleSymbol sym : syms.getAllModules()) { ModuleSymbol javaSE = syms.getModule(java_se);
if (systemModulePred.test(sym) && observablePred.test(sym)) { Predicate<ModuleSymbol> jdkModulePred;
if (javaSE != null && (observable == null || observable.contains(javaSE))) {
jdkModulePred = sym -> {
sym.complete();
return !sym.name.startsWith(java_)
&& sym.exports.stream().anyMatch(e -> e.modules == null);
};
enabledRoot.add(javaSE);
} else {
jdkModulePred = sym -> true;
}
for (ModuleSymbol sym : new HashSet<>(syms.getAllModules())) {
if (systemModulePred.test(sym) && observablePred.test(sym) && jdkModulePred.test(sym)) {
enabledRoot.add(sym); enabledRoot.add(sym);
} }
} }

View file

@ -74,6 +74,8 @@ import com.sun.tools.javac.code.Lint;
import com.sun.tools.javac.main.Option; import com.sun.tools.javac.main.Option;
import com.sun.tools.javac.resources.CompilerProperties.Errors; import com.sun.tools.javac.resources.CompilerProperties.Errors;
import com.sun.tools.javac.resources.CompilerProperties.Warnings; import com.sun.tools.javac.resources.CompilerProperties.Warnings;
import com.sun.tools.javac.util.DefinedBy;
import com.sun.tools.javac.util.DefinedBy.Api;
import com.sun.tools.javac.util.ListBuffer; import com.sun.tools.javac.util.ListBuffer;
import com.sun.tools.javac.util.Log; import com.sun.tools.javac.util.Log;
import com.sun.tools.javac.util.Pair; import com.sun.tools.javac.util.Pair;
@ -813,7 +815,7 @@ public class Locations {
* SYSTEM_MODULES and MODULE_PATH. * SYSTEM_MODULES and MODULE_PATH.
* *
* The Location can be specified to accept overriding classes from the * The Location can be specified to accept overriding classes from the
* -Xpatch:dir parameter. * {@code -Xpatch:<module>=<path> } parameter.
*/ */
private class ModuleLocationHandler extends LocationHandler implements Location { private class ModuleLocationHandler extends LocationHandler implements Location {
protected final String name; protected final String name;
@ -829,47 +831,27 @@ public class Locations {
this.searchPath = searchPath; this.searchPath = searchPath;
this.output = output; this.output = output;
if (allowOverrides) { if (allowOverrides && patchMap != null) {
if (patchMap != null) { SearchPath mPatch = patchMap.get(moduleName);
SearchPath mPatch = patchMap.get(moduleName); if (mPatch != null) {
if (mPatch != null) { SearchPath sp = new SearchPath();
SearchPath sp = new SearchPath(); sp.addAll(mPatch);
sp.addAll(mPatch); sp.addAll(searchPath);
sp.addAll(searchPath); searchPathWithOverrides = sp;
searchPathWithOverrides = sp;
} else {
searchPathWithOverrides = searchPath;
}
} else { } else {
// for old style patch option; retained for transition searchPathWithOverrides = searchPath;
Set<Path> overrides = new LinkedHashSet<>();
if (moduleOverrideSearchPath != null) {
for (Path p: moduleOverrideSearchPath) {
Path o = p.resolve(moduleName);
if (Files.isDirectory(o)) {
overrides.add(o);
}
}
}
if (!overrides.isEmpty()) {
overrides.addAll(searchPath);
searchPathWithOverrides = overrides;
} else {
searchPathWithOverrides = searchPath;
}
} }
} else { } else {
searchPathWithOverrides = searchPath; searchPathWithOverrides = searchPath;
} }
} }
@Override // defined by Location @Override @DefinedBy(Api.COMPILER)
public String getName() { public String getName() {
return name; return name;
} }
@Override // defined by Location @Override @DefinedBy(Api.COMPILER)
public boolean isOutputLocation() { public boolean isOutputLocation() {
return output; return output;
} }
@ -1522,41 +1504,33 @@ public class Locations {
} }
} }
private SearchPath moduleOverrideSearchPath; // for old style patch option; retained for transition
private Map<String, SearchPath> patchMap; private Map<String, SearchPath> patchMap;
boolean handleOption(Option option, String value) { boolean handleOption(Option option, String value) {
switch (option) { switch (option) {
case XPATCH: case XPATCH:
if (value.contains("=")) { Map<String, SearchPath> map = new LinkedHashMap<>();
Map<String, SearchPath> map = new LinkedHashMap<>(); int eq = value.indexOf('=');
for (String entry: value.split(",")) { if (eq > 0) {
int eq = entry.indexOf('='); String mName = value.substring(0, eq);
if (eq > 0) { SearchPath mPatchPath = new SearchPath()
String mName = entry.substring(0, eq); .addFiles(value.substring(eq + 1));
SearchPath mPatchPath = new SearchPath() boolean ok = true;
.addFiles(entry.substring(eq + 1)); for (Path p: mPatchPath) {
boolean ok = true; Path mi = p.resolve("module-info.class");
for (Path p: mPatchPath) { if (Files.exists(mi)) {
Path mi = p.resolve("module-info.class"); log.error(Errors.LocnModuleInfoNotAllowedOnPatchPath(mi));
if (Files.exists(mi)) { ok = false;
log.error(Errors.LocnModuleInfoNotAllowedOnPatchPath(mi));
ok = false;
}
}
if (ok && !mPatchPath.isEmpty()) {
map.computeIfAbsent(mName, (_x) -> new SearchPath())
.addAll(mPatchPath);
}
} else {
log.error(Errors.LocnInvalidArgForXpatch(entry));
} }
} }
patchMap = map; if (ok && !mPatchPath.isEmpty()) {
map.computeIfAbsent(mName, (_x) -> new SearchPath())
.addAll(mPatchPath);
}
} else { } else {
// for old style patch option; retained for transition log.error(Errors.LocnInvalidArgForXpatch(value));
moduleOverrideSearchPath = new SearchPath().addFiles(value);
} }
patchMap = map;
return true; return true;
default: default:
LocationHandler h = handlersForOption.get(option); LocationHandler h = handlersForOption.get(option);

View file

@ -199,7 +199,7 @@ public enum Option {
SYSTEM("-system", "opt.arg.jdk", "opt.system", STANDARD, FILEMANAGER), SYSTEM("-system", "opt.arg.jdk", "opt.system", STANDARD, FILEMANAGER),
XPATCH("-Xpatch:", "opt.arg.path", "opt.Xpatch", EXTENDED, FILEMANAGER), XPATCH("-Xpatch:", "opt.arg.patch", "opt.patch", EXTENDED, FILEMANAGER),
BOOTCLASSPATH("-bootclasspath", "opt.arg.path", "opt.bootclasspath", STANDARD, FILEMANAGER) { BOOTCLASSPATH("-bootclasspath", "opt.arg.path", "opt.bootclasspath", STANDARD, FILEMANAGER) {
@Override @Override
@ -529,83 +529,21 @@ public enum Option {
XADDEXPORTS("-XaddExports:", "opt.arg.addExports", "opt.addExports", EXTENDED, BASIC) { XADDEXPORTS("-XaddExports:", "opt.arg.addExports", "opt.addExports", EXTENDED, BASIC) {
@Override @Override
public boolean process(OptionHelper helper, String option) { public boolean process(OptionHelper helper, String option) {
if (option.matches(".*,.*=.*")) { // temporary, for backwards compatibility
return processOldStyle(helper, option);
}
String p = option.substring(option.indexOf(':') + 1).trim(); String p = option.substring(option.indexOf(':') + 1).trim();
String prev = helper.get(XADDEXPORTS); String prev = helper.get(XADDEXPORTS);
helper.put(XADDEXPORTS.text, (prev == null) ? p : prev + '\0' + p); helper.put(XADDEXPORTS.text, (prev == null) ? p : prev + '\0' + p);
return false; return false;
} }
// convert old style option into a series of new-style options
private boolean processOldStyle(OptionHelper helper, String option) {
String p = option.substring(option.indexOf(':') + 1).trim();
String[] entries = p.split("[ ,]+");
Map<String, String> map = new LinkedHashMap<>();
for (String e: entries) {
// Each entry is of the form module/package=target
// we must group values for the same module/package together
int eq = e.indexOf('=');
if (eq == -1) {
// don't bother with error message for backwards compatible support
continue;
}
String modPkg = e.substring(0, eq);
String target = e.substring(eq + 1);
String targets = map.get(modPkg);
map.put(modPkg, (targets == null) ? target : targets + "," + target);
}
boolean ok = true;
for (Map.Entry<String, String> e: map.entrySet()) {
// process as new-style options
String key = e.getKey();
String value = e.getValue();
ok = ok & process(helper, XADDEXPORTS.text + key + "=" + value);
};
return ok;
}
}, },
XADDREADS("-XaddReads:", "opt.arg.addReads", "opt.addReads", EXTENDED, BASIC) { XADDREADS("-XaddReads:", "opt.arg.addReads", "opt.addReads", EXTENDED, BASIC) {
@Override @Override
public boolean process(OptionHelper helper, String option) { public boolean process(OptionHelper helper, String option) {
if (option.matches(".*,.*=.*")) { // temporary, for backwards compatibility
return processOldStyle(helper, option);
}
String p = option.substring(option.indexOf(':') + 1).trim(); String p = option.substring(option.indexOf(':') + 1).trim();
String prev = helper.get(XADDREADS); String prev = helper.get(XADDREADS);
helper.put(XADDREADS.text, (prev == null) ? p : prev + '\0' + p); helper.put(XADDREADS.text, (prev == null) ? p : prev + '\0' + p);
return false; return false;
} }
// convert old style option into a series of new-style options
private boolean processOldStyle(OptionHelper helper, String option) {
String p = option.substring(option.indexOf(':') + 1).trim();
String[] entries = p.split("[ ,]+");
Map<String, String> map = new LinkedHashMap<>();
for (String e: entries) {
// Each entry is of the form module=target
// we must group values for the same module together
int eq = e.indexOf('=');
if (eq == -1) {
// don't bother with error message for backwards compatible support
continue;
}
String modPkg = e.substring(0, eq);
String target = e.substring(eq + 1);
String targets = map.get(modPkg);
map.put(modPkg, (targets == null) ? target : targets + "," + target);
}
boolean ok = true;
for (Map.Entry<String, String> e: map.entrySet()) {
// process as new-style options
String key = e.getKey();
String value = e.getValue();
ok = ok & process(helper, XADDEXPORTS.text + key + "=" + value);
};
return ok;
}
}, },
XMODULE("-Xmodule:", "opt.arg.module", "opt.module", EXTENDED, BASIC) { XMODULE("-Xmodule:", "opt.arg.module", "opt.module", EXTENDED, BASIC) {

View file

@ -107,12 +107,13 @@ public class JavacElements implements Elements {
return modules.getObservableModule(names.fromString(strName)); return modules.getObservableModule(names.fromString(strName));
} }
@DefinedBy(Api.LANGUAGE_MODEL) @Override @DefinedBy(Api.LANGUAGE_MODEL)
public PackageSymbol getPackageElement(CharSequence name) { public PackageSymbol getPackageElement(CharSequence name) {
ensureEntered("getPackageElement"); ensureEntered("getPackageElement");
return getPackageElement(modules.getDefaultModule(), name); return getPackageElement(modules.getDefaultModule(), name);
} }
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public PackageSymbol getPackageElement(ModuleElement module, CharSequence name) { public PackageSymbol getPackageElement(ModuleElement module, CharSequence name) {
String strName = name.toString(); String strName = name.toString();
if (strName.equals("")) if (strName.equals(""))
@ -122,12 +123,13 @@ public class JavacElements implements Elements {
: null; : null;
} }
@DefinedBy(Api.LANGUAGE_MODEL) @Override @DefinedBy(Api.LANGUAGE_MODEL)
public ClassSymbol getTypeElement(CharSequence name) { public ClassSymbol getTypeElement(CharSequence name) {
ensureEntered("getTypeElement"); ensureEntered("getTypeElement");
return getTypeElement(modules.getDefaultModule(), name); return getTypeElement(modules.getDefaultModule(), name);
} }
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public ClassSymbol getTypeElement(ModuleElement module, CharSequence name) { public ClassSymbol getTypeElement(ModuleElement module, CharSequence name) {
String strName = name.toString(); String strName = name.toString();
return SourceVersion.isName(strName) return SourceVersion.isName(strName)

View file

@ -53,12 +53,6 @@ javac.opt.system=\
Override location of system modules Override location of system modules
javac.opt.upgrademodulepath=\ javac.opt.upgrademodulepath=\
Override location of upgradeable modules Override location of upgradeable modules
javac.opt.Xbootclasspath.p=\
Prepend to the bootstrap class path
javac.opt.Xbootclasspath.a=\
Append to the bootstrap class path
javac.opt.Xpatch=\
Specify location of module class files to patch
javac.opt.endorseddirs=\ javac.opt.endorseddirs=\
Override location of endorsed standards path Override location of endorsed standards path
javac.opt.extdirs=\ javac.opt.extdirs=\
@ -160,6 +154,10 @@ javac.opt.arg.pathname=\
<pathname> <pathname>
javac.opt.arg.file=\ javac.opt.arg.file=\
<filename> <filename>
javac.opt.Xbootclasspath.p=\
Prepend to the bootstrap class path
javac.opt.Xbootclasspath.a=\
Append to the bootstrap class path
javac.opt.Xlint=\ javac.opt.Xlint=\
Enable recommended warnings Enable recommended warnings
javac.opt.Xlint.all=\ javac.opt.Xlint.all=\
@ -286,6 +284,11 @@ javac.opt.addReads=\n\
\ <other-module> may be ALL-UNNAMED to require the unnamed module. \ <other-module> may be ALL-UNNAMED to require the unnamed module.
javac.opt.arg.addReads=\ javac.opt.arg.addReads=\
<module>=<other-module>(,<other-module>)* <module>=<other-module>(,<other-module>)*
javac.opt.patch=\n\
\ Override or augment a module with classes and resources\n\
\ in JAR files or directories
javac.opt.arg.patch=\
<module>=<file>(:<file>)*
javac.opt.module=\ javac.opt.module=\
Specify a module to which the classes being compiled belong. Specify a module to which the classes being compiled belong.
javac.opt.arg.module=\ javac.opt.arg.module=\

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -2626,22 +2626,22 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
@Override @Override
public void accept(Visitor v) { v.visitModuleDef(this); } public void accept(Visitor v) { v.visitModuleDef(this); }
@Override @Override @DefinedBy(Api.COMPILER_TREE)
public Kind getKind() { public Kind getKind() {
return Kind.MODULE; return Kind.MODULE;
} }
// @Override @Override @DefinedBy(Api.COMPILER_TREE)
public JCExpression getName() { public JCExpression getName() {
return qualId; return qualId;
} }
@Override @Override @DefinedBy(Api.COMPILER_TREE)
public List<JCDirective> getDirectives() { public List<JCDirective> getDirectives() {
return directives; return directives;
} }
@Override @Override @DefinedBy(Api.COMPILER_TREE)
public <R, D> R accept(TreeVisitor<R, D> v, D d) { public <R, D> R accept(TreeVisitor<R, D> v, D d) {
return v.visitModule(this, d); return v.visitModule(this, d);
} }
@ -2666,22 +2666,22 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
@Override @Override
public void accept(Visitor v) { v.visitExports(this); } public void accept(Visitor v) { v.visitExports(this); }
@Override @Override @DefinedBy(Api.COMPILER_TREE)
public Kind getKind() { public Kind getKind() {
return Kind.EXPORTS; return Kind.EXPORTS;
} }
@Override @Override @DefinedBy(Api.COMPILER_TREE)
public JCExpression getExportName() { public JCExpression getExportName() {
return qualid; return qualid;
} }
@Override @Override @DefinedBy(Api.COMPILER_TREE)
public List<JCExpression> getModuleNames() { public List<JCExpression> getModuleNames() {
return moduleNames; return moduleNames;
} }
@Override @Override @DefinedBy(Api.COMPILER_TREE)
public <R, D> R accept(TreeVisitor<R, D> v, D d) { public <R, D> R accept(TreeVisitor<R, D> v, D d) {
return v.visitExports(this, d); return v.visitExports(this, d);
} }
@ -2705,22 +2705,22 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
@Override @Override
public void accept(Visitor v) { v.visitProvides(this); } public void accept(Visitor v) { v.visitProvides(this); }
@Override @Override @DefinedBy(Api.COMPILER_TREE)
public Kind getKind() { public Kind getKind() {
return Kind.PROVIDES; return Kind.PROVIDES;
} }
@Override @Override @DefinedBy(Api.COMPILER_TREE)
public <R, D> R accept(TreeVisitor<R, D> v, D d) { public <R, D> R accept(TreeVisitor<R, D> v, D d) {
return v.visitProvides(this, d); return v.visitProvides(this, d);
} }
@Override @Override @DefinedBy(Api.COMPILER_TREE)
public JCExpression getServiceName() { public JCExpression getServiceName() {
return serviceName; return serviceName;
} }
@Override @Override @DefinedBy(Api.COMPILER_TREE)
public JCExpression getImplementationName() { public JCExpression getImplementationName() {
return implName; return implName;
} }
@ -2745,22 +2745,22 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
@Override @Override
public void accept(Visitor v) { v.visitRequires(this); } public void accept(Visitor v) { v.visitRequires(this); }
@Override @Override @DefinedBy(Api.COMPILER_TREE)
public Kind getKind() { public Kind getKind() {
return Kind.REQUIRES; return Kind.REQUIRES;
} }
@Override @Override @DefinedBy(Api.COMPILER_TREE)
public <R, D> R accept(TreeVisitor<R, D> v, D d) { public <R, D> R accept(TreeVisitor<R, D> v, D d) {
return v.visitRequires(this, d); return v.visitRequires(this, d);
} }
@Override @Override @DefinedBy(Api.COMPILER_TREE)
public boolean isPublic() { public boolean isPublic() {
return isPublic; return isPublic;
} }
@Override @Override @DefinedBy(Api.COMPILER_TREE)
public JCExpression getModuleName() { public JCExpression getModuleName() {
return moduleName; return moduleName;
} }
@ -2782,17 +2782,17 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
@Override @Override
public void accept(Visitor v) { v.visitUses(this); } public void accept(Visitor v) { v.visitUses(this); }
@Override @Override @DefinedBy(Api.COMPILER_TREE)
public Kind getKind() { public Kind getKind() {
return Kind.USES; return Kind.USES;
} }
@Override @Override @DefinedBy(Api.COMPILER_TREE)
public JCExpression getServiceName() { public JCExpression getServiceName() {
return qualid; return qualid;
} }
@Override @Override @DefinedBy(Api.COMPILER_TREE)
public <R, D> R accept(TreeVisitor<R, D> v, D d) { public <R, D> R accept(TreeVisitor<R, D> v, D d) {
return v.visitUses(this, d); return v.visitUses(this, d);
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -505,7 +505,7 @@ public class TreeCopier<P> implements TreeVisitor<JCTree,P> {
return M.at(t.pos).Wildcard(kind, inner); return M.at(t.pos).Wildcard(kind, inner);
} }
@Override @Override @DefinedBy(Api.COMPILER_TREE)
public JCTree visitModule(ModuleTree node, P p) { public JCTree visitModule(ModuleTree node, P p) {
JCModuleDecl t = (JCModuleDecl) node; JCModuleDecl t = (JCModuleDecl) node;
JCExpression qualId = copy(t.qualId); JCExpression qualId = copy(t.qualId);
@ -513,7 +513,7 @@ public class TreeCopier<P> implements TreeVisitor<JCTree,P> {
return M.at(t.pos).ModuleDef(qualId, directives); return M.at(t.pos).ModuleDef(qualId, directives);
} }
@Override @Override @DefinedBy(Api.COMPILER_TREE)
public JCExports visitExports(ExportsTree node, P p) { public JCExports visitExports(ExportsTree node, P p) {
JCExports t = (JCExports) node; JCExports t = (JCExports) node;
JCExpression qualId = copy(t.qualid, p); JCExpression qualId = copy(t.qualid, p);
@ -521,7 +521,7 @@ public class TreeCopier<P> implements TreeVisitor<JCTree,P> {
return M.at(t.pos).Exports(qualId, moduleNames); return M.at(t.pos).Exports(qualId, moduleNames);
} }
@Override @Override @DefinedBy(Api.COMPILER_TREE)
public JCProvides visitProvides(ProvidesTree node, P p) { public JCProvides visitProvides(ProvidesTree node, P p) {
JCProvides t = (JCProvides) node; JCProvides t = (JCProvides) node;
JCExpression serviceName = copy(t.serviceName, p); JCExpression serviceName = copy(t.serviceName, p);
@ -529,14 +529,14 @@ public class TreeCopier<P> implements TreeVisitor<JCTree,P> {
return M.at(t.pos).Provides(serviceName, implName); return M.at(t.pos).Provides(serviceName, implName);
} }
@Override @Override @DefinedBy(Api.COMPILER_TREE)
public JCRequires visitRequires(RequiresTree node, P p) { public JCRequires visitRequires(RequiresTree node, P p) {
JCRequires t = (JCRequires) node; JCRequires t = (JCRequires) node;
JCExpression moduleName = copy(t.moduleName, p); JCExpression moduleName = copy(t.moduleName, p);
return M.at(t.pos).Requires(t.isPublic, moduleName); return M.at(t.pos).Requires(t.isPublic, moduleName);
} }
@Override @Override @DefinedBy(Api.COMPILER_TREE)
public JCUses visitUses(UsesTree node, P p) { public JCUses visitUses(UsesTree node, P p) {
JCUses t = (JCUses) node; JCUses t = (JCUses) node;
JCExpression serviceName = copy(t.qualid, p); JCExpression serviceName = copy(t.qualid, p);

View file

@ -25,7 +25,6 @@
package com.sun.tools.javac.util; package com.sun.tools.javac.util;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.nio.file.Path; import java.nio.file.Path;

View file

@ -203,7 +203,7 @@ public class SmartFileManager extends ForwardingJavaFileManager<JavaFileManager>
return file; return file;
} }
@Override @Override @DefinedBy(Api.COMPILER)
public Location getModuleLocation(Location location, JavaFileObject fo, String pkgName) throws IOException { public Location getModuleLocation(Location location, JavaFileObject fo, String pkgName) throws IOException {
return super.getModuleLocation(location, locUnwrap(fo), pkgName); return super.getModuleLocation(location, locUnwrap(fo), pkgName);
} }

View file

@ -339,7 +339,8 @@ doclet.xusage.xdoclint-extended.description=Enable or disable specific checks fo
doclet.xusage.xdoclint-package.name=Xdoclint/package: doclet.xusage.xdoclint-package.name=Xdoclint/package:
doclet.xusage.xdoclint-package.parameters=([-]<packages>) doclet.xusage.xdoclint-package.parameters=([-]<packages>)
doclet.xusage.xdoclint-package.description=Enable or disable checks in specific packages. <packages> is a comma separated\n\ doclet.xusage.xdoclint-package.description=\n\
\ Enable or disable checks in specific packages. <packages> is a comma separated\n\
\ list of package specifiers. Package specifier is either a qualified name of a package\n\ \ list of package specifiers. Package specifier is either a qualified name of a package\n\
\ or a package name prefix followed by .*, which expands to all sub-packages of\n\ \ or a package name prefix followed by .*, which expands to all sub-packages of\n\
\ the given package. Prefix the package specifier with - to disable checks for\n\ \ the given package. Prefix the package specifier with - to disable checks for\n\

View file

@ -1140,7 +1140,7 @@ public abstract class Configuration {
*/ */
@Override @Override
public String toString() { public String toString() {
String opt = name + " " + parameters; String opt = name + (name.endsWith(":") ? "" : " ") + parameters;
int optlen = opt.length(); int optlen = opt.length();
int spaces = 32 - optlen; int spaces = 32 - optlen;
StringBuffer sb = new StringBuffer(" -").append(opt); StringBuffer sb = new StringBuffer(" -").append(opt);

View file

@ -1,5 +1,5 @@
# #
# Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
@ -73,7 +73,9 @@ main.Xusage=\
\ given module. <other-module> may be ALL-UNNAMED to require\n\ \ given module. <other-module> may be ALL-UNNAMED to require\n\
\ the unnamed module.\n\ \ the unnamed module.\n\
\ -Xmodule:<module-name> Specify a module to which the classes being compiled belong.\n\ \ -Xmodule:<module-name> Specify a module to which the classes being compiled belong.\n\
\ -Xpatch:<path> Specify location of module class files to patch\n \ -Xpatch:<module>=<file>(:<file>)*\n\
\ Override or augment a module with classes and resources\n\
\ in JAR files or directories
main.Xusage.foot=\ main.Xusage.foot=\
These options are non-standard and subject to change without notice. These options are non-standard and subject to change without notice.

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -231,6 +231,7 @@ class MemoryFileManager implements JavaFileManager {
} }
// Make compatible with Jigsaw // Make compatible with Jigsaw
@DefinedBy(Api.COMPILER)
public String inferModuleName(Location location) { public String inferModuleName(Location location) {
try { try {
if (inferModuleNameMethod == null) { if (inferModuleNameMethod == null) {
@ -249,6 +250,7 @@ class MemoryFileManager implements JavaFileManager {
} }
// Make compatible with Jigsaw // Make compatible with Jigsaw
@DefinedBy(Api.COMPILER)
public Iterable<Set<Location>> listModuleLocations(Location location) throws IOException { public Iterable<Set<Location>> listModuleLocations(Location location) throws IOException {
try { try {
if (listModuleLocationsMethod == null) { if (listModuleLocationsMethod == null) {

View file

@ -14,5 +14,8 @@ keys=intermittent randomness
# Group definitions # Group definitions
groups=TEST.groups groups=TEST.groups
# Tests using jtreg 4.2 b01 features # Tests using jtreg 4.2 b02 features
requiredVersion=4.2 b01 requiredVersion=4.2 b02
# Use new form of -Xpatch
useNewXpatch=true

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,11 +25,7 @@
* @test * @test
* @bug 8043643 * @bug 8043643
* @summary Run the langtools coding rules over the langtools source code. * @summary Run the langtools coding rules over the langtools source code.
* @modules java.base/sun.reflect.annotation * @modules jdk.compiler/com.sun.tools.javac.util
* java.logging
* java.xml
* jdk.compiler/com.sun.tools.javac.resources
* jdk.compiler/com.sun.tools.javac.util
*/ */
@ -58,25 +54,33 @@ public class RunCodingRules {
public void run() throws Exception { public void run() throws Exception {
Path testSrc = Paths.get(System.getProperty("test.src", ".")); Path testSrc = Paths.get(System.getProperty("test.src", "."));
Path targetDir = Paths.get(System.getProperty("test.classes", ".")); Path targetDir = Paths.get(".");
List<Path> sourceDirs = null; List<Path> sourceDirs = null;
Path crulesDir = null; Path crulesDir = null;
Path mainSrcDir = null;
List<Path> genSrcDirs = null;
for (Path d = testSrc; d != null; d = d.getParent()) { for (Path d = testSrc; d != null; d = d.getParent()) {
if (Files.exists(d.resolve("TEST.ROOT"))) { if (Files.exists(d.resolve("TEST.ROOT"))) {
d = d.getParent(); d = d.getParent();
Path toolsPath = d.resolve("make/tools"); Path toolsPath = d.resolve("make/tools");
if (Files.exists(toolsPath)) { Path buildDir = d.getParent().resolve("build");
if (Files.exists(toolsPath) && Files.exists(buildDir)) {
mainSrcDir = d.resolve("src");
crulesDir = toolsPath; crulesDir = toolsPath;
sourceDirs = Files.walk(d.resolve("src"), 1) sourceDirs = Files.walk(mainSrcDir, 1)
.map(p -> p.resolve("share/classes")) .map(p -> p.resolve("share/classes"))
.filter(p -> Files.isDirectory(p)) .filter(p -> Files.isDirectory(p))
.collect(Collectors.toList()); .collect(Collectors.toList());
genSrcDirs = Files.walk(buildDir, 1)
.map(p -> p.resolve("support/gensrc"))
.filter(p -> Files.isDirectory(p.resolve("jdk.compiler")))
.collect(Collectors.toList());
break; break;
} }
} }
} }
if (sourceDirs == null || crulesDir == null) { if (sourceDirs == null || crulesDir == null || genSrcDirs == null) {
System.err.println("Warning: sources not found, test skipped."); System.err.println("Warning: sources not found, test skipped.");
return ; return ;
} }
@ -96,12 +100,11 @@ public class RunCodingRules {
Path crulesTarget = targetDir.resolve("crules"); Path crulesTarget = targetDir.resolve("crules");
Files.createDirectories(crulesTarget); Files.createDirectories(crulesTarget);
List<String> crulesOptions = Arrays.asList( List<String> crulesOptions = Arrays.asList(
"-XaddExports:" "-XaddExports:jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
+ "jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED," "-XaddExports:jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
+ "jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED," "-XaddExports:jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED",
+ "jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED," "-XaddExports:jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
+ "jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED," "-XaddExports:jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
+ "jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
"-d", crulesTarget.toString()); "-d", crulesTarget.toString());
javaCompiler.getTask(null, fm, noErrors, crulesOptions, null, javaCompiler.getTask(null, fm, noErrors, crulesOptions, null,
fm.getJavaFileObjectsFromFiles(crulesFiles)).call(); fm.getJavaFileObjectsFromFiles(crulesFiles)).call();
@ -117,11 +120,36 @@ public class RunCodingRules {
.map(p -> p.toFile()) .map(p -> p.toFile())
.collect(Collectors.toList()); .collect(Collectors.toList());
String FS = File.separator;
String PS = File.pathSeparator;
Path genSrcTarget = targetDir.resolve("gensrc");
List<String> genSrcFiles = Arrays.asList(
"jdk.compiler/com/sun/tools/javac/resources/CompilerProperties.java"
);
for (String f : genSrcFiles) {
for (Path dir : genSrcDirs) {
Path from = dir.resolve(f.replace("/", FS));
if (Files.exists(from)) {
try {
Path to = genSrcTarget.resolve(f.replace("/", FS));
Files.createDirectories(to.getParent());
Files.copy(from, to);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Path sourceTarget = targetDir.resolve("classes"); Path sourceTarget = targetDir.resolve("classes");
Files.createDirectories(sourceTarget); Files.createDirectories(sourceTarget);
String processorPath = crulesTarget.toString() + File.pathSeparator + crulesDir.toString(); String processorPath = crulesTarget + PS + crulesDir;
List<String> options = Arrays.asList( List<String> options = Arrays.asList(
"-d", sourceTarget.toString(), "-d", sourceTarget.toString(),
"-modulesourcepath", mainSrcDir + FS + "*" + FS + "share" + FS + "classes" + PS + genSrcTarget,
"-XDaccessInternalAPI",
"-processorpath", processorPath, "-processorpath", processorPath,
"-Xplugin:coding_rules"); "-Xplugin:coding_rules");
javaCompiler.getTask(null, fm, noErrors, options, null, javaCompiler.getTask(null, fm, noErrors, options, null,

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -69,10 +69,10 @@ public class T6358024 extends AbstractProcessor {
JavacTool tool = JavacTool.create(); JavacTool tool = JavacTool.create();
List<String> flags = new ArrayList<String>(); List<String> flags = new ArrayList<String>();
flags.add("-XaddExports:" flags.addAll(Arrays.asList(
+ "jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED," "-XaddExports:jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
+ "jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED," "-XaddExports:jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
+ "jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED"); "-XaddExports:jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED"));
for (Option opt: opts) { for (Option opt: opts) {
flags.add(opt.name); flags.add(opt.name);
for (Object arg : opt.args) for (Object arg : opt.args)

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -42,8 +42,7 @@ import com.sun.tools.javac.api.JavacTaskImpl;
import com.sun.tools.javac.api.JavacTool; import com.sun.tools.javac.api.JavacTool;
import com.sun.tools.javac.file.JavacFileManager; import com.sun.tools.javac.file.JavacFileManager;
import com.sun.tools.javac.main.JavaCompiler; import com.sun.tools.javac.main.JavaCompiler;
import com.sun.tools.javac.util.*; import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.List; // disambiguate
@SupportedAnnotationTypes("*") @SupportedAnnotationTypes("*")
@ -56,22 +55,26 @@ public class T6358166 extends AbstractProcessor {
JavacFileManager fm = new JavacFileManager(new Context(), false, null); JavacFileManager fm = new JavacFileManager(new Context(), false, null);
JavaFileObject f = fm.getJavaFileObject(testSrc + File.separatorChar + self + ".java"); JavaFileObject f = fm.getJavaFileObject(testSrc + File.separatorChar + self + ".java");
String addExports = "-XaddExports:" List<String> addExports = Arrays.asList(
+ "jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED," "-XaddExports:jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
+ "jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED," "-XaddExports:jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
+ "jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED," "-XaddExports:jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
+ "jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED"; "-XaddExports:jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED");
test(fm, f, addExports, "-verbose", "-d", "."); test(fm, f, addExports, "-verbose", "-d", ".");
test(fm, f, addExports, "-verbose", "-d", ".", "-XprintRounds", "-processorpath", ".", "-processor", self); test(fm, f, addExports, "-verbose", "-d", ".", "-XprintRounds", "-processorpath", ".", "-processor", self);
} }
static void test(JavacFileManager fm, JavaFileObject f, String... args) throws Throwable { static void test(JavacFileManager fm, JavaFileObject f, List<String> addExports, String... args) throws Throwable {
List<String> allArgs = new ArrayList<>();
allArgs.addAll(addExports);
allArgs.addAll(Arrays.asList(args));
Context context = new Context(); Context context = new Context();
JavacTool tool = JavacTool.create(); JavacTool tool = JavacTool.create();
JavacTaskImpl task = (JavacTaskImpl) tool.getTask(null, fm, null, Arrays.asList(args), null, List.of(f), context); JavacTaskImpl task = (JavacTaskImpl) tool.getTask(null, fm, null, allArgs, null, List.of(f), context);
task.call(); task.call();
JavaCompiler c = JavaCompiler.instance(context); JavaCompiler c = JavaCompiler.instance(context);

View file

@ -50,9 +50,8 @@ public class T6406771 extends AbstractProcessor {
JavaFileObject f = fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, self+".java"))).iterator().next(); JavaFileObject f = fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, self+".java"))).iterator().next();
List<String> opts = Arrays.asList( List<String> opts = Arrays.asList(
"-XaddExports:" "-XaddExports:jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
+ "jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED," "-XaddExports:jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
+ "jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
"-XDaccessInternalAPI", "-XDaccessInternalAPI",
"-d", ".", "-d", ".",
"-processorpath", testClasses, "-processorpath", testClasses,

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -143,12 +143,11 @@ public class ParameterNamesAreNotCopiedToAnonymousInitTest {
Arrays.asList(new File(System.getProperty("test.src"), Arrays.asList(new File(System.getProperty("test.src"),
this.getClass().getName() + ".java"))); this.getClass().getName() + ".java")));
java.util.List<String> options = Arrays.asList( java.util.List<String> options = Arrays.asList(
"-XaddExports:" "-XaddExports:jdk.jdeps/com.sun.tools.classfile=ALL-UNNAMED",
+ "jdk.jdeps/com.sun.tools.classfile=ALL-UNNAMED," "-XaddExports:jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
+ "jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED," "-XaddExports:jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
+ "jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED," "-XaddExports:jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
+ "jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED," "-XaddExports:jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
+ "jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
"-d", System.getProperty("user.dir") "-d", System.getProperty("user.dir")
); );
JavacTask task = (JavacTask) c.getTask(null, fm, null, options, null, fos); JavacTask task = (JavacTask) c.getTask(null, fm, null, options, null, fos);

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -73,11 +73,11 @@ public class TestJavacTaskScanner extends ToolTester {
final Iterable<? extends JavaFileObject> compilationUnits = final Iterable<? extends JavaFileObject> compilationUnits =
fm.getJavaFileObjects(new File[] {file}); fm.getJavaFileObjects(new File[] {file});
StandardJavaFileManager fm = getLocalFileManager(tool, null, null); StandardJavaFileManager fm = getLocalFileManager(tool, null, null);
java.util.List<String> options = Arrays.asList("-XaddExports:" java.util.List<String> options = Arrays.asList(
+ "jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED," "-XaddExports:jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
+ "jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED," "-XaddExports:jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
+ "jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED," "-XaddExports:jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED",
+ "jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED"); "-XaddExports:jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED");
task = (JavacTaskImpl)tool.getTask(null, fm, null, options, null, compilationUnits); task = (JavacTaskImpl)tool.getTask(null, fm, null, options, null, compilationUnits);
task.getContext().put(ScannerFactory.scannerFactoryKey, task.getContext().put(ScannerFactory.scannerFactoryKey,
new MyScanner.Factory(task.getContext(), this)); new MyScanner.Factory(task.getContext(), this));

View file

@ -294,6 +294,7 @@ public class CheckResourceKeys {
"opt.Xlint.desc.", "opt.Xlint.desc.",
"count.", "count.",
"illegal.", "illegal.",
"java.",
"javac.", "javac.",
"verbose.", "verbose.",
"locn." "locn."

View file

@ -60,10 +60,9 @@ public class T7018098 extends JavacTestingAbstractProcessor {
_assert(!testDir.exists()); _assert(!testDir.exists());
compile( compile(
"-XaddExports:" "-XaddExports:jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
+ "jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED," "-XaddExports:jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED",
+ "jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED," "-XaddExports:jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
+ "jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
"-XDaccessInternalAPI", "-XDaccessInternalAPI",
"-proc:only", "-proc:only",
"-processor", myName, "-processor", myName,
@ -74,10 +73,9 @@ public class T7018098 extends JavacTestingAbstractProcessor {
_assert(testDir.exists()); _assert(testDir.exists());
compile( compile(
"-XaddExports:" "-XaddExports:jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
+ "jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED," "-XaddExports:jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED",
+ "jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED," "-XaddExports:jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
+ "jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
"-XDaccessInternalAPI", "-XDaccessInternalAPI",
"-proc:only", "-proc:only",
"-processor", myName, "-processor", myName,

View file

@ -40,6 +40,7 @@
import java.io.File; import java.io.File;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.AbstractMap.SimpleEntry;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
@ -69,7 +70,6 @@ import toolbox.JarTask;
import toolbox.JavacTask; import toolbox.JavacTask;
import toolbox.JavaTask; import toolbox.JavaTask;
import toolbox.Task; import toolbox.Task;
import toolbox.ToolBox;
public class AddLimitMods extends ModuleTestBase { public class AddLimitMods extends ModuleTestBase {
@ -175,6 +175,58 @@ public class AddLimitMods extends ModuleTestBase {
.writeAll(); .writeAll();
} }
@Test
void testObservableForUnnamed(Path base) throws Exception {
Path src = base.resolve("src");
tb.writeJavaFiles(src,
"package test;\n" +
"@javax.annotation.Generated(\"test\")\n" +
"public class Test {\n" +
" com.sun.tools.javac.Main m;\n" +
" javax.xml.bind.JAXBException e;\n" +
"}\n");
Path out = base.resolve("out");
Files.createDirectories(out);
for (Entry<String[], String> variant : variants) {
System.err.println("running variant: options=" + Arrays.asList(variant.getKey()) + ", expected log: " + variant.getValue());
List<String> options = new ArrayList<>();
options.add("-XDrawDiagnostics");
options.addAll(Arrays.asList(variant.getKey()));
String log = new JavacTask(tb)
.options(options.toArray(new String[0]))
.outdir(out)
.files(findJavaFiles(src))
.run(variant.getValue() == null ? Task.Expect.SUCCESS : Task.Expect.FAIL)
.writeAll()
.getOutput(Task.OutputKind.DIRECT);
log = log.replace(System.getProperty("line.separator"), "\n");
if (variant.getValue() != null && !log.equals(variant.getValue())) {
throw new AssertionError();
}
}
}
private static final List<Entry<String[], String>> variants = Arrays.asList(
new SimpleEntry<String[], String>(new String[] {},
"Test.java:2:18: compiler.err.doesnt.exist: javax.annotation\n"
+ "Test.java:5:19: compiler.err.doesnt.exist: javax.xml.bind\n"
+ "2 errors\n"),
new SimpleEntry<String[], String>(new String[] {"-addmods", "java.annotations.common,java.xml.bind"},
null),
new SimpleEntry<String[], String>(new String[] {"-limitmods", "java.xml.ws,jdk.compiler"},
null),
new SimpleEntry<String[], String>(new String[] {"-addmods", "ALL-SYSTEM"},
null)
);
@Test @Test
void testAllModulePath(Path base) throws Exception { void testAllModulePath(Path base) throws Exception {
if (Files.isDirectory(base)) if (Files.isDirectory(base))

View file

@ -132,9 +132,8 @@ public class TestClose implements TaskListener {
new MemFile("AnnoProc.java", annoProc), new MemFile("AnnoProc.java", annoProc),
new MemFile("Callback.java", callback)); new MemFile("Callback.java", callback));
List<String> options = Arrays.asList( List<String> options = Arrays.asList(
"-XaddExports:" "-XaddExports:jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED",
+ "jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED," "-XaddExports:jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
+ "jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
"-XDaccessInternalAPI"); "-XDaccessInternalAPI");
JavacTask task = tool.getTask(null, fm, null, options, null, files); JavacTask task = tool.getTask(null, fm, null, options, null, files);
check(task.call()); check(task.call());

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -92,10 +92,9 @@ public class TestClose2 extends AbstractProcessor implements TaskListener {
Iterable<? extends JavaFileObject> files = Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjects(new File(testSrc, TestClose2.class.getName() + ".java")); fm.getJavaFileObjects(new File(testSrc, TestClose2.class.getName() + ".java"));
List<String> options = Arrays.asList( List<String> options = Arrays.asList(
"-XaddExports:" "-XaddExports:jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
+ "jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED," "-XaddExports:jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
+ "jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED," "-XaddExports:jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
+ "jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
"-processor", TestClose2.class.getName()); "-processor", TestClose2.class.getName());
JavacTask task = tool.getTask(null, fm, null, options, null, files); JavacTask task = tool.getTask(null, fm, null, options, null, files);

View file

@ -33,7 +33,6 @@
import java.io.File; import java.io.File;
import java.util.*; import java.util.*;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.stream.StreamSupport;
import javax.lang.model.element.Element; import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind; import javax.lang.model.element.ElementKind;
@ -42,14 +41,12 @@ import javax.lang.model.element.PackageElement;
import javax.lang.model.element.TypeElement; import javax.lang.model.element.TypeElement;
import javax.lang.model.util.Elements; import javax.lang.model.util.Elements;
import javax.tools.*; import javax.tools.*;
import javax.tools.JavaFileManager.Location;
import com.sun.source.util.JavacTask; import com.sun.source.util.JavacTask;
import com.sun.tools.javac.model.JavacElements; import com.sun.tools.javac.model.JavacElements;
import static javax.tools.StandardLocation.CLASS_PATH; import static javax.tools.StandardLocation.CLASS_PATH;
import static javax.tools.StandardLocation.PLATFORM_CLASS_PATH; import static javax.tools.StandardLocation.PLATFORM_CLASS_PATH;
import static javax.tools.StandardLocation.SYSTEM_MODULES;
import static javax.tools.JavaFileObject.Kind.CLASS; import static javax.tools.JavaFileObject.Kind.CLASS;
@ -67,11 +64,13 @@ public class Main {
static JavacTask javac; static JavacTask javac;
static Elements elements; static Elements elements;
static List<String> addmods_ALL_SYSTEM = Arrays.asList("-addmods", "ALL-SYSTEM");
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) { try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
fm.setLocation(CLASS_PATH, Collections.<File>emptyList()); fm.setLocation(CLASS_PATH, Collections.<File>emptyList());
JavacTask javac = (JavacTask)tool.getTask(null, fm, null, null, null, null); JavacTask javac = (JavacTask)tool.getTask(null, fm, null, addmods_ALL_SYSTEM, null, null);
Elements elements = javac.getElements(); Elements elements = javac.getElements();
final Map<String, Set<String>> packages = new LinkedHashMap<>(); final Map<String, Set<String>> packages = new LinkedHashMap<>();
@ -109,11 +108,12 @@ public class Main {
javac = null; javac = null;
elements = null; elements = null;
javac = (JavacTask)tool.getTask(null, fm, null, null, null, null); javac = (JavacTask)tool.getTask(null, fm, null, addmods_ALL_SYSTEM, null, null);
elements = javac.getElements(); elements = javac.getElements();
for (Entry<String, Set<String>> module2Packages : packages.entrySet()) { for (Entry<String, Set<String>> module2Packages : packages.entrySet()) {
ModuleElement me = elements.getModuleElement(module2Packages.getKey()); ModuleElement me = elements.getModuleElement(module2Packages.getKey());
me.getClass();
for (String name : module2Packages.getValue()) { for (String name : module2Packages.getValue()) {
PackageElement pe = ((JavacElements) elements).getPackageElement(me, name); PackageElement pe = ((JavacElements) elements).getPackageElement(me, name);
for (Element e : pe.getEnclosedElements()) { for (Element e : pe.getEnclosedElements()) {

View file

@ -59,9 +59,8 @@ public class T6597678 extends JavacTestingAbstractProcessor {
PrintWriter pw = new PrintWriter(sw); PrintWriter pw = new PrintWriter(sw);
compile(sw, pw, compile(sw, pw,
"-XaddExports:" "-XaddExports:jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED",
+ "jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED," "-XaddExports:jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
+ "jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
"-XDaccessInternalAPI", "-XDaccessInternalAPI",
"-proc:only", "-proc:only",
"-processor", myName, "-processor", myName,

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -65,11 +65,9 @@ public class APIDeps {
for (String s : testModules.split("\\s+")) { for (String s : testModules.split("\\s+")) {
if (s.isEmpty()) continue; if (s.isEmpty()) continue;
if (s.indexOf('/') != -1) if (s.indexOf('/') != -1)
addExports.add(s.trim() + "=ALL-UNNAMED"); addExports.add("-XaddExports:" + s.trim() + "=ALL-UNNAMED");
}
if (addExports.size() > 0) {
options.add(addExports.stream().collect(Collectors.joining(",", "-XaddExports:", "")));
} }
options.addAll(addExports);
for (String dir : srcDirs) { for (String dir : srcDirs) {
Path source = testsrc.resolve(dir); Path source = testsrc.resolve(dir);