Skip to content

Commit

Permalink
java.se is participating in preview.
Browse files Browse the repository at this point in the history
  • Loading branch information
lahodaj committed Oct 7, 2024
1 parent 852c288 commit b454cb7
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ private Builder readModuleAttribute(DataInput in, ConstantPool cpool, int major,
+ " has ACC_SYNTHETIC set");
}
if (major >= 54
&& ((mods.contains(Requires.Modifier.TRANSITIVE) && !previewClassfile)
&& ((mods.contains(Requires.Modifier.TRANSITIVE) && !previewClassfile && !mn.startsWith("java."))
|| mods.contains(Requires.Modifier.STATIC))) {
String flagName;
if (mods.contains(Requires.Modifier.TRANSITIVE) && !previewClassfile) {
Expand Down
1 change: 1 addition & 0 deletions src/java.base/share/classes/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
exports jdk.internal.javac to
java.compiler,
java.desktop, // for ScopedValue
java.se, // for ParticipatesInPreview
jdk.compiler,
jdk.incubator.vector, // participates in preview features
jdk.jartool, // participates in preview features
Expand Down
4 changes: 4 additions & 0 deletions src/java.se/share/classes/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
* questions.
*/

import jdk.internal.javac.ParticipatesInPreview;

/**
* Defines the API of the Java SE Platform.
*
Expand All @@ -38,7 +40,9 @@
* @moduleGraph
* @since 9
*/
@ParticipatesInPreview
module java.se {
requires transitive java.base;
requires transitive java.compiler;
requires transitive java.datatransfer;
requires transitive java.desktop;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import com.sun.tools.javac.code.Lint.LintCategory;
import com.sun.tools.javac.code.Source.Feature;
import com.sun.tools.javac.code.Symbol.ModuleSymbol;
import com.sun.tools.javac.jvm.Target;
import com.sun.tools.javac.resources.CompilerProperties.Errors;
import com.sun.tools.javac.resources.CompilerProperties.Warnings;
Expand Down Expand Up @@ -133,11 +134,23 @@ public boolean participatesInPreview(Symtab syms, Symbol s, Symbol previewSymbol
return true;
}

return participatesInPreview(syms, s.packge().modle);
}

/**
* Returns true if module {@code m} is deemed to participate in the preview, and
* therefore no warnings or errors will be produced.
*
* @param syms the symbol table
* @param m the module to check
* @return true if {@code m} is participating in the preview of {@code previewSymbol}
*/
public boolean participatesInPreview(Symtab syms, ModuleSymbol m) {
// If java.base's jdk.internal.javac package is exported to s's module then
// 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(s.packge().modle));
.anyMatch(ed -> ed.modules.contains(m));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1204,7 +1204,8 @@ protected void read(Symbol sym, int attrLen) {
Set<RequiresFlag> flags = readRequiresFlags(nextChar());
if (rsym == syms.java_base && majorVersion >= V54.major) {
if (flags.contains(RequiresFlag.TRANSITIVE) &&
(majorVersion != Version.MAX().major || !previewClassFile)) {
(majorVersion != Version.MAX().major || !previewClassFile) &&
!preview.participatesInPreview(syms, msym)) {
throw badClassFile("bad.requires.flag", RequiresFlag.TRANSITIVE);
}
if (flags.contains(RequiresFlag.STATIC_PHASE)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ public static Names instance(Context context) {

// module names
public final Name java_base;
public final Name java_se;
public final Name jdk_unsupported;

// attribute names
Expand Down Expand Up @@ -316,7 +315,6 @@ public Names(Context context) {

// module names
java_base = fromString("java.base");
java_se = fromString("java.se");
jdk_unsupported = fromString("jdk.unsupported");

// attribute names
Expand Down
11 changes: 5 additions & 6 deletions test/langtools/tools/javac/modules/EdgeCases.java
Original file line number Diff line number Diff line change
Expand Up @@ -1179,16 +1179,15 @@ public class Test {
log = new JavacTask(tb)
.outdir(classes)
.options("-XDrawDiagnostics", "-XDshould-stop.at=FLOW")
.callback(verifyJavaSEDependency(false, seenJavaSEDependency))
.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:4:5: compiler.err.cant.resolve.location: kindname.class, ArrayList, , , (compiler.misc.location: kindname.class, test.Test, null)",
"2 errors");
"1 error");

if (!expected.equals(log))
throw new Exception("expected output not found: " + log);
Expand Down Expand Up @@ -1225,17 +1224,17 @@ public void finished(TaskEvent e) {
t.getElements().getModuleElement("java.base");
ModuleElement javaSE =
t.getElements().getModuleElement("java.se");
RequiresDirective requiresJavaSE =
RequiresDirective requiresJavaBase =
javaSE.getDirectives()
.stream()
.filter(d -> d.getKind() == DirectiveKind.REQUIRES)
.map(d -> (RequiresDirective) d)
.filter(d -> d.getDependency() == javaBase)
.findAny()
.orElseThrow();
if (requiresJavaSE.isTransitive() != expectedTransitive) {
if (requiresJavaBase.isTransitive() != expectedTransitive) {
throw new AssertionError("Expected: " + expectedTransitive + ", " +
"but got: " + requiresJavaSE.isTransitive());
"but got: " + requiresJavaBase.isTransitive());
}
seenJavaSEDependency.set(true);
}
Expand Down

0 comments on commit b454cb7

Please sign in to comment.