8344708: Implement JEP 511: Module Import Declarations

Reviewed-by: mcimadamore, vromero, alanb
This commit is contained in:
Jan Lahoda 2025-05-01 07:42:38 +00:00
parent b218410508
commit 0a697f6ff4
32 changed files with 359 additions and 217 deletions

View File

@ -76,8 +76,7 @@ public @interface PreviewFeature {
STRUCTURED_CONCURRENCY,
CLASSFILE_API,
STREAM_GATHERERS,
@JEP(number=494, title="Module Import Declarations", status="Second Preview")
MODULE_IMPORTS,
MODULE_IMPORTS, //remove when the boot JDK is JDK 25
@JEP(number=478, title="Key Derivation Function API", status="Preview")
KEY_DERIVATION,
@JEP(number = 502, title = "Stable Values", status = "Preview")

View File

@ -408,24 +408,10 @@ public final class ModuleInfo {
throw invalidModuleDescriptor("The requires entry for java.base"
+ " has ACC_SYNTHETIC set");
}
// requires transitive java.base is illegal unless:
// - the major version is 53 (JDK 9), or:
// - the classfile is a preview classfile, or:
// - the module is deemed to be participating in preview
// (i.e. the module is a java.* module)
// requires static java.base is illegal unless:
// - the major version is 53 (JDK 9), or:
if (major >= 54
&& ((mods.contains(Requires.Modifier.TRANSITIVE)
&& !isPreview
&& !"java.se".equals(mn))
|| mods.contains(Requires.Modifier.STATIC))) {
String flagName;
if (mods.contains(Requires.Modifier.STATIC)) {
flagName = "ACC_STATIC_PHASE";
} else {
flagName = "ACC_TRANSITIVE";
}
// requires static java.base is illegal unless
// the major version is 53 (JDK 9)
if (major >= 54 && mods.contains(Requires.Modifier.STATIC)) {
String flagName = "ACC_STATIC_PHASE";
throw invalidModuleDescriptor("The requires entry for java.base"
+ " has " + flagName + " set");
}

View File

@ -25,8 +25,6 @@
package com.sun.source.tree;
import jdk.internal.javac.PreviewFeature;
/**
* A tree node for an import declaration.
*
@ -49,11 +47,11 @@ public interface ImportTree extends Tree {
* @return true if this is a static import
*/
boolean isStatic();
/**
* {@return true if this is an module import declaration.}
* @since 23
* @since 25
*/
@PreviewFeature(feature=PreviewFeature.Feature.MODULE_IMPORTS, reflective=true)
boolean isModule();
/**

View File

@ -153,9 +153,7 @@ public class Preview {
// s participates in the preview API
return syms.java_base.exports.stream()
.filter(ed -> ed.packge.fullname == names.jdk_internal_javac)
.anyMatch(ed -> ed.modules.contains(m)) ||
//the specification lists the java.se module as participating in preview:
m.name == names.java_se;
.anyMatch(ed -> ed.modules.contains(m));
}
/**
@ -231,8 +229,6 @@ public class Preview {
case IMPLICIT_CLASSES -> true;
case FLEXIBLE_CONSTRUCTORS -> true;
case PRIMITIVE_PATTERNS -> true;
case MODULE_IMPORTS -> true;
case JAVA_BASE_TRANSITIVE -> true;
//Note: this is a backdoor which allows to optionally treat all features as 'preview' (for testing).
//When real preview features will be added, this method can be implemented to return 'true'
//for those selected features, and 'false' for all the others.

View File

@ -267,8 +267,8 @@ public enum Source {
UNNAMED_VARIABLES(JDK22, Fragments.FeatureUnnamedVariables, DiagKind.PLURAL),
PRIMITIVE_PATTERNS(JDK23, Fragments.FeaturePrimitivePatterns, DiagKind.PLURAL),
FLEXIBLE_CONSTRUCTORS(JDK22, Fragments.FeatureFlexibleConstructors, DiagKind.NORMAL),
MODULE_IMPORTS(JDK23, Fragments.FeatureModuleImports, DiagKind.PLURAL),
JAVA_BASE_TRANSITIVE(JDK24, Fragments.FeatureJavaBaseTransitive, DiagKind.PLURAL),
MODULE_IMPORTS(JDK25, Fragments.FeatureModuleImports, DiagKind.PLURAL),
JAVA_BASE_TRANSITIVE(JDK25, Fragments.FeatureJavaBaseTransitive, DiagKind.PLURAL),
PRIVATE_MEMBERS_IN_PERMITS_CLAUSE(JDK19),
ERASE_POLY_SIG_RETURN_TYPE(JDK24),
;

View File

@ -1202,11 +1202,6 @@ public class ClassReader {
ModuleSymbol rsym = poolReader.getModule(nextChar());
Set<RequiresFlag> flags = readRequiresFlags(nextChar());
if (rsym == syms.java_base && majorVersion >= V54.major) {
if (flags.contains(RequiresFlag.TRANSITIVE) &&
(majorVersion != Version.MAX().major || !previewClassFile) &&
!preview.participatesInPreview(syms, msym)) {
throw badClassFile("bad.requires.flag", RequiresFlag.TRANSITIVE);
}
if (flags.contains(RequiresFlag.STATIC_PHASE)) {
throw badClassFile("bad.requires.flag", RequiresFlag.STATIC_PHASE);
}

View File

@ -131,6 +131,7 @@ import static java.util.stream.Collectors.joining;
import static jdk.jshell.Snippet.SubKind.TEMP_VAR_EXPRESSION_SUBKIND;
import static jdk.jshell.Snippet.SubKind.VAR_VALUE_SUBKIND;
import static java.util.stream.Collectors.toMap;
import javax.lang.model.SourceVersion;
import static jdk.internal.jshell.debug.InternalDebugControl.DBG_COMPA;
import static jdk.internal.jshell.debug.InternalDebugControl.DBG_DEP;
import static jdk.internal.jshell.debug.InternalDebugControl.DBG_EVNT;
@ -642,7 +643,10 @@ public class JShellTool implements MessageHandler {
} else {
String packedStartup = prefs.get(STARTUP_KEY);
boolean preview = previewEnabled(options);
initialStartup = Startup.unpack(packedStartup, preview, new InitMessageHandler());
String sourceLevel = detectSourceLevel(options.valuesOf(argC)
.toArray(String[]::new));
initialStartup = Startup.unpack(packedStartup, sourceLevel,
preview, new InitMessageHandler());
}
if (options.has(argExecution)) {
executionControlSpec = options.valueOf(argExecution);
@ -2311,7 +2315,8 @@ public class JShellTool implements MessageHandler {
}
} else if (defaultOption) {
boolean preview = options.hasOption(OptionKind.ENABLE_PREVIEW);
startup = Startup.defaultStartup(preview, this);
String sourceLevel = detectSourceLevel(options.compilerOptions());
startup = Startup.defaultStartup(sourceLevel, preview, this);
} else if (noneOption) {
startup = Startup.noStartup();
}
@ -2329,7 +2334,8 @@ public class JShellTool implements MessageHandler {
String retained = prefs.get(STARTUP_KEY);
if (retained != null) {
boolean preview = options.hasOption(OptionKind.ENABLE_PREVIEW);
Startup retainedStart = Startup.unpack(retained, preview, this);
String sourceLevel = detectSourceLevel(options.compilerOptions());
Startup retainedStart = Startup.unpack(retained, sourceLevel, preview, this);
boolean currentDifferent = !startup.equals(retainedStart);
sb.append(retainedStart.show(true));
if (currentDifferent) {
@ -2346,6 +2352,19 @@ public class JShellTool implements MessageHandler {
hard(escape(sb));
}
private String detectSourceLevel(String[] compilerOptions) {
for (int i = 0; i < compilerOptions.length; i++) {
switch (compilerOptions[i]) {
case "-source", "--source", "--release":
if (i + 1 < compilerOptions.length) {
return compilerOptions[i + 1];
}
}
}
return Integer.toString(SourceVersion.latest().runtimeVersion().feature());
}
private void showIndent() {
hard("/set indent %s", indent());
}

View File

@ -25,6 +25,8 @@
package jdk.internal.jshell.tool;
import com.sun.tools.javac.code.Source;
import com.sun.tools.javac.code.Source.Feature;
import java.nio.file.AccessDeniedException;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
@ -32,8 +34,11 @@ import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import static java.util.stream.Collectors.joining;
import static jdk.internal.jshell.tool.JShellTool.RECORD_SEPARATOR;
@ -118,13 +123,10 @@ class Startup {
}
private static final String DEFAULT_STARTUP_NAME = "DEFAULT";
private static final String PREVIEW_DEFAULT_STARTUP_NAME = "PREVIEW_DEFAULT";
// cached DEFAULT start-up
private static Startup[] defaultStartup = new Startup[] {
null, //standard startup
null //preview startup
};
private static Map<DefaultStartupType, Startup> defaultStartup =
new EnumMap<>(DefaultStartupType.class);
// the list of entries
private List<StartupEntry> entries;
@ -170,8 +172,10 @@ class Startup {
boolean isDefault() {
if (entries.size() == 1) {
StartupEntry sue = entries.get(0);
if (sue.isBuiltIn && (sue.name.equals(DEFAULT_STARTUP_NAME) ||
sue.name.equals(PREVIEW_DEFAULT_STARTUP_NAME))) {
if (sue.isBuiltIn &&
Arrays.stream(DefaultStartupType.values())
.map(DefaultStartupType::getResourceName)
.anyMatch(sue.name::equals)) {
return true;
}
}
@ -222,7 +226,7 @@ class Startup {
* @param mh handler for error messages
* @return Startup, or default startup when error (message has been printed)
*/
static Startup unpack(String storedForm, boolean preview, MessageHandler mh) {
static Startup unpack(String storedForm, String sourceLevel, boolean preview, MessageHandler mh) {
if (storedForm != null) {
if (storedForm.isEmpty()) {
return noStartup();
@ -243,14 +247,18 @@ class Startup {
String name = all[i + 1];
String timeStamp = all[i + 2];
String content = all[i + 3];
if (isBuiltIn) {
// update to current definition, use stored if removed/error
String resource = getResource(name);
if (resource != null) {
content = resource;
if (isBuiltIn && DEFAULT_STARTUP_NAME.equals(name)) {
e.addAll(defaultStartup(sourceLevel, preview, mh).entries);
} else {
if (isBuiltIn) {
// update to current definition, use stored if removed/error
String resource = getResource(name);
if (resource != null) {
content = resource;
}
}
e.add(new StartupEntry(isBuiltIn, name, content, timeStamp));
}
e.add(new StartupEntry(isBuiltIn, name, content, timeStamp));
}
return new Startup(e);
} else {
@ -260,7 +268,7 @@ class Startup {
mh.errormsg("jshell.err.corrupted.stored.startup", ex.getMessage());
}
}
return defaultStartup(preview, mh);
return defaultStartup(sourceLevel, preview, mh);
}
/**
@ -329,26 +337,49 @@ class Startup {
* @param mh handler for error messages
* @return The default Startup, or empty startup when error (message has been printed)
*/
static Startup defaultStartup(boolean preview, MessageHandler mh) {
int idx = preview ? 1 : 0;
static Startup defaultStartup(String sourceLevel, boolean preview, MessageHandler mh) {
Source source = Source.lookup(sourceLevel);
DefaultStartupType type;
if (preview) {
type = DefaultStartupType.PREVIEW_DEFAULT_STARTUP;
} else if (source == null ||
Feature.MODULE_IMPORTS.allowedInSource(source)) {
type = DefaultStartupType.DEFAULT_STARTUP;
} else {
type = DefaultStartupType.DEFAULT_STARTUP_NO_MODULE_IMPORTS;
}
if (defaultStartup[idx] != null) {
return defaultStartup[idx];
}
String resourceName = preview ? PREVIEW_DEFAULT_STARTUP_NAME
: DEFAULT_STARTUP_NAME;
try {
String content = readResource(resourceName);
return defaultStartup[idx] = new Startup(
new StartupEntry(true, resourceName, content));
} catch (AccessDeniedException e) {
mh.errormsg("jshell.err.file.not.accessible", "jshell", resourceName, e.getMessage());
} catch (NoSuchFileException e) {
mh.errormsg("jshell.err.file.not.found", "jshell", resourceName);
} catch (Exception e) {
mh.errormsg("jshell.err.file.exception", "jshell", resourceName, e);
}
return defaultStartup[idx] = noStartup();
return defaultStartup.computeIfAbsent(type, t -> {
String resourceName = t.getResourceName();
try {
String content = readResource(resourceName);
return new Startup(
new StartupEntry(true, DEFAULT_STARTUP_NAME, content));
} catch (AccessDeniedException e) {
mh.errormsg("jshell.err.file.not.accessible", "jshell", resourceName, e.getMessage());
} catch (NoSuchFileException e) {
mh.errormsg("jshell.err.file.not.found", "jshell", resourceName);
} catch (Exception e) {
mh.errormsg("jshell.err.file.exception", "jshell", resourceName, e);
}
return noStartup();
});
}
private enum DefaultStartupType {
DEFAULT_STARTUP("DEFAULT"),
DEFAULT_STARTUP_NO_MODULE_IMPORTS("DEFAULT_NO_MODULE_IMPORTS"),
PREVIEW_DEFAULT_STARTUP("PREVIEW_DEFAULT");
private final String resourceName;
private DefaultStartupType(String resourceName) {
this.resourceName = resourceName;
}
public String getResourceName() {
return resourceName;
}
}
}

View File

@ -28,7 +28,6 @@ package jdk.jshell;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import jdk.internal.javac.PreviewFeature;
/**
* A Snippet represents a snippet of Java source code as passed to
@ -219,9 +218,8 @@ public abstract class Snippet {
* Import Module Declaration.
* An import declaration of a module.
* @jls 7.5.5 Import Module Declarations
* @since 23
* @since 25
*/
@PreviewFeature(feature=PreviewFeature.Feature.MODULE_IMPORTS, reflective=true)
MODULE_IMPORT_SUBKIND(Kind.IMPORT),
/**

View File

@ -36,6 +36,13 @@ import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.stream.Stream;
import javax.lang.model.element.ModuleElement;
import javax.lang.model.element.ModuleElement.ExportsDirective;
import javax.lang.model.element.ModuleElement.RequiresDirective;
import javax.lang.model.util.ElementFilter;
import jdk.jshell.Snippet.SubKind;
import jdk.jshell.TaskFactory.AnalyzeTask;
import static jdk.jshell.Util.PREFIX_PATTERN;
import static jdk.jshell.Util.REPL_PACKAGE;
@ -51,6 +58,7 @@ final class SnippetMaps {
private final List<Snippet> keyIndexToSnippet = new ArrayList<>();
private final Set<Snippet> snippets = new LinkedHashSet<>();
private final Map<String, Set<Integer>> dependencies = new HashMap<>();
private final Map<String, Set<String>> module2PackagesForImport = new HashMap<>();
private final JShell state;
SnippetMaps(JShell proc) {
@ -186,6 +194,13 @@ final class SnippetMaps {
if (Stream.concat(Stream.of("java.lang"), pkgs).anyMatch(pkg::equals)) {
return full.substring(pkg.length() + 1);
}
Stream<String> modPkgs = importSnippets()
.filter(isi -> isi.subKind() == SubKind.MODULE_IMPORT_SUBKIND)
.map(isi -> isi.fullname)
.flatMap(this::module2PackagesForImport);
if (modPkgs.anyMatch(pkg::equals)) {
return full.substring(pkg.length() + 1);
}
return full;
}
@ -198,4 +213,38 @@ final class SnippetMaps {
.map(key -> (ImportSnippet)getSnippet(key))
.filter(sn -> sn != null && state.status(sn).isDefined());
}
private Stream<String> module2PackagesForImport(String module) {
return module2PackagesForImport.computeIfAbsent(module, mod -> {
return state.taskFactory
.analyze(new OuterWrap(Wrap.identityWrap(" ")),
at -> computeImports(at, mod));
}).stream();
}
private Set<String> computeImports(AnalyzeTask at, String mod) {
List<ModuleElement> todo = new ArrayList<>();
Set<ModuleElement> seenModules = new HashSet<>();
Set<String> exportedPackages = new HashSet<>();
todo.add(at.getElements().getModuleElement(mod));
while (!todo.isEmpty()) {
ModuleElement current = todo.remove(todo.size() - 1);
if (current == null || !seenModules.add(current)) {
continue;
}
for (ExportsDirective exp : ElementFilter.exportsIn(current.getDirectives())) {
if (exp.getTargetModules() != null) {
continue;
}
exportedPackages.add(exp.getPackage().getQualifiedName().toString());
}
for (RequiresDirective req : ElementFilter.requiresIn(current.getDirectives())) {
if (!req.isTransitive()) {
continue;
}
todo.add(req.getDependency());
}
}
return exportedPackages;
}
}

View File

@ -1,10 +1 @@
import java.io.*;
import java.math.*;
import java.net.*;
import java.nio.file.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.prefs.*;
import java.util.regex.*;
import java.util.stream.*;
import module java.base;

View File

@ -0,0 +1,10 @@
import java.io.*;
import java.math.*;
import java.net.*;
import java.nio.file.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.prefs.*;
import java.util.regex.*;
import java.util.stream.*;

View File

@ -78,6 +78,7 @@ public class ClassFileVersionsTest {
// for JDK 10 through FEATURE.
for (int i = 10; i <= FEATURE; i++) {
result.add(new Object[]{ 44 + i, 0, Set.of()});
result.add(new Object[]{ 44 + i, 0, Set.of(TRANSITIVE)});
}
result.add(new Object[]{ 44 + FEATURE,
@ -110,7 +111,6 @@ public class ClassFileVersionsTest {
for (int i = 10; i <= FEATURE ; i++) {
// Major class file version of JDK N is 44+n
result.add(new Object[]{i + 44, 0, Set.of(STATIC)});
result.add(new Object[]{i + 44, 0, Set.of(TRANSITIVE)});
result.add(new Object[]{i + 44, 0, Set.of(STATIC, TRANSITIVE)});
}

View File

@ -1523,7 +1523,6 @@ public class ModuleDescriptorTest {
assertTrue(s.contains("p1"));
}
@Test(expectedExceptions = InvalidModuleDescriptorException.class)
public void testRequiresTransitiveJavaBaseNotPermitted1() throws Exception {
ModuleDescriptor descriptor = ModuleDescriptor.newModule("foo")
.requires(Set.of(Modifier.TRANSITIVE), "java.base")
@ -1536,7 +1535,6 @@ public class ModuleDescriptorTest {
ModuleDescriptor.read(bb, () -> Set.of("p", "q"));
}
@Test(expectedExceptions = InvalidModuleDescriptorException.class)
public void testRequiresTransitiveJavaBaseNotPermitted2() throws Exception {
ModuleDescriptor descriptor = ModuleDescriptor.newModule("foo")
.requires(Set.of(Modifier.TRANSITIVE), "java.base")

View File

@ -57,19 +57,8 @@ import static org.testng.Assert.fail;
public class ReplToolTesting {
private final static String DEFAULT_STARTUP_MESSAGE = "| Welcome to";
final static List<ImportInfo> START_UP_IMPORTS = Stream.of(
"java.io.*",
"java.math.*",
"java.net.*",
"java.nio.file.*",
"java.util.*",
"java.util.concurrent.*",
"java.util.function.*",
"java.util.prefs.*",
"java.util.regex.*",
"java.util.stream.*")
.map(s -> new ImportInfo("import " + s + ";", "", s))
.collect(toList());
final static List<ImportInfo> START_UP_IMPORTS = List.of(
new ImportInfo("import module java.base;", "", "java.base"));
final static List<MethodInfo> START_UP_METHODS = Stream.<MethodInfo>of()
.collect(toList());
final static List<String> START_UP_CMD_METHOD = Stream.<String>of()

View File

@ -42,6 +42,7 @@ import java.nio.file.Path;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.function.Consumer;
@ -68,6 +69,7 @@ public class StartOptionTest {
protected ByteArrayOutputStream userout;
protected ByteArrayOutputStream usererr;
protected InputStream cmdInStream;
private Map<String, String> testPersistence;
private JavaShellToolBuilder builder() {
// turn on logging of launch failures
@ -77,12 +79,23 @@ public class StartOptionTest {
.out(new PrintStream(cmdout), new PrintStream(console), new PrintStream(userout))
.err(new PrintStream(cmderr), new PrintStream(usererr))
.in(cmdInStream, null)
.persistence(new HashMap<>())
.persistence(getThisTestPersistence())
.env(new HashMap<>())
.locale(Locale.ROOT);
}
protected Map<String, String> getThisTestPersistence() {
return testPersistence != null ? testPersistence
: new HashMap<>();
}
protected int runShell(String... args) {
cmdout.reset();
cmderr.reset();
console.reset();
userout.reset();
usererr.reset();
try {
return builder()
.start(Presets.addExecutionIfMissing(args));
@ -150,6 +163,17 @@ public class StartOptionTest {
String... args) {
runShell(args);
check(userout, checkUserOutput, "userout");
check(cmderr, null, "cmderr");
check(usererr, null, "usererr");
}
protected void startCheckCommandUserOutput(Consumer<String> checkCommandOutput,
Consumer<String> checkUserOutput,
Consumer<String> checkCombinedCommandUserOutput,
String... args) {
runShell(args);
check(cmdout, checkCommandOutput, "cmdout");
check(userout, checkUserOutput, "userout");
check(usererr, null, "usererr");
}
@ -226,8 +250,12 @@ public class StartOptionTest {
}
protected String writeToFile(String stuff) {
return writeToFile("doit.repl", stuff);
}
protected String writeToFile(String fileName, String stuff) {
Compiler compiler = new Compiler();
Path p = compiler.getPath("doit.repl");
Path p = compiler.getPath(fileName);
compiler.writeToFile(p, stuff);
return p.toString();
}
@ -393,7 +421,7 @@ public class StartOptionTest {
"--show-version");
}
public void testPreviewEnabled() {
public void testSourceLevel() {
String fn = writeToFile(
"""
System.out.println(\"prefix\");
@ -401,23 +429,105 @@ public class StartOptionTest {
System.out.println(\"suffix\");
/exit
""");
startCheckUserOutput(s -> assertEquals(s, "prefix\nsuffix\n"),
startCheckUserOutput(s -> assertEquals(s, "prefix\njava.lang.invoke.MethodHandle\nsuffix\n"),
fn);
startCheckUserOutput(s -> assertEquals(s, "prefix\njava.lang.invoke.MethodHandle\nsuffix\n"),
"--enable-preview", fn);
String fn24 = writeToFile(
"""
System.out.println(\"test\");
/exit
""");
startCheckUserOutput(s -> assertEquals(s, "test\n"),
"-C--release", "-C24", fn24);
startCheckUserOutput(s -> assertEquals(s, "test\n"),
"-C--source", "-C24", fn24);
startCheckUserOutput(s -> assertEquals(s, "test\n"),
"-C-source", "-C24", fn24);
//JDK-8341631:
String fn2 = writeToFile(
"""
System.out.println(\"test\");
/exit
""");
startCheckUserOutput(s -> assertEquals(s, "test\n"),
fn2);
String fn2Preview = writeToFile(
"""
System.out.println(\"prefix\");
IO.println(\"test\");
System.out.println(\"suffix\");
/exit
""");
startCheckUserOutput(s -> assertEquals(s, "prefix\nsuffix\n"),
fn2);
startCheckUserOutput(s -> assertEquals(s, "prefix\ntest\nsuffix\n"),
"--enable-preview", fn2);
"--enable-preview", fn2Preview);
testPersistence = new HashMap<>();
String newStartupScript = writeToFile("test-startup.repl",
"""
System.out.println("Custom start script");
""");
String setStartup = writeToFile(
"""
/set start -retain {file}
/exit
""".replace("{file}", newStartupScript));
startCheckUserOutput(s -> {}, setStartup);
String exit = writeToFile(
"""
/exit
""");
startCheckUserOutput(s -> assertEquals(s, "Custom start script\n"),
exit);
String clearStartup = writeToFile(
"""
/set start -retain -default
/exit
""");
startCheckUserOutput(s -> {}, clearStartup);
String retainTest = writeToFile(
"""
/set start
System.out.println(\"prefix\");
System.out.println(MethodHandle.class.getName());
System.out.println(\"suffix\");
/exit
""");
startCheckCommandUserOutput(s -> assertEquals(s, "/set start -retain -default\n"),
s -> assertEquals(s, "prefix\njava.lang.invoke.MethodHandle\nsuffix\n"),
s -> assertEquals(s, "/set start -retain -default\nprefix\njava.lang.invoke.MethodHandle\nsuffix\n"),
retainTest);
String retainTest24 = writeToFile(
"""
System.out.println(\"test\");
/exit
""");
startCheckUserOutput(s -> assertEquals(s, "test\n"),
"-C--release", "-C24", retainTest24);
String set24DefaultTest = writeToFile(
"""
/set start -default -retain
/exit
""");
startCheckUserOutput(s -> {},
"-C--release", "-C24", set24DefaultTest);
String checkDefaultAfterSet24Test = writeToFile(
"""
/set start
System.out.println(\"prefix\");
System.out.println(MethodHandle.class.getName());
System.out.println(\"suffix\");
/exit
""");
startCheckCommandUserOutput(s -> assertEquals(s, "/set start -retain -default\n"),
s -> assertEquals(s, "prefix\njava.lang.invoke.MethodHandle\nsuffix\n"),
s -> assertEquals(s, "/set start -retain -default\nprefix\njava.lang.invoke.MethodHandle\nsuffix\n"),
checkDefaultAfterSet24Test);
}
public void testInput() {
//readLine(String):
String readLinePrompt = writeToFile(

View File

@ -274,7 +274,7 @@ public class ToolCommandOptionTest extends ReplToolTesting {
(a) -> assertCommand(a, "/set start DEFAULT PRINTING",
""),
(a) -> assertCommandOutputContains(a, "/set start",
"/set start DEFAULT PRINTING", "void println", "import java.util.*"),
"/set start DEFAULT PRINTING", "void println", "import module java.base;"),
(a) -> assertCommand(a, "/set start " + startup.toString(),
""),
(a) -> assertCommandOutputContains(a, "/set start",
@ -333,7 +333,7 @@ public class ToolCommandOptionTest extends ReplToolTesting {
"| ---- PRINTING ----\n",
"| int iAmHere = 1234;\n",
"| void println(String s)",
"| import java.io.*;")
"| import module java.base;")
);
}

View File

@ -28,6 +28,11 @@
* @run testng ToolEnablePreviewTest
*/
import java.io.IOException;
import java.io.Writer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.testng.annotations.Test;
import static org.testng.Assert.assertTrue;
@ -70,8 +75,14 @@ public class ToolEnablePreviewTest extends ReplToolTesting {
}
@Test
public void testCompilerTestFlagEnv() {
test(new String[] {"-C", "-XDforcePreview"},
public void testCompilerTestFlagEnv() throws IOException {
Path startupFile = Paths.get("startup.repl");
try (Writer w = Files.newBufferedWriter(startupFile)) {
w.write("""
import java.util.function.*;
""");
}
test(new String[] {"-C", "-XDforcePreview", "-startup", startupFile.toString()},
(a) -> assertCommandOutputContains(a, "Function<Integer,Integer> f = (var i) -> i + i",
"Error", "preview feature"),
(a) -> assertCommand(a, "/env --enable-preview",

View File

@ -73,7 +73,7 @@ public class ToolLocalSimpleTest extends ToolSimpleTest {
public void testCompoundStart() {
test(new String[]{"--startup", "DEFAULT", "--startup", "PRINTING", "--startup", "TOOLING"},
(a) -> assertCommandOutputContains(a, "/list -start",
"System.out.println", "import java.util.concurrent", "tools()")
"System.out.println", "import module java.base;", "tools()")
);
}

View File

@ -72,11 +72,21 @@ public class ToolProviderTest extends StartOptionTest {
check(usererr, null, "usererr");
}
@Override
protected void startCheckCommandUserOutput(Consumer<String> checkCommandOutput,
Consumer<String> checkUserOutput,
Consumer<String> checkCombinedCommandUserOutput,
String... args) {
runShell(args);
check(cmdout, checkCombinedCommandUserOutput, "userout");
check(usererr, null, "usererr");
}
@Override
protected int runShell(String... args) {
//make sure the JShell running during the test is not using persisted preferences from the machine:
Function<JavaShellToolBuilder, JavaShellToolBuilder> prevAugmentedToolBuilder =
getAndSetAugmentedToolBuilder(builder -> builder.persistence(new HashMap<>()));
getAndSetAugmentedToolBuilder(builder -> builder.persistence(getThisTestPersistence()));
try {
ServiceLoader<Tool> sl = ServiceLoader.load(Tool.class);
for (Tool provider : sl) {

View File

@ -33,6 +33,7 @@
* jdk.compiler/com.sun.tools.javac.main
* jdk.jdeps/com.sun.tools.javap
* jdk.jshell/jdk.internal.jshell.tool
* java.desktop
* @build KullaTesting TestingInputStream
* @run testng ToolSimpleTest
*/
@ -566,11 +567,11 @@ public class ToolSimpleTest extends ReplToolTesting {
s -> checkLineToList(s, START_UP)),
a -> assertCommandCheckOutput(a, "/list -all",
s -> checkLineToList(s, startVarList)),
a -> assertCommandOutputStartsWith(a, "/list s3",
"s3 : import"),
a -> assertCommandCheckOutput(a, "/list 1-2 s3",
a -> assertCommandOutputStartsWith(a, "/list s1",
"s1 : import"),
a -> assertCommandCheckOutput(a, "/list 1-2 s1",
s -> {
assertTrue(Pattern.matches(".*aardvark.*\\R.*weevil.*\\R.*s3.*import.*", s.trim()),
assertTrue(Pattern.matches(".*aardvark.*\\R.*weevil.*\\R.*s1.*import.*", s.trim()),
"No match: " + s);
}),
a -> assertCommandOutputStartsWith(a, "/list " + arg,
@ -977,4 +978,14 @@ public class ToolSimpleTest extends ReplToolTesting {
(a) -> assertCommandOutputContains(a, "var a = a;", "cannot use 'var' on self-referencing variable")
);
}
@Test
public void testModuleImportShortenedTypes() {
test(
(a) -> assertCommandOutputContains(a, "import module java.desktop;", ""),
(a) -> assertCommandOutputContains(a, "var r1 = new JButton()", ""),
(a) -> assertCommandOutputContains(a, "/vars r1", "| JButton r1 =")
);
}
}

View File

@ -92,7 +92,6 @@ public class ImportModule extends TestRunner {
{//with --release:
new JavacTask(tb)
.options("--enable-preview", "--release", SOURCE_VERSION)
.outdir(classes)
.files(tb.findJavaFiles(src))
.run(Task.Expect.SUCCESS)
@ -101,7 +100,6 @@ public class ImportModule extends TestRunner {
var out = new JavaTask(tb)
.classpath(classes.toString())
.className("test.Test")
.vmOptions("--enable-preview")
.run()
.writeAll()
.getOutputLines(Task.OutputKind.STDOUT);
@ -117,7 +115,6 @@ public class ImportModule extends TestRunner {
{//with --source:
new JavacTask(tb)
.options("--enable-preview", "--source", SOURCE_VERSION)
.outdir(classes)
.files(tb.findJavaFiles(src))
.run(Task.Expect.SUCCESS)
@ -126,7 +123,6 @@ public class ImportModule extends TestRunner {
var out = new JavaTask(tb)
.classpath(classes.toString())
.className("test.Test")
.vmOptions("--enable-preview")
.run()
.writeAll()
.getOutputLines(Task.OutputKind.STDOUT);
@ -161,7 +157,7 @@ public class ImportModule extends TestRunner {
actualErrors =
new JavacTask(tb)
.options("--release", "21", "-XDrawDiagnostics")
.options("--release", "24", "-XDrawDiagnostics")
.outdir(classes)
.files(tb.findJavaFiles(src))
.run(Task.Expect.FAIL)
@ -169,34 +165,22 @@ public class ImportModule extends TestRunner {
.getOutputLines(Task.OutputKind.DIRECT);
expectedErrors = List.of(
"Test.java:2:8: compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.module.imports)",
"Test.java:2:8: compiler.err.feature.not.supported.in.source.plural: (compiler.misc.feature.module.imports), 24, 25",
"1 error"
);
if (!Objects.equals(expectedErrors, actualErrors)) {
throw new AssertionError("Incorrect Output, expected: " + expectedErrors +
", actual: " + out);
", actual: " + actualErrors);
}
actualErrors =
new JavacTask(tb)
.options("-XDrawDiagnostics")
.outdir(classes)
.files(tb.findJavaFiles(src))
.run(Task.Expect.FAIL)
.writeAll()
.getOutputLines(Task.OutputKind.DIRECT);
expectedErrors = List.of(
"Test.java:2:8: compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.module.imports)",
"1 error"
);
if (!Objects.equals(expectedErrors, actualErrors)) {
throw new AssertionError("Incorrect Output, expected: " + expectedErrors +
", actual: " + out);
}
new JavacTask(tb)
.options("-XDrawDiagnostics")
.outdir(classes)
.files(tb.findJavaFiles(src))
.run()
.writeAll();
}
@Test
@ -220,8 +204,7 @@ public class ImportModule extends TestRunner {
List<String> expectedErrors;
new JavacTask(tb)
.options("--enable-preview", "--release", SOURCE_VERSION,
"-XDrawDiagnostics")
.options("-XDrawDiagnostics")
.outdir(classes)
.files(tb.findJavaFiles(src))
.run(Task.Expect.SUCCESS)
@ -240,7 +223,6 @@ public class ImportModule extends TestRunner {
""");
new JavacTask(tb)
.options("--enable-preview", "--release", SOURCE_VERSION)
.outdir(classes)
.files(tb.findJavaFiles(src))
.run()
@ -258,7 +240,6 @@ public class ImportModule extends TestRunner {
""");
new JavacTask(tb)
.options("--enable-preview", "--release", SOURCE_VERSION)
.outdir(classes)
.files(tb.findJavaFiles(src))
.run()
@ -274,7 +255,6 @@ public class ImportModule extends TestRunner {
""");
new JavacTask(tb)
.options("--enable-preview", "--release", SOURCE_VERSION)
.outdir(classes)
.files(tb.findJavaFiles(src))
.run()
@ -292,8 +272,7 @@ public class ImportModule extends TestRunner {
actualErrors =
new JavacTask(tb)
.options("--enable-preview", "--release", SOURCE_VERSION,
"-XDrawDiagnostics")
.options("-XDrawDiagnostics")
.outdir(classes)
.files(tb.findJavaFiles(src))
.run(Task.Expect.FAIL)
@ -302,8 +281,6 @@ public class ImportModule extends TestRunner {
expectedErrors = List.of(
"Test.java:5:5: compiler.err.ref.ambiguous: Date, kindname.class, java.sql.Date, java.sql, kindname.class, java.util.Date, java.util",
"- compiler.note.preview.filename: Test.java, DEFAULT",
"- compiler.note.preview.recompile",
"1 error"
);
@ -325,7 +302,6 @@ public class ImportModule extends TestRunner {
""");
new JavacTask(tb)
.options("--enable-preview", "--release", SOURCE_VERSION)
.outdir(classes)
.files(tb.findJavaFiles(src))
.run()
@ -387,8 +363,7 @@ public class ImportModule extends TestRunner {
actualErrors =
new JavacTask(tb)
.options("--enable-preview", "--release", SOURCE_VERSION,
"-p", libClasses.toString(),
.options("-p", libClasses.toString(),
"--add-modules", "lib",
"-XDrawDiagnostics")
.outdir(classes)
@ -399,8 +374,6 @@ public class ImportModule extends TestRunner {
expectedErrors = List.of(
"Test.java:6:9: compiler.err.cant.resolve.location: kindname.class, Impl, , , (compiler.misc.location: kindname.class, test.Test, null)",
"- compiler.note.preview.filename: Test.java, DEFAULT",
"- compiler.note.preview.recompile",
"1 error"
);
@ -412,8 +385,7 @@ public class ImportModule extends TestRunner {
actualErrors =
new JavacTask(tb)
.options("--enable-preview", "--release", SOURCE_VERSION,
"-p", libClasses.toString(),
.options("-p", libClasses.toString(),
"-XDdev",
"-XDrawDiagnostics")
.outdir(classes)
@ -425,8 +397,6 @@ public class ImportModule extends TestRunner {
expectedErrors = List.of(
"Test.java:2:1: compiler.err.import.module.does.not.read.unnamed: lib",
"Test.java:6:9: compiler.err.cant.resolve.location: kindname.class, Impl, , , (compiler.misc.location: kindname.class, test.Test, null)",
"- compiler.note.preview.filename: Test.java, DEFAULT",
"- compiler.note.preview.recompile",
"2 errors"
);
@ -444,8 +414,7 @@ public class ImportModule extends TestRunner {
actualErrors =
new JavacTask(tb)
.options("--enable-preview", "--release", SOURCE_VERSION,
"-p", libClasses.toString(),
.options("-p", libClasses.toString(),
"-XDdev",
"-XDrawDiagnostics")
.outdir(classes)
@ -457,8 +426,6 @@ public class ImportModule extends TestRunner {
expectedErrors = List.of(
"Test.java:2:1: compiler.err.import.module.does.not.read: test.module, lib",
"Test.java:6:9: compiler.err.cant.resolve.location: kindname.class, Impl, , , (compiler.misc.location: kindname.class, test.Test, null)",
"- compiler.note.preview.filename: Test.java, DEFAULT",
"- compiler.note.preview.recompile",
"2 errors"
);
@ -539,8 +506,7 @@ public class ImportModule extends TestRunner {
Files.createDirectories(libClasses);
new JavacTask(tb)
.options("--enable-preview", "--release", SOURCE_VERSION,
"--module-source-path", libSrc.toString(),
.options("--module-source-path", libSrc.toString(),
"-XDrawDiagnostics")
.outdir(libClasses)
.files(tb.findJavaFiles(libSrc))
@ -591,8 +557,7 @@ public class ImportModule extends TestRunner {
actualErrors =
new JavacTask(tb)
.options("--enable-preview", "--release", SOURCE_VERSION,
"--module-path", libClasses.toString(),
.options("--module-path", libClasses.toString(),
"-XDrawDiagnostics")
.outdir(classes)
.files(tb.findJavaFiles(src))
@ -611,8 +576,6 @@ public class ImportModule extends TestRunner {
"Test2.java:7:5: compiler.err.cant.resolve.location: kindname.class, Impl1, , , (compiler.misc.location: kindname.class, test.Test2, null)",
"Test2.java:10:5: compiler.err.cant.resolve.location: kindname.class, Api6, , , (compiler.misc.location: kindname.class, test.Test2, null)",
"Test2.java:11:5: compiler.err.cant.resolve.location: kindname.class, Impl2, , , (compiler.misc.location: kindname.class, test.Test2, null)",
"- compiler.note.preview.plural: DEFAULT",
"- compiler.note.preview.recompile",
"10 errors"
);
@ -640,7 +603,6 @@ public class ImportModule extends TestRunner {
List<String> kinds = new ArrayList<>();
new JavacTask(tb)
.options("--enable-preview", "--release", SOURCE_VERSION)
.outdir(classes)
.callback(task -> {
task.addTaskListener(new TaskListener() {
@ -699,7 +661,6 @@ public class ImportModule extends TestRunner {
List<String> kinds = new ArrayList<>();
new JavacTask(tb)
.options("--enable-preview", "--release", SOURCE_VERSION)
.outdir(classes)
.files(tb.findJavaFiles(src))
.run(Task.Expect.SUCCESS)
@ -721,7 +682,7 @@ public class ImportModule extends TestRunner {
Files.createDirectories(classes);
new JavacTask(tb)
.options("--enable-preview", "--release", SOURCE_VERSION)
.options("--enable-preview", "--release", SOURCE_VERSION) //for implicitly declared classes
.outdir(classes)
.files(tb.findJavaFiles(src))
.run(Task.Expect.SUCCESS)
@ -761,8 +722,7 @@ public class ImportModule extends TestRunner {
Files.createDirectories(classes);
List<String> actualErrors = new JavacTask(tb)
.options("-XDrawDiagnostics",
"--enable-preview", "--release", SOURCE_VERSION)
.options("-XDrawDiagnostics")
.outdir(classes)
.files(tb.findJavaFiles(src))
.run(Task.Expect.FAIL)
@ -772,8 +732,6 @@ public class ImportModule extends TestRunner {
List<String> expectedErrors = List.of(
"module-info.java:3:18: compiler.warn.module.not.found: M1",
"module-info.java:6:9: compiler.err.cant.resolve: kindname.class, A, , ",
"- compiler.note.preview.filename: module-info.java, DEFAULT",
"- compiler.note.preview.recompile",
"1 error",
"1 warning"
);
@ -816,7 +774,7 @@ public class ImportModule extends TestRunner {
"- compiler.warn.option.obsolete.source: 8",
"- compiler.warn.option.obsolete.target: 8",
"- compiler.warn.option.obsolete.suppression",
"Test.java:2:8: compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.module.imports)",
"Test.java:2:8: compiler.err.feature.not.supported.in.source.plural: (compiler.misc.feature.module.imports), 8, 25",
"Test.java:2:1: compiler.err.import.module.not.found: java.base",
"Test.java:4:5: compiler.err.cant.resolve.location: kindname.class, List, , , (compiler.misc.location: kindname.class, test.Test, null)",
"3 errors",
@ -825,7 +783,7 @@ public class ImportModule extends TestRunner {
if (!Objects.equals(expectedErrors, actualErrors)) {
throw new AssertionError("Incorrect Output, expected: " + expectedErrors +
", actual: " + out);
", actual: " + actualErrors);
}
}
@ -878,7 +836,6 @@ public class ImportModule extends TestRunner {
List<String> actualErrors = new JavacTask(tb)
.options("-XDrawDiagnostics",
"--enable-preview", "--release", SOURCE_VERSION,
"--module-source-path", src.toString())
.outdir(classes)
.files(tb.findJavaFiles(src))
@ -888,8 +845,6 @@ public class ImportModule extends TestRunner {
List<String> expectedErrors = List.of(
"Test.java:5:5: compiler.err.ref.ambiguous: A, kindname.class, mb.p1.A, mb.p1, kindname.class, ma.p1.A, ma.p1",
"- compiler.note.preview.filename: Test.java, DEFAULT",
"- compiler.note.preview.recompile",
"1 error"
);
@ -914,7 +869,6 @@ public class ImportModule extends TestRunner {
new JavacTask(tb)
.options("-XDrawDiagnostics",
"--enable-preview", "--release", SOURCE_VERSION,
"--module-source-path", src.toString())
.outdir(classes)
.files(tb.findJavaFiles(src))
@ -1001,7 +955,8 @@ public class ImportModule extends TestRunner {
Files.createDirectories(maClasses);
List<String> actualErrors = new JavacTask(tb)
.options("-XDrawDiagnostics")
.options("-XDrawDiagnostics",
"--release", "24")
.outdir(maClasses)
.files(tb.findJavaFiles(ma))
.run(Task.Expect.FAIL)
@ -1009,7 +964,7 @@ public class ImportModule extends TestRunner {
.getOutputLines(Task.OutputKind.DIRECT);
List<String> expectedErrors = List.of(
"module-info.java:2:4: compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.java.base.transitive)",
"module-info.java:2:4: compiler.err.feature.not.supported.in.source.plural: (compiler.misc.feature.java.base.transitive), 24, 25",
"1 error"
);
@ -1034,8 +989,7 @@ public class ImportModule extends TestRunner {
}
new JavacTask(tb)
.options("-XDrawDiagnostics",
"--enable-preview", "--release", SOURCE_VERSION)
.options("-XDrawDiagnostics")
.outdir(maClasses)
.files(tb.findJavaFiles(ma))
.run()
@ -1043,7 +997,7 @@ public class ImportModule extends TestRunner {
Path maModuleInfo2 = maClasses.resolve("module-info.class");
if (ClassFile.of().parse(maModuleInfo2).minorVersion() != ClassFile.PREVIEW_MINOR_VERSION) {
if (ClassFile.of().parse(maModuleInfo2).minorVersion() != 0) {
throw new AssertionError("wrong minor version");
}
}

View File

@ -22,8 +22,8 @@
*/
// key: compiler.misc.feature.module.imports
// key: compiler.warn.preview.feature.use.plural
// options: --release ${jdk.version} --enable-preview -Xlint:preview
// key: compiler.err.feature.not.supported.in.source.plural
// options: --release 24 -Xlint:preview
import module java.base;

View File

@ -22,7 +22,5 @@
*/
// key: compiler.err.import.module.does.not.read
// key: compiler.note.preview.filename
// key: compiler.note.preview.recompile
// options: --release ${jdk.version} --enable-preview
module m {}

View File

@ -22,9 +22,7 @@
*/
// key: compiler.err.import.module.does.not.read.unnamed
// key: compiler.note.preview.filename
// key: compiler.note.preview.recompile
// options: --release ${jdk.version} --enable-preview --limit-modules java.base
// options: --limit-modules java.base
import module java.compiler;

View File

@ -22,9 +22,6 @@
*/
// key: compiler.err.import.module.not.found
// key: compiler.note.preview.filename
// key: compiler.note.preview.recompile
// options: --release ${jdk.version} --enable-preview
import module unknown;

View File

@ -21,8 +21,9 @@
* questions.
*/
// key: compiler.err.preview.feature.disabled.plural
// key: compiler.err.feature.not.supported.in.source.plural
// key: compiler.misc.feature.java.base.transitive
// options: --release 24
module m {
requires transitive java.base;

View File

@ -755,7 +755,7 @@ public class AnnotationsOnModules extends ModuleTestBase {
for (ModuleRequireInfo mri : attr.requires()) {
if (mri.requires().name().equalsString("java.base")) {
requires.add(ModuleRequireInfo.of(mri.requires(),
List.of(AccessFlag.TRANSITIVE),
List.of(AccessFlag.STATIC_PHASE),
mri.requiresVersion()
.orElse(null)));
} else {
@ -804,7 +804,7 @@ public class AnnotationsOnModules extends ModuleTestBase {
.writeAll()
.getOutputLines(OutputKind.DIRECT);
List<String> expectedErrors = List.of(
"- compiler.err.cant.access: m.module-info, (compiler.misc.bad.class.file.header: module-info.class, (compiler.misc.bad.requires.flag: ACC_TRANSITIVE (0x0020)))",
"- compiler.err.cant.access: m.module-info, (compiler.misc.bad.class.file.header: module-info.class, (compiler.misc.bad.requires.flag: ACC_STATIC_PHASE (0x0040)))",
"1 error"
);

View File

@ -448,7 +448,6 @@ public class ConvenientAccessErrorsTest extends ModuleTestBase {
List<String> log = new JavacTask(tb)
.options("-XDrawDiagnostics",
"--enable-preview", "--source", System.getProperty("java.specification.version"),
"--module-source-path", src.toString())
.outdir(classes)
.files(findJavaFiles(src))
@ -458,8 +457,6 @@ public class ConvenientAccessErrorsTest extends ModuleTestBase {
List<String> expected = Arrays.asList(
"Test.java:1:54: compiler.err.cant.resolve.location: kindname.class, Api, , , (compiler.misc.location: kindname.class, test.Test, null)",
"- compiler.note.preview.filename: Test.java, DEFAULT",
"- compiler.note.preview.recompile",
"1 error");
if (!expected.equals(log))

View File

@ -1178,7 +1178,8 @@ public class EdgeCases extends ModuleTestBase {
log = new JavacTask(tb)
.outdir(classes)
.options("-XDrawDiagnostics", "-XDshould-stop.at=FLOW")
.options("-XDrawDiagnostics", "-XDshould-stop.at=FLOW",
"--release", "24")
.callback(verifyJavaSEDependency(true, seenJavaSEDependency))
.files(findJavaFiles(src))
.run(Task.Expect.FAIL)
@ -1186,7 +1187,7 @@ public class EdgeCases extends ModuleTestBase {
.getOutputLines(Task.OutputKind.DIRECT);
List<String> expected = List.of(
"Test.java:2:8: compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.module.imports)",
"Test.java:2:8: compiler.err.feature.not.supported.in.source.plural: (compiler.misc.feature.module.imports), 24, 25",
"1 error");
if (!expected.equals(log))

View File

@ -129,7 +129,7 @@ public class JavaBaseTest {
case "current":
options.add("--release");
options.add(CURRENT_VERSION);
expectOK = false;
expectOK = true;
break;
case "current-preview":
options.add("--enable-preview");
@ -166,7 +166,7 @@ public class JavaBaseTest {
for (String mod : mods) {
String key = mod.equals("static")
? "compiler.err.mod.not.allowed.here: " + mod
: "compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.java.base.transitive)";
: "compiler.err.feature.not.supported.in.source.plural: (compiler.misc.feature.java.base.transitive), $(VERSION), 25".replace("$(VERSION)", target);
String message = "module-info.java:1:12: " + key;
if (log.contains(message)) {
foundErrorMessage = true;
@ -179,30 +179,26 @@ public class JavaBaseTest {
}
void testClass(Path base, List<String> mods, String target) throws Exception {
boolean expectOK;
boolean expectOK = true;
List<String> options = new ArrayList<>();
switch (target) {
case "current":
options.add("--release");
options.add(CURRENT_VERSION);
expectOK = false;
break;
case "current-preview":
options.add("--enable-preview");
options.add("--release");
options.add(CURRENT_VERSION);
expectOK = true;
break;
case "9":
options.add("--release");
options.add(target);
expectOK = true;
break;
default:
options.add("--release");
options.add(target);
expectOK = false;
break;
}

View File

@ -92,7 +92,6 @@ public class ListModuleDeps {
public Object[][] jdkModules() {
return new Object[][]{
{"jdk.compiler", new String[]{
"java.base/jdk.internal.javac",
"java.base/jdk.internal.jmod",
"java.base/jdk.internal.misc",
"java.base/jdk.internal.module",