This commit is contained in:
Alan Bateman 2016-12-16 08:17:55 +00:00
commit 574ac0add6
147 changed files with 2482 additions and 1572 deletions

View File

@ -107,6 +107,8 @@ public class MutableFieldsAnalyzer extends AbstractCodingRulesAnalyzer {
"layerClass", "bootMethod", "defineModulesWithOneLoaderMethod", "configurationMethod");
ignoreFields("com.sun.tools.javac.util.JDK9Wrappers$Module",
"addExportsMethod", "addUsesMethod", "getModuleMethod", "getUnnamedModuleMethod");
ignoreFields("com.sun.tools.javac.util.JDK9Wrappers$ModuleDescriptor$Version",
"versionClass", "parseMethod");
ignoreFields("com.sun.tools.javac.util.JDK9Wrappers$ServiceLoaderHelper",
"loadMethod");
ignoreFields("com.sun.tools.javac.util.JDK9Wrappers$VMHelper",

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.
*
* This code is free software; you can redistribute it and/or modify it
@ -36,6 +36,7 @@ import javax.lang.model.element.*;
import javax.lang.model.element.ModuleElement.Directive;
import javax.lang.model.element.ModuleElement.DirectiveKind;
import javax.lang.model.element.ModuleElement.ExportsDirective;
import javax.lang.model.element.ModuleElement.OpensDirective;
import javax.lang.model.element.ModuleElement.ProvidesDirective;
import javax.lang.model.element.ModuleElement.RequiresDirective;
import javax.lang.model.element.ModuleElement.UsesDirective;
@ -239,11 +240,9 @@ public class ElementFilter {
return set;
}
/**
* Returns a list of export directives in {@code directives}.
* @return a list of export directives in {@code directives}
* Returns a list of {@code exports} directives in {@code directives}.
* @return a list of {@code exports} directives in {@code directives}
* @param directives the directives to filter
* @since 9
*/
@ -253,8 +252,19 @@ public class ElementFilter {
}
/**
* Returns a list of provides directives in {@code directives}.
* @return a list of provides directives in {@code directives}
* Returns a list of {@code opens} directives in {@code directives}.
* @return a list of {@code opens} directives in {@code directives}
* @param directives the directives to filter
* @since 9
*/
public static List<OpensDirective>
opensIn(Iterable<? extends Directive> directives) {
return listFilter(directives, DirectiveKind.OPENS, OpensDirective.class);
}
/**
* Returns a list of {@code provides} directives in {@code directives}.
* @return a list of {@code provides} directives in {@code directives}
* @param directives the directives to filter
* @since 9
*/
@ -264,8 +274,8 @@ public class ElementFilter {
}
/**
* Returns a list of requires directives in {@code directives}.
* @return a list of requires directives in {@code directives}
* Returns a list of {@code requires} directives in {@code directives}.
* @return a list of {@code requires} directives in {@code directives}
* @param directives the directives to filter
* @since 9
*/
@ -275,8 +285,8 @@ public class ElementFilter {
}
/**
* Returns a list of uses directives in {@code directives}.
* @return a list of uses directives in {@code directives}
* Returns a list of {@code uses} directives in {@code directives}.
* @return a list of {@code uses} directives in {@code directives}
* @param directives the directives to filter
* @since 9
*/

View File

@ -118,6 +118,7 @@ public class Lint
if (source.compareTo(Source.JDK1_9) >= 0) {
values.add(LintCategory.DEP_ANN);
}
values.add(LintCategory.MODULE);
values.add(LintCategory.REMOVAL);
}
@ -204,6 +205,11 @@ public class Lint
*/
FINALLY("finally"),
/**
* Warn about module system related issues.
*/
MODULE("module"),
/**
* Warn about issues relating to use of command line options
*/

View File

