Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8344708: Compiler Implementation of Module Import Declarations #23801

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -76,8 +76,7 @@ public enum Feature {
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,
LANGUAGE_MODEL,
Original file line number Diff line number Diff line change
@@ -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();

/**
Original file line number Diff line number Diff line change
@@ -231,8 +231,6 @@ public boolean isPreview(Feature feature) {
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.
Original file line number Diff line number Diff line change
@@ -267,8 +267,8 @@ public enum Feature {
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),
;
4 changes: 1 addition & 3 deletions src/jdk.jshell/share/classes/jdk/jshell/Snippet.java
Original file line number Diff line number Diff line change
@@ -28,7 +28,6 @@
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 enum SubKind {
* 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),

/**
96 changes: 25 additions & 71 deletions test/langtools/tools/javac/ImportModule.java
Original file line number Diff line number Diff line change
@@ -92,7 +92,6 @@ public static void main(String... args) {

{//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 static void main(String... args) {
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 static void main(String... args) {

{//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 static void main(String... args) {
var out = new JavaTask(tb)
.classpath(classes.toString())
.className("test.Test")
.vmOptions("--enable-preview")
.run()
.writeAll()
.getOutputLines(Task.OutputKind.STDOUT);
@@ -161,42 +157,30 @@ public class Test {

actualErrors =
new JavacTask(tb)
.options("--release", "21", "-XDrawDiagnostics")
.options("--release", "24", "-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)",
"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 Test {
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 Test {
""");

new JavacTask(tb)
.options("--enable-preview", "--release", SOURCE_VERSION)
.outdir(classes)
.files(tb.findJavaFiles(src))
.run()
@@ -258,7 +240,6 @@ public class Test {
""");

new JavacTask(tb)
.options("--enable-preview", "--release", SOURCE_VERSION)
.outdir(classes)
.files(tb.findJavaFiles(src))
.run()
@@ -274,7 +255,6 @@ public class Test {
""");

new JavacTask(tb)
.options("--enable-preview", "--release", SOURCE_VERSION)
.outdir(classes)
.files(tb.findJavaFiles(src))
.run()
@@ -292,8 +272,7 @@ public class Test {

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 Test {

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 Test {
""");

new JavacTask(tb)
.options("--enable-preview", "--release", SOURCE_VERSION)
.outdir(classes)
.files(tb.findJavaFiles(src))
.run()
@@ -387,8 +363,7 @@ public static void main(String... args) {

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 static void main(String... args) {

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 static void main(String... args) {

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 static void main(String... args) {
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 static void main(String... args) {

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 static void main(String... args) {
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 Impl2 {
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 Test2 {

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 Test2 {
"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 Test {
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 ModuleModuleClass {
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 @@ void main() {
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 C {}
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 C {}
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 Test {
"- 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 Test {

if (!Objects.equals(expectedErrors, actualErrors)) {
throw new AssertionError("Incorrect Output, expected: " + expectedErrors +
", actual: " + out);
", actual: " + actualErrors);

}
}
@@ -878,7 +836,6 @@ public class Test {

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 Test {

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 Test {

new JavacTask(tb)
.options("-XDrawDiagnostics",
"--enable-preview", "--release", SOURCE_VERSION,
"--module-source-path", src.toString())
.outdir(classes)
.files(tb.findJavaFiles(src))
@@ -1001,15 +955,16 @@ public static void main(String... args) {
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)
.writeAll()
.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,16 +989,15 @@ public static void main(String... args) {
}

new JavacTask(tb)
.options("-XDrawDiagnostics",
"--enable-preview", "--release", SOURCE_VERSION)
.options("-XDrawDiagnostics")
.outdir(maClasses)
.files(tb.findJavaFiles(ma))
.run()
.writeAll();

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");
}
}
4 changes: 2 additions & 2 deletions test/langtools/tools/javac/diags/examples/ImportModule.java
Original file line number Diff line number Diff line change
@@ -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;

Original file line number Diff line number Diff line change
@@ -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 {}
Original file line number Diff line number Diff line change
@@ -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;

Original file line number Diff line number Diff line change
@@ -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;

Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -448,7 +448,6 @@ public void testInModuleImport(Path base) throws Exception {

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 void testInModuleImport(Path base) throws Exception {

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))
5 changes: 3 additions & 2 deletions test/langtools/tools/javac/modules/EdgeCases.java
Original file line number Diff line number Diff line change
@@ -1178,15 +1178,16 @@ public class Test {

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)
.writeAll()
.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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't there a similar test above?

"1 error");

if (!expected.equals(log))
4 changes: 2 additions & 2 deletions test/langtools/tools/javac/modules/JavaBaseTest.java
Original file line number Diff line number Diff line change
@@ -129,7 +129,7 @@ void testSource(Path base, List<String> mods, String target) throws Exception {
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 @@ void testSource(Path base, List<String> mods, String target) throws Exception {
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;
1 change: 0 additions & 1 deletion test/langtools/tools/jdeps/listdeps/ListModuleDeps.java
Original file line number Diff line number Diff line change
@@ -92,7 +92,6 @@ public void compileAll() throws Exception {
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",