Support parameter names for Java 8 classes in reflection
Also support specifying additional options to javac in codegen tests, which was needed to compile Java sources with the "-parameters" option
This commit is contained in:
+22
@@ -89,4 +89,26 @@ public class BlackBoxWithJava8CodegenTestGenerated extends AbstractBlackBoxCodeg
|
||||
doTestWithJava(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/java8/boxWithJava/reflection")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Reflection extends AbstractBlackBoxCodegenTest {
|
||||
public void testAllFilesPresentInReflection() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/java8/boxWithJava/reflection"), Pattern.compile("^([^\\.]+)$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("realParameterNames")
|
||||
public void testRealParameterNames() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/java8/boxWithJava/reflection/realParameterNames/");
|
||||
doTestWithJava(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("synthesizedParameterNames")
|
||||
public void testSynthesizedParameterNames() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/java8/boxWithJava/reflection/synthesizedParameterNames/");
|
||||
doTestWithJava(fileName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
public class J {
|
||||
public J(String constructorParam) {}
|
||||
|
||||
public static void foo(int methodParam) {}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// JAVAC_OPTIONS: -parameters
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun box(): String {
|
||||
val methodParam = J::foo.parameters.single()
|
||||
if (methodParam.name == null) return "Fail: method parameter has no name"
|
||||
assertEquals("methodParam", methodParam.name)
|
||||
|
||||
val constructorParam = J::class.constructors.single().parameters.single()
|
||||
if (constructorParam.name == null) return "Fail: constructor parameter has no name"
|
||||
assertEquals("constructorParam", constructorParam.name)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
public class J {
|
||||
public J(String constructorParam) {}
|
||||
|
||||
public static void foo(int methodParam) {}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun box(): String {
|
||||
val methodParam = J::foo.parameters.single()
|
||||
if (methodParam.name == null) return "Fail: method parameter has no name"
|
||||
assertEquals("arg0", methodParam.name)
|
||||
|
||||
val constructorParam = J::class.constructors.single().parameters.single()
|
||||
if (constructorParam.name == null) return "Fail: constructor parameter has no name"
|
||||
assertEquals("arg0", constructorParam.name)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -111,24 +111,30 @@ public class CodegenTestUtil {
|
||||
|
||||
@NotNull
|
||||
public static File compileJava(@NotNull String filename, @NotNull String... additionalClasspath) {
|
||||
return compileJava(Collections.singletonList(filename), additionalClasspath);
|
||||
return compileJava(Collections.singletonList(filename), Arrays.asList(additionalClasspath), Collections.<String>emptyList());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File compileJava(@NotNull List<String> filenames, @NotNull String... additionalClasspath) {
|
||||
public static File compileJava(
|
||||
@NotNull List<String> fileNames,
|
||||
@NotNull List<String> additionalClasspath,
|
||||
@NotNull List<String> additionalOptions
|
||||
) {
|
||||
try {
|
||||
File javaClassesTempDirectory = JetTestUtils.tmpDir("java-classes");
|
||||
List<String> classpath = new ArrayList<String>();
|
||||
classpath.add(ForTestCompileRuntime.runtimeJarForTests().getPath());
|
||||
classpath.add(ForTestCompileRuntime.reflectJarForTests().getPath());
|
||||
classpath.add(JetTestUtils.getAnnotationsJar().getPath());
|
||||
classpath.addAll(Arrays.asList(additionalClasspath));
|
||||
List<String> options = Arrays.asList(
|
||||
classpath.addAll(additionalClasspath);
|
||||
|
||||
List<String> options = new ArrayList<String>(Arrays.asList(
|
||||
"-classpath", KotlinPackage.join(classpath, File.pathSeparator, "", "", -1, ""),
|
||||
"-d", javaClassesTempDirectory.getPath()
|
||||
);
|
||||
));
|
||||
options.addAll(additionalOptions);
|
||||
|
||||
List<File> fileList = Lists.transform(filenames, new Function<String, File>() {
|
||||
List<File> fileList = Lists.transform(fileNames, new Function<String, File>() {
|
||||
@Override
|
||||
public File apply(@Nullable String input) {
|
||||
return new File(JetTestUtils.getTestDataPathBase() + "/codegen/" + input);
|
||||
|
||||
+6
-1
@@ -158,7 +158,12 @@ public abstract class AbstractBlackBoxCodegenTest extends CodegenTestCase {
|
||||
File kotlinOut = JetTestUtils.tmpDir(toString());
|
||||
OutputUtilsPackage.writeAllTo(classFileFactory, kotlinOut);
|
||||
|
||||
File javaOut = compileJava(javaFilePaths, kotlinOut.getPath());
|
||||
List<String> javacOptions = new ArrayList<String>(0);
|
||||
for (JetFile jetFile : myFiles.getPsiFiles()) {
|
||||
javacOptions.addAll(InTextDirectivesUtils.findListWithPrefixes(jetFile.getText(), "// JAVAC_OPTIONS:"));
|
||||
}
|
||||
|
||||
File javaOut = compileJava(javaFilePaths, Collections.singletonList(kotlinOut.getPath()), javacOptions);
|
||||
// Add javac output to classpath so that the created class loader can find generated Java classes
|
||||
addJvmClasspathRoot(configuration, javaOut);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user