@ -925,6 +925,7 @@ public abstract class Symbol extends AnnoConstruct implements Element {
public Completer usesProvidesCompleter = Completer.NULL_COMPLETER;
public final Set<ModuleFlags> flags = EnumSet.noneOf(ModuleFlags.class);
public final Set<ModuleResolutionFlags> resolutionFlags = EnumSet.noneOf(ModuleResolutionFlags.class);
/**
* Create a ModuleSymbol with an associated module-info ClassSymbol.
@ -1037,7 +1038,26 @@ public abstract class Symbol extends AnnoConstruct implements Element {
}
public final int value;
}
public enum ModuleResolutionFlags {
DO_NOT_RESOLVE_BY_DEFAULT(0x0001),
WARN_DEPRECATED(0x0002),
WARN_DEPRECATED_REMOVAL(0x0004),
WARN_INCUBATOR(0x0008);
public static int value(Set<ModuleResolutionFlags> s) {
int v = 0;
for (ModuleResolutionFlags f: s)
v |= f.value;
return v;
}
private ModuleResolutionFlags(int value) {
this.value = value;
}
public final int value;
}
/** A class for package symbols

View File

@ -4444,7 +4444,7 @@ public class Attr extends JCTree.Visitor {
ModuleSymbol msym = tree.sym;
Lint lint = env.outer.info.lint = env.outer.info.lint.augment(msym);
Lint prevLint = chk.setLint(lint);
chk.checkModuleName(tree);
chk.checkDeprecatedAnnotation(tree, msym);
try {

View File

@ -2116,6 +2116,18 @@ public class Check {
}
}
public void checkModuleName (JCModuleDecl tree) {
Name moduleName = tree.sym.name;
Assert.checkNonNull(moduleName);
if (lint.isEnabled(LintCategory.MODULE)) {
String moduleNameString = moduleName.toString();
int nameLength = moduleNameString.length();
if (nameLength > 0 && Character.isDigit(moduleNameString.charAt(nameLength - 1))) {
log.warning(Lint.LintCategory.MODULE, tree.qualId.pos(), Warnings.PoorChoiceForModuleName(moduleName));
}
}
}
private boolean checkNameClash(ClassSymbol origin, Symbol s1, Symbol s2) {
ClashFilter cf = new ClashFilter(origin.type);
return (cf.accepts(s1) &&
@ -3877,4 +3889,17 @@ public class Check {
log.warning(LintCategory.EXPORTS, pos, Warnings.LeaksNotAccessibleNotRequiredTransitive(kindName(what), what, what.packge().modle));
}
}
void checkModuleExists(final DiagnosticPosition pos, ModuleSymbol msym) {
if (msym.kind != MDL) {
deferredLintHandler.report(new DeferredLintHandler.LintLogger() {
@Override
public void report() {
if (lint.isEnabled(Lint.LintCategory.MODULE))
log.warning(LintCategory.MODULE, pos, Warnings.ModuleNotFound(msym));
}
});
}
}
}

View File

@ -158,6 +158,7 @@ public class Modules extends JCTree.Visitor {
private final Set<String> extraAddMods = new HashSet<>();
private final String limitModsOpt;
private final Set<String> extraLimitMods = new HashSet<>();
private final String moduleVersionOpt;
private final boolean lintOptions;
@ -203,6 +204,7 @@ public class Modules extends JCTree.Visitor {
addReadsOpt = options.get(Option.ADD_READS);
addModsOpt = options.get(Option.ADD_MODULES);
limitModsOpt = options.get(Option.LIMIT_MODULES);
moduleVersionOpt = options.get(Option.MODULE_VERSION);
}
int depth = -1;
@ -605,13 +607,16 @@ public class Modules extends JCTree.Visitor {
msym.flags_field |= UNATTRIBUTED;
ModuleVisitor v = new ModuleVisitor();
JavaFileObject prev = log.useSource(tree.sourcefile);
JCModuleDecl moduleDecl = tree.getModuleDecl();
DiagnosticPosition prevLintPos = deferredLintHandler.setPos(moduleDecl.pos());
try {
JCModuleDecl moduleDecl = tree.getModuleDecl();
moduleDecl.accept(v);
completeModule(msym);
checkCyclicDependencies(moduleDecl);
} finally {
log.useSource(prev);
deferredLintHandler.setPos(prevLintPos);
msym.flags_field &= ~UNATTRIBUTED;
}
}
@ -693,15 +698,12 @@ public class Modules extends JCTree.Visitor {
Set<ModuleSymbol> to = new LinkedHashSet<>();
for (JCExpression n: tree.moduleNames) {
ModuleSymbol msym = lookupModule(n);
if (msym.kind != MDL) {
log.error(n.pos(), Errors.ModuleNotFound(msym));
} else {
for (ExportsDirective d : exportsForPackage) {
checkDuplicateExportsToModule(n, msym, d);
}
if (!to.add(msym)) {
reportExportsConflictToModule(n, msym);
}
chk.checkModuleExists(n.pos(), msym);
for (ExportsDirective d : exportsForPackage) {
checkDuplicateExportsToModule(n, msym, d);
}
if (!to.add(msym)) {
reportExportsConflictToModule(n, msym);
}
}
toModules = List.from(to);
@ -755,15 +757,12 @@ public class Modules extends JCTree.Visitor {
Set<ModuleSymbol> to = new LinkedHashSet<>();
for (JCExpression n: tree.moduleNames) {
ModuleSymbol msym = lookupModule(n);
if (msym.kind != MDL) {
log.error(n.pos(), Errors.ModuleNotFound(msym));
} else {
for (OpensDirective d : opensForPackage) {
checkDuplicateOpensToModule(n, msym, d);
}
if (!to.add(msym)) {
reportOpensConflictToModule(n, msym);
}
chk.checkModuleExists(n.pos(), msym);
for (OpensDirective d : opensForPackage) {
checkDuplicateOpensToModule(n, msym, d);
}
if (!to.add(msym)) {
reportOpensConflictToModule(n, msym);
}
}
toModules = List.from(to);
@ -1148,6 +1147,12 @@ public class Modules extends JCTree.Visitor {
result.add(syms.unnamedModule);
allModules = result;
//add module versions from options, if any:
if (moduleVersionOpt != null) {
Name version = names.fromString(moduleVersionOpt);
rootModules.forEach(m -> m.version = version);
}
}
public boolean isInModuleGraph(ModuleSymbol msym) {

View File

@ -85,6 +85,8 @@ public class ClassFile {
public final static int CONSTANT_MethodHandle = 15;
public final static int CONSTANT_MethodType = 16;
public final static int CONSTANT_InvokeDynamic = 18;
public final static int CONSTANT_Module = 19;
public final static int CONSTANT_Package = 20;
public final static int REF_getField = 1;
public final static int REF_getStatic = 2;

View File

@ -161,9 +161,6 @@ public class ClassReader {
*/
protected ModuleSymbol currentModule = null;
// FIXME: temporary compatibility code
private boolean readNewModuleAttribute;
/** The buffer containing the currently read class file.
*/
byte[] buf = new byte[INITIAL_BUFFER_SIZE];
@ -392,6 +389,8 @@ public class ClassReader {
case CONSTANT_Class:
case CONSTANT_String:
case CONSTANT_MethodType:
case CONSTANT_Module:
case CONSTANT_Package:
bp = bp + 2;
break;
case CONSTANT_MethodHandle:
@ -481,6 +480,11 @@ public class ClassReader {
case CONSTANT_InvokeDynamic:
skipBytes(5);
break;
case CONSTANT_Module:
case CONSTANT_Package:
// this is temporary for now: treat as a simple reference to the underlying Utf8.
poolObj[i] = readName(getChar(index + 1));
break;
default:
throw badClassFile("bad.const.pool.tag", Byte.toString(tag));
}
@ -567,40 +571,12 @@ public class ClassReader {
return (NameAndType)obj;
}
/** Read the class name of a module-info.class file.
* The name is stored in a CONSTANT_Class entry, where the
* class name is of the form module-name.module-info.
*/
Name readModuleInfoName(int i) {
if (majorVersion < Version.V53.major) {
throw badClassFile("anachronistic.module.info",
Integer.toString(majorVersion),
Integer.toString(minorVersion));
}
int classIndex = poolIdx[i];
if (buf[classIndex] == CONSTANT_Class) {
int utf8Index = poolIdx[getChar(classIndex + 1)];
if (buf[utf8Index] == CONSTANT_Utf8) {
int len = getChar(utf8Index + 1);
int start = utf8Index + 3;
return names.fromUtf(internalize(buf, start, len));
}
}
throw badClassFile("bad.module-info.name");
}
/** Read the name of a module.
* The name is stored in a CONSTANT_Utf8 entry, in
* JVMS 4.2 internal form (with '/' instead of '.')
* The name is stored in a CONSTANT_Module entry, in
* JVMS 4.2 binary form (using ".", not "/")
*/
Name readModuleName(int i) {
Name name = readName(i);
// FIXME: temporary compatibility code
if (readNewModuleAttribute) {
return names.fromUtf(internalize(name));
} else {
return name;
}
return readName(i);
}
/** Read module_flags.
@ -614,6 +590,17 @@ public class ClassReader {
return set;
}
/** Read resolution_flags.
*/
Set<ModuleResolutionFlags> readModuleResolutionFlags(int flags) {
Set<ModuleResolutionFlags> set = EnumSet.noneOf(ModuleResolutionFlags.class);
for (ModuleResolutionFlags f : ModuleResolutionFlags.values()) {
if ((flags & f.value) != 0)
set.add(f);
}
return set;
}
/** Read exports_flags.
*/
Set<ExportsFlag> readExportsFlags(int flags) {
@ -1282,21 +1269,20 @@ public class ClassReader {
ModuleSymbol msym = (ModuleSymbol) sym.owner;
ListBuffer<Directive> directives = new ListBuffer<>();
// FIXME: temporary compatibility code
if (readNewModuleAttribute) {
Name moduleName = readModuleName(nextChar());
if (currentModule.name != moduleName) {
throw badClassFile("module.name.mismatch", moduleName, currentModule.name);
}
Name moduleName = readModuleName(nextChar());
if (currentModule.name != moduleName) {
throw badClassFile("module.name.mismatch", moduleName, currentModule.name);
}
msym.flags.addAll(readModuleFlags(nextChar()));
msym.version = readName(nextChar());
ListBuffer<RequiresDirective> requires = new ListBuffer<>();
int nrequires = nextChar();
for (int i = 0; i < nrequires; i++) {
ModuleSymbol rsym = syms.enterModule(readModuleName(nextChar()));
Set<RequiresFlag> flags = readRequiresFlags(nextChar());
nextChar(); // skip compiled version
requires.add(new RequiresDirective(rsym, flags));
}
msym.requires = requires.toList();
@ -1372,7 +1358,7 @@ public class ClassReader {
}
},
new AttributeReader(names.ModuleVersion, V53, CLASS_ATTRIBUTE) {
new AttributeReader(names.ModuleResolution, V53, CLASS_ATTRIBUTE) {
@Override
protected boolean accepts(AttributeKind kind) {
return super.accepts(kind) && allowModules;
@ -1380,7 +1366,7 @@ public class ClassReader {
protected void read(Symbol sym, int attrLen) {
if (sym.kind == TYP && sym.owner.kind == MDL) {
ModuleSymbol msym = (ModuleSymbol) sym.owner;
msym.version = readName(nextChar());
msym.resolutionFlags.addAll(readModuleResolutionFlags(nextChar()));
}
}
},
@ -2564,24 +2550,15 @@ public class ClassReader {
self.flatname);
}
} else {
if (majorVersion < Version.V53.major) {
throw badClassFile("anachronistic.module.info",
Integer.toString(majorVersion),
Integer.toString(minorVersion));
}
c.flags_field = flags;
currentModule = (ModuleSymbol) c.owner;
int this_class = nextChar();
// FIXME: temporary compatibility code
if (this_class == 0) {
readNewModuleAttribute = true;
} else {
Name modInfoName = readModuleInfoName(this_class);
if (currentModule.name.append('.', names.module_info) != modInfoName) {
//strip trailing .module-info, if exists:
int modInfoStart = modInfoName.length() - names.module_info.length();
modInfoName = modInfoName.subName(modInfoStart, modInfoName.length()) == names.module_info &&
modInfoName.charAt(modInfoStart - 1) == '.' ?
modInfoName.subName(0, modInfoStart - 1) : modInfoName;
throw badClassFile("module.name.mismatch", modInfoName, currentModule.name);
}
readNewModuleAttribute = false;
}
// temp, no check on this_class
}
// class attributes must be read before class

View File

@ -474,6 +474,14 @@ public class ClassWriter extends ClassFile {
poolbuf.appendByte(CONSTANT_MethodHandle);
poolbuf.appendByte(ref.refKind);
poolbuf.appendChar(pool.put(ref.refSym));
} else if (value instanceof ModuleSymbol) {
ModuleSymbol m = (ModuleSymbol)value;
poolbuf.appendByte(CONSTANT_Module);
poolbuf.appendChar(pool.put(m.name));
} else if (value instanceof PackageSymbol) {
PackageSymbol m = (PackageSymbol)value;
poolbuf.appendByte(CONSTANT_Package);
poolbuf.appendChar(pool.put(names.fromUtf(externalize(m.fullname))));
} else {
Assert.error("writePool " + value);
}
@ -954,8 +962,9 @@ public class ClassWriter extends ClassFile {
int alenIdx = writeAttr(names.Module);
databuf.appendChar(pool.put(names.fromUtf(externalize(m.name))));
databuf.appendChar(pool.put(m));
databuf.appendChar(ModuleFlags.value(m.flags)); // module_flags
databuf.appendChar(m.version != null ? pool.put(m.version) : 0);
ListBuffer<RequiresDirective> requires = new ListBuffer<>();
for (RequiresDirective r: m.requires) {
@ -964,21 +973,22 @@ public class ClassWriter extends ClassFile {
}
databuf.appendChar(requires.size());
for (RequiresDirective r: requires) {
databuf.appendChar(pool.put(names.fromUtf(externalize(r.module.name))));
databuf.appendChar(pool.put(r.module));
databuf.appendChar(RequiresFlag.value(r.flags));
databuf.appendChar(r.module.version != null ? pool.put(r.module.version) : 0);
}
List<ExportsDirective> exports = m.exports;
databuf.appendChar(exports.size());
for (ExportsDirective e: exports) {
databuf.appendChar(pool.put(names.fromUtf(externalize(e.packge.flatName()))));
databuf.appendChar(pool.put(e.packge));
databuf.appendChar(ExportsFlag.value(e.flags));
if (e.modules == null) {
databuf.appendChar(0);
} else {
databuf.appendChar(e.modules.size());
for (ModuleSymbol msym: e.modules) {
databuf.appendChar(pool.put(names.fromUtf(externalize(msym.name))));
databuf.appendChar(pool.put(msym));
}
}
}
@ -986,14 +996,14 @@ public class ClassWriter extends ClassFile {
List<OpensDirective> opens = m.opens;
databuf.appendChar(opens.size());
for (OpensDirective o: opens) {
databuf.appendChar(pool.put(names.fromUtf(externalize(o.packge.flatName()))));
databuf.appendChar(pool.put(o.packge));
databuf.appendChar(OpensFlag.value(o.flags));
if (o.modules == null) {
databuf.appendChar(0);
} else {
databuf.appendChar(o.modules.size());
for (ModuleSymbol msym: o.modules) {
databuf.appendChar(pool.put(names.fromUtf(externalize(msym.name))));
databuf.appendChar(pool.put(msym));
}
}
}
@ -1718,7 +1728,8 @@ public class ClassWriter extends ClassFile {
databuf.appendChar(flags);
if (c.owner.kind == MDL) {
databuf.appendChar(0);
PackageSymbol unnamed = ((ModuleSymbol) c.owner).unnamedPackage;
databuf.appendChar(pool.put(new ClassSymbol(0, names.module_info, unnamed)));
} else {
databuf.appendChar(pool.put(c));
}

View File

@ -100,30 +100,24 @@ public class ModuleNameReader {
if (access_flags != 0x8000)
throw new BadClassFile("invalid access flags for module: 0x" + Integer.toHexString(access_flags));
// FIXME: temporary compatibility code
int this_class = nextChar();
if (this_class == 0) {
// new form
checkZero(nextChar(), "super_class");
checkZero(nextChar(), "interface_count");
checkZero(nextChar(), "fields_count");
checkZero(nextChar(), "methods_count");
int attributes_count = nextChar();
for (int i = 0; i < attributes_count; i++) {
int attr_name = nextChar();
int attr_length = nextInt();
if (getUtf8Value(attr_name, false).equals("Module") && attr_length > 2) {
return getUtf8Value(nextChar(), true);
} else {
// skip over unknown attributes
bp += attr_length;
}
// could, should, check this_class == CONSTANT_Class("mdoule-info")
checkZero(nextChar(), "super_class");
checkZero(nextChar(), "interface_count");
checkZero(nextChar(), "fields_count");
checkZero(nextChar(), "methods_count");
int attributes_count = nextChar();
for (int i = 0; i < attributes_count; i++) {
int attr_name = nextChar();
int attr_length = nextInt();
if (getUtf8Value(attr_name, false).equals("Module") && attr_length > 2) {
return getModuleName(nextChar());
} else {
// skip over unknown attributes
bp += attr_length;
}
throw new BadClassFile("no Module attribute");
} else {
// old form
return readModuleInfoName(this_class);
}
throw new BadClassFile("no Module attribute");
}
void checkZero(int count, String name) throws BadClassFile {
@ -172,6 +166,8 @@ public class ModuleNameReader {
case CONSTANT_Class:
case CONSTANT_String:
case CONSTANT_MethodType:
case CONSTANT_Module:
case CONSTANT_Package:
bp = bp + 2;
break;
case CONSTANT_MethodHandle:
@ -211,33 +207,13 @@ public class ModuleNameReader {
throw new BadClassFile("bad name at index " + index);
}
/** Read the class name of a module-info.class file.
* The name is stored in a CONSTANT_Class entry, where the
* class name is of the form module-name/module-info.
*/
String readModuleInfoName(int i) throws BadClassFile {
int classIndex = poolIdx[i];
if (buf[classIndex] == CONSTANT_Class) {
int utf8Index = poolIdx[getChar(classIndex + 1)];
if (buf[utf8Index] == CONSTANT_Utf8) {
int len = getChar(utf8Index + 1);
int start = utf8Index + 3;
String suffix = "/module-info";
if (endsWith(buf, start, len, suffix))
return new String(ClassFile.internalize(buf, start, len - suffix.length()));
}
String getModuleName(int index) throws BadClassFile {
int infoIndex = poolIdx[index];
if (buf[infoIndex] == CONSTANT_Module) {
return getUtf8Value(getChar(infoIndex + 1), true);
} else {
throw new BadClassFile("bad module name at index " + index);
}
throw new BadClassFile("bad module-info name");
}
private boolean endsWith(byte[] buf, int start, int len, String suffix) {
if (len <= suffix.length())
return false;
for (int i = 0; i < suffix.length(); i++) {
if (buf[start + len - suffix.length() + i] != suffix.charAt(i))
return false;
}
return true;
}
private static byte[] readInputStream(byte[] buf, InputStream s) throws IOException {

View File

@ -582,7 +582,8 @@ public class Arguments {
Option.BOOT_CLASS_PATH,
Option.XBOOTCLASSPATH_PREPEND, Option.XBOOTCLASSPATH, Option.XBOOTCLASSPATH_APPEND,
Option.ENDORSEDDIRS, Option.DJAVA_ENDORSED_DIRS,
Option.EXTDIRS, Option.DJAVA_EXT_DIRS);
Option.EXTDIRS, Option.DJAVA_EXT_DIRS,
Option.PROFILE);
checkOptionAllowed(t.compareTo(Target.JDK1_9) >= 0,
option -> error("err.option.not.allowed.with.target", option.getPrimaryName(), t.name),

View File

@ -35,16 +35,12 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Locale;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
@ -60,7 +56,6 @@ import com.sun.tools.javac.jvm.Profile;
import com.sun.tools.javac.jvm.Target;
import com.sun.tools.javac.platform.PlatformProvider;
import com.sun.tools.javac.processing.JavacProcessingEnvironment;
import com.sun.tools.javac.resources.CompilerProperties.Errors;
import com.sun.tools.javac.util.Assert;
import com.sun.tools.javac.util.JDK9Wrappers;
import com.sun.tools.javac.util.Log;
@ -634,6 +629,33 @@ public enum Option {
}
},
MODULE_VERSION("--module-version", "opt.arg.module.version", "opt.module.version", STANDARD, BASIC) {
@Override
public void process(OptionHelper helper, String option, String arg) throws InvalidValueException {
if (arg.isEmpty()) {
throw helper.newInvalidValueException("err.no.value.for.option", option);
} else {
try {
Class.forName(JDK9Wrappers.ModuleDescriptor.Version.CLASSNAME);
// use official parser if available
try {
JDK9Wrappers.ModuleDescriptor.Version.parse(arg);
} catch (IllegalArgumentException e) {
throw helper.newInvalidValueException("err.bad.value.for.option", option, arg);
}
} catch (ClassNotFoundException ex) {
// fall-back to simplistic rules when running on older platform
if (!(arg.charAt(0) >= '0' && arg.charAt(0) <= '9') ||
arg.endsWith("-") ||
arg.endsWith("+")) {
throw helper.newInvalidValueException("err.bad.value.for.option", option, arg);
}
}
}
super.process(helper, option, arg);
}
},
// This option exists only for the purpose of documenting itself.
// It's actually implemented by the CommandLine class.
AT("@", "opt.arg.file", "opt.AT", STANDARD, INFO, ArgKind.ADJACENT) {
@ -681,7 +703,7 @@ public enum Option {
@Override
public void process(OptionHelper helper, String option) throws InvalidValueException {
try {
Class.forName(JDK9Wrappers.VMHelper.VM_CLASSNAME);
Class.forName(JDK9Wrappers.VMHelper.CLASSNAME);
String[] runtimeArgs = JDK9Wrappers.VMHelper.getRuntimeArguments();
for (String arg : runtimeArgs) {
// Handle any supported runtime options; ignore all others.
@ -1035,7 +1057,7 @@ public enum Option {
* @param helper a helper to provide access to the environment
* @param arg the arg string that identified this option
* @param rest the remaining strings to be analysed
* @return true if the operation was successful, and false otherwise
* @throws InvalidValueException if the value of the option was invalid
* @implNote The return value is the opposite of that used by {@link #process}.
*/
public void handleOption(OptionHelper helper, String arg, Iterator<String> rest) throws InvalidValueException {
@ -1084,6 +1106,7 @@ public enum Option {
* @param option the option to be processed
* @param arg the value to associate with the option, or a default value
* to be used if the option does not otherwise take an argument.
* @throws InvalidValueException if an error occurred
*/
public void process(OptionHelper helper, String option, String arg) throws InvalidValueException {
if (choices != null) {

View File

@ -1457,6 +1457,10 @@ compiler.warn.dir.path.element.not.directory=\
compiler.warn.finally.cannot.complete=\
finally clause cannot complete normally
# 0: name
compiler.warn.poor.choice.for.module.name=\
module name {0} should avoid terminal digits
# 0: symbol, 1: symbol
compiler.warn.has.been.deprecated=\
{0} in {1} has been deprecated
@ -2749,6 +2753,10 @@ compiler.err.expected.module=\
compiler.err.module.not.found=\
module not found: {0}
# 0: symbol
compiler.warn.module.not.found=\
module not found: {0}
compiler.err.too.many.modules=\
too many module declarations found

View File

@ -201,6 +201,9 @@ javac.opt.Xlint.desc.fallthrough=\
javac.opt.Xlint.desc.finally=\
Warn about finally clauses that do not terminate normally.
javac.opt.Xlint.desc.module=\
Warn about module system related issues.
javac.opt.Xlint.desc.options=\
Warn about issues relating to use of command line options.
@ -308,6 +311,10 @@ javac.opt.limitmods=\
Limit the universe of observable modules
javac.opt.arg.limitmods=\
<module>(,<module>)*
javac.opt.module.version=\
Specify version of modules that are being compiled
javac.opt.arg.module.version=\
<version>
javac.opt.inherit_runtime_environment=\
Inherit module system configuration options from the runtime environment.

View File

@ -462,11 +462,22 @@ public class Pretty extends JCTree.Visitor {
@Override
public void visitExports(JCExports tree) {
try {
if (tree.hasTag(EXPORTS)) {
print("exports ");
} else {
print("opens ");
print("exports ");
printExpr(tree.qualid);
if (tree.moduleNames != null) {
print(" to ");
printExprs(tree.moduleNames);
}
print(";");
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
@Override
public void visitOpens(JCOpens tree) {
try {
print("opens ");
printExpr(tree.qualid);
if (tree.moduleNames != null) {
print(" to ");
@ -1493,7 +1504,7 @@ public class Pretty extends JCTree.Visitor {
public void visitTree(JCTree tree) {
try {
print("(UNKNOWN: " + tree + ")");
print("(UNKNOWN: " + tree.getTag() + ")");
println();
} catch (IOException e) {
throw new UncheckedIOException(e);

View File

@ -85,6 +85,58 @@ public class JDK9Wrappers {
}
}
/**
* Wrapper class for java.lang.module.ModuleDescriptor and ModuleDescriptor.Version.
*/
public static class ModuleDescriptor {
public static class Version {
public static final String CLASSNAME = "java.lang.module.ModuleDescriptor$Version";
private final Object theRealVersion;
private Version(Object version) {
this.theRealVersion = version;
}
public static Version parse(String v) {
try {
init();
Object result = parseMethod.invoke(null, v);
Version version = new Version(result);
return version;
} catch (InvocationTargetException ex) {
if (ex.getCause() instanceof IllegalArgumentException) {
throw (IllegalArgumentException) ex.getCause();
} else {
throw new Abort(ex);
}
} catch (IllegalAccessException | IllegalArgumentException | SecurityException ex) {
throw new Abort(ex);
}
}
@Override
public String toString() {
return theRealVersion.toString();
}
// -----------------------------------------------------------------------------------------
private static Class<?> versionClass = null;
private static Method parseMethod = null;
private static void init() {
if (versionClass == null) {
try {
versionClass = Class.forName(CLASSNAME, false, null);
parseMethod = versionClass.getDeclaredMethod("parse", String.class);
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException ex) {
throw new Abort(ex);
}
}
}
}
}
/**
* Wrapper class for java.lang.module.ModuleFinder.
*/
@ -338,7 +390,7 @@ public class JDK9Wrappers {
* Helper class for new method in jdk.internal.misc.VM.
*/
public static final class VMHelper {
public static final String VM_CLASSNAME = "jdk.internal.misc.VM";
public static final String CLASSNAME = "jdk.internal.misc.VM";
@SuppressWarnings("unchecked")
public static String[] getRuntimeArguments() {
@ -360,7 +412,7 @@ public class JDK9Wrappers {
private static void init() {
if (vmClass == null) {
try {
vmClass = Class.forName(VM_CLASSNAME, false, null);
vmClass = Class.forName(CLASSNAME, false, null);
getRuntimeArgumentsMethod = vmClass.getDeclaredMethod("getRuntimeArguments");
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException ex) {
throw new Abort(ex);

View File

@ -150,7 +150,7 @@ public class Names {
public final Name LocalVariableTypeTable;
public final Name MethodParameters;
public final Name Module;
public final Name ModuleVersion;
public final Name ModuleResolution;
public final Name RuntimeInvisibleAnnotations;
public final Name RuntimeInvisibleParameterAnnotations;
public final Name RuntimeInvisibleTypeAnnotations;
@ -312,7 +312,7 @@ public class Names {
LocalVariableTypeTable = fromString("LocalVariableTypeTable");
MethodParameters = fromString("MethodParameters");
Module = fromString("Module");
ModuleVersion = fromString("ModuleVersion");
ModuleResolution = fromString("ModuleResolution");
RuntimeInvisibleAnnotations = fromString("RuntimeInvisibleAnnotations");
RuntimeInvisibleParameterAnnotations = fromString("RuntimeInvisibleParameterAnnotations");
RuntimeInvisibleTypeAnnotations = fromString("RuntimeInvisibleTypeAnnotations");

View File

@ -56,8 +56,8 @@ public abstract class Attribute {
public static final String ModuleHashes = "ModuleHashes";
public static final String ModuleMainClass = "ModuleMainClass";
public static final String ModulePackages = "ModulePackages";
public static final String ModuleResolution = "ModuleResolution";
public static final String ModuleTarget = "ModuleTarget";
public static final String ModuleVersion = "ModuleVersion";
public static final String RuntimeVisibleAnnotations = "RuntimeVisibleAnnotations";
public static final String RuntimeInvisibleAnnotations = "RuntimeInvisibleAnnotations";
public static final String RuntimeVisibleParameterAnnotations = "RuntimeVisibleParameterAnnotations";
@ -128,8 +128,8 @@ public abstract class Attribute {
standardAttributes.put(ModuleHashes, ModuleHashes_attribute.class);
standardAttributes.put(ModuleMainClass, ModuleMainClass_attribute.class);
standardAttributes.put(ModulePackages, ModulePackages_attribute.class);
standardAttributes.put(ModuleResolution, ModuleResolution_attribute.class);
standardAttributes.put(ModuleTarget, ModuleTarget_attribute.class);
standardAttributes.put(ModuleVersion, ModuleVersion_attribute.class);
standardAttributes.put(RuntimeInvisibleAnnotations, RuntimeInvisibleAnnotations_attribute.class);
standardAttributes.put(RuntimeInvisibleParameterAnnotations, RuntimeInvisibleParameterAnnotations_attribute.class);
standardAttributes.put(RuntimeVisibleAnnotations, RuntimeVisibleAnnotations_attribute.class);
@ -191,8 +191,8 @@ public abstract class Attribute {
R visitModuleHashes(ModuleHashes_attribute attr, P p);
R visitModuleMainClass(ModuleMainClass_attribute attr, P p);
R visitModulePackages(ModulePackages_attribute attr, P p);
R visitModuleResolution(ModuleResolution_attribute attr, P p);
R visitModuleTarget(ModuleTarget_attribute attr, P p);
R visitModuleVersion(ModuleVersion_attribute attr, P p);
R visitRuntimeVisibleAnnotations(RuntimeVisibleAnnotations_attribute attr, P p);
R visitRuntimeInvisibleAnnotations(RuntimeInvisibleAnnotations_attribute attr, P p);
R visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations_attribute attr, P p);

View File

@ -38,7 +38,9 @@ import com.sun.tools.classfile.ConstantPool.CONSTANT_Long_info;
import com.sun.tools.classfile.ConstantPool.CONSTANT_MethodHandle_info;
import com.sun.tools.classfile.ConstantPool.CONSTANT_MethodType_info;
import com.sun.tools.classfile.ConstantPool.CONSTANT_Methodref_info;
import com.sun.tools.classfile.ConstantPool.CONSTANT_Module_info;
import com.sun.tools.classfile.ConstantPool.CONSTANT_NameAndType_info;
import com.sun.tools.classfile.ConstantPool.CONSTANT_Package_info;
import com.sun.tools.classfile.ConstantPool.CONSTANT_String_info;
import com.sun.tools.classfile.ConstantPool.CONSTANT_Utf8_info;
import com.sun.tools.classfile.ConstantPool.CPInfo;
@ -242,6 +244,7 @@ public class ClassTranslator
return true;
}
@Override
public CPInfo visitClass(CONSTANT_Class_info info, Map<Object, Object> translations) {
CONSTANT_Class_info info2 = (CONSTANT_Class_info) translations.get(info);
if (info2 == null) {
@ -255,6 +258,7 @@ public class ClassTranslator
return info;
}
@Override
public CPInfo visitDouble(CONSTANT_Double_info info, Map<Object, Object> translations) {
CONSTANT_Double_info info2 = (CONSTANT_Double_info) translations.get(info);
if (info2 == null) {
@ -264,6 +268,7 @@ public class ClassTranslator
return info;
}
@Override
public CPInfo visitFieldref(CONSTANT_Fieldref_info info, Map<Object, Object> translations) {
CONSTANT_Fieldref_info info2 = (CONSTANT_Fieldref_info) translations.get(info);
if (info2 == null) {
@ -277,6 +282,7 @@ public class ClassTranslator
return info;
}
@Override
public CPInfo visitFloat(CONSTANT_Float_info info, Map<Object, Object> translations) {
CONSTANT_Float_info info2 = (CONSTANT_Float_info) translations.get(info);
if (info2 == null) {
@ -286,6 +292,7 @@ public class ClassTranslator
return info;
}
@Override
public CPInfo visitInteger(CONSTANT_Integer_info info, Map<Object, Object> translations) {
CONSTANT_Integer_info info2 = (CONSTANT_Integer_info) translations.get(info);
if (info2 == null) {
@ -295,6 +302,7 @@ public class ClassTranslator
return info;
}
@Override
public CPInfo visitInterfaceMethodref(CONSTANT_InterfaceMethodref_info info, Map<Object, Object> translations) {
CONSTANT_InterfaceMethodref_info info2 = (CONSTANT_InterfaceMethodref_info) translations.get(info);
if (info2 == null) {
@ -308,6 +316,7 @@ public class ClassTranslator
return info;
}
@Override
public CPInfo visitInvokeDynamic(CONSTANT_InvokeDynamic_info info, Map<Object, Object> translations) {
CONSTANT_InvokeDynamic_info info2 = (CONSTANT_InvokeDynamic_info) translations.get(info);
if (info2 == null) {
@ -322,6 +331,7 @@ public class ClassTranslator
return info;
}
@Override
public CPInfo visitLong(CONSTANT_Long_info info, Map<Object, Object> translations) {
CONSTANT_Long_info info2 = (CONSTANT_Long_info) translations.get(info);
if (info2 == null) {
@ -331,19 +341,7 @@ public class ClassTranslator
return info;
}
public CPInfo visitNameAndType(CONSTANT_NameAndType_info info, Map<Object, Object> translations) {
CONSTANT_NameAndType_info info2 = (CONSTANT_NameAndType_info) translations.get(info);
if (info2 == null) {
ConstantPool cp2 = translate(info.cp, translations);
if (cp2 == info.cp)
info2 = info;
else
info2 = new CONSTANT_NameAndType_info(cp2, info.name_index, info.type_index);
translations.put(info, info2);
}
return info;
}
@Override
public CPInfo visitMethodref(CONSTANT_Methodref_info info, Map<Object, Object> translations) {
CONSTANT_Methodref_info info2 = (CONSTANT_Methodref_info) translations.get(info);
if (info2 == null) {
@ -357,6 +355,7 @@ public class ClassTranslator
return info;
}
@Override
public CPInfo visitMethodHandle(CONSTANT_MethodHandle_info info, Map<Object, Object> translations) {
CONSTANT_MethodHandle_info info2 = (CONSTANT_MethodHandle_info) translations.get(info);
if (info2 == null) {
@ -371,6 +370,7 @@ public class ClassTranslator
return info;
}
@Override
public CPInfo visitMethodType(CONSTANT_MethodType_info info, Map<Object, Object> translations) {
CONSTANT_MethodType_info info2 = (CONSTANT_MethodType_info) translations.get(info);
if (info2 == null) {
@ -385,6 +385,49 @@ public class ClassTranslator
return info;
}
@Override
public CPInfo visitModule(CONSTANT_Module_info info, Map<Object, Object> translations) {
CONSTANT_Module_info info2 = (CONSTANT_Module_info) translations.get(info);
if (info2 == null) {
ConstantPool cp2 = translate(info.cp, translations);
if (cp2 == info.cp)
info2 = info;
else
info2 = new CONSTANT_Module_info(cp2, info.name_index);
translations.put(info, info2);
}
return info;
}
@Override
public CPInfo visitNameAndType(CONSTANT_NameAndType_info info, Map<Object, Object> translations) {
CONSTANT_NameAndType_info info2 = (CONSTANT_NameAndType_info) translations.get(info);
if (info2 == null) {
ConstantPool cp2 = translate(info.cp, translations);
if (cp2 == info.cp)
info2 = info;
else
info2 = new CONSTANT_NameAndType_info(cp2, info.name_index, info.type_index);
translations.put(info, info2);
}
return info;
}
@Override
public CPInfo visitPackage(CONSTANT_Package_info info, Map<Object, Object> translations) {
CONSTANT_Package_info info2 = (CONSTANT_Package_info) translations.get(info);
if (info2 == null) {
ConstantPool cp2 = translate(info.cp, translations);
if (cp2 == info.cp)
info2 = info;
else
info2 = new CONSTANT_Package_info(cp2, info.name_index);
translations.put(info, info2);
}
return info;
}
@Override
public CPInfo visitString(CONSTANT_String_info info, Map<Object, Object> translations) {
CONSTANT_String_info info2 = (CONSTANT_String_info) translations.get(info);
if (info2 == null) {
@ -398,6 +441,7 @@ public class ClassTranslator
return info;
}
@Override
public CPInfo visitUtf8(CONSTANT_Utf8_info info, Map<Object, Object> translations) {
CONSTANT_Utf8_info info2 = (CONSTANT_Utf8_info) translations.get(info);
if (info2 == null) {

View File

@ -289,13 +289,6 @@ public class ClassWriter {
return 2;
}
@Override
public Integer visitNameAndType(CONSTANT_NameAndType_info info, ClassOutputStream out) {
out.writeShort(info.name_index);
out.writeShort(info.type_index);
return 1;
}
@Override
public Integer visitMethodHandle(CONSTANT_MethodHandle_info info, ClassOutputStream out) {
out.writeByte(info.reference_kind.tag);
@ -314,6 +307,25 @@ public class ClassWriter {
return writeRef(info, out);
}
@Override
public Integer visitModule(CONSTANT_Module_info info, ClassOutputStream out) {
out.writeShort(info.name_index);
return 1;
}
@Override
public Integer visitNameAndType(CONSTANT_NameAndType_info info, ClassOutputStream out) {
out.writeShort(info.name_index);
out.writeShort(info.type_index);
return 1;
}
@Override
public Integer visitPackage(CONSTANT_Package_info info, ClassOutputStream out) {
out.writeShort(info.name_index);
return 1;
}
@Override
public Integer visitString(CONSTANT_String_info info, ClassOutputStream out) {
out.writeShort(info.string_index);
@ -424,14 +436,6 @@ public class ClassWriter {
return null;
}
@Override
public Void visitModulePackages(ModulePackages_attribute attr, ClassOutputStream out) {
out.writeShort(attr.packages_count);
for (int i: attr.packages_index)
out.writeShort(i);
return null;
}
@Override
public Void visitConstantValue(ConstantValue_attribute attr, ClassOutputStream out) {
out.writeShort(attr.constantvalue_index);
@ -466,20 +470,6 @@ public class ClassWriter {
return null;
}
@Override
public Void visitModuleHashes(ModuleHashes_attribute attr, ClassOutputStream out) {
out.writeShort(attr.algorithm_index);
out.writeShort(attr.hashes_table.length);
for (ModuleHashes_attribute.Entry e: attr.hashes_table) {
out.writeShort(e.module_name_index);
out.writeShort(e.hash.length);
for (byte b: e.hash) {
out.writeByte(b);
}
}
return null;
}
protected void writeInnerClassesInfo(InnerClasses_attribute.Info info, ClassOutputStream out) {
out.writeShort(info.inner_class_info_index);
out.writeShort(info.outer_class_info_index);
@ -542,21 +532,17 @@ public class ClassWriter {
return null;
}
@Override
public Void visitModuleMainClass(ModuleMainClass_attribute attr, ClassOutputStream out) {
out.writeShort(attr.main_class_index);
return null;
}
@Override
public Void visitModule(Module_attribute attr, ClassOutputStream out) {
out.writeShort(attr.module_name);
out.writeShort(attr.module_flags);
out.writeShort(attr.module_version_index);
out.writeShort(attr.requires.length);
for (Module_attribute.RequiresEntry e: attr.requires) {
out.writeShort(e.requires_index);
out.writeShort(e.requires_flags);
out.writeShort(e.requires_version_index);
}
out.writeShort(attr.exports.length);
@ -595,8 +581,44 @@ public class ClassWriter {
}
@Override
public Void visitRuntimeVisibleAnnotations(RuntimeVisibleAnnotations_attribute attr, ClassOutputStream out) {
annotationWriter.write(attr.annotations, out);
public Void visitModuleHashes(ModuleHashes_attribute attr, ClassOutputStream out) {
out.writeShort(attr.algorithm_index);
out.writeShort(attr.hashes_table.length);
for (ModuleHashes_attribute.Entry e: attr.hashes_table) {
out.writeShort(e.module_name_index);
out.writeShort(e.hash.length);
for (byte b: e.hash) {
out.writeByte(b);
}
}
return null;
}
@Override
public Void visitModuleMainClass(ModuleMainClass_attribute attr, ClassOutputStream out) {
out.writeShort(attr.main_class_index);
return null;
}
@Override
public Void visitModulePackages(ModulePackages_attribute attr, ClassOutputStream out) {
out.writeShort(attr.packages_count);
for (int i: attr.packages_index)
out.writeShort(i);
return null;
}
@Override
public Void visitModuleResolution(ModuleResolution_attribute attr, ClassOutputStream out) {
out.writeShort(attr.resolution_flags);
return null;
}
@Override
public Void visitModuleTarget(ModuleTarget_attribute attr, ClassOutputStream out) {
out.writeShort(attr.os_name_index);
out.writeShort(attr.os_arch_index);
out.writeShort(attr.os_version_index);
return null;
}
@ -607,8 +629,10 @@ public class ClassWriter {
}
@Override
public Void visitRuntimeVisibleTypeAnnotations(RuntimeVisibleTypeAnnotations_attribute attr, ClassOutputStream out) {
annotationWriter.write(attr.annotations, out);
public Void visitRuntimeInvisibleParameterAnnotations(RuntimeInvisibleParameterAnnotations_attribute attr, ClassOutputStream out) {
out.writeByte(attr.parameter_annotations.length);
for (Annotation[] annos: attr.parameter_annotations)
annotationWriter.write(annos, out);
return null;
}
@ -618,6 +642,12 @@ public class ClassWriter {
return null;
}
@Override
public Void visitRuntimeVisibleAnnotations(RuntimeVisibleAnnotations_attribute attr, ClassOutputStream out) {
annotationWriter.write(attr.annotations, out);
return null;
}
@Override
public Void visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations_attribute attr, ClassOutputStream out) {
out.writeByte(attr.parameter_annotations.length);
@ -627,10 +657,8 @@ public class ClassWriter {
}
@Override
public Void visitRuntimeInvisibleParameterAnnotations(RuntimeInvisibleParameterAnnotations_attribute attr, ClassOutputStream out) {
out.writeByte(attr.parameter_annotations.length);
for (Annotation[] annos: attr.parameter_annotations)
annotationWriter.write(annos, out);
public Void visitRuntimeVisibleTypeAnnotations(RuntimeVisibleTypeAnnotations_attribute attr, ClassOutputStream out) {
annotationWriter.write(attr.annotations, out);
return null;
}
@ -685,24 +713,10 @@ public class ClassWriter {
return null;
}
@Override
public Void visitModuleTarget(ModuleTarget_attribute attr, ClassOutputStream out) {
out.writeShort(attr.os_name_index);
out.writeShort(attr.os_arch_index);
out.writeShort(attr.os_version_index);
return null;
}
protected void writeAccessFlags(AccessFlags flags, ClassOutputStream p) {
sharedOut.writeShort(flags.flags);
}
@Override
public Void visitModuleVersion(ModuleVersion_attribute attr, ClassOutputStream out) {
out.writeShort(attr.version_index);
return null;
}
protected StackMapTableWriter stackMapWriter;
}

View File

@ -117,6 +117,8 @@ public class ConstantPool {
public static final int CONSTANT_MethodHandle = 15;
public static final int CONSTANT_MethodType = 16;
public static final int CONSTANT_InvokeDynamic = 18;
public static final int CONSTANT_Module = 19;
public static final int CONSTANT_Package = 20;
public static enum RefKind {
REF_getField(1),
@ -213,10 +215,18 @@ public class ConstantPool {
pool[i] = new CONSTANT_Methodref_info(this, cr);
break;
case CONSTANT_Module:
pool[i] = new CONSTANT_Module_info(this, cr);
break;
case CONSTANT_NameAndType:
pool[i] = new CONSTANT_NameAndType_info(this, cr);
break;
case CONSTANT_Package:
pool[i] = new CONSTANT_Package_info(this, cr);
break;
case CONSTANT_String:
pool[i] = new CONSTANT_String_info(this, cr);
break;
@ -276,10 +286,18 @@ public class ConstantPool {
return ((CONSTANT_Class_info) get(index, CONSTANT_Class));
}
public CONSTANT_Module_info getModuleInfo(int index) throws InvalidIndex, UnexpectedEntry {
return ((CONSTANT_Module_info) get(index, CONSTANT_Module));
}
public CONSTANT_NameAndType_info getNameAndTypeInfo(int index) throws InvalidIndex, UnexpectedEntry {
return ((CONSTANT_NameAndType_info) get(index, CONSTANT_NameAndType));
}
public CONSTANT_Package_info getPackageInfo(int index) throws InvalidIndex, UnexpectedEntry {
return ((CONSTANT_Package_info) get(index, CONSTANT_Package));
}
public String getUTF8Value(int index) throws InvalidIndex, UnexpectedEntry {
return getUTF8Info(index).value;
}
@ -339,10 +357,12 @@ public class ConstantPool {
R visitInterfaceMethodref(CONSTANT_InterfaceMethodref_info info, P p);
R visitInvokeDynamic(CONSTANT_InvokeDynamic_info info, P p);
R visitLong(CONSTANT_Long_info info, P p);
R visitNameAndType(CONSTANT_NameAndType_info info, P p);
R visitMethodref(CONSTANT_Methodref_info info, P p);
R visitMethodHandle(CONSTANT_MethodHandle_info info, P p);
R visitMethodType(CONSTANT_MethodType_info info, P p);
R visitModule(CONSTANT_Module_info info, P p);
R visitNameAndType(CONSTANT_NameAndType_info info, P p);
R visitPackage(CONSTANT_Package_info info, P p);
R visitString(CONSTANT_String_info info, P p);
R visitUtf8(CONSTANT_Utf8_info info, P p);
}
@ -781,6 +801,46 @@ public class ConstantPool {
}
}
public static class CONSTANT_Module_info extends CPInfo {
CONSTANT_Module_info(ConstantPool cp, ClassReader cr) throws IOException {
super(cp);
name_index = cr.readUnsignedShort();
}
public CONSTANT_Module_info(ConstantPool cp, int name_index) {
super(cp);
this.name_index = name_index;
}
public int getTag() {
return CONSTANT_Module;
}
public int byteLength() {
return 3;
}
/**
* Get the raw value of the module name referenced by this constant pool entry.
* This will be the name of the module.
* @return the raw value of the module name
*/
public String getName() throws ConstantPoolException {
return cp.getUTF8Value(name_index);
}
@Override
public String toString() {
return "CONSTANT_Module_info[name_index: " + name_index + "]";
}
public <R, D> R accept(Visitor<R, D> visitor, D data) {
return visitor.visitModule(this, data);
}
public final int name_index;
}
public static class CONSTANT_NameAndType_info extends CPInfo {
CONSTANT_NameAndType_info(ConstantPool cp, ClassReader cr) throws IOException {
super(cp);
@ -823,6 +883,46 @@ public class ConstantPool {
public final int type_index;
}
public static class CONSTANT_Package_info extends CPInfo {
CONSTANT_Package_info(ConstantPool cp, ClassReader cr) throws IOException {
super(cp);
name_index = cr.readUnsignedShort();
}
public CONSTANT_Package_info(ConstantPool cp, int name_index) {
super(cp);
this.name_index = name_index;
}
public int getTag() {
return CONSTANT_Package;
}
public int byteLength() {
return 3;
}
/**
* Get the raw value of the package name referenced by this constant pool entry.
* This will be the name of the package, in internal form.
* @return the raw value of the module name
*/
public String getName() throws ConstantPoolException {
return cp.getUTF8Value(name_index);
}
@Override
public String toString() {
return "CONSTANT_Package_info[name_index: " + name_index + "]";
}
public <R, D> R accept(Visitor<R, D> visitor, D data) {
return visitor.visitPackage(this, data);
}
public final int name_index;
}
public static class CONSTANT_String_info extends CPInfo {
CONSTANT_String_info(ConstantPool cp, ClassReader cr) throws IOException {
super(cp);

View File

@ -708,6 +708,10 @@ public class Dependencies {
return visitRef(info, p);
}
public Void visitModule(CONSTANT_Module_info info, Void p) {
return null;
}
public Void visitNameAndType(CONSTANT_NameAndType_info info, Void p) {
try {
new Signature(info.type_index).getType(constant_pool).accept(this, null);
@ -717,6 +721,10 @@ public class Dependencies {
}
}
public Void visitPackage(CONSTANT_Package_info info, Void p) {
return null;
}
public Void visitString(CONSTANT_String_info info, Void p) {
return null;
}

View File

@ -27,6 +27,8 @@ package com.sun.tools.classfile;
import java.io.IOException;
import com.sun.tools.classfile.ConstantPool.CONSTANT_Package_info;
/**
* See JVMS, section 4.8.15.
*
@ -61,7 +63,8 @@ public class ModulePackages_attribute extends Attribute {
public String getPackage(int index, ConstantPool constant_pool) throws ConstantPoolException {
int package_index = packages_index[index];
return constant_pool.getUTF8Value(package_index);
CONSTANT_Package_info info = constant_pool.getPackageInfo(package_index);
return info.getName();
}
@Override

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -35,26 +35,35 @@ import java.io.IOException;
* This code and its internal interfaces are subject to change or
* deletion without notice.</b>
*/
public class ModuleVersion_attribute extends Attribute {
ModuleVersion_attribute(ClassReader cr, int name_index, int length) throws IOException {
public class ModuleResolution_attribute extends Attribute {
public static final int DO_NOT_RESOLVE_BY_DEFAULT = 0x0001;
public static final int WARN_DEPRECATED = 0x0002;
public static final int WARN_DEPRECATED_FOR_REMOVAL = 0x0004;
public static final int WARN_INCUBATING = 0x0008;
ModuleResolution_attribute(ClassReader cr, int name_index, int length)
throws IOException {
super(name_index, length);
version_index = cr.readUnsignedShort();
resolution_flags = cr.readUnsignedShort();
}
public ModuleVersion_attribute(ConstantPool constant_pool, int version_index)
public ModuleResolution_attribute(ConstantPool constant_pool,
int resolution_flags)
throws ConstantPoolException {
this(constant_pool.getUTF8Index(Attribute.ModuleVersion), version_index);
this(constant_pool.getUTF8Index(Attribute.ModulePackages),
resolution_flags);
}
public ModuleVersion_attribute(int name_index, int version_index) {
public ModuleResolution_attribute(int name_index,
int resolution_flags) {
super(name_index, 2);
this.version_index = version_index;
this.resolution_flags = resolution_flags;
}
@Override
public <R, D> R accept(Visitor<R, D> visitor, D data) {
return visitor.visitModuleVersion(this, data);
return visitor.visitModuleResolution(this, data);
}
public final int version_index;
public final int resolution_flags;
}

View File

@ -27,6 +27,8 @@ package com.sun.tools.classfile;
import java.io.IOException;
import com.sun.tools.classfile.ConstantPool.CONSTANT_Module_info;
/**
* See Jigsaw.
*
@ -48,6 +50,8 @@ public class Module_attribute extends Attribute {
module_name = cr.readUnsignedShort();
module_flags = cr.readUnsignedShort();
module_version_index = cr.readUnsignedShort();
requires_count = cr.readUnsignedShort();
requires = new RequiresEntry[requires_count];
for (int i = 0; i < requires_count; i++)
@ -77,6 +81,7 @@ public class Module_attribute extends Attribute {
public Module_attribute(int name_index,
int module_name,
int module_flags,
int module_version_index,
RequiresEntry[] requires,
ExportsEntry[] exports,
OpensEntry[] opens,
@ -85,6 +90,7 @@ public class Module_attribute extends Attribute {
super(name_index, 2);
this.module_name = module_name;
this.module_flags = module_flags;
this.module_version_index = module_version_index;
requires_count = requires.length;
this.requires = requires;
exports_count = exports.length;
@ -109,6 +115,7 @@ public class Module_attribute extends Attribute {
public final int module_name;
public final int module_flags;
public final int module_version_index;
public final int requires_count;
public final RequiresEntry[] requires;
public final int exports_count;
@ -124,21 +131,25 @@ public class Module_attribute extends Attribute {
RequiresEntry(ClassReader cr) throws IOException {
requires_index = cr.readUnsignedShort();
requires_flags = cr.readUnsignedShort();
requires_version_index = cr.readUnsignedShort();
}
public RequiresEntry(int index, int flags) {
public RequiresEntry(int index, int flags, int version_index) {
this.requires_index = index;
this.requires_flags = flags;
this.requires_version_index = version_index;
}
public String getRequires(ConstantPool constant_pool) throws ConstantPoolException {
return constant_pool.getUTF8Value(requires_index);
CONSTANT_Module_info info = constant_pool.getModuleInfo(requires_index);
return info.getName();
}
public static final int length = 4;
public final int requires_index;
public final int requires_flags;
public final int requires_version_index;
}
public static class ExportsEntry {

View File

@ -136,14 +136,6 @@ public final class ReferenceFinder {
return false;
}
public Boolean visitInterfaceMethodref(CONSTANT_InterfaceMethodref_info info, ConstantPool cpool) {
return filter.accept(cpool, info);
}
public Boolean visitMethodref(CONSTANT_Methodref_info info, ConstantPool cpool) {
return filter.accept(cpool, info);
}
public Boolean visitFieldref(CONSTANT_Fieldref_info info, ConstantPool cpool) {
return filter.accept(cpool, info);
}
@ -160,6 +152,10 @@ public final class ReferenceFinder {
return false;
}
public Boolean visitInterfaceMethodref(CONSTANT_InterfaceMethodref_info info, ConstantPool cpool) {
return filter.accept(cpool, info);
}
public Boolean visitInvokeDynamic(CONSTANT_InvokeDynamic_info info, ConstantPool cpool) {
return false;
}
@ -168,18 +164,30 @@ public final class ReferenceFinder {
return false;
}
public Boolean visitNameAndType(CONSTANT_NameAndType_info info, ConstantPool cpool) {
return false;
}
public Boolean visitMethodHandle(CONSTANT_MethodHandle_info info, ConstantPool cpool) {
return false;
}
public Boolean visitMethodref(CONSTANT_Methodref_info info, ConstantPool cpool) {
return filter.accept(cpool, info);
}
public Boolean visitMethodType(CONSTANT_MethodType_info info, ConstantPool cpool) {
return false;
}
public Boolean visitModule(CONSTANT_Module_info info, ConstantPool cpool) {
return false;
}
public Boolean visitNameAndType(CONSTANT_NameAndType_info info, ConstantPool cpool) {
return false;
}
public Boolean visitPackage(CONSTANT_Package_info info, ConstantPool cpool) {
return false;
}
public Boolean visitString(CONSTANT_String_info info, ConstantPool cpool) {
return false;
}

View File

@ -51,8 +51,8 @@ import com.sun.tools.classfile.Module_attribute;
import com.sun.tools.classfile.ModuleHashes_attribute;
import com.sun.tools.classfile.ModuleMainClass_attribute;
import com.sun.tools.classfile.ModulePackages_attribute;
import com.sun.tools.classfile.ModuleResolution_attribute;
import com.sun.tools.classfile.ModuleTarget_attribute;
import com.sun.tools.classfile.ModuleVersion_attribute;
import com.sun.tools.classfile.RuntimeInvisibleAnnotations_attribute;
import com.sun.tools.classfile.RuntimeInvisibleParameterAnnotations_attribute;
import com.sun.tools.classfile.RuntimeInvisibleTypeAnnotations_attribute;
@ -237,27 +237,6 @@ public class AttributeWriter extends BasicWriter
return null;
}
private String getJavaPackage(ModulePackages_attribute attr, int index) {
try {
return getJavaName(attr.getPackage(index, constant_pool));
} catch (ConstantPoolException e) {
return report(e);
}
}
@Override
public Void visitModulePackages(ModulePackages_attribute attr, Void ignore) {
println("ModulePackages: ");
indent(+1);
for (int i = 0; i < attr.packages_count; i++) {
print("#" + attr.packages_index[i]);
tab();
println("// " + getJavaPackage(attr, i));
}
indent(-1);
return null;
}
@Override
public Void visitConstantValue(ConstantValue_attribute attr, Void ignore) {
print("ConstantValue: ");
@ -322,39 +301,6 @@ public class AttributeWriter extends BasicWriter
}
}
@Override
public Void visitModuleHashes(ModuleHashes_attribute attr, Void ignore) {
println("ModuleHashes:");
indent(+1);
print("algorithm #" + attr.algorithm_index);
tab();
println("// " + getAlgorithm(attr));
for (ModuleHashes_attribute.Entry e : attr.hashes_table) {
print("#" + e.module_name_index);
tab();
println("// " + getModuleName(e));
println("hash_length: " + e.hash.length);
println("hash: [" + toHex(e.hash) + "]");
}
indent(-1);
return null;
}
private String getAlgorithm(ModuleHashes_attribute attr) {
try {
return constant_pool.getUTF8Value(attr.algorithm_index);
} catch (ConstantPoolException e) {
return report(e);
}
}
private String getModuleName(ModuleHashes_attribute.Entry entry) {
try {
return constant_pool.getUTF8Value(entry.module_name_index);
} catch (ConstantPoolException e) {
return report(e);
}
}
@Override
public Void visitInnerClasses(InnerClasses_attribute attr, Void ignore) {
@ -449,15 +395,6 @@ public class AttributeWriter extends BasicWriter
return null;
}
@Override
public Void visitModuleMainClass(ModuleMainClass_attribute attr, Void ignore) {
print("ModuleMainClass: #" + attr.main_class_index);
tab();
print("// " + getJavaClassName(attr));
println();
return null;
}
private String getJavaClassName(ModuleMainClass_attribute a) {
try {
return getJavaName(a.getMainClassName(constant_pool));
@ -495,13 +432,11 @@ public class AttributeWriter extends BasicWriter
println("Module:");
indent(+1);
print(attr.module_name);
tab();
println("// " + constantWriter.stringValue(attr.module_name));
print("#" + attr.module_name);
print(",");
print(String.format("%x", attr.module_flags));
tab();
print("// ");
print("// " + constantWriter.stringValue(attr.module_name));
if ((attr.module_flags & Module_attribute.ACC_OPEN) != 0)
print(" ACC_OPEN");
if ((attr.module_flags & Module_attribute.ACC_MANDATED) != 0)
@ -509,6 +444,12 @@ public class AttributeWriter extends BasicWriter
if ((attr.module_flags & Module_attribute.ACC_SYNTHETIC) != 0)
print(" ACC_SYNTHETIC");
println();
print("#" + attr.module_version_index);
if (attr.module_version_index != 0) {
tab();
print("// " + constantWriter.stringValue(attr.module_version_index));
}
println();
printRequiresTable(attr);
printExportsTable(attr);
@ -538,6 +479,12 @@ public class AttributeWriter extends BasicWriter
if ((e.requires_flags & Module_attribute.ACC_MANDATED) != 0)
print(" ACC_MANDATED");
println();
print("#" + e.requires_version_index);
if (e.requires_version_index != 0) {
tab();
print("// " + constantWriter.stringValue(e.requires_version_index));
}
println();
}
indent(-1);
}
@ -626,6 +573,145 @@ public class AttributeWriter extends BasicWriter
indent(-1);
}
@Override
public Void visitModuleHashes(ModuleHashes_attribute attr, Void ignore) {
println("ModuleHashes:");
indent(+1);
print("algorithm: #" + attr.algorithm_index);
tab();
println("// " + getAlgorithm(attr));
print(attr.hashes_table_length);
tab();
println("// hashes");
for (ModuleHashes_attribute.Entry e : attr.hashes_table) {
print("#" + e.module_name_index);
tab();
println("// " + getModuleName(e));
println("hash_length: " + e.hash.length);
println("hash: [" + toHex(e.hash) + "]");
}
indent(-1);
return null;
}
private String getAlgorithm(ModuleHashes_attribute attr) {
try {
return constant_pool.getUTF8Value(attr.algorithm_index);
} catch (ConstantPoolException e) {
return report(e);
}
}
private String getModuleName(ModuleHashes_attribute.Entry entry) {
try {
int utf8Index = constant_pool.getModuleInfo(entry.module_name_index).name_index;
return constant_pool.getUTF8Value(utf8Index);
} catch (ConstantPoolException e) {
return report(e);
}
}
@Override
public Void visitModuleMainClass(ModuleMainClass_attribute attr, Void ignore) {
print("ModuleMainClass: #" + attr.main_class_index);
tab();
print("// " + getJavaClassName(attr));
println();
return null;
}
@Override
public Void visitModulePackages(ModulePackages_attribute attr, Void ignore) {
println("ModulePackages: ");
indent(+1);
for (int i = 0; i < attr.packages_count; i++) {
print("#" + attr.packages_index[i]);
tab();
println("// " + getJavaPackage(attr, i));
}
indent(-1);
return null;
}
private String getJavaPackage(ModulePackages_attribute attr, int index) {
try {
return getJavaName(attr.getPackage(index, constant_pool));
} catch (ConstantPoolException e) {
return report(e);
}
}
@Override
public Void visitModuleResolution(ModuleResolution_attribute attr, Void ignore) {
println("ModuleResolution:");
indent(+1);
print(String.format("%x", attr.resolution_flags));
tab();
print("// ");
int flags = attr.resolution_flags;
if ((flags & ModuleResolution_attribute.DO_NOT_RESOLVE_BY_DEFAULT) != 0)
print(" DO_NOT_RESOLVE_BY_DEFAULT");
if ((flags & ModuleResolution_attribute.WARN_DEPRECATED) != 0)
print(" WARN_DEPRECATED");
if ((flags & ModuleResolution_attribute.WARN_DEPRECATED_FOR_REMOVAL) != 0)
print(" WARN_DEPRECATED_FOR_REMOVAL");
if ((flags & ModuleResolution_attribute.WARN_INCUBATING) != 0)
print(" WARN_INCUBATING");
println();
indent(-1);
return null;
}
@Override
public Void visitModuleTarget(ModuleTarget_attribute attr, Void ignore) {
println("ModuleTarget:");
indent(+1);
print("os_name: #" + attr.os_name_index);
if (attr.os_name_index != 0) {
tab();
print("// " + getOSName(attr));
}
println();
print("os_arch: #" + attr.os_arch_index);
if (attr.os_arch_index != 0) {
tab();
print("// " + getOSArch(attr));
}
println();
print("os_version: #" + attr.os_version_index);
if (attr.os_version_index != 0) {
tab();
print("// " + getOSVersion(attr));
}
println();
indent(-1);
return null;
}
private String getOSName(ModuleTarget_attribute attr) {
try {
return constant_pool.getUTF8Value(attr.os_name_index);
} catch (ConstantPoolException e) {
return report(e);
}
}
private String getOSArch(ModuleTarget_attribute attr) {
try {
return constant_pool.getUTF8Value(attr.os_arch_index);
} catch (ConstantPoolException e) {
return report(e);
}
}
private String getOSVersion(ModuleTarget_attribute attr) {
try {
return constant_pool.getUTF8Value(attr.os_version_index);
} catch (ConstantPoolException e) {
return report(e);
}
}
@Override
public Void visitRuntimeVisibleAnnotations(RuntimeVisibleAnnotations_attribute attr, Void ignore) {
println("RuntimeVisibleAnnotations:");
@ -929,74 +1015,6 @@ public class AttributeWriter extends BasicWriter
return null;
}
@Override
public Void visitModuleTarget(ModuleTarget_attribute attr, Void ignore) {
println("ModuleTarget:");
indent(+1);
print("os_name: #" + attr.os_name_index);
if (attr.os_name_index != 0) {
tab();
print("// " + getOSName(attr));
}
println();
print("os_arch: #" + attr.os_arch_index);
if (attr.os_arch_index != 0) {
tab();
print("// " + getOSArch(attr));
}
println();
print("os_version: #" + attr.os_version_index);
if (attr.os_version_index != 0) {
tab();
print("// " + getOSVersion(attr));
}
println();
indent(-1);
return null;
}
private String getOSName(ModuleTarget_attribute attr) {
try {
return constant_pool.getUTF8Value(attr.os_name_index);
} catch (ConstantPoolException e) {
return report(e);
}
}
private String getOSArch(ModuleTarget_attribute attr) {
try {
return constant_pool.getUTF8Value(attr.os_arch_index);
} catch (ConstantPoolException e) {
return report(e);
}
}
private String getOSVersion(ModuleTarget_attribute attr) {
try {
return constant_pool.getUTF8Value(attr.os_version_index);
} catch (ConstantPoolException e) {
return report(e);
}
}
@Override
public Void visitModuleVersion(ModuleVersion_attribute attr, Void ignore) {
print("ModuleVersion: #" + attr.version_index);
indent(+1);
tab();
println("// " + getVersion(attr));
indent(-1);
return null;
}
private String getVersion(ModuleVersion_attribute attr) {
try {
return constant_pool.getUTF8Value(attr.version_index);
} catch (ConstantPoolException e) {
return report(e);
}
}
static String getJavaName(String name) {
return name.replace('/', '.');
}

View File

@ -58,6 +58,8 @@ import com.sun.tools.classfile.Type.TypeParamType;
import com.sun.tools.classfile.Type.WildcardType;
import static com.sun.tools.classfile.AccessFlags.*;
import static com.sun.tools.classfile.ConstantPool.CONSTANT_Module;
import static com.sun.tools.classfile.ConstantPool.CONSTANT_Package;
/*
* The main javap class to write the contents of a class file as text.
@ -166,7 +168,12 @@ public class ClassWriter extends BasicWriter {
Module_attribute modAttr = (Module_attribute) attr;
String name;
try {
name = getJavaName(constant_pool.getUTF8Value(modAttr.module_name));
// FIXME: compatibility code
if (constant_pool.get(modAttr.module_name).getTag() == CONSTANT_Module) {
name = getJavaName(constant_pool.getModuleInfo(modAttr.module_name).getName());
} else {
name = getJavaName(constant_pool.getUTF8Value(modAttr.module_name));
}
} catch (ConstantPoolException e) {
name = report(e);
}
@ -175,6 +182,10 @@ public class ClassWriter extends BasicWriter {
}
print("module ");
print(name);
if (modAttr.module_version_index != 0) {
print("@");
print(getUTF8Value(modAttr.module_version_index));
}
} else {
// fallback for malformed class files
print("class ");
@ -602,19 +613,31 @@ public class ClassWriter extends BasicWriter {
if ((entry.requires_flags & Module_attribute.ACC_TRANSITIVE) != 0)
print(" transitive");
print(" ");
print(getUTF8Value(entry.requires_index).replace('/', '.'));
String mname;
try {
mname = getModuleName(entry.requires_index);
} catch (ConstantPoolException e) {
mname = report(e);
}
print(mname);
println(";");
}
for (Module_attribute.ExportsEntry entry: m.exports) {
print("exports");
print(" ");
print(getUTF8Value(entry.exports_index).replace('/', '.'));
String pname;
try {
pname = getPackageName(entry.exports_index).replace('/', '.');
} catch (ConstantPoolException e) {
pname = report(e);
}
print(pname);
boolean first = true;
for (int i: entry.exports_to_index) {
String mname;
try {
mname = classFile.constant_pool.getUTF8Value(i).replace('/', '.');
mname = getModuleName(i);
} catch (ConstantPoolException e) {
mname = report(e);
}
@ -635,12 +658,18 @@ public class ClassWriter extends BasicWriter {
for (Module_attribute.OpensEntry entry: m.opens) {
print("opens");
print(" ");
print(getUTF8Value(entry.opens_index).replace('/', '.'));
String pname;
try {
pname = getPackageName(entry.opens_index).replace('/', '.');
} catch (ConstantPoolException e) {
pname = report(e);
}
print(pname);
boolean first = true;
for (int i: entry.opens_to_index) {
String mname;
try {
mname = classFile.constant_pool.getUTF8Value(i).replace('/', '.');
mname = getModuleName(i);
} catch (ConstantPoolException e) {
mname = report(e);
}
@ -684,6 +713,22 @@ public class ClassWriter extends BasicWriter {
}
}
String getModuleName(int index) throws ConstantPoolException {
if (constant_pool.get(index).getTag() == CONSTANT_Module) {
return constant_pool.getModuleInfo(index).getName();
} else {
return constant_pool.getUTF8Value(index);
}
}
String getPackageName(int index) throws ConstantPoolException {
if (constant_pool.get(index).getTag() == CONSTANT_Package) {
return constant_pool.getPackageInfo(index).getName();
} else {
return constant_pool.getUTF8Value(index);
}
}
String getUTF8Value(int index) {
try {
return classFile.constant_pool.getUTF8Value(index);

View File

@ -109,13 +109,6 @@ public class ConstantWriter extends BasicWriter {
return 2;
}
public Integer visitNameAndType(CONSTANT_NameAndType_info info, Void p) {
print("#" + info.name_index + ":#" + info.type_index);
tab();
println("// " + stringValue(info));
return 1;
}
public Integer visitMethodref(CONSTANT_Methodref_info info, Void p) {
print("#" + info.class_index + ".#" + info.name_and_type_index);
tab();
@ -137,6 +130,27 @@ public class ConstantWriter extends BasicWriter {
return 1;
}
public Integer visitModule(CONSTANT_Module_info info, Void p) {
print("#" + info.name_index);
tab();
println("// " + stringValue(info));
return 1;
}
public Integer visitNameAndType(CONSTANT_NameAndType_info info, Void p) {
print("#" + info.name_index + ":#" + info.type_index);
tab();
println("// " + stringValue(info));
return 1;
}
public Integer visitPackage(CONSTANT_Package_info info, Void p) {
print("#" + info.name_index);
tab();
println("// " + stringValue(info));
return 1;
}
public Integer visitString(CONSTANT_String_info info, Void p) {
print("#" + info.string_index);
tab();
@ -304,6 +318,14 @@ public class ConstantWriter extends BasicWriter {
return info.value + "l";
}
public String visitModule(CONSTANT_Module_info info, Void p) {
try {
return checkName(info.getName());
} catch (ConstantPoolException e) {
return report(e);
}
}
public String visitNameAndType(CONSTANT_NameAndType_info info, Void p) {
return getCheckedName(info) + ":" + getType(info);
}
@ -316,6 +338,14 @@ public class ConstantWriter extends BasicWriter {
}
}
public String visitPackage(CONSTANT_Package_info info, Void p) {
try {
return checkName(info.getName());
} catch (ConstantPoolException e) {
return report(e);
}
}
String getType(CONSTANT_NameAndType_info info) {
try {
return info.getType();

View File

@ -75,11 +75,6 @@ class CPSelector implements ConstantPool.Visitor<Void,CPEntries> {
return null;
}
@Override
public Void visitNameAndType(ConstantPool.CONSTANT_NameAndType_info info, CPEntries p) {
return null;
}
@Override
public Void visitMethodref(ConstantPool.CONSTANT_Methodref_info info, CPEntries p) {
p.methodRefs.add(info);
@ -96,6 +91,21 @@ class CPSelector implements ConstantPool.Visitor<Void,CPEntries> {
return null;
}
@Override
public Void visitModule(ConstantPool.CONSTANT_Module_info info, CPEntries p) {
return null;
}
@Override
public Void visitNameAndType(ConstantPool.CONSTANT_NameAndType_info info, CPEntries p) {
return null;
}
@Override
public Void visitPackage(ConstantPool.CONSTANT_Package_info info, CPEntries p) {
return null;
}
@Override
public Void visitString(ConstantPool.CONSTANT_String_info info, CPEntries p) {
return null;

View File

@ -416,7 +416,12 @@ public class JdepsConfiguration implements AutoCloseable {
}
};
return new ModuleReference(descriptor, uri, readerSupplier);
return new ModuleReference(descriptor, uri) {
@Override
public ModuleReader open() {
return readerSupplier.get();
}
};
} catch (IOException e) {
throw new UncheckedIOException(e);
}

View File

@ -45,8 +45,8 @@ public class TestModules extends JavadocTester {
void testHtml4() {
javadoc("-d", "out", "-use",
"--module-source-path", testSrc,
"--add-modules", "module1,module2",
"testpkgmdl1", "testpkgmdl2");
"--add-modules", "moduleA,moduleB",
"testpkgmdlA", "testpkgmdlB");
checkExit(Exit.OK);
checkDescription(true);
checkNoDescription(false);
@ -66,8 +66,8 @@ public class TestModules extends JavadocTester {
void testHtml5() {
javadoc("-d", "out-html5", "-html5", "-use",
"--module-source-path", testSrc,
"--add-modules", "module1,module2",
"testpkgmdl1", "testpkgmdl2");
"--add-modules", "moduleA,moduleB",
"testpkgmdlA", "testpkgmdlB");
checkExit(Exit.OK);
checkHtml5Description(true);
checkHtml5NoDescription(false);
@ -87,8 +87,8 @@ public class TestModules extends JavadocTester {
void testHtml4NoComment() {
javadoc("-d", "out-nocomment", "-nocomment", "-use",
"--module-source-path", testSrc,
"--add-modules", "module1,module2",
"testpkgmdl1", "testpkgmdl2");
"--add-modules", "moduleA,moduleB",
"testpkgmdlA", "testpkgmdlB");
checkExit(Exit.OK);
checkDescription(false);
checkNoDescription(true);
@ -104,8 +104,8 @@ public class TestModules extends JavadocTester {
void testHtml5NoComment() {
javadoc("-d", "out-html5-nocomment", "-nocomment", "-html5", "-use",
"--module-source-path", testSrc,
"--add-modules", "module1,module2",
"testpkgmdl1", "testpkgmdl2");
"--add-modules", "moduleA,moduleB",
"testpkgmdlA", "testpkgmdlB");
checkExit(Exit.OK);
checkHtml5Description(false);
checkHtml5NoDescription(true);
@ -154,8 +154,8 @@ public class TestModules extends JavadocTester {
"-tag", "regular:a:Regular Tag:",
"-tag", "moduletag:s:Module Tag:",
"--module-source-path", testSrc,
"--add-modules", "moduletags,module2",
"testpkgmdltags", "testpkgmdl2");
"--add-modules", "moduletags,moduleB",
"testpkgmdltags", "testpkgmdlB");
checkExit(Exit.OK);
checkModuleTags();
}
@ -167,8 +167,8 @@ public class TestModules extends JavadocTester {
void testModuleSummary() {
javadoc("-d", "out-moduleSummary", "-use",
"--module-source-path", testSrc,
"--add-modules", "module1,module2",
"testpkgmdl1", "testpkgmdl2", "module2/testpkg2mdl2");
"--add-modules", "moduleA,moduleB",
"testpkgmdlA", "testpkgmdlB", "moduleB/testpkg2mdlB");
checkExit(Exit.OK);
checkModuleSummary();
checkNegatedModuleSummary();
@ -181,8 +181,8 @@ public class TestModules extends JavadocTester {
void testModuleFilesAndLinks() {
javadoc("-d", "out-modulelinks",
"--module-source-path", testSrc,
"--add-modules", "module1",
"testpkgmdl1");
"--add-modules", "moduleA",
"testpkgmdlA");
checkExit(Exit.OK);
checkModuleFilesAndLinks(true);
checkNegatedOverviewFrame();
@ -197,8 +197,8 @@ public class TestModules extends JavadocTester {
"-tag", "regular:a:Regular Tag:",
"-tag", "moduletag:s:Module Tag:",
"--module-source-path", testSrc,
"--module", "module1,module2,moduletags",
"testpkgmdl1", "testpkgmdl2", "testpkgmdltags");
"--module", "moduleA,moduleB,moduletags",
"testpkgmdlA", "testpkgmdlB", "testpkgmdltags");
checkExit(Exit.OK);
checkModuleDeprecation(true);
}
@ -210,38 +210,38 @@ public class TestModules extends JavadocTester {
void testModuleAnnotation() {
javadoc("-d", "out-moduleanno",
"--module-source-path", testSrc,
"--module", "module1,module2",
"testpkgmdl1", "testpkgmdl2");
"--module", "moduleA,moduleB",
"testpkgmdlA", "testpkgmdlB");
checkExit(Exit.OK);
checkModuleAnnotation();
}
void checkDescription(boolean found) {
checkOutput("module1-summary.html", found,
checkOutput("moduleA-summary.html", found,
"<!-- ============ MODULE DESCRIPTION =========== -->\n"
+ "<a name=\"module.description\">\n"
+ "<!-- -->\n"
+ "</a>\n"
+ "<div class=\"block\">This is a test description for the module1 module. Search "
+ "<div class=\"block\">This is a test description for the moduleA module. Search "
+ "phrase <a id=\"searchphrase\">search phrase</a>.</div>");
checkOutput("module2-summary.html", found,
checkOutput("moduleB-summary.html", found,
"<!-- ============ MODULE DESCRIPTION =========== -->\n"
+ "<a name=\"module.description\">\n"
+ "<!-- -->\n"
+ "</a>\n"
+ "<div class=\"block\">This is a test description for the module2 module. Search "
+ "<div class=\"block\">This is a test description for the moduleB module. Search "
+ "word <a id=\"search_word\">search_word</a> with no description.</div>");
}
void checkNoDescription(boolean found) {
checkOutput("module1-summary.html", found,
checkOutput("moduleA-summary.html", found,
"<div class=\"contentContainer\">\n"
+ "<ul class=\"blockList\">\n"
+ "<li class=\"blockList\">\n"
+ "<ul class=\"blockList\">\n"
+ "<li class=\"blockList\">\n"
+ "<!-- ============ MODULES SUMMARY =========== -->");
checkOutput("module2-summary.html", found,
checkOutput("moduleB-summary.html", found,
"<div class=\"contentContainer\">\n"
+ "<ul class=\"blockList\">\n"
+ "<li class=\"blockList\">\n"
@ -251,7 +251,7 @@ public class TestModules extends JavadocTester {
}
void checkHtml5Description(boolean found) {
checkOutput("module1-summary.html", found,
checkOutput("moduleA-summary.html", found,
"<section role=\"region\">\n"
+ "<div class=\"deprecatedContent\"><span class=\"deprecatedLabel\">Deprecated, for removal:"
+ " This API element is subject to removal in a future version. </span>\n"
@ -261,27 +261,27 @@ public class TestModules extends JavadocTester {
+ "<a id=\"module.description\">\n"
+ "<!-- -->\n"
+ "</a>\n"
+ "<div class=\"block\">This is a test description for the module1 module. Search "
+ "<div class=\"block\">This is a test description for the moduleA module. Search "
+ "phrase <a id=\"searchphrase\">search phrase</a>.</div>");
checkOutput("module2-summary.html", found,
checkOutput("moduleB-summary.html", found,
"<section role=\"region\">\n"
+ "<!-- ============ MODULE DESCRIPTION =========== -->\n"
+ "<a id=\"module.description\">\n"
+ "<!-- -->\n"
+ "</a>\n"
+ "<div class=\"block\">This is a test description for the module2 module. Search "
+ "<div class=\"block\">This is a test description for the moduleB module. Search "
+ "word <a id=\"search_word\">search_word</a> with no description.</div>");
}
void checkHtml5NoDescription(boolean found) {
checkOutput("module1-summary.html", found,
checkOutput("moduleA-summary.html", found,
"<div class=\"contentContainer\">\n"
+ "<ul class=\"blockList\">\n"
+ "<li class=\"blockList\">\n"
+ "<ul class=\"blockList\">\n"
+ "<li class=\"blockList\">\n"
+ "<!-- ============ MODULES SUMMARY =========== -->");
checkOutput("module2-summary.html", found,
checkOutput("moduleB-summary.html", found,
"<div class=\"contentContainer\">\n"
+ "<ul class=\"blockList\">\n"
+ "<li class=\"blockList\">\n"
@ -293,18 +293,18 @@ public class TestModules extends JavadocTester {
void checkModuleLink() {
checkOutput("overview-summary.html", true,
"<li>Module</li>");
checkOutput("module1-summary.html", true,
checkOutput("moduleA-summary.html", true,
"<li class=\"navBarCell1Rev\">Module</li>");
checkOutput("module2-summary.html", true,
checkOutput("moduleB-summary.html", true,
"<li class=\"navBarCell1Rev\">Module</li>");
checkOutput("testpkgmdl1/class-use/TestClassInModule1.html", true,
"<li><a href=\"../../module1-summary.html\">Module</a></li>");
checkOutput("testpkgmdl2/package-summary.html", true,
"<li><a href=\"../module2-summary.html\">Module</a></li>");
checkOutput("testpkgmdl2/TestClassInModule2.html", true,
"<li><a href=\"../module2-summary.html\">Module</a></li>");
checkOutput("testpkgmdl2/class-use/TestClassInModule2.html", true,
"<li><a href=\"../../module2-summary.html\">Module</a></li>");
checkOutput("testpkgmdlA/class-use/TestClassInModuleA.html", true,
"<li><a href=\"../../moduleA-summary.html\">Module</a></li>");
checkOutput("testpkgmdlB/package-summary.html", true,
"<li><a href=\"../moduleB-summary.html\">Module</a></li>");
checkOutput("testpkgmdlB/TestClassInModuleB.html", true,
"<li><a href=\"../moduleB-summary.html\">Module</a></li>");
checkOutput("testpkgmdlB/class-use/TestClassInModuleB.html", true,
"<li><a href=\"../../moduleB-summary.html\">Module</a></li>");
}
void checkNoModuleLink() {
@ -422,102 +422,102 @@ public class TestModules extends JavadocTester {
}
void checkModuleSummary() {
checkOutput("module1-summary.html", true,
checkOutput("moduleA-summary.html", true,
"<ul class=\"subNavList\">\n"
+ "<li>Module:&nbsp;</li>\n"
+ "<li><a href=\"#module.description\">Description</a>&nbsp;|&nbsp;<a "
+ "href=\"#modules.summary\">Modules</a>&nbsp;|&nbsp;<a href=\"#packages.summary\">"
+ "Packages</a>&nbsp;|&nbsp;Services</li>\n"
+ "</ul>");
checkOutput("module1-summary.html", true,
checkOutput("moduleA-summary.html", true,
"<!-- ============ MODULES SUMMARY =========== -->\n"
+ "<a name=\"modules.summary\">\n"
+ "<!-- -->\n"
+ "</a>");
checkOutput("module1-summary.html", true,
checkOutput("moduleA-summary.html", true,
"<tr class=\"altColor\">\n"
+ "<th class=\"colFirst\" scope=\"row\"><a href=\"testpkgmdl1/package-summary.html\">testpkgmdl1</a></th>\n"
+ "<th class=\"colFirst\" scope=\"row\"><a href=\"testpkgmdlA/package-summary.html\">testpkgmdlA</a></th>\n"
+ "<td class=\"colSecond\">All Modules</td>\n"
+ "<td class=\"colLast\">&nbsp;</td>\n"
+ "</tr>");
checkOutput("module1-summary.html", true,
checkOutput("moduleA-summary.html", true,
"<!-- ============ PACKAGES SUMMARY =========== -->\n"
+ "<a name=\"packages.summary\">\n"
+ "<!-- -->\n"
+ "</a>");
checkOutput("module1-summary.html", true,
checkOutput("moduleA-summary.html", true,
"<tr class=\"rowColor\">\n"
+ "<th class=\"colFirst\" scope=\"row\"><a href=\"module2-summary.html\">module2</a></th>\n"
+ "<th class=\"colFirst\" scope=\"row\"><a href=\"moduleB-summary.html\">moduleB</a></th>\n"
+ "<td class=\"colLast\">\n"
+ "<div class=\"block\">This is a test description for the module2 module.</div>\n"
+ "<div class=\"block\">This is a test description for the moduleB module.</div>\n"
+ "</td>\n"
+ "</tr>");
checkOutput("module2-summary.html", true,
checkOutput("moduleB-summary.html", true,
"<li><a href=\"#module.description\">Description</a>&nbsp;|&nbsp;<a "
+ "href=\"#modules.summary\">Modules</a>&nbsp;|&nbsp;<a href=\"#packages.summary\">"
+ "Packages</a>&nbsp;|&nbsp;<a href=\"#services.summary\">Services</a></li>");
checkOutput("module2-summary.html", true,
checkOutput("moduleB-summary.html", true,
"<!-- ============ MODULES SUMMARY =========== -->\n"
+ "<a name=\"modules.summary\">\n"
+ "<!-- -->\n"
+ "</a>");
checkOutput("module2-summary.html", true,
checkOutput("moduleB-summary.html", true,
"<tr class=\"rowColor\">\n"
+ "<th class=\"colFirst\" scope=\"row\"><a href=\"testpkg2mdl2/package-summary.html\">"
+ "testpkg2mdl2</a></th>\n"
+ "<td class=\"colSecond\">module1</td>\n"
+ "<th class=\"colFirst\" scope=\"row\"><a href=\"testpkg2mdlB/package-summary.html\">"
+ "testpkg2mdlB</a></th>\n"
+ "<td class=\"colSecond\">moduleA</td>\n"
+ "<td class=\"colLast\">&nbsp;</td>\n"
+ "</tr>");
checkOutput("module2-summary.html", true,
checkOutput("moduleB-summary.html", true,
"<!-- ============ PACKAGES SUMMARY =========== -->\n"
+ "<a name=\"packages.summary\">\n"
+ "<!-- -->\n"
+ "</a>");
checkOutput("module2-summary.html", true,
checkOutput("moduleB-summary.html", true,
"<tr class=\"altColor\">\n"
+ "<th class=\"colFirst\" scope=\"row\"><a href=\"java.base-summary.html\">java.base</a></th>\n"
+ "<td class=\"colLast\">&nbsp;</td>\n"
+ "</tr>");
checkOutput("module2-summary.html", true,
checkOutput("moduleB-summary.html", true,
"<!-- ============ SERVICES SUMMARY =========== -->\n"
+ "<a name=\"services.summary\">\n"
+ "<!-- -->\n"
+ "</a>");
checkOutput("module2-summary.html", true,
checkOutput("moduleB-summary.html", true,
"<tr class=\"altColor\">\n"
+ "<th class=\"colFirst\" scope=\"row\"><a href=\"testpkgmdl2/TestClassInModule2.html\" "
+ "title=\"class in testpkgmdl2\">TestClassInModule2</a></th>\n"
+ "<th class=\"colFirst\" scope=\"row\"><a href=\"testpkgmdlB/TestClassInModuleB.html\" "
+ "title=\"class in testpkgmdlB\">TestClassInModuleB</a></th>\n"
+ "<td class=\"colLast\">&nbsp;</td>\n"
+ "</tr>");
checkOutput("module2-summary.html", true,
checkOutput("moduleB-summary.html", true,
"<tr class=\"altColor\">\n"
+ "<th class=\"colFirst\" scope=\"row\"><a href=\"testpkg2mdl2/TestInterfaceInModule2.html\" "
+ "title=\"interface in testpkg2mdl2\">TestInterfaceInModule2</a><br>"
+ "<th class=\"colFirst\" scope=\"row\"><a href=\"testpkg2mdlB/TestInterfaceInModuleB.html\" "
+ "title=\"interface in testpkg2mdlB\">TestInterfaceInModuleB</a><br>"
+ "(<span class=\"implementationLabel\">Implementation:</span>&nbsp;"
+ "<a href=\"testpkgmdl2/TestClassInModule2.html\" title=\"class in testpkgmdl2\">"
+ "TestClassInModule2</a>)</th>\n"
+ "<a href=\"testpkgmdlB/TestClassInModuleB.html\" title=\"class in testpkgmdlB\">"
+ "TestClassInModuleB</a>)</th>\n"
+ "<td class=\"colLast\">&nbsp;</td>\n"
+ "</tr");
checkOutput("module2-summary.html", true,
checkOutput("moduleB-summary.html", true,
"<caption><span>Exported Packages</span><span class=\"tabEnd\">&nbsp;</span></caption>\n"
+ "<tr>\n"
+ "<th class=\"colFirst\" scope=\"col\">Package</th>\n"
+ "<th class=\"colSecond\" scope=\"col\">Module</th>\n"
+ "<th class=\"colLast\" scope=\"col\">Description</th>\n"
+ "</tr>");
checkOutput("module2-summary.html", true,
checkOutput("moduleB-summary.html", true,
"<caption><span>Requires</span><span class=\"tabEnd\">&nbsp;</span></caption>\n"
+ "<tr>\n"
+ "<th class=\"colFirst\" scope=\"col\">Module</th>\n"
+ "<th class=\"colLast\" scope=\"col\">Description</th>\n"
+ "</tr>");
checkOutput("module2-summary.html", true,
checkOutput("moduleB-summary.html", true,
"<caption><span>Uses</span><span class=\"tabEnd\">&nbsp;</span></caption>\n"
+ "<tr>\n"
+ "<th class=\"colFirst\" scope=\"col\">Type</th>\n"
+ "<th class=\"colLast\" scope=\"col\">Description</th>\n"
+ "</tr>");
checkOutput("module2-summary.html", true,
checkOutput("moduleB-summary.html", true,
"<caption><span>Provides</span><span class=\"tabEnd\">&nbsp;</span></caption>\n"
+ "<tr>\n"
+ "<th class=\"colFirst\" scope=\"col\">Type</th>\n"
@ -526,7 +526,7 @@ public class TestModules extends JavadocTester {
}
void checkNegatedModuleSummary() {
checkOutput("module1-summary.html", false,
checkOutput("moduleA-summary.html", false,
"<!-- ============ SERVICES SUMMARY =========== -->\n"
+ "<a name=\"services.summary\">\n"
+ "<!-- -->\n"
@ -535,13 +535,13 @@ public class TestModules extends JavadocTester {
void checkModuleClickThroughLinks() {
checkOutput("module-overview-frame.html", true,
"<li><a href=\"module1-frame.html\" target=\"packageListFrame\" "
+ "onclick=\"updateModuleFrame('module1-type-frame.html','module1-summary.html');"
+ "\">module1</a></li>");
"<li><a href=\"moduleA-frame.html\" target=\"packageListFrame\" "
+ "onclick=\"updateModuleFrame('moduleA-type-frame.html','moduleA-summary.html');"
+ "\">moduleA</a></li>");
checkOutput("module-overview-frame.html", true,
"<li><a href=\"module2-frame.html\" target=\"packageListFrame\" "
+ "onclick=\"updateModuleFrame('module2-type-frame.html','module2-summary.html');"
+ "\">module2</a></li>");
"<li><a href=\"moduleB-frame.html\" target=\"packageListFrame\" "
+ "onclick=\"updateModuleFrame('moduleB-type-frame.html','moduleB-summary.html');"
+ "\">moduleB</a></li>");
checkOutput("script.js", true,
"function updateModuleFrame(pFrame, cFrame)\n"
+ "{\n"
@ -552,52 +552,52 @@ public class TestModules extends JavadocTester {
void checkModuleClickThrough(boolean found) {
checkFiles(found,
"module1-type-frame.html",
"module2-type-frame.html");
"moduleA-type-frame.html",
"moduleB-type-frame.html");
}
void checkModuleFilesAndLinks(boolean found) {
checkOutput("testpkgmdl1/package-summary.html", found,
"<li><a href=\"../module1-summary.html\">Module</a></li>");
checkOutput("testpkgmdl1/package-summary.html", found,
checkOutput("testpkgmdlA/package-summary.html", found,
"<li><a href=\"../moduleA-summary.html\">Module</a></li>");
checkOutput("testpkgmdlA/package-summary.html", found,
"<div class=\"subTitle\"><span class=\"moduleLabelInClass\">Module</span>&nbsp;"
+ "<a href=\"../module1-summary.html\">module1</a></div>");
checkOutput("testpkgmdl1/TestClassInModule1.html", found,
"<li><a href=\"../module1-summary.html\">Module</a></li>");
checkOutput("testpkgmdl1/TestClassInModule1.html", found,
+ "<a href=\"../moduleA-summary.html\">moduleA</a></div>");
checkOutput("testpkgmdlA/TestClassInModuleA.html", found,
"<li><a href=\"../moduleA-summary.html\">Module</a></li>");
checkOutput("testpkgmdlA/TestClassInModuleA.html", found,
"<div class=\"subTitle\"><span class=\"moduleLabelInClass\">Module</span>&nbsp;"
+ "<a href=\"../module1-summary.html\">module1</a></div>");
+ "<a href=\"../moduleA-summary.html\">moduleA</a></div>");
checkFiles(found,
"module1-frame.html",
"module1-summary.html",
"moduleA-frame.html",
"moduleA-summary.html",
"module-overview-frame.html");
}
void checkModulesInSearch(boolean found) {
checkOutput("index-all.html", found,
"<dl>\n"
+ "<dt><a href=\"module1-summary.html\">module1</a> - module module1</dt>\n"
+ "<dt><a href=\"moduleA-summary.html\">moduleA</a> - module moduleA</dt>\n"
+ "<dd>\n"
+ "<div class=\"block\">This is a test description for the module1 module.</div>\n"
+ "<div class=\"block\">This is a test description for the moduleA module.</div>\n"
+ "</dd>\n"
+ "<dt><a href=\"module2-summary.html\">module2</a> - module module2</dt>\n"
+ "<dt><a href=\"moduleB-summary.html\">moduleB</a> - module moduleB</dt>\n"
+ "<dd>\n"
+ "<div class=\"block\">This is a test description for the module2 module.</div>\n"
+ "<div class=\"block\">This is a test description for the moduleB module.</div>\n"
+ "</dd>\n"
+ "</dl>");
checkOutput("index-all.html", found,
"<dl>\n"
+ "<dt><span class=\"searchTagLink\"><a href=\"module1-summary.html#searchphrase\">"
+ "search phrase</a></span> - Search tag in module1</dt>\n"
+ "<dt><span class=\"searchTagLink\"><a href=\"moduleA-summary.html#searchphrase\">"
+ "search phrase</a></span> - Search tag in moduleA</dt>\n"
+ "<dd>with description</dd>\n"
+ "<dt><span class=\"searchTagLink\"><a href=\"module2-summary.html#search_word\">"
+ "search_word</a></span> - Search tag in module2</dt>\n"
+ "<dt><span class=\"searchTagLink\"><a href=\"moduleB-summary.html#search_word\">"
+ "search_word</a></span> - Search tag in moduleB</dt>\n"
+ "<dd>&nbsp;</dd>\n"
+ "</dl>");
}
void checkModuleDeprecation(boolean found) {
checkOutput("module1-summary.html", found,
checkOutput("moduleA-summary.html", found,
"<div class=\"deprecatedContent\"><span class=\"deprecatedLabel\">Deprecated, for removal:"
+ " This API element is subject to removal in a future version. </span>\n"
+ "<div class=\"block\"><span class=\"deprecationComment\">This module is deprecated.</span></div>\n"
@ -608,12 +608,12 @@ public class TestModules extends JavadocTester {
+ "<li><a href=\"#module\">Deprecated Modules</a></li>\n"
+ "</ul>",
"<tr class=\"altColor\">\n"
+ "<th class=\"colFirst\" scope=\"row\"><a href=\"module1-summary.html\">module1</a></th>\n"
+ "<th class=\"colFirst\" scope=\"row\"><a href=\"moduleA-summary.html\">moduleA</a></th>\n"
+ "<td class=\"colLast\">\n"
+ "<div class=\"block\"><span class=\"deprecationComment\">This module is deprecated.</span></div>\n"
+ "</td>\n"
+ "</tr>");
checkOutput("module2-summary.html", !found,
checkOutput("moduleB-summary.html", !found,
"<div class=\"deprecatedContent\"><span class=\"deprecatedLabel\">Deprecated.</span>\n"
+ "<div class=\"block\"><span class=\"deprecationComment\">This module is deprecated using just the javadoc tag.</span></div>");
checkOutput("moduletags-summary.html", found,
@ -623,11 +623,11 @@ public class TestModules extends JavadocTester {
}
void checkModuleAnnotation() {
checkOutput("module2-summary.html", true,
"<p><a href=\"testpkgmdl2/AnnotationType.html\" title=\"annotation in testpkgmdl2\">@AnnotationType</a>(<a href=\"testpkgmdl2/AnnotationType.html#optional--\">optional</a>=\"Module Annotation\",\n"
+ " <a href=\"testpkgmdl2/AnnotationType.html#required--\">required</a>=2016)\n"
checkOutput("moduleB-summary.html", true,
"<p><a href=\"testpkgmdlB/AnnotationType.html\" title=\"annotation in testpkgmdlB\">@AnnotationType</a>(<a href=\"testpkgmdlB/AnnotationType.html#optional--\">optional</a>=\"Module Annotation\",\n"
+ " <a href=\"testpkgmdlB/AnnotationType.html#required--\">required</a>=2016)\n"
+ "</p>");
checkOutput("module2-summary.html", false,
checkOutput("moduleB-summary.html", false,
"@AnnotationTypeUndocumented");
}

View File

@ -24,13 +24,13 @@
*/
/**
* This is a test description for the module1 module. Search phrase {@index "search phrase" with description}.
* This is a test description for the moduleA module. Search phrase {@index "search phrase" with description}.
*
* @deprecated This module is deprecated.
*/
@Deprecated(forRemoval=true)
module module1 {
requires module2;
module moduleA {
requires moduleB;
exports testpkgmdl1;
exports testpkgmdlA;
}

View File

@ -22,7 +22,7 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package testpkgmdl1;
package testpkgmdlA;
public class TestClassInModule1 {
public class TestClassInModuleA {
}

View File

@ -24,18 +24,18 @@
*/
/**
* This is a test description for the module2 module. Search word {@index search_word} with no description.
* This is a test description for the moduleB module. Search word {@index search_word} with no description.
*
* @deprecated This module is deprecated using just the javadoc tag.
*/
@testpkgmdl2.AnnotationType(optional="Module Annotation", required=2016)
@testpkgmdl2.AnnotationTypeUndocumented(optional="Module Annotation", required=2016)
module module2 {
exports testpkgmdl2;
@testpkgmdlB.AnnotationType(optional="Module Annotation", required=2016)
@testpkgmdlB.AnnotationTypeUndocumented(optional="Module Annotation", required=2016)
module moduleB {
exports testpkgmdlB;
exports testpkg2mdl2 to module1;
exports testpkg2mdlB to moduleA;
uses testpkgmdl2.TestClassInModule2;
uses testpkgmdlB.TestClassInModuleB;
provides testpkg2mdl2.TestInterfaceInModule2 with testpkgmdl2.TestClassInModule2;
provides testpkg2mdlB.TestInterfaceInModuleB with testpkgmdlB.TestClassInModuleB;
}

View File

@ -22,8 +22,8 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package testpkg2mdl2;
package testpkg2mdlB;
public interface TestInterfaceInModule2 {
public interface TestInterfaceInModuleB {
void testMethod();
}

View File

@ -21,7 +21,7 @@
* questions.
*/
package testpkgmdl2;
package testpkgmdlB;
import java.lang.annotation.*;

View File

@ -22,10 +22,10 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package testpkgmdl2;
package testpkgmdlB;
import testpkg2mdl2.TestInterfaceInModule2;
import testpkg2mdlB.TestInterfaceInModuleB;
public class TestClassInModule2 implements TestInterfaceInModule2 {
public class TestClassInModuleB implements TestInterfaceInModuleB {
void testMethod() {}
}

View File

@ -24,7 +24,7 @@
*/
/**
* This is a test description for the module1 module.<br>
* This is a test description for the moduleA module.<br>
* Type Link: {@link testpkgmdltags.TestClassInModuleTags}.<br>
* Member Link: {@link testpkgmdltags.TestClassInModuleTags#testMethod(String)}.<br>
* Package Link: {@link testpkgmdltags}.<br>
@ -39,7 +39,7 @@
*/
@Deprecated
module moduletags {
requires module2;
requires moduleB;
exports testpkgmdltags;
}

View File

@ -1182,16 +1182,6 @@ public class ClassfileInspector {
private static class AbstractAttributeVisitor<T> implements Attribute.Visitor<Void, T> {
@Override
public Void visitBootstrapMethods(BootstrapMethods_attribute attr, T p) {
return null;
}
@Override
public Void visitModulePackages(ModulePackages_attribute attr, T p) {
return null;
}
@Override
public Void visitDefault(DefaultAttribute attr, T p) {
return null;
@ -1202,6 +1192,11 @@ public class ClassfileInspector {
return null;
}
@Override
public Void visitBootstrapMethods(BootstrapMethods_attribute attr, T p) {
return null;
}
@Override
public Void visitCharacterRangeTable(CharacterRangeTable_attribute attr, T p) {
return null;
@ -1237,11 +1232,6 @@ public class ClassfileInspector {
return null;
}
@Override
public Void visitModuleHashes(ModuleHashes_attribute attr, T p) {
return null;
}
@Override
public Void visitInnerClasses(InnerClasses_attribute attr, T p) {
return null;
@ -1262,11 +1252,6 @@ public class ClassfileInspector {
return null;
}
@Override
public Void visitModuleMainClass(ModuleMainClass_attribute attr, T p) {
return null;
}
@Override
public Void visitMethodParameters(MethodParameters_attribute attr, T p) {
return null;
@ -1278,7 +1263,27 @@ public class ClassfileInspector {
}
@Override
public Void visitRuntimeVisibleAnnotations(RuntimeVisibleAnnotations_attribute attr, T p) {
public Void visitModuleHashes(ModuleHashes_attribute attr, T p) {
return null;
}
@Override
public Void visitModuleMainClass(ModuleMainClass_attribute attr, T p) {
return null;
}
@Override
public Void visitModulePackages(ModulePackages_attribute attr, T p) {
return null;
}
@Override
public Void visitModuleResolution(ModuleResolution_attribute attr, T p) {
return null;
}
@Override
public Void visitModuleTarget(ModuleTarget_attribute attr, T p) {
return null;
}
@ -1287,23 +1292,28 @@ public class ClassfileInspector {
return null;
}
@Override
public Void visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations_attribute attr, T p) {
return null;
}
@Override
public Void visitRuntimeInvisibleParameterAnnotations(RuntimeInvisibleParameterAnnotations_attribute attr, T p) {
return null;
}
@Override
public Void visitRuntimeVisibleTypeAnnotations(RuntimeVisibleTypeAnnotations_attribute attr, T p) {
public Void visitRuntimeInvisibleTypeAnnotations(RuntimeInvisibleTypeAnnotations_attribute attr, T p) {
return null;
}
@Override
public Void visitRuntimeInvisibleTypeAnnotations(RuntimeInvisibleTypeAnnotations_attribute attr, T p) {
public Void visitRuntimeVisibleAnnotations(RuntimeVisibleAnnotations_attribute attr, T p) {
return null;
}
@Override
public Void visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations_attribute attr, T p) {
return null;
}
@Override
public Void visitRuntimeVisibleTypeAnnotations(RuntimeVisibleTypeAnnotations_attribute attr, T p) {
return null;
}
@ -1341,17 +1351,6 @@ public class ClassfileInspector {
public Void visitSynthetic(Synthetic_attribute attr, T p) {
return null;
}
@Override
public Void visitModuleTarget(ModuleTarget_attribute attr, T p) {
return null;
}
@Override
public Void visitModuleVersion(ModuleVersion_attribute attr, T p) {
return null;
}
}
private static final Attribute.Visitor<Void, ExpectedTypeAnnotation> typeAnnoMatcher

View File

@ -47,8 +47,8 @@ class AttributeVisitor<R, P> implements Attribute.Visitor<R, P> {
public R visitModuleHashes(ModuleHashes_attribute attr, P p) { return null; }
public R visitModuleMainClass(ModuleMainClass_attribute attr, P p) { return null; }
public R visitModulePackages(ModulePackages_attribute attr, P p) { return null; }
public R visitModuleResolution(ModuleResolution_attribute attr, P p) { return null; }
public R visitModuleTarget(ModuleTarget_attribute attr, P p) { return null; }
public R visitModuleVersion(ModuleVersion_attribute attr, P p) { return null; }
public R visitRuntimeVisibleAnnotations(RuntimeVisibleAnnotations_attribute attr, P p) { return null; }
public R visitRuntimeInvisibleAnnotations(RuntimeInvisibleAnnotations_attribute attr, P p) { return null; }
public R visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations_attribute attr, P p) { return null; }

View File

@ -112,6 +112,8 @@ public class DetectMutableStaticFields {
"bootMethod", "defineModulesWithOneLoaderMethod", "configurationMethod", "layerClass");
ignore("com/sun/tools/javac/util/JDK9Wrappers$Module",
"addExportsMethod", "addUsesMethod", "getModuleMethod", "getUnnamedModuleMethod");
ignore("com/sun/tools/javac/util/JDK9Wrappers$ModuleDescriptor$Version",
"versionClass", "parseMethod");
ignore("com/sun/tools/javac/util/JDK9Wrappers$ModuleFinder",
"moduleFinderClass", "ofMethod");
ignore("com/sun/tools/javac/util/JDK9Wrappers$ServiceLoaderHelper",

View File

@ -46,7 +46,7 @@ public class ModuleTest extends ModuleTestBase {
@Test
public void testEmptyModule(Path base) throws Exception {
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m1")
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m")
.write(base);
compile(base);
testModuleAttribute(base, moduleDescriptor);
@ -54,7 +54,7 @@ public class ModuleTest extends ModuleTestBase {
@Test
public void testExports(Path base) throws Exception {
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m1")
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m")
.exports("pack")
.write(base);
tb.writeJavaFiles(base, "package pack; public class C extends java.util.ArrayList{ }");
@ -64,7 +64,7 @@ public class ModuleTest extends ModuleTestBase {
@Test
public void testSeveralExports(Path base) throws Exception {
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m1")
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m")
.exports("pack")
.exports("pack2")
.exports("pack3")
@ -83,7 +83,7 @@ public class ModuleTest extends ModuleTestBase {
@Test
public void testQualifiedExports(Path base) throws Exception {
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m1")
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m")
.exportsTo("pack", "jdk.compiler")
.write(base);
tb.writeJavaFiles(base, "package pack; public class A { }");
@ -93,7 +93,7 @@ public class ModuleTest extends ModuleTestBase {
@Test
public void testQualifiedDynamicExports(Path base) throws Exception {
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m1")
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m")
.exportsTo("pack", "jdk.compiler")
.write(base);
tb.writeJavaFiles(base, "package pack; public class A { }");
@ -103,7 +103,7 @@ public class ModuleTest extends ModuleTestBase {
@Test
public void testSeveralQualifiedExports(Path base) throws Exception {
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m1")
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m")
.exportsTo("pack", "jdk.compiler, jdk.jdeps")
.exportsTo("pack2", "jdk.jdeps")
.exportsTo("pack3", "jdk.compiler")
@ -122,7 +122,7 @@ public class ModuleTest extends ModuleTestBase {
@Test
public void testRequires(Path base) throws Exception {
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m1")
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m")
.requires("jdk.compiler")
.write(base);
compile(base);
@ -131,7 +131,7 @@ public class ModuleTest extends ModuleTestBase {
@Test
public void testRequiresTransitive(Path base) throws Exception {
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m1")
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m")
.requires("jdk.jdeps", RequiresFlag.TRANSITIVE)
.write(base);
compile(base);
@ -140,7 +140,7 @@ public class ModuleTest extends ModuleTestBase {
@Test
public void testRequiresStatic(Path base) throws Exception {
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m1")
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m")
.requires("jdk.jdeps", RequiresFlag.STATIC)
.write(base);
compile(base);
@ -149,26 +149,26 @@ public class ModuleTest extends ModuleTestBase {
@Test
public void testSeveralRequires(Path base) throws Exception {
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m1")
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m1x")
.requires("jdk.jdeps", RequiresFlag.TRANSITIVE)
.requires("jdk.compiler")
.requires("m2", RequiresFlag.STATIC)
.requires("m3")
.requires("m4", RequiresFlag.TRANSITIVE)
.requires("m5", RequiresFlag.STATIC, RequiresFlag.TRANSITIVE)
.write(base.resolve("m1"));
tb.writeJavaFiles(base.resolve("m2"), "module m2 { }");
tb.writeJavaFiles(base.resolve("m3"), "module m3 { }");
tb.writeJavaFiles(base.resolve("m4"), "module m4 { }");
tb.writeJavaFiles(base.resolve("m5"), "module m5 { }");
.requires("m2x", RequiresFlag.STATIC)
.requires("m3x")
.requires("m4x", RequiresFlag.TRANSITIVE)
.requires("m5x", RequiresFlag.STATIC, RequiresFlag.TRANSITIVE)
.write(base.resolve("m1x"));
tb.writeJavaFiles(base.resolve("m2x"), "module m2x { }");
tb.writeJavaFiles(base.resolve("m3x"), "module m3x { }");
tb.writeJavaFiles(base.resolve("m4x"), "module m4x { }");
tb.writeJavaFiles(base.resolve("m5x"), "module m5x { }");
compile(base, "--module-source-path", base.toString(),
"-d", base.toString());
testModuleAttribute(base.resolve("m1"), moduleDescriptor);
testModuleAttribute(base.resolve("m1x"), moduleDescriptor);
}
@Test
public void testProvides(Path base) throws Exception {
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m1")
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m")
.provides("java.util.Collection", "pack2.D")
.write(base);
tb.writeJavaFiles(base, "package pack2; public class D extends java.util.ArrayList{ }");
@ -178,7 +178,7 @@ public class ModuleTest extends ModuleTestBase {
@Test
public void testSeveralProvides(Path base) throws Exception {
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m1")
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m")
.provides("java.util.Collection", "pack2.D")
.provides("java.util.List", "pack2.D")
.requires("jdk.compiler")
@ -192,7 +192,7 @@ public class ModuleTest extends ModuleTestBase {
@Test
public void testUses(Path base) throws Exception {
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m1")
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m")
.uses("java.util.List")
.write(base);
compile(base);
@ -201,7 +201,7 @@ public class ModuleTest extends ModuleTestBase {
@Test
public void testSeveralUses(Path base) throws Exception {
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m1")
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m")
.uses("java.util.List")
.uses("java.util.Collection")
.requires("jdk.compiler")
@ -213,22 +213,22 @@ public class ModuleTest extends ModuleTestBase {
@Test
public void testComplex(Path base) throws Exception {
Path m1 = base.resolve("m1");
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m1")
Path m1 = base.resolve("m1x");
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m1x")
.exports("pack1")
.exports("pack3")
.exportsTo("packTo1", "m2")
.exportsTo("packTo3", "m3")
.exportsTo("packTo1", "m2x")
.exportsTo("packTo3", "m3x")
.requires("jdk.compiler")
.requires("m2", RequiresFlag.TRANSITIVE)
.requires("m3", RequiresFlag.STATIC)
.requires("m4", RequiresFlag.TRANSITIVE, RequiresFlag.STATIC)
.requires("m2x", RequiresFlag.TRANSITIVE)
.requires("m3x", RequiresFlag.STATIC)
.requires("m4x", RequiresFlag.TRANSITIVE, RequiresFlag.STATIC)
.provides("java.util.List", "pack1.C", "pack2.D")
.uses("java.util.List")
.uses("java.nio.file.Path")
.requires("jdk.jdeps", RequiresFlag.STATIC, RequiresFlag.TRANSITIVE)
.requires("m5", RequiresFlag.STATIC)
.requires("m6", RequiresFlag.TRANSITIVE)
.requires("m5x", RequiresFlag.STATIC)
.requires("m6x", RequiresFlag.TRANSITIVE)
.requires("java.compiler")
.exportsTo("packTo4", "java.compiler")
.exportsTo("packTo2", "java.compiler")
@ -244,11 +244,11 @@ public class ModuleTest extends ModuleTestBase {
"package packTo2; public class T2 {}",
"package packTo3; public class T3 {}",
"package packTo4; public class T4 {}");
tb.writeJavaFiles(base.resolve("m2"), "module m2 { }");
tb.writeJavaFiles(base.resolve("m3"), "module m3 { }");
tb.writeJavaFiles(base.resolve("m4"), "module m4 { }");
tb.writeJavaFiles(base.resolve("m5"), "module m5 { }");
tb.writeJavaFiles(base.resolve("m6"), "module m6 { }");
tb.writeJavaFiles(base.resolve("m2x"), "module m2x { }");
tb.writeJavaFiles(base.resolve("m3x"), "module m3x { }");
tb.writeJavaFiles(base.resolve("m4x"), "module m4x { }");
tb.writeJavaFiles(base.resolve("m5x"), "module m5x { }");
tb.writeJavaFiles(base.resolve("m6x"), "module m6x { }");
compile(base, "--module-source-path", base.toString(),
"-d", base.toString());
testModuleAttribute(m1, moduleDescriptor);

View File

@ -93,10 +93,10 @@ public class ModuleTestBase {
tr.checkContains(actualRequires, moduleDescriptor.requires, "Lists of requires don't match");
}
private void testExports(ModuleDescriptor moduleDescriptor, Module_attribute module, ConstantPool constantPool) throws ConstantPool.InvalidIndex, ConstantPool.UnexpectedEntry {
private void testExports(ModuleDescriptor moduleDescriptor, Module_attribute module, ConstantPool constantPool) throws ConstantPoolException {
tr.checkEquals(module.exports_count, moduleDescriptor.exports.size(), "Wrong amount of exports.");
for (Module_attribute.ExportsEntry export : module.exports) {
String pkg = constantPool.getUTF8Value(export.exports_index);
String pkg = constantPool.getPackageInfo(export.exports_index).getName();
if (tr.checkTrue(moduleDescriptor.exports.containsKey(pkg), "Unexpected export " + pkg)) {
Export expectedExport = moduleDescriptor.exports.get(pkg);
tr.checkEquals(expectedExport.mask, export.exports_flags, "Wrong export flags");
@ -104,7 +104,7 @@ public class ModuleTestBase {
tr.checkEquals(export.exports_to_count, expectedTo.size(), "Wrong amount of exports to");
List<String> actualTo = new ArrayList<>();
for (int toIdx : export.exports_to_index) {
actualTo.add(constantPool.getUTF8Value(toIdx).replace('/', '.'));
actualTo.add(constantPool.getModuleInfo(toIdx).getName().replace('/', '.'));
}
tr.checkContains(actualTo, expectedTo, "Lists of \"exports to\" don't match.");
}

View File

@ -1,26 +0,0 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
module m2 {
requires m1;
}

View File

@ -0,0 +1,26 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
module m2x {
requires m1x;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -22,7 +22,7 @@
*/
// key: compiler.err.not.in.profile
// options: -profile compact1
// options: --release 8 -profile compact1
class NotInProfile {
Class<?> c = java.awt.Frame.class;

View File

@ -22,6 +22,6 @@
*/
module use {
requires lib1;
requires lib2;
requires lib1x;
requires lib2x;
}

View File

@ -0,0 +1,27 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
// key: compiler.warn.poor.choice.for.module.name
// options: -Xlint:module
module mango19 {}

View File

@ -21,7 +21,7 @@
* questions.
*/
module m2 {
requires m1;
module m2x {
requires m1x;
provides exported.Service with exported.ServiceImplementation;
}

View File

@ -21,4 +21,4 @@
* questions.
*/
module m1 {}
module m1x {}

View File

@ -21,4 +21,4 @@
* questions.
*/
module m2 {}
module m2x {}

View File

@ -1,24 +0,0 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
module m1 {}

View File

@ -0,0 +1,24 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
module m1x {}

View File

@ -0,0 +1,25 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
// key: compiler.warn.module.not.found
// options: -Xlint:module

View File

@ -0,0 +1,27 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package api;
public class Api {
}

View File

@ -0,0 +1,26 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
module m {
exports api to does.not.exist;
}

View File

@ -618,6 +618,36 @@ public class ByteCodeTest {
return value;
}
@Override
public String visitModule(CONSTANT_Module_info c, Integer p) {
String value = slist.get(p);
if (value == null) {
try {
value = visit(cfpool.get(c.name_index), c.name_index);
slist.set(p, value);
} catch (ConstantPoolException ex) {
ex.printStackTrace();
}
}
return value;
}
@Override
public String visitPackage(CONSTANT_Package_info c, Integer p) {
String value = slist.get(p);
if (value == null) {
try {
value = visit(cfpool.get(c.name_index), c.name_index);
slist.set(p, value);
} catch (ConstantPoolException ex) {
ex.printStackTrace();
}
}
return value;
}
@Override
public String visitString(CONSTANT_String_info c, Integer p) {

View File

@ -31,13 +31,10 @@
* @run main AddExportsTest
*/
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Set;
import toolbox.JavacTask;
import toolbox.Task;
import toolbox.ToolBox;
public class AddExportsTest extends ModuleTestBase {
@ -71,24 +68,24 @@ public class AddExportsTest extends ModuleTestBase {
@Test
public void testEmptyItem(Path base) throws Exception {
Path src = base.resolve("src");
Path src_m1 = src.resolve("m1");
Path src_m1 = src.resolve("m1x");
tb.writeJavaFiles(src_m1,
"module m1 { }",
"module m1x { }",
"package p1; public class C1 { }");
Path src_m2 = src.resolve("m2");
Path src_m2 = src.resolve("m2x");
tb.writeJavaFiles(src_m2,
"module m2 { }",
"module m2x { }",
"package p2; class C2 { p1.C1 c1; }");
Path src_m3 = src.resolve("m3");
Path src_m3 = src.resolve("m3x");
tb.writeJavaFiles(src_m3,
"module m3 { }",
"module m3x { }",
"package p3; class C3 { p1.C1 c1; }");
Path classes = base.resolve("classes");
tb.createDirectories(classes);
testEmptyItem(src, classes, "m1/p1=,m2,m3");
testEmptyItem(src, classes, "m1/p1=m2,,m3");
testEmptyItem(src, classes, "m1/p1=m2,m3,");
testEmptyItem(src, classes, "m1x/p1=,m2x,m3x");
testEmptyItem(src, classes, "m1x/p1=m2x,,m3x");
testEmptyItem(src, classes, "m1x/p1=m2x,m3x,");
}
void testEmptyItem(Path src, Path classes, String option) throws Exception {
@ -104,15 +101,15 @@ public class AddExportsTest extends ModuleTestBase {
@Test
public void testEmptyList(Path base) throws Exception {
Path src = base.resolve("src");
Path src_m1 = src.resolve("m1");
Path src_m1 = src.resolve("m1x");
tb.writeJavaFiles(src_m1,
"module m1 { exports p1; }",
"module m1x { exports p1; }",
"package p1; public class C1 { }");
Path classes = base.resolve("classes");
tb.createDirectories(classes);
testEmptyList(src, classes, "m1/p1=");
testEmptyList(src, classes, "m1/p1=,");
testEmptyList(src, classes, "m1x/p1=");
testEmptyList(src, classes, "m1x/p1=,");
}
void testEmptyList(Path src, Path classes, String option) throws Exception {
@ -132,22 +129,22 @@ public class AddExportsTest extends ModuleTestBase {
@Test
public void testMissingSourceParts(Path base) throws Exception {
Path src = base.resolve("src");
Path src_m1 = src.resolve("m1");
Path src_m1 = src.resolve("m1x");
tb.writeJavaFiles(src_m1,
"module m1 { exports p1; }",
"module m1x { exports p1; }",
"package p1; public class C1 { }");
Path src_m2 = src.resolve("m2");
Path src_m2 = src.resolve("m2x");
tb.writeJavaFiles(src_m2,
"module m2 { }",
"module m2x { }",
"package p2; class C2 { p1.C1 c1; }");
Path classes = base.resolve("classes");
tb.createDirectories(classes);
testMissingSourcePart(src, classes, "=m2");
testMissingSourcePart(src, classes, "/=m2");
testMissingSourcePart(src, classes, "m1/=m2");
testMissingSourcePart(src, classes, "/p1=m2");
testMissingSourcePart(src, classes, "m1p1=m2");
testMissingSourcePart(src, classes, "=m2x");
testMissingSourcePart(src, classes, "/=m2x");
testMissingSourcePart(src, classes, "m1x/=m2x");
testMissingSourcePart(src, classes, "/p1=m2x");
testMissingSourcePart(src, classes, "m1xp1=m2x");
}
private void testMissingSourcePart(Path src, Path classes, String option) throws Exception {
@ -167,19 +164,19 @@ public class AddExportsTest extends ModuleTestBase {
@Test
public void testBadSourceParts(Path base) throws Exception {
Path src = base.resolve("src");
Path src_m1 = src.resolve("m1");
Path src_m1 = src.resolve("m1x");
tb.writeJavaFiles(src_m1,
"module m1 { exports p1; }",
"module m1x { exports p1; }",
"package p1; public class C1 { }");
Path src_m2 = src.resolve("m2");
Path src_m2 = src.resolve("m2x");
tb.writeJavaFiles(src_m2,
"module m2 { }",
"module m2x { }",
"package p2; class C2 { p1.C1 c1; }");
Path classes = base.resolve("classes");
tb.createDirectories(classes);
testBadSourcePart(src, classes, "m!/p1=m2", "m!");
testBadSourcePart(src, classes, "m1/p!=m2", "p!");
testBadSourcePart(src, classes, "m!/p1=m2x", "m!");
testBadSourcePart(src, classes, "m1x/p!=m2x", "p!");
}
private void testBadSourcePart(Path src, Path classes, String option, String badName)
@ -201,9 +198,9 @@ public class AddExportsTest extends ModuleTestBase {
@Test
public void testBadTarget(Path base) throws Exception {
Path src = base.resolve("src");
Path src_m1 = src.resolve("m1");
Path src_m1 = src.resolve("m1x");
tb.writeJavaFiles(src_m1,
"module m1 { exports p1; }",
"module m1x { exports p1; }",
"package p1; public class C1 { }");
Path classes = base.resolve("classes");
tb.createDirectories(classes);
@ -211,7 +208,7 @@ public class AddExportsTest extends ModuleTestBase {
String log = new JavacTask(tb, Task.Mode.CMDLINE)
.options("-XDrawDiagnostics",
"--module-source-path", src.toString(),
"--add-exports", "m1/p1=m!")
"--add-exports", "m1x/p1=m!")
.outdir(classes)
.files(findJavaFiles(src))
.run()
@ -225,16 +222,16 @@ public class AddExportsTest extends ModuleTestBase {
@Test
public void testSourceNotFound(Path base) throws Exception {
Path src = base.resolve("src");
Path src_m1 = src.resolve("m1");
Path src_m1 = src.resolve("m1x");
tb.writeJavaFiles(src_m1,
"module m1 { }");
"module m1x { }");
Path classes = base.resolve("classes");
tb.createDirectories(classes);
String log = new JavacTask(tb, Task.Mode.CMDLINE)
.options("-XDrawDiagnostics",
"--module-source-path", src.toString(),
"--add-exports", "DoesNotExist/p=m1")
"--add-exports", "DoesNotExist/p=m1x")
.outdir(classes)
.files(findJavaFiles(src))
.run()
@ -248,9 +245,9 @@ public class AddExportsTest extends ModuleTestBase {
@Test
public void testTargetNotFound(Path base) throws Exception {
Path src = base.resolve("src");
Path src_m1 = src.resolve("m1");
Path src_m1 = src.resolve("m1x");
tb.writeJavaFiles(src_m1,
"module m1 { }",
"module m1x { }",
"package p1; class C1 { }");
Path classes = base.resolve("classes");
tb.createDirectories(classes);
@ -258,7 +255,7 @@ public class AddExportsTest extends ModuleTestBase {
String log = new JavacTask(tb, Task.Mode.CMDLINE)
.options("-XDrawDiagnostics",
"--module-source-path", src.toString(),
"--add-exports", "m1/p1=DoesNotExist")
"--add-exports", "m1x/p1=DoesNotExist")
.outdir(classes)
.files(findJavaFiles(src))
.run()
@ -272,20 +269,20 @@ public class AddExportsTest extends ModuleTestBase {
@Test
public void testDuplicate(Path base) throws Exception {
Path src = base.resolve("src");
Path src_m1 = src.resolve("m1");
Path src_m1 = src.resolve("m1x");
tb.writeJavaFiles(src_m1,
"module m1 { }",
"module m1x { }",
"package p1; public class C1 { }");
Path src_m2 = src.resolve("m2");
Path src_m2 = src.resolve("m2x");
tb.writeJavaFiles(src_m2,
"module m2 { }",
"module m2x { }",
"package p2; class C2 { p1.C1 c1; }");
Path classes = base.resolve("classes");
tb.createDirectories(classes);
new JavacTask(tb)
.options("--module-source-path", src.toString(),
"--add-exports", "m1/p1=m2,m2")
"--add-exports", "m1x/p1=m2x,m2x")
.outdir(classes)
.files(findJavaFiles(src))
.run()
@ -295,21 +292,21 @@ public class AddExportsTest extends ModuleTestBase {
@Test
public void testRepeated_SameTarget(Path base) throws Exception {
Path src = base.resolve("src");
Path src_m1 = src.resolve("m1");
Path src_m1 = src.resolve("m1x");
tb.writeJavaFiles(src_m1,
"module m1 { }",
"module m1x { }",
"package p1; public class C1 { }");
Path src_m2 = src.resolve("m2");
Path src_m2 = src.resolve("m2x");
tb.writeJavaFiles(src_m2,
"module m2 { }",
"module m2x { }",
"package p2; class C2 { p1.C1 c1; }");
Path classes = base.resolve("classes");
tb.createDirectories(classes);
new JavacTask(tb)
.options("--module-source-path", src.toString(),
"--add-exports", "m1/p1=m2",
"--add-exports", "m1/p1=m2")
"--add-exports", "m1x/p1=m2x",
"--add-exports", "m1x/p1=m2x")
.outdir(classes)
.files(findJavaFiles(src))
.run()
@ -319,25 +316,25 @@ public class AddExportsTest extends ModuleTestBase {
@Test
public void testRepeated_DifferentTarget(Path base) throws Exception {
Path src = base.resolve("src");
Path src_m1 = src.resolve("m1");
Path src_m1 = src.resolve("m1x");
tb.writeJavaFiles(src_m1,
"module m1 { }",
"module m1x { }",
"package p1; public class C1 { }");
Path src_m2 = src.resolve("m2");
Path src_m2 = src.resolve("m2x");
tb.writeJavaFiles(src_m2,
"module m2 { }",
"module m2x { }",
"package p2; class C2 { p1.C1 c1; }");
Path src_m3 = src.resolve("m3");
Path src_m3 = src.resolve("m3x");
tb.writeJavaFiles(src_m3,
"module m3 { }",
"module m3x { }",
"package p3; class C3 { p1.C1 c1; }");
Path classes = base.resolve("classes");
tb.createDirectories(classes);
new JavacTask(tb)
.options("--module-source-path", src.toString(),
"--add-exports", "m1/p1=m2",
"--add-exports", "m1/p1=m3")
"--add-exports", "m1x/p1=m2x",
"--add-exports", "m1x/p1=m3x")
.outdir(classes)
.files(findJavaFiles(src))
.run()

View File

@ -81,22 +81,22 @@ public class AddLimitMods extends ModuleTestBase {
@Test
public void testManual(Path base) throws Exception {
Path moduleSrc = base.resolve("module-src");
Path m1 = moduleSrc.resolve("m1");
Path m1 = moduleSrc.resolve("m1x");
tb.writeJavaFiles(m1,
"module m1 { requires m2; requires m3; }");
"module m1x { requires m2x; requires m3x; }");
Path m2 = moduleSrc.resolve("m2");
Path m2 = moduleSrc.resolve("m2x");
tb.writeJavaFiles(m2,
"module m2 { requires m3; exports m2; }",
"package m2; public class M2 {}");
"module m2x { requires m3x; exports m2x; }",
"package m2x; public class M2 {}");
Path m3 = moduleSrc.resolve("m3");
Path m3 = moduleSrc.resolve("m3x");
tb.writeJavaFiles(m3,
"module m3 { exports m3; }",
"package m3; public class M3 {}");
"module m3x { exports m3x; }",
"package m3x; public class M3 {}");
Path modulePath = base.resolve("module-path");
@ -130,7 +130,7 @@ public class AddLimitMods extends ModuleTestBase {
.options("--module-path", modulePath.toString(),
"--should-stop:ifNoError=FLOW",
"--limit-modules", "java.base",
"--add-modules", "m2")
"--add-modules", "m2x")
.outdir(modulePath)
.files(findJavaFiles(m1))
.run(Task.Expect.FAIL)
@ -140,7 +140,7 @@ public class AddLimitMods extends ModuleTestBase {
.options("--module-path", modulePath.toString(),
"--should-stop:ifNoError=FLOW",
"--limit-modules", "java.base",
"--add-modules", "m2,m3")
"--add-modules", "m2x,m3x")
.outdir(modulePath)
.files(findJavaFiles(m1))
.run()
@ -149,7 +149,7 @@ public class AddLimitMods extends ModuleTestBase {
new JavacTask(tb)
.options("--module-path", modulePath.toString(),
"--should-stop:ifNoError=FLOW",
"--limit-modules", "m2")
"--limit-modules", "m2x")
.outdir(modulePath)
.files(findJavaFiles(m1))
.run()
@ -158,7 +158,7 @@ public class AddLimitMods extends ModuleTestBase {
new JavacTask(tb)
.options("--module-path", modulePath.toString(),
"--should-stop:ifNoError=FLOW",
"--limit-modules", "m3")
"--limit-modules", "m3x")
.outdir(modulePath)
.files(findJavaFiles(m1))
.run(Task.Expect.FAIL)
@ -167,8 +167,8 @@ public class AddLimitMods extends ModuleTestBase {
new JavacTask(tb)
.options("--module-path", modulePath.toString(),
"--should-stop:ifNoError=FLOW",
"--limit-modules", "m3",
"--add-modules", "m2")
"--limit-modules", "m3x",
"--add-modules", "m2x")
.outdir(modulePath)
.files(findJavaFiles(m1))
.run()
@ -233,10 +233,10 @@ public class AddLimitMods extends ModuleTestBase {
tb.cleanDirectory(base);
Path moduleSrc = base.resolve("module-src");
Path m1 = moduleSrc.resolve("m1");
Path m1 = moduleSrc.resolve("m1x");
tb.writeJavaFiles(m1,
"module m1 { exports api; }",
"module m1x { exports api; }",
"package api; public class Api { }");
Path modulePath = base.resolve("module-path");
@ -319,7 +319,7 @@ public class AddLimitMods extends ModuleTestBase {
throw new IllegalStateException("incorrect errors; actual=" + actual);
}
tb.writeJavaFiles(cpSrc, "module m1 {}");
tb.writeJavaFiles(cpSrc, "module m1x {}");
actual = new JavacTask(tb)
.options("-XDrawDiagnostics",
@ -382,10 +382,10 @@ public class AddLimitMods extends ModuleTestBase {
.run();
Path moduleSrc = base.resolve("module-src");
Path m1 = moduleSrc.resolve("m1");
Path m1 = moduleSrc.resolve("m1x");
tb.writeJavaFiles(m1,
"module m1 { exports api; }",
"module m1x { exports api; }",
"package api; public class Api { public void test() { } }");
System.err.println("Compiling module-src files:");
@ -405,8 +405,8 @@ public class AddLimitMods extends ModuleTestBase {
System.err.println("Running check: " + moduleInfo + "; " + Arrays.asList(options));
Path m2Runtime = base.resolve(index + "-runtime").resolve("m2");
Path out = base.resolve(index + "-runtime").resolve("out").resolve("m2");
Path m2Runtime = base.resolve(index + "-runtime").resolve("m2x");
Path out = base.resolve(index + "-runtime").resolve("out").resolve("m2x");
Files.createDirectories(out);
@ -443,14 +443,14 @@ public class AddLimitMods extends ModuleTestBase {
String output;
try {
System.err.println("Running m2/test.Test:");
System.err.println("Running m2x/test.Test:");
output = new JavaTask(tb)
.vmOptions(augmentOptions(options,
Collections.emptyList(),
"--module-path", modulePath.toString() + File.pathSeparator + out.getParent().toString(),
"--class-path", classpathOut.toString(),
"--add-reads", "m2=ALL-UNNAMED,automatic",
"-m", "m2/test.Test"))
"--add-reads", "m2x=ALL-UNNAMED,automatic",
"-m", "m2x/test.Test"))
.run()
.writeAll()
.getOutput(Task.OutputKind.STDERR);
@ -461,7 +461,7 @@ public class AddLimitMods extends ModuleTestBase {
output = "";
}
Path m2 = base.resolve(String.valueOf(index)).resolve("m2");
Path m2 = base.resolve(String.valueOf(index)).resolve("m2x");
tb.writeJavaFiles(m2,
moduleInfo,
@ -475,7 +475,7 @@ public class AddLimitMods extends ModuleTestBase {
"-XDaccessInternalAPI=true"
) : Collections.emptyList();
System.err.println("Compiling/processing m2 files:");
System.err.println("Compiling/processing m2x files:");
new JavacTask(tb)
.options(augmentOptions(options,
auxOptions,
@ -515,8 +515,8 @@ public class AddLimitMods extends ModuleTestBase {
private static final Map<String, String> MODULES_TO_CHECK_TO_SAMPLE_CLASS = new LinkedHashMap<>();
static {
MODULES_TO_CHECK_TO_SAMPLE_CLASS.put("m1", "api.Api");
MODULES_TO_CHECK_TO_SAMPLE_CLASS.put("m2", "test.Test");
MODULES_TO_CHECK_TO_SAMPLE_CLASS.put("m1x", "api.Api");
MODULES_TO_CHECK_TO_SAMPLE_CLASS.put("m2x", "test.Test");
MODULES_TO_CHECK_TO_SAMPLE_CLASS.put("java.base", "java.lang.Object");
};
@ -578,19 +578,19 @@ public class AddLimitMods extends ModuleTestBase {
}
private static final String[] MODULE_INFO_VARIANTS = {
"module m2 { exports test; }",
"module m2 { requires m1; exports test; }"
"module m2x { exports test; }",
"module m2x { requires m1x; exports test; }"
};
private static final String[][] OPTIONS_VARIANTS = {
{"--add-modules", "automatic"},
{"--add-modules", "m1,automatic"},
{"--add-modules", "m1x,automatic"},
{"--add-modules", "jdk.compiler,automatic"},
{"--add-modules", "m1,jdk.compiler,automatic"},
{"--add-modules", "m1x,jdk.compiler,automatic"},
{"--add-modules", "ALL-SYSTEM,automatic"},
{"--limit-modules", "java.base", "--add-modules", "automatic"},
{"--limit-modules", "java.base", "--add-modules", "ALL-SYSTEM,automatic"},
{"--limit-modules", "m2", "--add-modules", "automatic"},
{"--limit-modules", "m2x", "--add-modules", "automatic"},
{"--limit-modules", "jdk.compiler", "--add-modules", "automatic"},
};
}

View File

@ -36,7 +36,6 @@ import java.nio.file.Path;
import toolbox.JavacTask;
import toolbox.Task;
import toolbox.ToolBox;
public class AddModulesTest extends ModuleTestBase {
public static void main(String... args) throws Exception {
@ -70,18 +69,18 @@ public class AddModulesTest extends ModuleTestBase {
@Test
public void testEmptyItem(Path base) throws Exception {
Path src = base.resolve("src");
Path src_m1 = src.resolve("m1");
Path src_m1 = src.resolve("m1x");
tb.writeJavaFiles(src_m1,
"module m1 { }");
Path src_m2 = src.resolve("m2");
"module m1x { }");
Path src_m2 = src.resolve("m2x");
tb.writeJavaFiles(src_m2,
"module m2 { }");
"module m2x { }");
Path classes = base.resolve("classes");
tb.createDirectories(classes);
testEmptyItem(src, classes, ",m1");
testEmptyItem(src, classes, "m1,,m2");
testEmptyItem(src, classes, "m1,");
testEmptyItem(src, classes, ",m1x");
testEmptyItem(src, classes, "m1x,,m2x");
testEmptyItem(src, classes, "m1x,");
}
private void testEmptyItem(Path src, Path classes, String option) throws Exception {
@ -159,9 +158,9 @@ public class AddModulesTest extends ModuleTestBase {
Path src = base.resolve("src");
// setup a utility module
Path src_m1 = src.resolve("m1");
Path src_m1 = src.resolve("m1x");
tb.writeJavaFiles(src_m1,
"module m1 { exports p1; }",
"module m1x { exports p1; }",
"package p1; public class C1 { }");
Path modules = base.resolve("modules");
tb.createDirectories(modules);
@ -182,7 +181,7 @@ public class AddModulesTest extends ModuleTestBase {
new JavacTask(tb)
.options("--module-path", modules.toString(),
"--add-modules", "m1,m1")
"--add-modules", "m1x,m1x")
.outdir(classes)
.files(findJavaFiles(src2))
.run()
@ -194,13 +193,13 @@ public class AddModulesTest extends ModuleTestBase {
Path src = base.resolve("src");
// setup some utility modules
Path src_m1 = src.resolve("m1");
Path src_m1 = src.resolve("m1x");
tb.writeJavaFiles(src_m1,
"module m1 { exports p1; }",
"module m1x { exports p1; }",
"package p1; public class C1 { }");
Path src_m2 = src.resolve("m2");
Path src_m2 = src.resolve("m2x");
tb.writeJavaFiles(src_m2,
"module m2 { exports p2; }",
"module m2x { exports p2; }",
"package p2; public class C2 { }");
Path modules = base.resolve("modules");
tb.createDirectories(modules);
@ -221,8 +220,8 @@ public class AddModulesTest extends ModuleTestBase {
new JavacTask(tb)
.options("--module-path", modules.toString(),
"--add-modules", "m1",
"--add-modules", "m2")
"--add-modules", "m1x",
"--add-modules", "m2x")
.outdir(classes)
.files(findJavaFiles(src2))
.run()

View File

@ -60,13 +60,13 @@ public class AddReadsTest extends ModuleTestBase {
@Test
public void testAddReads(Path base) throws Exception {
Path src = base.resolve("src");
Path src_m1 = src.resolve("m1");
Path src_m1 = src.resolve("m1x");
tb.writeJavaFiles(src_m1,
"module m1 { exports api; }",
"module m1x { exports api; }",
"package api; public class Api { }");
Path src_m2 = src.resolve("m2");
Path src_m2 = src.resolve("m2x");
tb.writeJavaFiles(src_m2,
"module m2 { }",
"module m2x { }",
"package test; public class Test extends api.Api { }");
Path classes = base.resolve("classes");
tb.createDirectories(classes);
@ -85,7 +85,7 @@ public class AddReadsTest extends ModuleTestBase {
//test add dependencies:
new JavacTask(tb)
.options("--add-reads", "m2=m1",
.options("--add-reads", "m2x=m1x",
"--module-source-path", src.toString(),
"-processor", VerifyRequires.class.getName())
.outdir(classes)
@ -94,18 +94,19 @@ public class AddReadsTest extends ModuleTestBase {
.writeAll();
String decompiled = new JavapTask(tb)
.options("-verbose", classes.resolve("m2").resolve("module-info.class").toString())
.options("-verbose",
classes.resolve("m2x").resolve("module-info.class").toString())
.run()
.getOutput(Task.OutputKind.DIRECT);
if (decompiled.contains("m1")) {
throw new Exception("Incorrectly refers to m1 module.");
if (decompiled.contains("m1x")) {
throw new Exception("Incorrectly refers to m1x module.");
}
//cyclic dependencies OK when created through addReads:
new JavacTask(tb)
.options("--add-reads", "m2=m1",
"--add-reads", "m1=m2",
.options("--add-reads", "m2x=m1x",
"--add-reads", "m1x=m2x",
"--module-source-path", src.toString())
.outdir(classes)
.files(findJavaFiles(src))
@ -113,10 +114,10 @@ public class AddReadsTest extends ModuleTestBase {
.writeAll();
tb.writeJavaFiles(src_m2,
"module m2 { requires m1; }");
"module m2x { requires m1x; }");
new JavacTask(tb)
.options("--add-reads", "m1=m2",
.options("--add-reads", "m1x=m2x",
"--module-source-path", src.toString())
.outdir(classes)
.files(findJavaFiles(src))
@ -129,16 +130,16 @@ public class AddReadsTest extends ModuleTestBase {
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
ModuleElement m2Module = processingEnv.getElementUtils().getModuleElement("m2");
ModuleElement m2Module = processingEnv.getElementUtils().getModuleElement("m2x");
if (m2Module == null) {
throw new AssertionError("Cannot find the m2 module!");
throw new AssertionError("Cannot find the m2x module!");
}
boolean foundM1 = false;
for (RequiresDirective rd : ElementFilter.requiresIn(m2Module.getDirectives())) {
foundM1 |= rd.getDependency().getSimpleName().contentEquals("m1");
foundM1 |= rd.getDependency().getSimpleName().contentEquals("m1x");
}
if (!foundM1) {
throw new AssertionError("Cannot find the dependency on m1 module!");
throw new AssertionError("Cannot find the dependency on m1x module!");
}
return false;
}
@ -155,19 +156,19 @@ public class AddReadsTest extends ModuleTestBase {
Path jar = prepareTestJar(base);
Path moduleSrc = base.resolve("module-src");
Path m1 = moduleSrc.resolve("m1");
Path m1 = moduleSrc.resolve("m1x");
Path classes = base.resolve("classes");
Files.createDirectories(classes);
tb.writeJavaFiles(m1,
"module m1 { }",
"module m1x { }",
"package impl; public class Impl { api.Api api; }");
new JavacTask(tb)
.options("--class-path", jar.toString(),
"--add-reads", "m1=ALL-UNNAMED",
"--add-reads", "m1x=ALL-UNNAMED",
"-XDrawDiagnostics")
.outdir(classes)
.files(findJavaFiles(moduleSrc))
@ -180,21 +181,21 @@ public class AddReadsTest extends ModuleTestBase {
Path jar = prepareTestJar(base);
Path moduleSrc = base.resolve("module-src");
Path m1 = moduleSrc.resolve("m1");
Path m1 = moduleSrc.resolve("m1x");
Path classes = base.resolve("classes");
Files.createDirectories(classes);
tb.writeJavaFiles(m1,
"module m1 { }",
"module m1x { }",
"package api; public class Api { public static void test() { } }",
"package impl; public class Impl { { api.Api.test(); } }");
new JavacTask(tb)
.options("--class-path", jar.toString(),
"--module-source-path", moduleSrc.toString(),
"--add-reads", "m1=ALL-UNNAMED",
"--add-reads", "m1x=ALL-UNNAMED",
"-XDrawDiagnostics")
.outdir(classes)
.files(m1.resolve("impl").resolve("Impl.java"))
@ -279,9 +280,9 @@ public class AddReadsTest extends ModuleTestBase {
@Test
public void testX(Path base) throws Exception {
Path src = base.resolve("src");
Path src_m1 = src.resolve("m1");
Path src_m1 = src.resolve("m1x");
tb.writeJavaFiles(src_m1,
"module m1 { provides java.lang.Runnable with impl.Impl; }",
"module m1x { provides java.lang.Runnable with impl.Impl; }",
"package impl; public class Impl implements Runnable { public void run() { } }");
Path classes = base.resolve("classes");
tb.createDirectories(classes);
@ -302,8 +303,8 @@ public class AddReadsTest extends ModuleTestBase {
"package impl; public class Impl { }");
new JavacTask(tb)
.options("--add-reads", "m1=ALL-UNNAMED",
"-Xmodule:m1",
.options("--add-reads", "m1x=ALL-UNNAMED",
"-Xmodule:m1x",
"--module-path", classes.toString())
.outdir(unnamedClasses)
.files(findJavaFiles(unnamedSrc))
@ -314,16 +315,16 @@ public class AddReadsTest extends ModuleTestBase {
@Test
public void testAddSelf(Path base) throws Exception {
Path src = base.resolve("src");
Path src_m1 = src.resolve("m1");
Path src_m1 = src.resolve("m1x");
tb.writeJavaFiles(src_m1,
"module m1 { exports p1; }",
"module m1x { exports p1; }",
"package p1; public class C1 { }");
Path classes = base.resolve("classes");
tb.createDirectories(classes);
new JavacTask(tb)
.options("--module-source-path", src.toString(),
"--add-reads", "m1=m1")
"--add-reads", "m1x=m1x")
.outdir(classes)
.files(findJavaFiles(src))
.run()
@ -357,24 +358,24 @@ public class AddReadsTest extends ModuleTestBase {
@Test
public void testEmptyItem(Path base) throws Exception {
Path src = base.resolve("src");
Path src_m1 = src.resolve("m1");
Path src_m1 = src.resolve("m1x");
tb.writeJavaFiles(src_m1,
"module m1 { exports p1; }",
"module m1x { exports p1; }",
"package p1; public class C1 { }");
Path src_m2 = src.resolve("m2");
Path src_m2 = src.resolve("m2x");
tb.writeJavaFiles(src_m2,
"module m2 { }",
"module m2x { }",
"package p2; class C2 { }");
Path src_m3 = src.resolve("m3");
Path src_m3 = src.resolve("m3x");
tb.writeJavaFiles(src_m3,
"module m3 { }",
"module m3x { }",
"package p3; class C3 { p1.C1 c1; }");
Path classes = base.resolve("classes");
tb.createDirectories(classes);
testEmptyItem(src, classes, "m3=,m1");
testEmptyItem(src, classes, "m3=m1,,m2");
testEmptyItem(src, classes, "m3=m1,");
testEmptyItem(src, classes, "m3x=,m1x");
testEmptyItem(src, classes, "m3x=m1x,,m2x");
testEmptyItem(src, classes, "m3x=m1x,");
}
private void testEmptyItem(Path src, Path classes, String option) throws Exception {
@ -390,23 +391,23 @@ public class AddReadsTest extends ModuleTestBase {
@Test
public void testEmptyList(Path base) throws Exception {
Path src = base.resolve("src");
Path src_m1 = src.resolve("m1");
Path src_m1 = src.resolve("m1x");
tb.writeJavaFiles(src_m1,
"module m1 { exports p1; }",
"module m1x { exports p1; }",
"package p1; public class C1 { }");
Path src_m2 = src.resolve("m2");
Path src_m2 = src.resolve("m2x");
tb.writeJavaFiles(src_m2,
"module m2 { }",
"module m2x { }",
"package p2; class C2 { }");
Path src_m3 = src.resolve("m3");
Path src_m3 = src.resolve("m3x");
tb.writeJavaFiles(src_m3,
"module m3 { }",
"module m3x { }",
"package p3; class C3 { p1.C1 c1; }");
Path classes = base.resolve("classes");
tb.createDirectories(classes);
testEmptyList(src, classes, "m3=");
testEmptyList(src, classes, "m3=,");
testEmptyList(src, classes, "m3x=");
testEmptyList(src, classes, "m3x=,");
}
private void testEmptyList(Path src, Path classes, String option) throws Exception {
@ -426,25 +427,25 @@ public class AddReadsTest extends ModuleTestBase {
@Test
public void testMultipleAddReads_DifferentModules(Path base) throws Exception {
Path src = base.resolve("src");
Path src_m1 = src.resolve("m1");
Path src_m1 = src.resolve("m1x");
tb.writeJavaFiles(src_m1,
"module m1 { exports p1; }",
"module m1x { exports p1; }",
"package p1; public class C1 { }");
Path src_m2 = src.resolve("m2");
Path src_m2 = src.resolve("m2x");
tb.writeJavaFiles(src_m2,
"module m2 { }",
"module m2x { }",
"package p2; class C2 { p1.C1 c1; }");
Path src_m3 = src.resolve("m3");
Path src_m3 = src.resolve("m3x");
tb.writeJavaFiles(src_m3,
"module m3 { }",
"module m3x { }",
"package p3; class C3 { p1.C1 c1; }");
Path classes = base.resolve("classes");
tb.createDirectories(classes);
new JavacTask(tb)
.options("--module-source-path", src.toString(),
"--add-reads", "m2=m1",
"--add-reads", "m3=m1")
"--add-reads", "m2x=m1x",
"--add-reads", "m3x=m1x")
.outdir(classes)
.files(findJavaFiles(src))
.run()
@ -454,25 +455,25 @@ public class AddReadsTest extends ModuleTestBase {
@Test
public void testMultipleAddReads_SameModule(Path base) throws Exception {
Path src = base.resolve("src");
Path src_m1 = src.resolve("m1");
Path src_m1 = src.resolve("m1x");
tb.writeJavaFiles(src_m1,
"module m1 { exports p1; }",
"module m1x { exports p1; }",
"package p1; public class C1 { }");
Path src_m2 = src.resolve("m2");
Path src_m2 = src.resolve("m2x");
tb.writeJavaFiles(src_m2,
"module m2 { exports p2; }",
"module m2x { exports p2; }",
"package p2; public class C2 { }");
Path src_m3 = src.resolve("m3");
Path src_m3 = src.resolve("m3x");
tb.writeJavaFiles(src_m3,
"module m3 { }",
"module m3x { }",
"package p3; class C3 { p1.C1 c1; p2.C2 c2; }");
Path classes = base.resolve("classes");
tb.createDirectories(classes);
new JavacTask(tb)
.options("--module-source-path", src.toString(),
"--add-reads", "m3=m1",
"--add-reads", "m3=m2")
"--add-reads", "m3x=m1x",
"--add-reads", "m3x=m2x")
.outdir(classes)
.files(findJavaFiles(src))
.run()
@ -482,20 +483,20 @@ public class AddReadsTest extends ModuleTestBase {
@Test
public void testDuplicateAddReads_SameOption(Path base) throws Exception {
Path src = base.resolve("src");
Path src_m1 = src.resolve("m1");
Path src_m1 = src.resolve("m1x");
tb.writeJavaFiles(src_m1,
"module m1 { exports p1; }",
"module m1x { exports p1; }",
"package p1; public class C1 { }");
Path src_m2 = src.resolve("m2");
Path src_m2 = src.resolve("m2x");
tb.writeJavaFiles(src_m2,
"module m2 { exports p2; }",
"module m2x { exports p2; }",
"package p2; class C2 { p1.C1 c1; }");
Path classes = base.resolve("classes");
tb.createDirectories(classes);
new JavacTask(tb)
.options("--module-source-path", src.toString(),
"--add-reads", "m2=m1,m1")
"--add-reads", "m2x=m1x,m1x")
.outdir(classes)
.files(findJavaFiles(src))
.run()
@ -505,21 +506,21 @@ public class AddReadsTest extends ModuleTestBase {
@Test
public void testDuplicateAddReads_MultipleOptions(Path base) throws Exception {
Path src = base.resolve("src");
Path src_m1 = src.resolve("m1");
Path src_m1 = src.resolve("m1x");
tb.writeJavaFiles(src_m1,
"module m1 { exports p1; }",
"module m1x { exports p1; }",
"package p1; public class C1 { }");
Path src_m2 = src.resolve("m2");
Path src_m2 = src.resolve("m2x");
tb.writeJavaFiles(src_m2,
"module m2 { }",
"module m2x { }",
"package p2; class C2 { p1.C1 c1; }");
Path classes = base.resolve("classes");
tb.createDirectories(classes);
new JavacTask(tb)
.options("--module-source-path", src.toString(),
"--add-reads", "m2=m1",
"--add-reads", "m2=m1")
"--add-reads", "m2x=m1x",
"--add-reads", "m2x=m1x")
.outdir(classes)
.files(findJavaFiles(src))
.run()
@ -529,25 +530,25 @@ public class AddReadsTest extends ModuleTestBase {
@Test
public void testRepeatedAddReads(Path base) throws Exception {
Path src = base.resolve("src");
Path src_m1 = src.resolve("m1");
Path src_m1 = src.resolve("m1x");
tb.writeJavaFiles(src_m1,
"module m1 { exports p1; }",
"module m1x { exports p1; }",
"package p1; public class C1 { }");
Path src_m2 = src.resolve("m2");
Path src_m2 = src.resolve("m2x");
tb.writeJavaFiles(src_m2,
"module m2 { exports p2; }",
"module m2x { exports p2; }",
"package p2; public class C2 { }");
Path src_m3 = src.resolve("m3");
Path src_m3 = src.resolve("m3x");
tb.writeJavaFiles(src_m3,
"module m3 { }",
"module m3x { }",
"package p3; class C3 { p1.C1 c1; p2.C2 c2; }");
Path classes = base.resolve("classes");
tb.createDirectories(classes);
new JavacTask(tb)
.options("--module-source-path", src.toString(),
"--add-reads", "m3=m1",
"--add-reads", "m3=m2")
"--add-reads", "m3x=m1x",
"--add-reads", "m3x=m2x")
.outdir(classes)
.files(findJavaFiles(src))
.run()
@ -563,7 +564,7 @@ public class AddReadsTest extends ModuleTestBase {
String log = new JavacTask(tb, Task.Mode.CMDLINE)
.options("-XDrawDiagnostics",
"--add-reads", "m1:m2")
"--add-reads", "m1x:m2x")
.outdir(classes)
.files(findJavaFiles(src))
.run(Task.Expect.FAIL)
@ -571,7 +572,7 @@ public class AddReadsTest extends ModuleTestBase {
.getOutput(Task.OutputKind.DIRECT);
checkOutputContains(log,
"javac: bad value for --add-reads option: 'm1:m2'");
"javac: bad value for --add-reads option: 'm1x:m2x'");
}
@Test
@ -583,7 +584,7 @@ public class AddReadsTest extends ModuleTestBase {
String log = new JavacTask(tb)
.options("-XDrawDiagnostics",
"--add-reads", "bad*Source=m2")
"--add-reads", "bad*Source=m2x")
.outdir(classes)
.files(findJavaFiles(src))
.run()
@ -597,16 +598,16 @@ public class AddReadsTest extends ModuleTestBase {
@Test
public void testBadTargetName(Path base) throws Exception {
Path src = base.resolve("src");
Path src_m1 = src.resolve("m1");
Path src_m1 = src.resolve("m1x");
tb.writeJavaFiles(src_m1,
"module m1 { }",
"module m1x { }",
"package p1; class C1 { }");
Path classes = base.resolve("classes");
tb.createDirectories(classes);
String log = new JavacTask(tb)
.options("-XDrawDiagnostics",
"--add-reads", "m1=badTarget!")
"--add-reads", "m1x=badTarget!")
.outdir(classes)
.files(findJavaFiles(src))
.run()
@ -620,16 +621,16 @@ public class AddReadsTest extends ModuleTestBase {
@Test
public void testSourceNameNotFound(Path base) throws Exception {
Path src = base.resolve("src");
Path src_m1 = src.resolve("m1");
Path src_m1 = src.resolve("m1x");
tb.writeJavaFiles(src_m1,
"module m1 { exports p1; }",
"module m1x { exports p1; }",
"package p1; public class C1 { }");
Path classes = base.resolve("classes");
tb.createDirectories(classes);
String log = new JavacTask(tb)
.options("-XDrawDiagnostics",
"--add-reads", "missingSource=m1")
"--add-reads", "missingSource=m")
.outdir(classes)
.files(findJavaFiles(src))
.run()
@ -643,16 +644,16 @@ public class AddReadsTest extends ModuleTestBase {
@Test
public void testTargetNameNotFound(Path base) throws Exception {
Path src = base.resolve("src");
Path src_m1 = src.resolve("m1");
Path src_m1 = src.resolve("m1x");
tb.writeJavaFiles(src_m1,
"module m1 { exports p1; }",
"module m1x { exports p1; }",
"package p1; public class C1 { }");
Path classes = base.resolve("classes");
tb.createDirectories(classes);
String log = new JavacTask(tb)
.options("-XDrawDiagnostics",
"--add-reads", "m1=missingTarget")
"--add-reads", "m1x=missingTarget")
.outdir(classes)
.files(findJavaFiles(src))
.run()

Some files were not shown because too many files have changed in this diff Show More