diff --git a/compiler/testData/loadJava/compiledJavaAndKotlin/MixedPackage.txt b/compiler/testData/loadJava/compiledJavaAndKotlin/MixedPackage.txt new file mode 100644 index 00000000000..abdd91c1dc8 --- /dev/null +++ b/compiler/testData/loadJava/compiledJavaAndKotlin/MixedPackage.txt @@ -0,0 +1,28 @@ +package test + +public fun topLevelFunction(): jet.Unit + +public open class JavaClass : java.lang.Object { + public constructor JavaClass() + public open fun instanceMethod(): jet.Unit +} + +public final class KotlinClass { + public constructor KotlinClass() +} + +package JavaClass { + public open fun staticMethod(): jet.Unit +} + +package sub { + + public open class JavaClassInSubpackage : java.lang.Object { + public constructor JavaClassInSubpackage() + public open fun instanceMethod(): jet.Unit + } + + package JavaClassInSubpackage { + public open fun staticMethod(): jet.Unit + } +} diff --git a/compiler/testData/loadJava/compiledJavaAndKotlin/MixedPackage/JavaClass.java b/compiler/testData/loadJava/compiledJavaAndKotlin/MixedPackage/JavaClass.java new file mode 100644 index 00000000000..cf7a971b0b2 --- /dev/null +++ b/compiler/testData/loadJava/compiledJavaAndKotlin/MixedPackage/JavaClass.java @@ -0,0 +1,7 @@ +package test; + +public class JavaClass { + public void instanceMethod() {} + + public static void staticMethod() {} +} \ No newline at end of file diff --git a/compiler/testData/loadJava/compiledJavaAndKotlin/MixedPackage/JavaClassInSubpackage.java b/compiler/testData/loadJava/compiledJavaAndKotlin/MixedPackage/JavaClassInSubpackage.java new file mode 100644 index 00000000000..db9241f8ee4 --- /dev/null +++ b/compiler/testData/loadJava/compiledJavaAndKotlin/MixedPackage/JavaClassInSubpackage.java @@ -0,0 +1,7 @@ +package test.sub; + +public class JavaClassInSubpackage { + public void instanceMethod() {} + + public static void staticMethod() {} +} \ No newline at end of file diff --git a/compiler/testData/loadJava/compiledJavaAndKotlin/MixedPackage/kotlin.kt b/compiler/testData/loadJava/compiledJavaAndKotlin/MixedPackage/kotlin.kt new file mode 100644 index 00000000000..3644bc4c15c --- /dev/null +++ b/compiler/testData/loadJava/compiledJavaAndKotlin/MixedPackage/kotlin.kt @@ -0,0 +1,5 @@ +package test + +public class KotlinClass + +public fun topLevelFunction() {} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/jvm/compiler/AbstractCompileJavaAgainstKotlinTest.java b/compiler/tests/org/jetbrains/jet/jvm/compiler/AbstractCompileJavaAgainstKotlinTest.java index 56df4d06c23..5cfc8970739 100644 --- a/compiler/tests/org/jetbrains/jet/jvm/compiler/AbstractCompileJavaAgainstKotlinTest.java +++ b/compiler/tests/org/jetbrains/jet/jvm/compiler/AbstractCompileJavaAgainstKotlinTest.java @@ -35,7 +35,7 @@ public abstract class AbstractCompileJavaAgainstKotlinTest extends TestCaseWithT Assert.assertTrue(ktFilePath.endsWith(".kt")); File ktFile = new File(ktFilePath); File javaFile = new File(ktFilePath.replaceFirst("\\.kt", ".java")); - compileKotlinToDirAndGetAnalyzeExhaust(ktFile, tmpdir, getTestRootDisposable(), ConfigurationKind.JDK_ONLY); + compileKotlinToDirAndGetAnalyzeExhaust(Collections.singletonList(ktFile), tmpdir, getTestRootDisposable(), ConfigurationKind.JDK_ONLY); List options = Arrays.asList( "-classpath", tmpdir.getPath() + System.getProperty("path.separator") + ForTestCompileRuntime.runtimeJarForTests(), diff --git a/compiler/tests/org/jetbrains/jet/jvm/compiler/AbstractLoadCompiledKotlinTest.java b/compiler/tests/org/jetbrains/jet/jvm/compiler/AbstractLoadCompiledKotlinTest.java index 9ae6c5331a3..6b56240577e 100644 --- a/compiler/tests/org/jetbrains/jet/jvm/compiler/AbstractLoadCompiledKotlinTest.java +++ b/compiler/tests/org/jetbrains/jet/jvm/compiler/AbstractLoadCompiledKotlinTest.java @@ -29,6 +29,7 @@ import org.jetbrains.jet.test.TestCaseWithTmpdir; import org.jetbrains.jet.test.util.RecursiveDescriptorComparator; import java.io.File; +import java.util.Collections; import static org.jetbrains.jet.jvm.compiler.LoadDescriptorUtil.TEST_PACKAGE_FQNAME; import static org.jetbrains.jet.jvm.compiler.LoadDescriptorUtil.compileKotlinToDirAndGetAnalyzeExhaust; @@ -43,7 +44,7 @@ public abstract class AbstractLoadCompiledKotlinTest extends TestCaseWithTmpdir public void doTest(@NotNull String ktFileName) throws Exception { File ktFile = new File(ktFileName); File txtFile = new File(ktFileName.replaceFirst("\\.kt$", ".txt")); - AnalyzeExhaust exhaust = compileKotlinToDirAndGetAnalyzeExhaust(ktFile, tmpdir, getTestRootDisposable(), + AnalyzeExhaust exhaust = compileKotlinToDirAndGetAnalyzeExhaust(Collections.singletonList(ktFile), tmpdir, getTestRootDisposable(), ConfigurationKind.JDK_ONLY); PackageViewDescriptor packageFromSource = exhaust.getModuleDescriptor().getPackage(TEST_PACKAGE_FQNAME); diff --git a/compiler/tests/org/jetbrains/jet/jvm/compiler/AbstractLoadJavaTest.java b/compiler/tests/org/jetbrains/jet/jvm/compiler/AbstractLoadJavaTest.java index bb1a39e0908..26a942036c9 100644 --- a/compiler/tests/org/jetbrains/jet/jvm/compiler/AbstractLoadJavaTest.java +++ b/compiler/tests/org/jetbrains/jet/jvm/compiler/AbstractLoadJavaTest.java @@ -30,7 +30,6 @@ import org.jetbrains.jet.cli.jvm.compiler.CliLightClassGenerationSupport; import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment; import org.jetbrains.jet.config.CommonConfigurationKeys; import org.jetbrains.jet.config.CompilerConfiguration; -import org.jetbrains.jet.di.InjectorForJavaDescriptorResolver; import org.jetbrains.jet.di.InjectorForTopDownAnalyzerForJvm; import org.jetbrains.jet.lang.descriptors.ModuleDescriptorImpl; import org.jetbrains.jet.lang.descriptors.PackageViewDescriptor; @@ -38,7 +37,6 @@ import org.jetbrains.jet.lang.resolve.AnalyzerScriptParameter; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingTrace; import org.jetbrains.jet.lang.resolve.TopDownAnalysisParameters; -import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM; import org.jetbrains.jet.test.TestCaseWithTmpdir; import org.junit.Assert; @@ -49,6 +47,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.regex.Pattern; import static org.jetbrains.jet.jvm.compiler.LoadDescriptorUtil.*; import static org.jetbrains.jet.test.util.DescriptorValidator.ValidationVisitor.ALLOW_ERROR_TYPES; @@ -74,6 +73,21 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir { doTestCompiledJava(javaFileName, DONT_INCLUDE_METHODS_OF_OBJECT); } + // Java-Kotlin dependencies are not supported in this method for simplicity + protected void doTestCompiledJavaAndKotlin(@NotNull String expectedFileName) throws Exception { + File expectedFile = new File(expectedFileName); + File sourcesDir = new File(expectedFileName.replaceFirst("\\.txt$", "")); + + List kotlinSources = FileUtil.findFilesByMask(Pattern.compile(".+\\.kt"), sourcesDir); + compileKotlinToDirAndGetAnalyzeExhaust(kotlinSources, tmpdir, myTestRootDisposable, ConfigurationKind.JDK_ONLY); + + List javaSources = FileUtil.findFilesByMask(Pattern.compile(".+\\.java"), sourcesDir); + Pair binaryPackageAndContext = compileJavaAndLoadTestPackageAndBindingContextFromBinary( + javaSources, tmpdir, myTestRootDisposable, ConfigurationKind.JDK_ONLY); + + checkJavaPackage(expectedFile, binaryPackageAndContext.first, binaryPackageAndContext.second, DONT_INCLUDE_METHODS_OF_OBJECT); + } + protected void doTestCompiledJavaIncludeObjectMethods(@NotNull String javaFileName) throws Exception { doTestCompiledJava(javaFileName, RECURSIVE); } diff --git a/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadDescriptorUtil.java b/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadDescriptorUtil.java index d5ec2078326..fb48a11501e 100644 --- a/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadDescriptorUtil.java +++ b/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadDescriptorUtil.java @@ -16,9 +16,13 @@ package org.jetbrains.jet.jvm.compiler; +import com.google.common.base.Predicates; import com.intellij.openapi.Disposable; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.io.FileUtil; +import com.intellij.psi.PsiFile; +import com.intellij.util.Function; +import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.ConfigurationKind; import org.jetbrains.jet.JetTestUtils; @@ -46,6 +50,7 @@ import java.io.IOException; import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.List; import static org.jetbrains.jet.JetTestUtils.createEnvironmentWithMockJdkAndIdeaAnnotations; @@ -59,14 +64,13 @@ public final class LoadDescriptorUtil { @NotNull public static AnalyzeExhaust compileKotlinToDirAndGetAnalyzeExhaust( - @NotNull File kotlinFile, + @NotNull List kotlinFiles, @NotNull File outDir, @NotNull Disposable disposable, @NotNull ConfigurationKind configurationKind ) throws IOException { - JetFileAndExhaust fileAndExhaust = JetFileAndExhaust.createJetFileAndAnalyze(kotlinFile, disposable, configurationKind); - GenerationState state = GenerationUtils.compileFilesGetGenerationState(fileAndExhaust.getJetFile().getProject(), fileAndExhaust.getExhaust(), Collections.singletonList( - fileAndExhaust.getJetFile())); + JetFilesAndExhaust fileAndExhaust = JetFilesAndExhaust.createJetFilesAndAnalyze(kotlinFiles, disposable, configurationKind); + GenerationState state = GenerationUtils.compileFilesGetGenerationState(fileAndExhaust.getJetFiles().get(0).getProject(), fileAndExhaust.getExhaust(), fileAndExhaust.getJetFiles()); OutputFileCollection outputFiles = state.getFactory(); OutputUtilsPackage.writeAllTo(outputFiles, outDir); return fileAndExhaust.getExhaust(); @@ -121,38 +125,53 @@ public final class LoadDescriptorUtil { @NotNull Disposable disposable, @NotNull ConfigurationKind configurationKind ) throws Exception { - JetFileAndExhaust fileAndExhaust = JetFileAndExhaust.createJetFileAndAnalyze(ktFile, disposable, configurationKind); + JetFilesAndExhaust fileAndExhaust = JetFilesAndExhaust.createJetFilesAndAnalyze(Collections.singletonList(ktFile), disposable, configurationKind); PackageViewDescriptor packageView = fileAndExhaust.getExhaust().getModuleDescriptor().getPackage(TEST_PACKAGE_FQNAME); assert packageView != null: TEST_PACKAGE_FQNAME + " package not found in " + ktFile.getName(); return packageView; } - private static class JetFileAndExhaust { + private static class JetFilesAndExhaust { @NotNull - public static JetFileAndExhaust createJetFileAndAnalyze(@NotNull File kotlinFile, @NotNull Disposable disposable, @NotNull ConfigurationKind configurationKind) + public static JetFilesAndExhaust createJetFilesAndAnalyze( + @NotNull List kotlinFiles, + @NotNull Disposable disposable, + @NotNull ConfigurationKind configurationKind + ) throws IOException { - JetCoreEnvironment jetCoreEnvironment = createEnvironmentWithMockJdkAndIdeaAnnotations(disposable, configurationKind); - JetFile jetFile = JetTestUtils.createFile(kotlinFile.getName(), FileUtil.loadFile(kotlinFile, true), jetCoreEnvironment.getProject()); - AnalyzeExhaust exhaust = AnalyzerFacadeForJVM.analyzeOneFileWithJavaIntegrationAndCheckForErrors( - jetFile, Collections.emptyList()); - return new JetFileAndExhaust(jetFile, exhaust); + final JetCoreEnvironment jetCoreEnvironment = createEnvironmentWithMockJdkAndIdeaAnnotations(disposable, configurationKind); + List jetFiles = ContainerUtil.map(kotlinFiles, new Function() { + @Override + public JetFile fun(File kotlinFile) { + try { + return JetTestUtils.createFile( + kotlinFile.getName(), FileUtil.loadFile(kotlinFile, true), jetCoreEnvironment.getProject()); + } + catch (IOException e) { + throw new AssertionError(e); + } + } + }); + AnalyzeExhaust exhaust = AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration( + jetCoreEnvironment.getProject(), jetFiles, Collections.emptyList(), Predicates.alwaysTrue()); + return new JetFilesAndExhaust(jetFiles, exhaust); } @NotNull - private final JetFile jetFile; + private final List jetFiles; @NotNull private final AnalyzeExhaust exhaust; - private JetFileAndExhaust(@NotNull JetFile file, @NotNull AnalyzeExhaust exhaust) { - jetFile = file; + private JetFilesAndExhaust(@NotNull List files, @NotNull AnalyzeExhaust exhaust) { + jetFiles = files; this.exhaust = exhaust; } @NotNull - public JetFile getJetFile() { - return jetFile; + public List getJetFiles() { + return jetFiles; } @NotNull diff --git a/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadJavaTestGenerated.java b/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadJavaTestGenerated.java index ddd3d99e896..ab41801b22c 100644 --- a/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadJavaTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadJavaTestGenerated.java @@ -30,7 +30,7 @@ import org.jetbrains.jet.jvm.compiler.AbstractLoadJavaTest; /** This class is generated by {@link org.jetbrains.jet.generators.tests.GenerateTests}. DO NOT MODIFY MANUALLY */ @SuppressWarnings("all") -@InnerTestClasses({LoadJavaTestGenerated.CompiledJavaCompareWithKotlin.class, LoadJavaTestGenerated.CompiledJavaIncludeObjectMethods.class, LoadJavaTestGenerated.CompiledJava.class, LoadJavaTestGenerated.SourceJava.class, LoadJavaTestGenerated.JavaAgainstKotlin.class}) +@InnerTestClasses({LoadJavaTestGenerated.CompiledJavaCompareWithKotlin.class, LoadJavaTestGenerated.CompiledJavaIncludeObjectMethods.class, LoadJavaTestGenerated.CompiledJava.class, LoadJavaTestGenerated.SourceJava.class, LoadJavaTestGenerated.JavaAgainstKotlin.class, LoadJavaTestGenerated.CompiledJavaAndKotlin.class}) public class LoadJavaTestGenerated extends AbstractLoadJavaTest { @TestMetadata("compiler/testData/loadJava/compiledJavaCompareWithKotlin") @InnerTestClasses({CompiledJavaCompareWithKotlin.Annotation.class, CompiledJavaCompareWithKotlin.Constructor.class, CompiledJavaCompareWithKotlin.JavaBean.class, CompiledJavaCompareWithKotlin.KotlinSignature.class, CompiledJavaCompareWithKotlin.Library.class, CompiledJavaCompareWithKotlin.Modality.class, CompiledJavaCompareWithKotlin.Mutability.class, CompiledJavaCompareWithKotlin.NotNull.class, CompiledJavaCompareWithKotlin.Vararg.class}) @@ -1637,6 +1637,25 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest { } } + @TestMetadata("compiler/testData/loadJava/compiledJavaAndKotlin") + @InnerTestClasses({}) + public static class CompiledJavaAndKotlin extends AbstractLoadJavaTest { + public void testAllFilesPresentInCompiledJavaAndKotlin() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/loadJava/compiledJavaAndKotlin"), Pattern.compile("^(.+)\\.txt$"), true); + } + + @TestMetadata("MixedPackage.txt") + public void testMixedPackage() throws Exception { + doTestCompiledJavaAndKotlin("compiler/testData/loadJava/compiledJavaAndKotlin/MixedPackage.txt"); + } + + public static Test innerSuite() { + TestSuite suite = new TestSuite("CompiledJavaAndKotlin"); + suite.addTestSuite(CompiledJavaAndKotlin.class); + return suite; + } + } + public static Test suite() { TestSuite suite = new TestSuite("LoadJavaTestGenerated"); suite.addTest(CompiledJavaCompareWithKotlin.innerSuite()); @@ -1644,6 +1663,7 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest { suite.addTest(CompiledJava.innerSuite()); suite.addTestSuite(SourceJava.class); suite.addTest(JavaAgainstKotlin.innerSuite()); + suite.addTest(CompiledJavaAndKotlin.innerSuite()); return suite; } } diff --git a/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.java b/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.java index e2ecb2cebd5..666663205d5 100644 --- a/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.java +++ b/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.java @@ -205,7 +205,8 @@ public class GenerateTests { "doTestCompiledJavaIncludeObjectMethods"), testModel("compiler/testData/loadJava/compiledJava", true, "java", "doTestCompiledJava"), testModel("compiler/testData/loadJava/sourceJava", true, "java", "doTestSourceJava"), - testModel("compiler/testData/loadJava/javaAgainstKotlin", true, "txt", "doTestJavaAgainstKotlin") + testModel("compiler/testData/loadJava/javaAgainstKotlin", true, "txt", "doTestJavaAgainstKotlin"), + testModel("compiler/testData/loadJava/compiledJavaAndKotlin", true, "txt", "doTestCompiledJavaAndKotlin") ); generateTest(