8264664: use text blocks in javac module tests

Reviewed-by: darcy
This commit is contained in:
Jonathan Gibbons 2021-04-03 01:18:00 +00:00
parent cec66cf8ef
commit e8eda655bb
18 changed files with 630 additions and 503 deletions

View File

@ -361,22 +361,24 @@ public class AddLimitMods extends ModuleTestBase {
StringBuilder testClassNamed = new StringBuilder(); StringBuilder testClassNamed = new StringBuilder();
testClassNamed.append("package test;\n" + testClassNamed.append("""
"public class Test {\n" + package test;
" public static void main(String... args) throws Exception {\n"); public class Test {
public static void main(String... args) throws Exception {
""");
for (Entry<String, String> e : MODULES_TO_CHECK_TO_SAMPLE_CLASS.entrySet()) { for (Entry<String, String> e : MODULES_TO_CHECK_TO_SAMPLE_CLASS.entrySet()) {
testClassNamed.append(" System.err.println(\"visible:" + e.getKey() + ":\" + ModuleLayer.boot().findModule(\"" + e.getKey() + "\").isPresent());\n"); testClassNamed.append(" System.err.println(\"visible:" + e.getKey() + ":\" + ModuleLayer.boot().findModule(\"" + e.getKey() + "\").isPresent());\n");
} }
testClassNamed.append(" Class<?> cp = Class.forName(Test.class.getClassLoader().getUnnamedModule(), \"cp.CP\");\n"); testClassNamed.append("""
testClassNamed.append(" cp.getDeclaredMethod(\"runMe\").invoke(null);\n"); Class<?> cp = Class.forName(Test.class.getClassLoader().getUnnamedModule(), "cp.CP");
cp.getDeclaredMethod("runMe").invoke(null);
testClassNamed.append(" Class<?> automatic = Class.forName(ModuleLayer.boot().findModule(\"automatic\").get(), \"automatic.Automatic\");\n"); Class<?> automatic = Class.forName(ModuleLayer.boot().findModule("automatic").get(), "automatic.Automatic");
testClassNamed.append(" automatic.getDeclaredMethod(\"runMe\").invoke(null);\n"); automatic.getDeclaredMethod("runMe").invoke(null);
}
testClassNamed.append(" }\n" + }
"}"); """);
tb.writeJavaFiles(m2Runtime, moduleInfo, testClassNamed.toString()); tb.writeJavaFiles(m2Runtime, moduleInfo, testClassNamed.toString());
@ -415,8 +417,10 @@ public class AddLimitMods extends ModuleTestBase {
tb.writeJavaFiles(m2, tb.writeJavaFiles(m2,
moduleInfo, moduleInfo,
"package test;\n" + """
"public class Test {}\n"); package test;
public class Test {}
""");
List<String> auxOptions = success ? Arrays.asList( List<String> auxOptions = success ? Arrays.asList(
"--processor-path", System.getProperty("test.class.path"), "--processor-path", System.getProperty("test.class.path"),
@ -448,12 +452,13 @@ public class AddLimitMods extends ModuleTestBase {
"public class " + simpleName + " {" + "public class " + simpleName + " {" +
" public static void runMe() throws Exception {"); " public static void runMe() throws Exception {");
for (Entry<String, String> e : MODULES_TO_CHECK_TO_SAMPLE_CLASS.entrySet()) { for (Entry<String, String> e : MODULES_TO_CHECK_TO_SAMPLE_CLASS.entrySet()) {
checkClassesAccessible.append("try {"); checkClassesAccessible
checkClassesAccessible.append("Class.forName(\"" + e.getValue() + "\").newInstance();"); .append("try {")
checkClassesAccessible.append("System.err.println(\"" + fqn + ":" + e.getKey() + ":true\");"); .append("Class.forName(\"" + e.getValue() + "\").newInstance();")
checkClassesAccessible.append("} catch (Exception ex) {"); .append("System.err.println(\"" + fqn + ":" + e.getKey() + ":true\");")
checkClassesAccessible.append("System.err.println(\"" + fqn + ":" + e.getKey() + ":false\");"); .append("} catch (Exception ex) {")
checkClassesAccessible.append("}"); .append("System.err.println(\"" + fqn + ":" + e.getKey() + ":false\");")
.append("}");
} }
checkClassesAccessible.append(" }\n" + checkClassesAccessible.append(" }\n" +

View File

@ -4,12 +4,12 @@ class foo/module-info {
52; // version 52; // version
[] { // Constant Pool [] { // Constant Pool
; // first element is empty ; // first element is empty
class #6; // #1 class #6; // #1
Utf8 "SourceFile"; // #2 Utf8 "SourceFile"; // #2
Utf8 "module-info.java"; // #3 Utf8 "module-info.java"; // #3
Utf8 "Module"; // #4 Utf8 "Module"; // #4
Utf8 "java.base"; // #5 Utf8 "java.base"; // #5
Utf8 "foo/module-info"; // #6 Utf8 "foo/module-info"; // #6
} // Constant Pool } // Constant Pool
0x8000; // access 0x8000; // access

View File

@ -906,7 +906,8 @@ public class AnnotationProcessing extends ModuleTestBase {
runCompiler(base, runCompiler(base,
m1, m1,
classes, classes,
"createSource(() -> filer.createResource(StandardLocation.CLASS_OUTPUT, \"impl\", \"impl\"" + originating + "), \"impl\", \"impl\")", """
createSource(() -> filer.createResource(StandardLocation.CLASS_OUTPUT, "impl", "impl\"""" + originating + "), \"impl\", \"impl\")",
options); options);
assertFileExists(classes, modulePath, "impl", "impl"); assertFileExists(classes, modulePath, "impl", "impl");
} }
@ -1044,28 +1045,31 @@ public class AnnotationProcessing extends ModuleTestBase {
private void compileAP(Path target, String code) { private void compileAP(Path target, String code) {
String processorCode = String processorCode =
"import java.util.*;\n" + """
"import javax.annotation.processing.*;\n" + import java.util.*;
"import javax.lang.model.*;\n" + import javax.annotation.processing.*;
"import javax.lang.model.element.*;\n" + import javax.lang.model.*;
"import javax.lang.model.type.*;\n" + import javax.lang.model.element.*;
"import javax.lang.model.util.*;\n" + import javax.lang.model.type.*;
"import javax.tools.*;\n" + import javax.lang.model.util.*;
"@SupportedAnnotationTypes(\"*\")\n" + import javax.tools.*;
"public final class AP extends AnnotationProcessing.GeneratingAP {\n" + @SupportedAnnotationTypes("*")
"\n" + public final class AP extends AnnotationProcessing.GeneratingAP {
" int round;\n" +
"\n" + int round;
" @Override\n" +
" public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {\n" + @Override
" if (round++ != 0)\n" + public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
" return false;\n" + if (round++ != 0)
" Filer filer = processingEnv.getFiler();\n" + return false;
" TypeElement jlObject = processingEnv.getElementUtils().getTypeElement(\"java.lang.Object\");\n" + Filer filer = processingEnv.getFiler();
code + ";\n" + TypeElement jlObject = processingEnv.getElementUtils().getTypeElement("java.lang.Object");
" return false;\n" + """ + code + """
" }\n" + ;
" }\n"; return false;
}
}
""";
new JavacTask(tb) new JavacTask(tb)
.options("-classpath", System.getProperty("test.class.path")) .options("-classpath", System.getProperty("test.class.path"))
.sources(processorCode) .sources(processorCode)

View File

@ -46,72 +46,76 @@ public class AnnotationProcessorsInModulesTest extends ModuleTestBase {
} }
private static final String annotationProcessorModule1 = private static final String annotationProcessorModule1 =
"module anno_proc1x {\n" + """
" requires java.compiler;\n" + module anno_proc1x {
"\n" + requires java.compiler;
" provides javax.annotation.processing.Processor\n" +
" with mypkg1.MyProcessor1;\n" + provides javax.annotation.processing.Processor
"}"; with mypkg1.MyProcessor1;
}""";
private static final String annotationProcessorModule2 = private static final String annotationProcessorModule2 =
"module anno_proc2x {\n" + """
" requires java.compiler;\n" + module anno_proc2x {
"\n" + requires java.compiler;
" provides javax.annotation.processing.Processor\n" +
" with mypkg2.MyProcessor2;\n" + provides javax.annotation.processing.Processor
"}"; with mypkg2.MyProcessor2;
}""";
private static final String annotationProcessor1 = private static final String annotationProcessor1 =
"package mypkg1;\n" + """
"\n" + package mypkg1;
"import javax.annotation.processing.AbstractProcessor;\n" +
"import javax.annotation.processing.RoundEnvironment;\n" + import javax.annotation.processing.AbstractProcessor;
"import javax.annotation.processing.SupportedAnnotationTypes;\n" + import javax.annotation.processing.RoundEnvironment;
"import javax.lang.model.SourceVersion;\n" + import javax.annotation.processing.SupportedAnnotationTypes;
"import javax.lang.model.element.*;\n" + import javax.lang.model.SourceVersion;
"\n" + import javax.lang.model.element.*;
"import java.util.*;\n" +
"\n" + import java.util.*;
"@SupportedAnnotationTypes(\"*\")\n" +
"public final class MyProcessor1 extends AbstractProcessor {\n" + @SupportedAnnotationTypes("*")
"\n" + public final class MyProcessor1 extends AbstractProcessor {
" @Override\n" +
" public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {\n" + @Override
" return false;\n" + public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
" }\n" + return false;
"\n" + }
" @Override\n" +
" public SourceVersion getSupportedSourceVersion() {\n" + @Override
" System.out.println(\"the annotation processor 1 is working!\");\n" + public SourceVersion getSupportedSourceVersion() {
" return SourceVersion.latest();\n" + System.out.println("the annotation processor 1 is working!");
" }\n" + return SourceVersion.latest();
"}"; }
}""";
private static final String annotationProcessor2 = private static final String annotationProcessor2 =
"package mypkg2;\n" + """
"\n" + package mypkg2;
"import javax.annotation.processing.AbstractProcessor;\n" +
"import javax.annotation.processing.RoundEnvironment;\n" + import javax.annotation.processing.AbstractProcessor;
"import javax.annotation.processing.SupportedAnnotationTypes;\n" + import javax.annotation.processing.RoundEnvironment;
"import javax.lang.model.SourceVersion;\n" + import javax.annotation.processing.SupportedAnnotationTypes;
"import javax.lang.model.element.*;\n" + import javax.lang.model.SourceVersion;
"\n" + import javax.lang.model.element.*;
"import java.util.*;\n" +
"\n" + import java.util.*;
"@SupportedAnnotationTypes(\"*\")\n" +
"public final class MyProcessor2 extends AbstractProcessor {\n" + @SupportedAnnotationTypes("*")
"\n" + public final class MyProcessor2 extends AbstractProcessor {
" @Override\n" +
" public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {\n" + @Override
" return false;\n" + public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
" }\n" + return false;
"\n" + }
" @Override\n" +
" public SourceVersion getSupportedSourceVersion() {\n" + @Override
" System.out.println(\"the annotation processor 2 is working!\");\n" + public SourceVersion getSupportedSourceVersion() {
" return SourceVersion.latest();\n" + System.out.println("the annotation processor 2 is working!");
" }\n" + return SourceVersion.latest();
"}"; }
}""";
private static final String testClass = "class Test{}"; private static final String testClass = "class Test{}";

View File

@ -270,11 +270,12 @@ public class AnnotationsOnModules extends ModuleTestBase {
Path m1 = base.resolve("src1/A"); Path m1 = base.resolve("src1/A");
tb.writeJavaFiles(m1, tb.writeJavaFiles(m1,
"module A { " + """
"exports p1 to B; opens p1 to B;" + module A {
"exports p2 to C; opens p2 to C;" + exports p1 to B; opens p1 to B;
"exports p3 to B,C; opens p3 to B,C;" + exports p2 to C; opens p2 to C;
"}", exports p3 to B,C; opens p3 to B,C;
}""",
"package p1; public class A { }", "package p1; public class A { }",
"package p2; public class A { }", "package p2; public class A { }",
"package p3; public class A { }"); "package p3; public class A { }");
@ -547,10 +548,11 @@ public class AnnotationsOnModules extends ModuleTestBase {
String DEPRECATED_JAVADOC = "/** @deprecated */"; String DEPRECATED_JAVADOC = "/** @deprecated */";
for (String suppress : new String[] {"", DEPRECATED_JAVADOC, "@Deprecated ", "@SuppressWarnings(\"deprecation\") "}) { for (String suppress : new String[] {"", DEPRECATED_JAVADOC, "@Deprecated ", "@SuppressWarnings(\"deprecation\") "}) {
tb.writeJavaFiles(m3, tb.writeJavaFiles(m3,
suppress + "module m3x {\n" + suppress + """
" requires m1x;\n" + module m3x {
" exports api to m1x, m2x;\n" + requires m1x;
"}", exports api to m1x, m2x;
}""",
"package api; public class Api { }"); "package api; public class Api { }");
System.err.println("compile m3x"); System.err.println("compile m3x");
actual = new JavacTask(tb) actual = new JavacTask(tb)

View File

@ -461,10 +461,11 @@ public class AutomaticModules extends ModuleTestBase {
Path src = base.resolve("src"); Path src = base.resolve("src");
tb.writeJavaFiles(src, tb.writeJavaFiles(src,
"module m1x {\n" + """
" requires transitive automaticA;\n" + module m1x {
" requires automaticB;\n" + requires transitive automaticA;
"}"); requires automaticB;
}""");
Path classes = base.resolve("classes"); Path classes = base.resolve("classes");
@ -550,11 +551,12 @@ public class AutomaticModules extends ModuleTestBase {
.getOutputLines(Task.OutputKind.DIRECT); .getOutputLines(Task.OutputKind.DIRECT);
tb.writeJavaFiles(src, tb.writeJavaFiles(src,
"@SuppressWarnings(\"requires-transitive-automatic\")\n" + """
"module m1x {\n" + @SuppressWarnings("requires-transitive-automatic")
" requires transitive automaticA;\n" + module m1x {
" requires automaticB;\n" + requires transitive automaticA;
"}"); requires automaticB;
}""");
new JavacTask(tb) new JavacTask(tb)
.options("--source-path", src.toString(), .options("--source-path", src.toString(),
@ -590,11 +592,12 @@ public class AutomaticModules extends ModuleTestBase {
} }
tb.writeJavaFiles(src, tb.writeJavaFiles(src,
"@SuppressWarnings(\"requires-automatic\")\n" + """
"module m1x {\n" + @SuppressWarnings("requires-automatic")
" requires transitive automaticA;\n" + module m1x {
" requires automaticB;\n" + requires transitive automaticA;
"}"); requires automaticB;
}""");
log = new JavacTask(tb) log = new JavacTask(tb)
.options("--source-path", src.toString(), .options("--source-path", src.toString(),

View File

@ -577,13 +577,15 @@ public class ConvenientAccessErrorsTest extends ModuleTestBase {
Path src_m2 = src.resolve("m2x"); Path src_m2 = src.resolve("m2x");
tb.writeJavaFiles(src_m2, tb.writeJavaFiles(src_m2,
"module m2x { requires m1x; }", "module m2x { requires m1x; }",
"package test;\n" + """
"import api.Sub;\n" + package test;
"import api.Base;\n" + import api.Sub;
"public class Test {\n" + import api.Base;
" Sub a2;\n" + public class Test {
" Base a;\n" + Sub a2;
"}\n"); Base a;
}
""");
Path m2xClasses = classes.resolve("m2x"); Path m2xClasses = classes.resolve("m2x");
tb.createDirectories(m2xClasses); tb.createDirectories(m2xClasses);
List<String> log = new JavacTask(tb) List<String> log = new JavacTask(tb)

View File

@ -302,13 +302,17 @@ public class EdgeCases extends ModuleTestBase {
Path src_m1 = src.resolve("m1x"); Path src_m1 = src.resolve("m1x");
tb.writeJavaFiles(src_m1, tb.writeJavaFiles(src_m1,
"module m1x { exports test.m1x; }", "module m1x { exports test.m1x; }",
"package test.m1x;\n" + """
"public class Test {}\n"); package test.m1x;
public class Test {}
""");
Path src_m2 = src.resolve("m2x"); Path src_m2 = src.resolve("m2x");
tb.writeJavaFiles(src_m2, tb.writeJavaFiles(src_m2,
"module m2x { requires m1x; }", "module m2x { requires m1x; }",
"package test;\n" + """
"public class m1x {}\n"); package test;
public class m1x {}
""");
Path classes = base.resolve("classes"); Path classes = base.resolve("classes");
tb.createDirectories(classes); tb.createDirectories(classes);
@ -515,15 +519,21 @@ public class EdgeCases extends ModuleTestBase {
Path src_m1 = src.resolve("m1x"); Path src_m1 = src.resolve("m1x");
tb.writeJavaFiles(src_m1, tb.writeJavaFiles(src_m1,
"module m1x { }", "module m1x { }",
"package m1x;\n" + """
"import m1x.a.*; public class Test { A a; }\n", package m1x;
"package m1x.a;\n" + import m1x.a.*; public class Test { A a; }
"public class A { }\n"); """,
"""
package m1x.a;
public class A { }
""");
Path src_m2 = src.resolve("m2x"); Path src_m2 = src.resolve("m2x");
tb.writeJavaFiles(src_m2, tb.writeJavaFiles(src_m2,
"module m2x { }", "module m2x { }",
"package m1x;\n" + """
"public class a { public static class A { } }\n"); package m1x;
public class a { public static class A { } }
""");
Path classes = base.resolve("classes"); Path classes = base.resolve("classes");
tb.createDirectories(classes); tb.createDirectories(classes);

View File

@ -53,27 +53,37 @@ public class ExportsUnexported extends ModuleTestBase {
@Test @Test
public void testLocations(Path base) throws Exception { public void testLocations(Path base) throws Exception {
String warningsTest = "package api;\n" + String warningsTest = """
"import impl.impl.*;\n" + package api;
"@impl.impl^.DocAnn\n" + import impl.impl.*;
"public abstract class Api<T extends impl.impl^.Cls&impl.impl^.Intf> extends impl.impl^.Cls implements impl.impl^.Intf, impl.impl^.NonDocAnn, impl.impl^.DocAnn {\n" + @impl.impl^.DocAnn
" public static <E extends impl.impl^.Cls&impl.impl^.Intf> impl.impl^.Cls m(impl.impl^.Intf i, impl.impl^.Cls c) throws impl.impl^.Exc { return null; }\n" + public abstract class Api<T extends impl.impl^.Cls&impl.impl^.Intf> extends impl\
" public static impl.impl^.Cls f;\n" + .impl^.Cls implements impl.impl^.Intf, impl.impl^.NonDocAnn, impl.impl^.DocAnn {
"}"; public static <E extends impl.impl^.Cls&impl.impl^.Intf> impl.impl^.Cls m(im\
String noWarningsTest = "package api;\n" + pl.impl^.Intf i, impl.impl^.Cls c) throws impl.impl^.Exc { return null; }
"import impl.impl.*;\n" + public static impl.impl^.Cls f;
"@impl.impl.NonDocAnn\n" + }""";
"public abstract class Api {\n" + String noWarningsTest = """
" private static abstract class I <T extends impl.impl.Cls&impl.impl.Intf> extends impl.impl.Cls implements impl.impl.Intf, impl.impl.NonDocAnn, impl.impl.DocAnn {\n" + package api;
" public static abstract class II <T extends impl.impl.Cls&impl.impl.Intf> extends impl.impl.Cls implements impl.impl.Intf, impl.impl.NonDocAnn, impl.impl.DocAnn { }\n" + import impl.impl.*;
" public static <E extends impl.impl.Cls&impl.impl.Intf> impl.impl.Cls m(impl.impl.Intf i, impl.impl.Cls c) throws impl.impl.Exc { return null; }\n" + @impl.impl.NonDocAnn
" public static impl.impl.Cls f;\n" + public abstract class Api {
" }\n" + private static abstract class I <T extends impl.impl.Cls&impl.impl.Intf> ext\
" private static <E extends impl.impl.Cls&impl.impl.Intf> impl.impl.Cls m(impl.impl.Intf i, impl.impl.Cls c) throws impl.impl.Exc { return null; }\n" + ends impl.impl.Cls implements impl.impl.Intf, impl.impl.NonDocAnn, impl.impl.Doc\
" private static impl.impl.Cls f1;\n" + Ann {
" public static void m() { new impl.impl.Cls(); }\n" + public static abstract class II <T extends impl.impl.Cls&impl.impl.Intf>\
" public static Object f2 = new impl.impl.Cls();\n" + extends impl.impl.Cls implements impl.impl.Intf, impl.impl.NonDocAnn, impl.impl\
"}"; .DocAnn { }
public static <E extends impl.impl.Cls&impl.impl.Intf> impl.impl.Cls m(i\
mpl.impl.Intf i, impl.impl.Cls c) throws impl.impl.Exc { return null; }
public static impl.impl.Cls f;
}
private static <E extends impl.impl.Cls&impl.impl.Intf> impl.impl.Cls m(impl\
.impl.Intf i, impl.impl.Cls c) throws impl.impl.Exc { return null; }
private static impl.impl.Cls f1;
public static void m() { new impl.impl.Cls(); }
public static Object f2 = new impl.impl.Cls();
}""";
for (String genericTest : new String[] {warningsTest, noWarningsTest}) { for (String genericTest : new String[] {warningsTest, noWarningsTest}) {
for (String test : new String[] {genericTest, genericTest.replaceAll("impl\\.impl\\^.([A-Za-z])", "^$1").replaceAll("impl\\.impl\\.([A-Za-z])", "$1")}) { for (String test : new String[] {genericTest, genericTest.replaceAll("impl\\.impl\\^.([A-Za-z])", "^$1").replaceAll("impl\\.impl\\.([A-Za-z])", "$1")}) {
System.err.println("testing: " + test); System.err.println("testing: " + test);
@ -171,31 +181,37 @@ public class ExportsUnexported extends ModuleTestBase {
"package lib2; public class Lib2 {}"); "package lib2; public class Lib2 {}");
Path src_api = src.resolve("api"); Path src_api = src.resolve("api");
tb.writeJavaFiles(src_api, tb.writeJavaFiles(src_api,
"module api {\n" + """
" exports api;\n" + module api {
" exports qapi1 to qual1x;\n" + exports api;
" exports qapi2 to qual1x, qual2x;\n" + exports qapi1 to qual1x;
" requires transitive lib1x;\n" + exports qapi2 to qual1x, qual2x;
" requires lib2x;\n" + requires transitive lib1x;
"}\n", requires lib2x;
"package api;\n" + }
"public class Api {\n" + """,
" public lib1.Lib1 lib1;\n" + """
" public lib2.Lib2 lib2;\n" + package api;
" public qapi1.QApi1 qapi1;\n" + public class Api {
" public impl.Impl impl;\n" + public lib1.Lib1 lib1;
"}", public lib2.Lib2 lib2;
"package qapi1;\n" + public qapi1.QApi1 qapi1;
"public class QApi1 {\n" + public impl.Impl impl;
" public qapi2.QApi2 qapi2;\n" + }""",
"}", """
"package qapi2;\n" + package qapi1;
"public class QApi2 {\n" + public class QApi1 {
" public qapi1.QApi1 qapi1;\n" + public qapi2.QApi2 qapi2;
"}", }""",
"package impl;\n" + """
"public class Impl {\n" + package qapi2;
"}"); public class QApi2 {
public qapi1.QApi1 qapi1;
}""",
"""
package impl;
public class Impl {
}""");
Path src_qual1 = src.resolve("qual1x"); Path src_qual1 = src.resolve("qual1x");
tb.writeJavaFiles(src_qual1, "module qual1x { }"); tb.writeJavaFiles(src_qual1, "module qual1x { }");
Path src_qual2 = src.resolve("qual2x"); Path src_qual2 = src.resolve("qual2x");
@ -232,21 +248,24 @@ public class ExportsUnexported extends ModuleTestBase {
Path src = base.resolve("src"); Path src = base.resolve("src");
Path src_api = src.resolve("api"); Path src_api = src.resolve("api");
tb.writeJavaFiles(src_api, tb.writeJavaFiles(src_api,
"module api {\n" + """
" exports api;\n" + module api {
"}\n", exports api;
"package api;\n" + }""",
"import impl.Impl.Nested;\n" + """
"public class Api {\n" + package api;
" public impl.Impl impl1;\n" + import impl.Impl.Nested;
" public impl.Impl.Nested impl2;\n" + public class Api {
" public Nested impl3;\n" + public impl.Impl impl1;
"}", public impl.Impl.Nested impl2;
"package impl;\n" + public Nested impl3;
"public class Impl {\n" + }""",
" public static class Nested {\n" + """
" }\n" + package impl;
"}"); public class Impl {
public static class Nested {
}
}""");
Path classes = base.resolve("classes"); Path classes = base.resolve("classes");
tb.createDirectories(classes); tb.createDirectories(classes);
@ -279,25 +298,29 @@ public class ExportsUnexported extends ModuleTestBase {
Path src = base.resolve("src"); Path src = base.resolve("src");
Path src_api = src.resolve("api"); Path src_api = src.resolve("api");
tb.writeJavaFiles(src_api, tb.writeJavaFiles(src_api,
"module api {\n" + """
" exports api;\n" + module api {
"}\n", exports api;
"package api;\n" + }""",
"public class Api extends PackagePrivateClass<PackagePrivateInterface> implements PackagePrivateInterface<PackagePrivateClass> {\n" + """
" protected PackagePrivateClass<?> f1;\n" + package api;
" protected PackagePrivateInterface<?> f2;\n" + public class Api extends PackagePrivateClass<PackagePrivateInterface> implements\
" protected Inner f3;\n" + PackagePrivateInterface<PackagePrivateClass> {
" protected PrivateInner f4;\n" + protected PackagePrivateClass<?> f1;
" protected impl.Impl f5;\n" + protected PackagePrivateInterface<?> f2;
" public static class InnerClass extends PrivateInner {}\n" + protected Inner f3;
" protected static class Inner {}\n" + protected PrivateInner f4;
" private static class PrivateInner {}\n" + protected impl.Impl f5;
"}\n" + public static class InnerClass extends PrivateInner {}
"class PackagePrivateClass<T> {}\n" + protected static class Inner {}
"interface PackagePrivateInterface<T> {}", private static class PrivateInner {}
"package impl;\n" + }
"public class Impl {\n" + class PackagePrivateClass<T> {}
"}"); interface PackagePrivateInterface<T> {}""",
"""
package impl;
public class Impl {
}""");
Path classes = base.resolve("classes"); Path classes = base.resolve("classes");
tb.createDirectories(classes); tb.createDirectories(classes);
@ -333,24 +356,27 @@ public class ExportsUnexported extends ModuleTestBase {
Path src = base.resolve("src"); Path src = base.resolve("src");
Path src_api = src.resolve("api"); Path src_api = src.resolve("api");
tb.writeJavaFiles(src_api, tb.writeJavaFiles(src_api,
"module api {\n" + """
" exports api;\n" + module api {
"}\n", exports api;
"package api;\n" + }""",
"public class Api {\n" + """
" @SuppressWarnings(\"exports\")\n" + package api;
" public PackagePrivateClass f1;\n" + public class Api {
" public PackagePrivateClass f2;\n" + @SuppressWarnings("exports")
" @SuppressWarnings(\"exports\")\n" + public PackagePrivateClass f1;
" public void t() {}\n" + public PackagePrivateClass f2;
" public PackagePrivateClass f3;\n" + @SuppressWarnings("exports")
" @SuppressWarnings(\"exports\")\n" + public void t() {}
" public static class C {\n" + public PackagePrivateClass f3;
" public PackagePrivateClass f4;\n" + @SuppressWarnings("exports")
" }\n" + public static class C {
" public PackagePrivateClass f5;\n" + public PackagePrivateClass f4;
"}\n" + }
"class PackagePrivateClass<T> {}\n"); public PackagePrivateClass f5;
}
class PackagePrivateClass<T> {}
""");
Path classes = base.resolve("classes"); Path classes = base.resolve("classes");
tb.createDirectories(classes); tb.createDirectories(classes);
@ -397,21 +423,29 @@ public class ExportsUnexported extends ModuleTestBase {
Path src = base.resolve("src"); Path src = base.resolve("src");
Path src_api = src.resolve("api"); Path src_api = src.resolve("api");
tb.writeJavaFiles(src_api, tb.writeJavaFiles(src_api,
"module api {\n" + """
" requires transitive dep;\n" + module api {
" requires transitive api.one;\n" + requires transitive dep;
" exports api;\n" + requires transitive api.one;
"}\n", exports api;
"package api;\n" + }
"public class Api extends dep.Dep implements api2.Api2 {}\n"); """,
"""
package api;
public class Api extends dep.Dep implements api2.Api2 {}
""");
Path src_dep = src.resolve("dep"); Path src_dep = src.resolve("dep");
tb.writeJavaFiles(src_dep, tb.writeJavaFiles(src_dep,
"module dep {\n" + """
" requires transitive api.one;\n" + module dep {
" exports dep;\n" + requires transitive api.one;
"}\n", exports dep;
"package dep;\n" + }
"public class Dep {}\n"); """,
"""
package dep;
public class Dep {}
""");
Path classes = base.resolve("classes"); Path classes = base.resolve("classes");
tb.createDirectories(classes); tb.createDirectories(classes);

View File

@ -47,11 +47,12 @@ public class HelloWorldTest extends ModuleTestBase {
} }
public static final String HELLO_WORLD = public static final String HELLO_WORLD =
"class HelloWorld {\n" """
+ " public static void main(String... args) {\n" class HelloWorld {
+ " System.out.println(\"Hello World!\");\n" public static void main(String... args) {
+ " }\n" System.out.println("Hello World!");
+ "}"; }
}""";
public static final String PKG_HELLO_WORLD = public static final String PKG_HELLO_WORLD =
"package p;\n" "package p;\n"

View File

@ -748,27 +748,31 @@ public class ModuleInfoTest extends ModuleTestBase {
public void testJDK8202832(Path base) throws Exception { public void testJDK8202832(Path base) throws Exception {
Path src = base.resolve("src"); Path src = base.resolve("src");
tb.writeJavaFiles(src.resolve("m1a"), tb.writeJavaFiles(src.resolve("m1a"),
"module m1a {\n" + """
" requires m2a;\n" + module m1a {
" requires m2b;\n" + requires m2a;
"}"); requires m2b;
}""");
tb.writeJavaFiles(src.resolve("m1b"), tb.writeJavaFiles(src.resolve("m1b"),
"module m1b {\n" + """
" requires m2b;\n" + module m1b {
" requires m2a;\n" + requires m2b;
"}"); requires m2a;
}""");
tb.writeJavaFiles(src.resolve("m2a"), tb.writeJavaFiles(src.resolve("m2a"),
"module m2a {\n" + """
" requires m3;\n" + module m2a {
" requires m1a;\n" + requires m3;
" requires m1b;\n" + requires m1a;
"}"); requires m1b;
}""");
tb.writeJavaFiles(src.resolve("m2b"), tb.writeJavaFiles(src.resolve("m2b"),
"module m2b {\n" + """
" requires m3;\n" + module m2b {
" requires m1a;\n" + requires m3;
" requires m1b;\n" + requires m1a;
"}"); requires m1b;
}""");
tb.writeJavaFiles(src.resolve("m3"), tb.writeJavaFiles(src.resolve("m3"),
"module m3 { }"); "module m3 { }");

View File

@ -90,11 +90,12 @@ public class OpenModulesTest extends ModuleTestBase {
.replace(System.getProperty("line.separator"), "\n") .replace(System.getProperty("line.separator"), "\n")
.replaceAll("@[^;]*;", ";"); .replaceAll("@[^;]*;", ";");
String expected = "module m1x {\n" + String expected = """
" requires java.base;\n" + module m1x {
" exports api1;\n" + requires java.base;
" opens api2;\n" + exports api1;
"}"; opens api2;
}""";
if (!decompiled.contains(expected)) { if (!decompiled.contains(expected)) {
throw new Exception("expected output not found: " + decompiled); throw new Exception("expected output not found: " + decompiled);
@ -154,10 +155,11 @@ public class OpenModulesTest extends ModuleTestBase {
.replace(System.getProperty("line.separator"), "\n") .replace(System.getProperty("line.separator"), "\n")
.replaceAll("@[^;]*;", ";"); .replaceAll("@[^;]*;", ";");
String expected = "open module m1x {\n" + String expected = """
" requires java.base;\n" + open module m1x {
" exports api1;\n" + requires java.base;
"}"; exports api1;
}""";
if (!decompiled.contains(expected)) { if (!decompiled.contains(expected)) {
throw new Exception("expected output not found: " + decompiled); throw new Exception("expected output not found: " + decompiled);

View File

@ -47,48 +47,50 @@ public class PluginsInModulesTest extends ModuleTestBase {
} }
private static final String pluginModule1 = private static final String pluginModule1 =
"module pluginMod1x {\n" + """
" requires jdk.compiler;\n" + module pluginMod1x {
"\n" + requires jdk.compiler;
" provides com.sun.source.util.Plugin\n" +
" with mypkg1.SimplePlugin1;\n" + provides com.sun.source.util.Plugin
"}"; with mypkg1.SimplePlugin1;
}""";
private static final String plugin1 = private static final String plugin1 =
"package mypkg1;\n" + """
"import com.sun.source.util.JavacTask;\n" + package mypkg1;
"import com.sun.source.util.Plugin;\n" + import com.sun.source.util.JavacTask;
"import com.sun.source.util.TaskEvent;\n" + import com.sun.source.util.Plugin;
"import com.sun.source.util.TaskListener;\n" + import com.sun.source.util.TaskEvent;
"\n" + import com.sun.source.util.TaskListener;
"public class SimplePlugin1 implements Plugin {\n" +
"\n" + public class SimplePlugin1 implements Plugin {
" @Override\n" +
" public String getName() {\n" + @Override
" return \"simpleplugin1\";\n" + public String getName() {
" }\n" + return "simpleplugin1";
"\n" + }
" @Override\n" +
" public void init(JavacTask task, String... args) {\n" + @Override
" task.addTaskListener(new PostAnalyzeTaskListener());\n" + public void init(JavacTask task, String... args) {
" }\n" + task.addTaskListener(new PostAnalyzeTaskListener());
"\n" + }
" private static class PostAnalyzeTaskListener implements TaskListener {\n" +
" @Override\n" + private static class PostAnalyzeTaskListener implements TaskListener {
" public void started(TaskEvent taskEvent) { \n" + @Override
" if (taskEvent.getKind().equals(TaskEvent.Kind.COMPILATION)) {\n" + public void started(TaskEvent taskEvent) {\s
" System.out.println(\"simpleplugin1 started for event \" + taskEvent.getKind());\n" + if (taskEvent.getKind().equals(TaskEvent.Kind.COMPILATION)) {
" }\n" + System.out.println("simpleplugin1 started for event " + taskEvent.getKind());
" }\n" + }
"\n" + }
" @Override\n" +
" public void finished(TaskEvent taskEvent) {\n" + @Override
" if (taskEvent.getKind().equals(TaskEvent.Kind.COMPILATION)) {\n" + public void finished(TaskEvent taskEvent) {
" System.out.println(\"simpleplugin1 finished for event \" + taskEvent.getKind());\n" + if (taskEvent.getKind().equals(TaskEvent.Kind.COMPILATION)) {
" }\n" + System.out.println("simpleplugin1 finished for event " + taskEvent.getKind());
" }\n" + }
" }\n" + }
"}"; }
}""";
private static final String testClass = "class Test { }"; private static final String testClass = "class Test { }";

View File

@ -56,11 +56,12 @@ public class RequiresStaticTest extends ModuleTestBase {
public void testJavaSE_OK(Path base) throws Exception { public void testJavaSE_OK(Path base) throws Exception {
Path src = base.resolve("src"); Path src = base.resolve("src");
tb.writeJavaFiles(src, tb.writeJavaFiles(src,
"module m { requires static java.se; }", // use class in java.se
"import java.awt.Frame;\n" // in java.se """
+ "class Test {\n" import java.awt.Frame;
+ " Frame f;\n" class Test {
+ "}"); Frame f;
}""");
Path classes = base.resolve("classes"); Path classes = base.resolve("classes");
Files.createDirectories(classes); Files.createDirectories(classes);
@ -76,10 +77,12 @@ public class RequiresStaticTest extends ModuleTestBase {
Path src = base.resolve("src"); Path src = base.resolve("src");
tb.writeJavaFiles(src, tb.writeJavaFiles(src,
"module m { requires static java.se; }", "module m { requires static java.se; }",
"import com.sun.source.tree.Tree;\n" // not in java.se (in jdk.compiler) // use class not in java.se (in jdk.compiler)
+ "class Test {\n" """
+ " Tree t;\n" import com.sun.source.tree.Tree;
+ "}"); class Test {
Tree t;
}""");
Path classes = base.resolve("classes"); Path classes = base.resolve("classes");
Files.createDirectories(classes); Files.createDirectories(classes);
@ -154,61 +157,73 @@ public class RequiresStaticTest extends ModuleTestBase {
Path src_m1 = src.resolve("m1x"); Path src_m1 = src.resolve("m1x");
tb.writeJavaFiles(src_m1, tb.writeJavaFiles(src_m1,
"module m1x { requires m2x; }", "module m1x { requires m2x; }",
"package p1;\n" """
+ "import p2.C2;\n" package p1;
+ "import p3.C3;\n" import p2.C2;
+ "import p4.C4;\n" import p3.C3;
import p4.C4;
"""
+ m1_extraImports + m1_extraImports
+ "class C1 {\n" + """
+ " C2 c2; C3 c3; C4 c4;\n" class C1 {
C2 c2; C3 c3; C4 c4;
"""
+ m1_extraUses + m1_extraUses
+ "}\n"); + "}\n");
Path src_m2 = src.resolve("m2x"); Path src_m2 = src.resolve("m2x");
tb.writeJavaFiles(src_m2, tb.writeJavaFiles(src_m2,
"module m2x {\n" """
+ " requires transitive m3x;\n" module m2x {
+ " requires static m6x;\n" requires transitive m3x;
+ " exports p2;\n" requires static m6x;
+ "}", exports p2;
"package p2;\n" }""",
+ "public class C2 {p7.C7 c7; p6.C6 c6; p4.C4 c4;}\n"); """
package p2;
public class C2 {p7.C7 c7; p6.C6 c6; p4.C4 c4;}""");
Path src_m3 = src.resolve("m3x"); Path src_m3 = src.resolve("m3x");
tb.writeJavaFiles(src_m3, tb.writeJavaFiles(src_m3,
"module m3x { requires transitive static m4x; exports p3; }", "module m3x { requires transitive static m4x; exports p3; }",
"package p3;\n" """
+ "public class C3 { }\n"); package p3;
public class C3 { }""");
Path src_m4 = src.resolve("m4x"); Path src_m4 = src.resolve("m4x");
tb.writeJavaFiles(src_m4, tb.writeJavaFiles(src_m4,
"module m4x { requires m5x; requires static m6x; exports p4; }", "module m4x { requires m5x; requires static m6x; exports p4; }",
"package p4;\n" """
+ "public class C4 { p6.C6 c6; p7.C7 c7;}\n"); package p4;
public class C4 { p6.C6 c6; p7.C7 c7;}""");
Path src_m5 = src.resolve("m5x"); Path src_m5 = src.resolve("m5x");
tb.writeJavaFiles(src_m5, tb.writeJavaFiles(src_m5,
"module m5x { exports p5; }", "module m5x { exports p5; }",
"package p5;\n" """
+ "public class C5 { }\n"); package p5;
public class C5 { }""");
Path src_m6 = src.resolve("m6x"); Path src_m6 = src.resolve("m6x");
tb.writeJavaFiles(src_m6, tb.writeJavaFiles(src_m6,
"module m6x { requires transitive m7x; exports p6; }", "module m6x { requires transitive m7x; exports p6; }",
"package p6;\n" """
+ "public class C6 { p7.C7 c7; }\n"); package p6;
public class C6 { p7.C7 c7; }""");
Path src_m7 = src.resolve("m7x"); Path src_m7 = src.resolve("m7x");
tb.writeJavaFiles(src_m7, tb.writeJavaFiles(src_m7,
"module m7x { requires static m8x; exports p7; }", "module m7x { requires static m8x; exports p7; }",
"package p7;\n" """
+ "public class C7 { p8.C8 c8; }\n"); package p7;
public class C7 { p8.C8 c8; }""");
Path src_m8 = src.resolve("m8x"); Path src_m8 = src.resolve("m8x");
tb.writeJavaFiles(src_m8, tb.writeJavaFiles(src_m8,
"module m8x { exports p8; }", "module m8x { exports p8; }",
"package p8;\n" """
+ "public class C8 { }\n"); package p8;
public class C8 { }""");
return src; return src;
} }
@ -235,20 +250,22 @@ public class RequiresStaticTest extends ModuleTestBase {
Path m3 = src.resolve("m3x"); Path m3 = src.resolve("m3x");
tb.writeJavaFiles(m3, tb.writeJavaFiles(m3,
"module m3x { requires static m1x; }", "module m3x { requires static m1x; }",
"package m3x;\n" + """
"public class Test {\n" + package m3x;
" public static void main(String... args) {\n" + public class Test {
" try {\n" + public static void main(String... args) {
" Class.forName(\"m1x.Api\");\n" + try {
" } catch (ClassNotFoundException e) {\n" + Class.forName("m1x.Api");
" System.err.println(\"ok\");\n" + } catch (ClassNotFoundException e) {
" }\n" + System.err.println("ok");
" }\n" + }
"}", }
"package m3x;\n" + }""",
"public class ApiUse{\n" + """
" m1x.Api api;\n" + package m3x;
"}"); public class ApiUse{
m1x.Api api;
}""");
Path m3Classes = classes.resolve("m3x"); Path m3Classes = classes.resolve("m3x");
Files.createDirectories(m3Classes); Files.createDirectories(m3Classes);
@ -307,20 +324,22 @@ public class RequiresStaticTest extends ModuleTestBase {
Path m3 = src.resolve("m3x"); Path m3 = src.resolve("m3x");
tb.writeJavaFiles(m3, tb.writeJavaFiles(m3,
"module m3x { requires m2x; }", "module m3x { requires m2x; }",
"package m3x;\n" + """
"public class Test {\n" + package m3x;
" public static void main(String... args) {\n" + public class Test {
" try {\n" + public static void main(String... args) {
" Class.forName(\"m1x.Api\");\n" + try {
" } catch (ClassNotFoundException e) {\n" + Class.forName("m1x.Api");
" System.err.println(\"ok\");\n" + } catch (ClassNotFoundException e) {
" }\n" + System.err.println("ok");
" }\n" + }
"}", }
"package m3x;\n" + }""",
"public class ApiUse{\n" + """
" m1x.Api api;\n" + package m3x;
"}"); public class ApiUse{
m1x.Api api;
}""");
Path m3Classes = classes.resolve("m3x"); Path m3Classes = classes.resolve("m3x");
Files.createDirectories(m3Classes); Files.createDirectories(m3Classes);

View File

@ -51,10 +51,12 @@ public class RequiresTransitiveTest extends ModuleTestBase {
Path src = base.resolve("src"); Path src = base.resolve("src");
tb.writeJavaFiles(src, tb.writeJavaFiles(src,
"module m { requires java.se; }", "module m { requires java.se; }",
"import java.awt.Frame;\n" // in java.se // use class in java.se
+ "class Test {\n" """
+ " Frame f;\n" import java.awt.Frame;
+ "}"); class Test {
Frame f;
}""");
Path classes = base.resolve("classes"); Path classes = base.resolve("classes");
Files.createDirectories(classes); Files.createDirectories(classes);
@ -70,10 +72,12 @@ public class RequiresTransitiveTest extends ModuleTestBase {
Path src = base.resolve("src"); Path src = base.resolve("src");
tb.writeJavaFiles(src, tb.writeJavaFiles(src,
"module m { requires java.se; }", "module m { requires java.se; }",
"import com.sun.source.tree.Tree;\n" // not in java.se (in jdk.compiler) // use class not in java.se (in jdk.compiler)
+ "class Test {\n" """
+ " Tree t;\n" import com.sun.source.tree.Tree;
+ "}"); class Test {
Tree t;
}""");
Path classes = base.resolve("classes"); Path classes = base.resolve("classes");
Files.createDirectories(classes); Files.createDirectories(classes);
@ -144,55 +148,76 @@ public class RequiresTransitiveTest extends ModuleTestBase {
Path src_m1 = src.resolve("m1x"); Path src_m1 = src.resolve("m1x");
tb.writeJavaFiles(src_m1, tb.writeJavaFiles(src_m1,
"module m1x { requires m2x; }", "module m1x { requires m2x; }",
"package p1;\n" """
+ "import p2.C2;\n" package p1;
+ "import p3.C3;\n" import p2.C2;
+ "import p4.C4;\n" import p3.C3;
import p4.C4;
"""
+ m1_extraImports + m1_extraImports
+ "class C1 {\n" + """
+ " C2 c2; C3 c3; C4 c4;\n" class C1 {
C2 c2; C3 c3; C4 c4;
"""
+ m1_extraUses + m1_extraUses
+ "}\n"); + "}\n");
Path src_m2 = src.resolve("m2x"); Path src_m2 = src.resolve("m2x");
tb.writeJavaFiles(src_m2, tb.writeJavaFiles(src_m2,
"module m2x {\n" """
+ " requires transitive m3x;\n" module m2x {
+ " requires m6x;\n" requires transitive m3x;
+ " exports p2;\n" requires m6x;
+ "}", exports p2;
"package p2;\n" }""",
+ "public class C2 { }\n"); """
package p2;
public class C2 { }
""");
Path src_m3 = src.resolve("m3x"); Path src_m3 = src.resolve("m3x");
tb.writeJavaFiles(src_m3, tb.writeJavaFiles(src_m3,
"module m3x { requires transitive m4x; exports p3; }", """
"package p3;\n" module m3x { requires transitive m4x; exports p3; }
+ "public class C3 { }\n"); """,
"""
package p3;
public class C3 { }
""");
Path src_m4 = src.resolve("m4x"); Path src_m4 = src.resolve("m4x");
tb.writeJavaFiles(src_m4, tb.writeJavaFiles(src_m4,
"module m4x { requires m5x; exports p4; }", """
"package p4;\n" module m4x { requires m5x; exports p4; }
+ "public class C4 { }\n"); """,
"""
package p4;
public class C4 { }
""");
Path src_m5 = src.resolve("m5x"); Path src_m5 = src.resolve("m5x");
tb.writeJavaFiles(src_m5, tb.writeJavaFiles(src_m5,
"module m5x { exports p5; }", """
"package p5;\n" module m5x { exports p5; }
+ "public class C5 { }\n"); """,
"""
package p5;
public class C5 { }
""");
Path src_m6 = src.resolve("m6x"); Path src_m6 = src.resolve("m6x");
tb.writeJavaFiles(src_m6, tb.writeJavaFiles(src_m6,
"module m6x { requires transitive m7x; exports p6; }", "module m6x { requires transitive m7x; exports p6; }",
"package p6;\n" """
+ "public class C6 { }\n"); package p6;
public class C6 { }""");
Path src_m7 = src.resolve("m7x"); Path src_m7 = src.resolve("m7x");
tb.writeJavaFiles(src_m7, tb.writeJavaFiles(src_m7,
"module m7x { exports p7; }", "module m7x { exports p7; }",
"package p7;\n" """
+ "public class C7 { }\n"); package p7;
public class C7 { }""");
return src; return src;
} }

View File

@ -66,11 +66,12 @@ public class SubpackageTest extends ModuleTestBase {
Path src = base.resolve("src"); Path src = base.resolve("src");
tb.writeJavaFiles(src, tb.writeJavaFiles(src,
"package p.q;\n" """
+ "import p.E;\n" package p.q;
+ "class Test {\n" import p.E;
+ " void m() { throw new E(); }\n" class Test {
+ "}"); void m() { throw new E(); }
}""");
Path classes = base.resolve("classes"); Path classes = base.resolve("classes");
Files.createDirectories(classes); Files.createDirectories(classes);
@ -95,17 +96,18 @@ public class SubpackageTest extends ModuleTestBase {
"module mpqr { exports p.q.r; }", "module mpqr { exports p.q.r; }",
"package p.q.r; public class C3 { }"); "package p.q.r; public class C3 { }");
tb.writeJavaFiles(src.resolve("m"), tb.writeJavaFiles(src.resolve("m"),
"module m {" """
+ " requires mp;\n" module m { requires mp;
+ " requires mpq;\n" requires mpq;
+ " requires mpqr;\n" requires mpqr;
+ "}", }""",
"package x;\n" """
+ "class C {\n" package x;
+ " p.C1 c1;\n" class C {
+ " p.q.C2 c2;\n" p.C1 c1;
+ " p.q.r.C3 c3;\n" p.q.C2 c2;
+ "}"); p.q.r.C3 c3;
}""");
Path modules = base.resolve("modules"); Path modules = base.resolve("modules");
Files.createDirectories(modules); Files.createDirectories(modules);

View File

@ -4,15 +4,15 @@ module mod {
53; // version 53; // version
[] { // Constant Pool [] { // Constant Pool
; // first element is empty ; // first element is empty
Utf8 "mod/module-info"; // #1 Utf8 "mod/module-info"; // #1
class #1; // #2 class #1; // #2
Utf8 "java/lang/Object"; // #3 Utf8 "java/lang/Object"; // #3
class #3; // #4 class #3; // #4
Utf8 "java.base"; // #5 Utf8 "java.base"; // #5
Utf8 "pkg"; // #6 Utf8 "pkg"; // #6
Utf8 "Module"; // #7 Utf8 "Module"; // #7
Utf8 "Version"; // #8 Utf8 "Version"; // #8
Utf8 "6.0"; // #9 Utf8 "6.0"; // #9
} // Constant Pool } // Constant Pool
0x8000; // access 0x8000; // access

View File

@ -49,23 +49,26 @@ public class WrongErrorMessageForNestedServiceProviderTest extends ModuleTestBas
} }
private static final String twoServicesModuleDef = private static final String twoServicesModuleDef =
"module m {\n" + """
" exports example;\n" + module m {
" provides example.SomeService with example.ServiceImpl;\n" + exports example;
" provides example.SomeServiceOuter with example.Outer.ServiceImplOuter;\n" + provides example.SomeService with example.ServiceImpl;
"}"; provides example.SomeServiceOuter with example.Outer.ServiceImplOuter;
}""";
private static final String someServiceInt = private static final String someServiceInt =
"package example;\n" + """
"public interface SomeService {\n" + package example;
" public void foo();\n" + public interface SomeService {
"}"; public void foo();
}""";
private static final String someServiceIntOuter = private static final String someServiceIntOuter =
"package example;\n" + """
"public interface SomeServiceOuter {\n" + package example;
" public void foo();\n" + public interface SomeServiceOuter {
"}"; public void foo();
}""";
@Test @Test
public void testPositive(Path base) throws Exception { public void testPositive(Path base) throws Exception {
@ -74,19 +77,21 @@ public class WrongErrorMessageForNestedServiceProviderTest extends ModuleTestBas
twoServicesModuleDef, twoServicesModuleDef,
someServiceInt, someServiceInt,
someServiceIntOuter, someServiceIntOuter,
"package example;\n" + """
"public class ServiceImpl implements example.SomeService {\n" + package example;
" public ServiceImpl() {}\n" + public class ServiceImpl implements example.SomeService {
" public void foo() {}\n" + public ServiceImpl() {}
"}", public void foo() {}
}""",
"package example;\n" + """
"class Outer {\n" + package example;
" public static class ServiceImplOuter implements example.SomeServiceOuter {\n" + class Outer {
" public ServiceImplOuter() {}\n" + public static class ServiceImplOuter implements example.SomeServiceOuter {
" public void foo() {}\n" + public ServiceImplOuter() {}
" }\n" + public void foo() {}
"}"); }
}""");
Path classes = base.resolve("classes"); Path classes = base.resolve("classes");
Files.createDirectories(classes); Files.createDirectories(classes);
@ -110,20 +115,21 @@ public class WrongErrorMessageForNestedServiceProviderTest extends ModuleTestBas
twoServicesModuleDef, twoServicesModuleDef,
someServiceInt, someServiceInt,
someServiceIntOuter, someServiceIntOuter,
"""
package example;
class ServiceImpl implements example.SomeService {
public ServiceImpl() {}
public void foo() {}
}""",
"package example;\n" + """
"class ServiceImpl implements example.SomeService {\n" + package example;
" public ServiceImpl() {}\n" + class Outer {
" public void foo() {}\n" + static class ServiceImplOuter implements example.SomeServiceOuter {
"}", public ServiceImplOuter() {}
public void foo() {}
"package example;\n" + }
"class Outer {\n" + }""");
" static class ServiceImplOuter implements example.SomeServiceOuter {\n" +
" public ServiceImplOuter() {}\n" +
" public void foo() {}\n" +
" }\n" +
"}");
Path classes = base.resolve("classes"); Path classes = base.resolve("classes");
Files.createDirectories(classes); Files.createDirectories(classes);
@ -147,22 +153,24 @@ public class WrongErrorMessageForNestedServiceProviderTest extends ModuleTestBas
public void testClassWrappedByPrivateClass(Path base) throws Exception { public void testClassWrappedByPrivateClass(Path base) throws Exception {
Path src = base.resolve("src"); Path src = base.resolve("src");
tb.writeJavaFiles(src, tb.writeJavaFiles(src,
"module m {\n" + """
" exports example;\n" + module m {
" provides example.SomeServiceOuter with example.Outer1.Outer2.ServiceImplOuter;\n" + exports example;
"}", provides example.SomeServiceOuter with example.Outer1.Outer2.ServiceImplOuter;
}""",
someServiceIntOuter, someServiceIntOuter,
"package example;\n" + """
"class Outer1 {\n" + package example;
" static private class Outer2 {\n" + class Outer1 {
" public static class ServiceImplOuter implements example.SomeServiceOuter {\n" + static private class Outer2 {
" public ServiceImplOuter() {}\n" + public static class ServiceImplOuter implements example.SomeServiceOuter {
" public void foo() {}\n" + public ServiceImplOuter() {}
" }\n" + public void foo() {}
" }\n" + }
"}"); }
}""");
Path classes = base.resolve("classes"); Path classes = base.resolve("classes");
Files.createDirectories(classes); Files.createDirectories(classes);