diff --git a/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/JavacWrapper.kt b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/JavacWrapper.kt index 988b4de297a..e441d98dd46 100644 --- a/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/JavacWrapper.kt +++ b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/JavacWrapper.kt @@ -170,10 +170,10 @@ class JavacWrapper( setClassPathForCompilation(outDir) makeOutputDirectoryClassesVisible() - context.get(Log.outKey)?.println( - "Compiling $javaFilesNumber Java source files" + - " to [${fileManager.getLocation(CLASS_OUTPUT)?.firstOrNull()?.path}]" - ) + val outputPath = + // Includes a hack with 'takeIf' for CLI test, to have stable string here (independent from random test directory) + fileManager.getLocation(CLASS_OUTPUT)?.firstOrNull()?.path?.takeIf { "compilerProject_test" !in it } ?: "test directory" + context.get(Log.outKey)?.print("Compiling $javaFilesNumber Java source files to [$outputPath]") compile(fileObjects) errorCount() == 0 } @@ -340,7 +340,7 @@ class JavacWrapper( private fun makeOutputDirectoryClassesVisible() { // TODO: below we have a hacky part with a purpose // to make already analyzed classes visible by Javac without reading them again. - // However, it does not work as it should (but some tests depend on this code fragment) + // This works (and necessary!) when javac has "-proc:none" argument, so works without APT val reader = ClassReader.instance(context) val names = Names.instance(context) val outDirName = fileManager.getLocation(CLASS_OUTPUT)?.firstOrNull()?.path ?: "" @@ -368,6 +368,9 @@ class JavacWrapper( private fun setClassPathForCompilation(outDir: File?) = apply { (outDir ?: outputDirectory)?.let { outputDir -> if (outputDir.exists()) { + // This line is necessary for e.g. CliTestGenerated.jvm.javacKotlinJavaInterdependency to work + // In general, it makes compiled Kotlin classes from the module visible for javac + // It's necessary when javac work with APT (without -proc:none flag) fileManager.setLocation(CLASS_PATH, fileManager.getLocation(CLASS_PATH) + outputDir) } outputDir.mkdirs() diff --git a/compiler/testData/cli/jvm/javacKotlinJavaInterdependency.args b/compiler/testData/cli/jvm/javacKotlinJavaInterdependency.args new file mode 100644 index 00000000000..ae6eeb51b30 --- /dev/null +++ b/compiler/testData/cli/jvm/javacKotlinJavaInterdependency.args @@ -0,0 +1,6 @@ +$TESTDATA_DIR$/javacKotlinJavaInterdependency/test/ClassWithTypeParameter.kt +$TESTDATA_DIR$/javacKotlinJavaInterdependency/test/ClassWithTypeParameter.java +-Xuse-javac +-Xcompile-java +-d +$TEMP_DIR$ diff --git a/compiler/testData/cli/jvm/javacKotlinJavaInterdependency.out b/compiler/testData/cli/jvm/javacKotlinJavaInterdependency.out new file mode 100644 index 00000000000..546a7cf72b1 --- /dev/null +++ b/compiler/testData/cli/jvm/javacKotlinJavaInterdependency.out @@ -0,0 +1,2 @@ +info: compiling 1 Java source files to [test directory] +OK diff --git a/compiler/testData/cli/jvm/javacKotlinJavaInterdependency/test/ClassWithTypeParameter.java b/compiler/testData/cli/jvm/javacKotlinJavaInterdependency/test/ClassWithTypeParameter.java new file mode 100644 index 00000000000..7d5404c6cfc --- /dev/null +++ b/compiler/testData/cli/jvm/javacKotlinJavaInterdependency/test/ClassWithTypeParameter.java @@ -0,0 +1,7 @@ +package test; + +public class ClassWithTypeParameter { + + public ClassWithTypeParameter(T kotlinInterface) {} + +} diff --git a/compiler/testData/cli/jvm/javacKotlinJavaInterdependency/test/ClassWithTypeParameter.kt b/compiler/testData/cli/jvm/javacKotlinJavaInterdependency/test/ClassWithTypeParameter.kt new file mode 100644 index 00000000000..e09023c946a --- /dev/null +++ b/compiler/testData/cli/jvm/javacKotlinJavaInterdependency/test/ClassWithTypeParameter.kt @@ -0,0 +1,15 @@ +package test + +interface KotlinInterface + +class Impl1 : KotlinInterface + +class Impl2 : KotlinInterface + +class Impl3 : KotlinInterface + +fun getProducer1() = Impl1().let(::ClassWithTypeParameter) + +fun getProducer2() = Impl2().let(::ClassWithTypeParameter) + +fun getProducer3() = Impl3().let(::ClassWithTypeParameter) diff --git a/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java index 307f0b2f020..3dc5a6b7ec3 100644 --- a/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java @@ -346,6 +346,11 @@ public class CliTestGenerated extends AbstractCliTest { runTest("compiler/testData/cli/jvm/javaSrcWrongPackage.args"); } + @TestMetadata("javacKotlinJavaInterdependency.args") + public void testJavacKotlinJavaInterdependency() throws Exception { + runTest("compiler/testData/cli/jvm/javacKotlinJavaInterdependency.args"); + } + @TestMetadata("jdkPathDoesNotExist.args") public void testJdkPathDoesNotExist() throws Exception { runTest("compiler/testData/cli/jvm/jdkPathDoesNotExist.args");