Added test for finding subpackages in mixed Java & compiled Kotlin package.
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package test;
|
||||
|
||||
public class JavaClass {
|
||||
public void instanceMethod() {}
|
||||
|
||||
public static void staticMethod() {}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package test.sub;
|
||||
|
||||
public class JavaClassInSubpackage {
|
||||
public void instanceMethod() {}
|
||||
|
||||
public static void staticMethod() {}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package test
|
||||
|
||||
public class KotlinClass
|
||||
|
||||
public fun topLevelFunction() {}
|
||||
+1
-1
@@ -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<String> options = Arrays.asList(
|
||||
"-classpath", tmpdir.getPath() + System.getProperty("path.separator") + ForTestCompileRuntime.runtimeJarForTests(),
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<File> kotlinSources = FileUtil.findFilesByMask(Pattern.compile(".+\\.kt"), sourcesDir);
|
||||
compileKotlinToDirAndGetAnalyzeExhaust(kotlinSources, tmpdir, myTestRootDisposable, ConfigurationKind.JDK_ONLY);
|
||||
|
||||
List<File> javaSources = FileUtil.findFilesByMask(Pattern.compile(".+\\.java"), sourcesDir);
|
||||
Pair<PackageViewDescriptor, BindingContext> 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);
|
||||
}
|
||||
|
||||
@@ -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<File> 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<File> 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.<AnalyzerScriptParameter>emptyList());
|
||||
return new JetFileAndExhaust(jetFile, exhaust);
|
||||
final JetCoreEnvironment jetCoreEnvironment = createEnvironmentWithMockJdkAndIdeaAnnotations(disposable, configurationKind);
|
||||
List<JetFile> jetFiles = ContainerUtil.map(kotlinFiles, new Function<File, JetFile>() {
|
||||
@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.<AnalyzerScriptParameter>emptyList(), Predicates.<PsiFile>alwaysTrue());
|
||||
return new JetFilesAndExhaust(jetFiles, exhaust);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private final JetFile jetFile;
|
||||
private final List<JetFile> jetFiles;
|
||||
@NotNull
|
||||
private final AnalyzeExhaust exhaust;
|
||||
|
||||
private JetFileAndExhaust(@NotNull JetFile file, @NotNull AnalyzeExhaust exhaust) {
|
||||
jetFile = file;
|
||||
private JetFilesAndExhaust(@NotNull List<JetFile> files, @NotNull AnalyzeExhaust exhaust) {
|
||||
jetFiles = files;
|
||||
this.exhaust = exhaust;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetFile getJetFile() {
|
||||
return jetFile;
|
||||
public List<JetFile> getJetFiles() {
|
||||
return jetFiles;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user