Minor, inline one overload of CodegenTestUtil.compileJava
This commit is contained in:
@@ -48,7 +48,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.jetbrains.kotlin.codegen.CodegenTestUtil.compileJava;
|
|
||||||
import static org.jetbrains.kotlin.test.KotlinTestUtils.compilerConfigurationForTests;
|
import static org.jetbrains.kotlin.test.KotlinTestUtils.compilerConfigurationForTests;
|
||||||
import static org.jetbrains.kotlin.test.KotlinTestUtils.getAnnotationsJar;
|
import static org.jetbrains.kotlin.test.KotlinTestUtils.getAnnotationsJar;
|
||||||
|
|
||||||
@@ -112,8 +111,9 @@ public abstract class AbstractBlackBoxCodegenTest extends CodegenTestCase {
|
|||||||
OutputUtilsKt.writeAllTo(classFileFactory, kotlinOut);
|
OutputUtilsKt.writeAllTo(classFileFactory, kotlinOut);
|
||||||
|
|
||||||
if (javaSourceDir != null) {
|
if (javaSourceDir != null) {
|
||||||
File output =
|
File output = CodegenTestUtil.compileJava(
|
||||||
compileJava(findJavaSourcesInDirectory(javaSourceDir), Collections.singletonList(kotlinOut.getPath()), javacOptions);
|
findJavaSourcesInDirectory(javaSourceDir), Collections.singletonList(kotlinOut.getPath()), javacOptions
|
||||||
|
);
|
||||||
// Add javac output to classpath so that the created class loader can find generated Java classes
|
// Add javac output to classpath so that the created class loader can find generated Java classes
|
||||||
JvmContentRootsKt.addJvmClasspathRoot(configuration, output);
|
JvmContentRootsKt.addJvmClasspathRoot(configuration, output);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ import java.lang.reflect.InvocationTargetException;
|
|||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
@@ -105,11 +104,6 @@ public class CodegenTestUtil {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static File compileJava(@NotNull String filename, @NotNull String... additionalClasspath) {
|
|
||||||
return compileJava(Collections.singletonList(filename), Arrays.asList(additionalClasspath), Collections.<String>emptyList());
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static File compileJava(
|
public static File compileJava(
|
||||||
@NotNull List<String> fileNames,
|
@NotNull List<String> fileNames,
|
||||||
|
|||||||
@@ -38,8 +38,7 @@ import org.jetbrains.org.objectweb.asm.Opcodes;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.util.Collections;
|
||||||
import static org.jetbrains.kotlin.codegen.CodegenTestUtil.compileJava;
|
|
||||||
|
|
||||||
public class GenerateNotNullAssertionsTest extends CodegenTestCase {
|
public class GenerateNotNullAssertionsTest extends CodegenTestCase {
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -62,10 +61,18 @@ public class GenerateNotNullAssertionsTest extends CodegenTestCase {
|
|||||||
loadFileByFullPath(KotlinTestUtils.getTestDataPathBase() + "/codegen/" + getPrefix() + "/" + fileName);
|
loadFileByFullPath(KotlinTestUtils.getTestDataPathBase() + "/codegen/" + getPrefix() + "/" + fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doTestCallAssertions(boolean disableCallAssertions) throws Exception {
|
@NotNull
|
||||||
File javaClassesTempDirectory = compileJava(KotlinTestUtils.getTestDataPathBase() + "/codegen/" + getPrefix() + "/A.java");
|
private File compileJava0(@NotNull String fileName) {
|
||||||
|
return CodegenTestUtil.compileJava(
|
||||||
|
Collections.singletonList(KotlinTestUtils.getTestDataPathBase() + "/codegen/" + getPrefix() + "/" + fileName),
|
||||||
|
Collections.<String>emptyList(),
|
||||||
|
Collections.<String>emptyList()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
setUpEnvironment(disableCallAssertions, true, javaClassesTempDirectory);
|
private void doTestCallAssertions(boolean disableCallAssertions) throws Exception {
|
||||||
|
File javaOut = compileJava0("A.java");
|
||||||
|
setUpEnvironment(disableCallAssertions, true, javaOut);
|
||||||
|
|
||||||
loadSource("AssertionChecker.kt");
|
loadSource("AssertionChecker.kt");
|
||||||
generateFunction("checkAssertions").invoke(null, !disableCallAssertions);
|
generateFunction("checkAssertions").invoke(null, !disableCallAssertions);
|
||||||
@@ -101,10 +108,8 @@ public class GenerateNotNullAssertionsTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testGenerateParamAssertions() throws Exception {
|
public void testGenerateParamAssertions() throws Exception {
|
||||||
File javaClassesTempDirectory =
|
File javaOut = compileJava0("doGenerateParamAssertions.java");
|
||||||
compileJava(KotlinTestUtils.getTestDataPathBase() + "/codegen/" + getPrefix() + "/doGenerateParamAssertions.java");
|
setUpEnvironment(true, false, javaOut);
|
||||||
|
|
||||||
setUpEnvironment(true, false, javaClassesTempDirectory);
|
|
||||||
|
|
||||||
loadSource("doGenerateParamAssertions.kt");
|
loadSource("doGenerateParamAssertions.kt");
|
||||||
generateFunction().invoke(null);
|
generateFunction().invoke(null);
|
||||||
@@ -137,9 +142,8 @@ public class GenerateNotNullAssertionsTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testJavaMultipleSubstitutions() {
|
public void testJavaMultipleSubstitutions() {
|
||||||
File javaClassesTempDirectory =
|
File javaOut = compileJava0("javaMultipleSubstitutions.java");
|
||||||
compileJava(KotlinTestUtils.getTestDataPathBase() + "/codegen/" + getPrefix() + "/javaMultipleSubstitutions.java");
|
setUpEnvironment(false, false, javaOut);
|
||||||
setUpEnvironment(false, false, javaClassesTempDirectory);
|
|
||||||
|
|
||||||
loadSource("javaMultipleSubstitutions.kt");
|
loadSource("javaMultipleSubstitutions.kt");
|
||||||
String text = generateToText();
|
String text = generateToText();
|
||||||
|
|||||||
@@ -33,12 +33,14 @@ import org.jetbrains.org.objectweb.asm.Opcodes;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.util.Collections;
|
||||||
import static org.jetbrains.kotlin.codegen.CodegenTestUtil.compileJava;
|
|
||||||
|
|
||||||
public class OuterClassGenTest extends CodegenTestCase {
|
public class OuterClassGenTest extends CodegenTestCase {
|
||||||
|
@NotNull
|
||||||
private static final String TEST_FOLDER = "outerClassInfo";
|
@Override
|
||||||
|
protected String getPrefix() {
|
||||||
|
return "outerClassInfo";
|
||||||
|
}
|
||||||
|
|
||||||
public void testClass() throws Exception {
|
public void testClass() throws Exception {
|
||||||
doTest("foo.Foo", "outerClassInfo");
|
doTest("foo.Foo", "outerClassInfo");
|
||||||
@@ -152,10 +154,13 @@ public class OuterClassGenTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void doTest(@NotNull String classFqName, @NotNull String javaClassName, @NotNull String testDataFile) throws Exception {
|
private void doTest(@NotNull String classFqName, @NotNull String javaClassName, @NotNull String testDataFile) throws Exception {
|
||||||
File javaClassesTempDirectory = compileJava(
|
File javaOut = CodegenTestUtil.compileJava(
|
||||||
KotlinTestUtils.getTestDataPathBase() + "/codegen/" + TEST_FOLDER + "/" + testDataFile + ".java");
|
Collections.singletonList(KotlinTestUtils.getTestDataPathBase() + "/codegen/" + getPrefix() + "/" + testDataFile + ".java"),
|
||||||
|
Collections.<String>emptyList(),
|
||||||
|
Collections.<String>emptyList()
|
||||||
|
);
|
||||||
|
|
||||||
UrlClassLoader javaClassLoader = UrlClassLoader.build().urls(javaClassesTempDirectory.toURI().toURL()).get();
|
UrlClassLoader javaClassLoader = UrlClassLoader.build().urls(javaOut.toURI().toURL()).get();
|
||||||
|
|
||||||
String javaClassPath = javaClassName.replace('.', File.separatorChar) + ".class";
|
String javaClassPath = javaClassName.replace('.', File.separatorChar) + ".class";
|
||||||
InputStream javaClassStream = javaClassLoader.getResourceAsStream(javaClassPath);
|
InputStream javaClassStream = javaClassLoader.getResourceAsStream(javaClassPath);
|
||||||
@@ -188,7 +193,7 @@ public class OuterClassGenTest extends CodegenTestCase {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private ClassReader getKotlinClassReader(@Language("RegExp") @NotNull String internalNameRegexp, @NotNull String testDataFile) {
|
private ClassReader getKotlinClassReader(@Language("RegExp") @NotNull String internalNameRegexp, @NotNull String testDataFile) {
|
||||||
loadFile(TEST_FOLDER + "/" + testDataFile + ".kt");
|
loadFile(getPrefix() + "/" + testDataFile + ".kt");
|
||||||
OutputFileCollection outputFiles = generateClassesInFile();
|
OutputFileCollection outputFiles = generateClassesInFile();
|
||||||
for (OutputFile file : outputFiles.asList()) {
|
for (OutputFile file : outputFiles.asList()) {
|
||||||
if (file.getRelativePath().matches(internalNameRegexp + "\\.class")) {
|
if (file.getRelativePath().matches(internalNameRegexp + "\\.class")) {
|
||||||
|
|||||||
Reference in New Issue
Block a user