Cleanup test utilities in JvmResolveUtil and GenerationUtils
Simplify usages and fix some warnings along the way. Rename: - analyzeFilesWithJavaIntegration, analyzeOneFileWithJavaIntegration -> analyze - analyzeFilesWithJavaIntegrationAndCheckForErrors, analyzeOneFileWithJavaIntegrationAndCheckForErrors -> analyzeAndCheckForErrors - compileFilesGetGenerationState, compileManyFilesGetGenerationStateForTest -> compileFiles - compileFileGetGenerationStateForTest -> compileFile - compileFileGetClassFileFactoryForTest -> compileFileTo
This commit is contained in:
+1
-7
@@ -25,7 +25,6 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.kotlin.backend.common.output.OutputFileCollection;
|
import org.jetbrains.kotlin.backend.common.output.OutputFileCollection;
|
||||||
import org.jetbrains.kotlin.cli.common.output.outputUtils.OutputUtilsKt;
|
import org.jetbrains.kotlin.cli.common.output.outputUtils.OutputUtilsKt;
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles;
|
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles;
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.JvmPackagePartProvider;
|
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
||||||
import org.jetbrains.kotlin.codegen.CodegenTestFiles;
|
import org.jetbrains.kotlin.codegen.CodegenTestFiles;
|
||||||
import org.jetbrains.kotlin.codegen.GenerationUtils;
|
import org.jetbrains.kotlin.codegen.GenerationUtils;
|
||||||
@@ -200,12 +199,7 @@ public class CodegenTestsOnAndroidGenerator extends UsefulTestCase {
|
|||||||
: isFullJdkAndRuntime ? " (full jdk and runtime)" : "") + "...");
|
: isFullJdkAndRuntime ? " (full jdk and runtime)" : "") + "...");
|
||||||
OutputFileCollection outputFiles;
|
OutputFileCollection outputFiles;
|
||||||
try {
|
try {
|
||||||
outputFiles = GenerationUtils.compileManyFilesGetGenerationStateForTest(
|
outputFiles = GenerationUtils.compileFiles(filesToCompile, environment).getFactory();
|
||||||
filesToCompile.iterator().next().getProject(),
|
|
||||||
filesToCompile,
|
|
||||||
new JvmPackagePartProvider(environment),
|
|
||||||
environment.getConfiguration()
|
|
||||||
).getFactory();
|
|
||||||
}
|
}
|
||||||
catch (Throwable e) {
|
catch (Throwable e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.cli.common.output.outputUtils.OutputUtilsKt;
|
import org.jetbrains.kotlin.cli.common.output.outputUtils.OutputUtilsKt;
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles;
|
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles;
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.JvmPackagePartProvider;
|
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
||||||
import org.jetbrains.kotlin.cli.jvm.config.JvmContentRootsKt;
|
import org.jetbrains.kotlin.cli.jvm.config.JvmContentRootsKt;
|
||||||
import org.jetbrains.kotlin.config.CompilerConfiguration;
|
import org.jetbrains.kotlin.config.CompilerConfiguration;
|
||||||
@@ -97,10 +96,7 @@ public abstract class AbstractBlackBoxCodegenTest extends CodegenTestCase {
|
|||||||
|
|
||||||
loadMultiFiles(files);
|
loadMultiFiles(files);
|
||||||
|
|
||||||
classFileFactory = GenerationUtils.compileManyFilesGetGenerationStateForTest(
|
classFileFactory = GenerationUtils.compileFiles(myFiles.getPsiFiles(), myEnvironment).getFactory();
|
||||||
myEnvironment.getProject(), myFiles.getPsiFiles(), new JvmPackagePartProvider(myEnvironment),
|
|
||||||
myEnvironment.getConfiguration()
|
|
||||||
).getFactory();
|
|
||||||
|
|
||||||
if (javaSourceDir != null) {
|
if (javaSourceDir != null) {
|
||||||
// If there are Java files, they should be compiled against the class files produced by Kotlin, so we dump them to the disk
|
// If there are Java files, they should be compiled against the class files produced by Kotlin, so we dump them to the disk
|
||||||
|
|||||||
+5
-6
@@ -44,9 +44,8 @@ import java.util.regex.Pattern;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public abstract class AbstractCheckLocalVariablesTableTest extends TestCaseWithTmpdir {
|
public abstract class AbstractCheckLocalVariablesTableTest extends TestCaseWithTmpdir {
|
||||||
|
|
||||||
private File ktFile;
|
private File ktFile;
|
||||||
private KotlinCoreEnvironment jetCoreEnvironment;
|
private KotlinCoreEnvironment environment;
|
||||||
|
|
||||||
public AbstractCheckLocalVariablesTableTest() {
|
public AbstractCheckLocalVariablesTableTest() {
|
||||||
}
|
}
|
||||||
@@ -54,12 +53,12 @@ public abstract class AbstractCheckLocalVariablesTableTest extends TestCaseWithT
|
|||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
jetCoreEnvironment = KotlinTestUtils.createEnvironmentWithMockJdkAndIdeaAnnotations(myTestRootDisposable);
|
environment = KotlinTestUtils.createEnvironmentWithMockJdkAndIdeaAnnotations(myTestRootDisposable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
jetCoreEnvironment = null;
|
environment = null;
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,9 +66,9 @@ public abstract class AbstractCheckLocalVariablesTableTest extends TestCaseWithT
|
|||||||
ktFile = new File(ktFileName);
|
ktFile = new File(ktFileName);
|
||||||
String text = FileUtil.loadFile(ktFile, true);
|
String text = FileUtil.loadFile(ktFile, true);
|
||||||
|
|
||||||
KtFile psiFile = KotlinTestUtils.createFile(ktFile.getName(), text, jetCoreEnvironment.getProject());
|
KtFile psiFile = KotlinTestUtils.createFile(ktFile.getName(), text, environment.getProject());
|
||||||
|
|
||||||
OutputFileCollection outputFiles = GenerationUtils.compileFileGetClassFileFactoryForTest(psiFile, jetCoreEnvironment);
|
OutputFileCollection outputFiles = GenerationUtils.compileFile(psiFile, environment);
|
||||||
|
|
||||||
String classAndMethod = parseClassAndMethodSignature();
|
String classAndMethod = parseClassAndMethodSignature();
|
||||||
String[] split = classAndMethod.split("\\.");
|
String[] split = classAndMethod.split("\\.");
|
||||||
|
|||||||
+7
-8
@@ -22,7 +22,6 @@ import kotlin.Pair;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.cli.common.modules.ModuleBuilder;
|
import org.jetbrains.kotlin.cli.common.modules.ModuleBuilder;
|
||||||
import org.jetbrains.kotlin.cli.common.output.outputUtils.OutputUtilsKt;
|
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles;
|
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles;
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
||||||
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime;
|
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime;
|
||||||
@@ -85,7 +84,7 @@ public abstract class AbstractCompileKotlinAgainstKotlinTest extends CodegenTest
|
|||||||
return new Pair<ClassFileFactory, ClassFileFactory>(factoryA, factoryB);
|
return new Pair<ClassFileFactory, ClassFileFactory>(factoryA, factoryB);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void invokeBox(@NotNull String className) throws Exception {
|
private void invokeBox(@NotNull String className) throws Exception {
|
||||||
Method box = createGeneratedClassLoader().loadClass(className).getMethod("box");
|
Method box = createGeneratedClassLoader().loadClass(className).getMethod("box");
|
||||||
String result = (String) box.invoke(null);
|
String result = (String) box.invoke(null);
|
||||||
assertEquals("OK", result);
|
assertEquals("OK", result);
|
||||||
@@ -100,7 +99,7 @@ public abstract class AbstractCompileKotlinAgainstKotlinTest extends CodegenTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
protected ClassFileFactory compileA(@NotNull String fileName, @NotNull String content, List<TestFile> files) throws IOException {
|
private ClassFileFactory compileA(@NotNull String fileName, @NotNull String content, List<TestFile> files) throws IOException {
|
||||||
Disposable compileDisposable = createDisposable("compileA");
|
Disposable compileDisposable = createDisposable("compileA");
|
||||||
KotlinCoreEnvironment environment =
|
KotlinCoreEnvironment environment =
|
||||||
KotlinTestUtils.createEnvironmentWithJdkAndNullabilityAnnotationsFromIdea(compileDisposable, ConfigurationKind.ALL, getJdkKind(files));
|
KotlinTestUtils.createEnvironmentWithJdkAndNullabilityAnnotationsFromIdea(compileDisposable, ConfigurationKind.ALL, getJdkKind(files));
|
||||||
@@ -108,7 +107,7 @@ public abstract class AbstractCompileKotlinAgainstKotlinTest extends CodegenTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
protected ClassFileFactory compileB(@NotNull String fileName, @NotNull String content, List<TestFile> files) throws IOException {
|
private ClassFileFactory compileB(@NotNull String fileName, @NotNull String content, List<TestFile> files) throws IOException {
|
||||||
CompilerConfiguration configurationWithADirInClasspath = KotlinTestUtils
|
CompilerConfiguration configurationWithADirInClasspath = KotlinTestUtils
|
||||||
.compilerConfigurationForTests(ConfigurationKind.ALL, getJdkKind(files), KotlinTestUtils.getAnnotationsJar(), aDir);
|
.compilerConfigurationForTests(ConfigurationKind.ALL, getJdkKind(files), KotlinTestUtils.getAnnotationsJar(), aDir);
|
||||||
|
|
||||||
@@ -132,11 +131,11 @@ public abstract class AbstractCompileKotlinAgainstKotlinTest extends CodegenTest
|
|||||||
) throws IOException {
|
) throws IOException {
|
||||||
KtFile psiFile = KotlinTestUtils.createFile(fileName, content, environment.getProject());
|
KtFile psiFile = KotlinTestUtils.createFile(fileName, content, environment.getProject());
|
||||||
|
|
||||||
ModuleVisibilityManager.SERVICE.getInstance(environment.getProject()).addModule(new ModuleBuilder("module for test", tmpdir.getAbsolutePath(), "test"));
|
ModuleVisibilityManager.SERVICE.getInstance(environment.getProject()).addModule(
|
||||||
|
new ModuleBuilder("module for test", tmpdir.getAbsolutePath(), "test")
|
||||||
|
);
|
||||||
|
|
||||||
ClassFileFactory outputFiles = GenerationUtils.compileFileGetClassFileFactoryForTest(psiFile, environment);
|
ClassFileFactory outputFiles = GenerationUtils.compileFileTo(psiFile, environment, outputDir);
|
||||||
|
|
||||||
OutputUtilsKt.writeAllTo(outputFiles, outputDir);
|
|
||||||
|
|
||||||
Disposer.dispose(disposable);
|
Disposer.dispose(disposable);
|
||||||
return outputFiles;
|
return outputFiles;
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
package org.jetbrains.kotlin.codegen
|
package org.jetbrains.kotlin.codegen
|
||||||
|
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
|
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.JvmPackagePartProvider
|
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||||
import org.jetbrains.kotlin.codegen.state.GenerationState
|
import org.jetbrains.kotlin.codegen.state.GenerationState
|
||||||
import org.jetbrains.kotlin.psi.KtFile
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
@@ -51,18 +50,14 @@ abstract class AbstractDumpDeclarationsTest : CodegenTestCase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun compileManyFilesGetDeclarationsDump(files: List<KtFile>): File {
|
private fun compileManyFilesGetDeclarationsDump(files: List<KtFile>): File {
|
||||||
val project = myEnvironment.project
|
val analysisResult = JvmResolveUtil.analyzeAndCheckForErrors(files, myEnvironment)
|
||||||
val packagePartProvider = JvmPackagePartProvider(myEnvironment)
|
|
||||||
|
|
||||||
val analysisResult = JvmResolveUtil.analyzeFilesWithJavaIntegrationAndCheckForErrors(
|
|
||||||
project, files, packagePartProvider)
|
|
||||||
|
|
||||||
analysisResult.throwIfError()
|
analysisResult.throwIfError()
|
||||||
|
|
||||||
val dumpToFile = KotlinTestUtils.tmpDirForTest(this).resolve(this.name + ".json")
|
val dumpToFile = KotlinTestUtils.tmpDirForTest(this).resolve(this.name + ".json")
|
||||||
|
|
||||||
val state = GenerationState(
|
val state = GenerationState(
|
||||||
project, ClassBuilderFactories.TEST,
|
myEnvironment.project, ClassBuilderFactories.TEST,
|
||||||
analysisResult.moduleDescriptor, analysisResult.bindingContext,
|
analysisResult.moduleDescriptor, analysisResult.bindingContext,
|
||||||
files,
|
files,
|
||||||
disableCallAssertions = false,
|
disableCallAssertions = false,
|
||||||
|
|||||||
@@ -25,11 +25,8 @@ import kotlin.collections.CollectionsKt;
|
|||||||
import kotlin.jvm.functions.Function1;
|
import kotlin.jvm.functions.Function1;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.kotlin.backend.common.output.OutputFile;
|
import org.jetbrains.kotlin.backend.common.output.OutputFile;
|
||||||
import org.jetbrains.kotlin.backend.common.output.OutputFileCollection;
|
|
||||||
import org.jetbrains.kotlin.cli.common.output.outputUtils.OutputUtilsKt;
|
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles;
|
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles;
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
||||||
import org.jetbrains.kotlin.codegen.state.GenerationState;
|
|
||||||
import org.jetbrains.kotlin.psi.KtFile;
|
import org.jetbrains.kotlin.psi.KtFile;
|
||||||
import org.jetbrains.kotlin.test.ConfigurationKind;
|
import org.jetbrains.kotlin.test.ConfigurationKind;
|
||||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||||
@@ -47,15 +44,9 @@ import java.util.regex.Matcher;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public abstract class AbstractLineNumberTest extends TestCaseWithTmpdir {
|
public abstract class AbstractLineNumberTest extends TestCaseWithTmpdir {
|
||||||
|
|
||||||
private static final String LINE_NUMBER_FUN = "lineNumber";
|
private static final String LINE_NUMBER_FUN = "lineNumber";
|
||||||
private static final Pattern TEST_LINE_NUMBER_PATTERN = Pattern.compile("^.*test." + LINE_NUMBER_FUN + "\\(\\).*$");
|
private static final Pattern TEST_LINE_NUMBER_PATTERN = Pattern.compile("^.*test." + LINE_NUMBER_FUN + "\\(\\).*$");
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private static String getTestDataPath() {
|
|
||||||
return KotlinTestUtils.getTestDataPathBase() + "/lineNumber";
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private KotlinCoreEnvironment createEnvironment() {
|
private KotlinCoreEnvironment createEnvironment() {
|
||||||
return KotlinCoreEnvironment.createForTests(
|
return KotlinCoreEnvironment.createForTests(
|
||||||
@@ -70,13 +61,13 @@ public abstract class AbstractLineNumberTest extends TestCaseWithTmpdir {
|
|||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
||||||
KotlinCoreEnvironment environment = createEnvironment();
|
KotlinCoreEnvironment environment = createEnvironment();
|
||||||
KtFile psiFile = KotlinTestUtils.createFile(LINE_NUMBER_FUN + ".kt",
|
KtFile psiFile = KotlinTestUtils.createFile(
|
||||||
"package test;\n\npublic fun " + LINE_NUMBER_FUN + "(): Int = 0\n",
|
LINE_NUMBER_FUN + ".kt",
|
||||||
environment.getProject());
|
"package test;\n\npublic fun " + LINE_NUMBER_FUN + "(): Int = 0\n",
|
||||||
|
environment.getProject()
|
||||||
|
);
|
||||||
|
|
||||||
OutputFileCollection outputFiles =
|
GenerationUtils.compileFileTo(psiFile, environment, tmpdir);
|
||||||
GenerationUtils.compileFileGetClassFileFactoryForTest(psiFile, environment);
|
|
||||||
OutputUtilsKt.writeAllTo(outputFiles, tmpdir);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -92,7 +83,9 @@ public abstract class AbstractLineNumberTest extends TestCaseWithTmpdir {
|
|||||||
throw ExceptionUtilsKt.rethrow(e);
|
throw ExceptionUtilsKt.rethrow(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Pair(KotlinTestUtils.createFile(file.getName(), text, environment.getProject()), environment);
|
return new Pair<KtFile, KotlinCoreEnvironment>(
|
||||||
|
KotlinTestUtils.createFile(file.getName(), text, environment.getProject()), environment
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doTest(@NotNull String filename, boolean custom) {
|
private void doTest(@NotNull String filename, boolean custom) {
|
||||||
@@ -100,17 +93,17 @@ public abstract class AbstractLineNumberTest extends TestCaseWithTmpdir {
|
|||||||
KtFile psiFile = fileAndEnv.getFirst();
|
KtFile psiFile = fileAndEnv.getFirst();
|
||||||
KotlinCoreEnvironment environment = fileAndEnv.getSecond();
|
KotlinCoreEnvironment environment = fileAndEnv.getSecond();
|
||||||
|
|
||||||
GenerationState state = GenerationUtils.compileFileGetGenerationStateForTest(psiFile, environment);
|
ClassFileFactory classFileFactory = GenerationUtils.compileFile(psiFile, environment);
|
||||||
|
|
||||||
if (custom) {
|
if (custom) {
|
||||||
List<Integer> actualLineNumbers = extractActualLineNumbersFromBytecode(state, false);
|
List<Integer> actualLineNumbers = extractActualLineNumbersFromBytecode(classFileFactory, false);
|
||||||
String text = psiFile.getText();
|
String text = psiFile.getText();
|
||||||
String newFileText = text.substring(0, text.indexOf("// ")) + getActualLineNumbersAsString(actualLineNumbers);
|
String newFileText = text.substring(0, text.indexOf("// ")) + getActualLineNumbersAsString(actualLineNumbers);
|
||||||
KotlinTestUtils.assertEqualsToFile(new File(filename), newFileText);
|
KotlinTestUtils.assertEqualsToFile(new File(filename), newFileText);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
List<Integer> expectedLineNumbers = extractSelectedLineNumbersFromSource(psiFile);
|
List<Integer> expectedLineNumbers = extractSelectedLineNumbersFromSource(psiFile);
|
||||||
List<Integer> actualLineNumbers = extractActualLineNumbersFromBytecode(state, true);
|
List<Integer> actualLineNumbers = extractActualLineNumbersFromBytecode(classFileFactory, true);
|
||||||
assertSameElements(actualLineNumbers, expectedLineNumbers);
|
assertSameElements(actualLineNumbers, expectedLineNumbers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,8 +119,7 @@ public abstract class AbstractLineNumberTest extends TestCaseWithTmpdir {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static List<Integer> extractActualLineNumbersFromBytecode(@NotNull GenerationState state, boolean testFunInvoke) {
|
private static List<Integer> extractActualLineNumbersFromBytecode(@NotNull ClassFileFactory factory, boolean testFunInvoke) {
|
||||||
ClassFileFactory factory = state.getFactory();
|
|
||||||
List<Integer> actualLineNumbers = Lists.newArrayList();
|
List<Integer> actualLineNumbers = Lists.newArrayList();
|
||||||
for (OutputFile outputFile : ClassFileUtilsKt.getClassFiles(factory)) {
|
for (OutputFile outputFile : ClassFileUtilsKt.getClassFiles(factory)) {
|
||||||
ClassReader cr = new ClassReader(outputFile.asByteArray());
|
ClassReader cr = new ClassReader(outputFile.asByteArray());
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import kotlin.jvm.functions.Function1;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.analyzer.AnalysisResult;
|
import org.jetbrains.kotlin.analyzer.AnalysisResult;
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.JvmPackagePartProvider;
|
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
||||||
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime;
|
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime;
|
||||||
import org.jetbrains.kotlin.codegen.state.GenerationState;
|
import org.jetbrains.kotlin.codegen.state.GenerationState;
|
||||||
@@ -48,11 +47,7 @@ public class CodegenTestUtil {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static ClassFileFactory generateFiles(@NotNull KotlinCoreEnvironment environment, @NotNull CodegenTestFiles files) {
|
public static ClassFileFactory generateFiles(@NotNull KotlinCoreEnvironment environment, @NotNull CodegenTestFiles files) {
|
||||||
AnalysisResult analysisResult = JvmResolveUtil.analyzeFilesWithJavaIntegrationAndCheckForErrors(
|
AnalysisResult analysisResult = JvmResolveUtil.analyzeAndCheckForErrors(files.getPsiFiles(), environment);
|
||||||
environment.getProject(),
|
|
||||||
files.getPsiFiles(),
|
|
||||||
new JvmPackagePartProvider(environment)
|
|
||||||
);
|
|
||||||
analysisResult.throwIfError();
|
analysisResult.throwIfError();
|
||||||
AnalyzingUtils.throwExceptionOnErrors(analysisResult.getBindingContext());
|
AnalyzingUtils.throwExceptionOnErrors(analysisResult.getBindingContext());
|
||||||
CompilerConfiguration configuration = environment.getConfiguration();
|
CompilerConfiguration configuration = environment.getConfiguration();
|
||||||
|
|||||||
@@ -16,109 +16,79 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.codegen;
|
package org.jetbrains.kotlin.codegen;
|
||||||
|
|
||||||
import com.intellij.openapi.project.Project;
|
import kotlin.collections.CollectionsKt;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.analyzer.AnalysisResult;
|
import org.jetbrains.kotlin.analyzer.AnalysisResult;
|
||||||
|
import org.jetbrains.kotlin.cli.common.output.outputUtils.OutputUtilsKt;
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.JvmPackagePartProvider;
|
import org.jetbrains.kotlin.cli.jvm.compiler.JvmPackagePartProvider;
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
||||||
import org.jetbrains.kotlin.codegen.state.GenerationState;
|
import org.jetbrains.kotlin.codegen.state.GenerationState;
|
||||||
import org.jetbrains.kotlin.config.CompilerConfiguration;
|
import org.jetbrains.kotlin.config.CompilerConfiguration;
|
||||||
import org.jetbrains.kotlin.config.CompilerConfigurationKey;
|
|
||||||
import org.jetbrains.kotlin.config.JVMConfigurationKeys;
|
import org.jetbrains.kotlin.config.JVMConfigurationKeys;
|
||||||
import org.jetbrains.kotlin.descriptors.PackagePartProvider;
|
import org.jetbrains.kotlin.descriptors.PackagePartProvider;
|
||||||
import org.jetbrains.kotlin.name.FqName;
|
import org.jetbrains.kotlin.name.FqName;
|
||||||
import org.jetbrains.kotlin.psi.KtFile;
|
import org.jetbrains.kotlin.psi.KtFile;
|
||||||
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil;
|
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class GenerationUtils {
|
public class GenerationUtils {
|
||||||
|
|
||||||
private GenerationUtils() {
|
private GenerationUtils() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static ClassFileFactory compileFileGetClassFileFactoryForTest(
|
public static ClassFileFactory compileFileTo(@NotNull KtFile ktFile, @NotNull KotlinCoreEnvironment environment, @NotNull File output) {
|
||||||
@NotNull KtFile psiFile,
|
ClassFileFactory factory = compileFile(ktFile, environment);
|
||||||
@NotNull KotlinCoreEnvironment environment
|
OutputUtilsKt.writeAllTo(factory, output);
|
||||||
) {
|
return factory;
|
||||||
return compileFileGetGenerationStateForTest(psiFile, environment).getFactory();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static GenerationState compileFileGetGenerationStateForTest(
|
public static ClassFileFactory compileFile(@NotNull KtFile ktFile, @NotNull KotlinCoreEnvironment environment) {
|
||||||
@NotNull KtFile psiFile,
|
AnalysisResult analysisResult = JvmResolveUtil.analyzeAndCheckForErrors(ktFile, environment);
|
||||||
@NotNull KotlinCoreEnvironment environment
|
GenerationState state = compileFiles(analysisResult, Collections.singletonList(ktFile), false, environment.getConfiguration());
|
||||||
) {
|
return state.getFactory();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static GenerationState compileFiles(@NotNull List<KtFile> files, @Nullable KotlinCoreEnvironment environment) {
|
||||||
|
PackagePartProvider packagePartProvider =
|
||||||
|
environment == null ? PackagePartProvider.Companion.getEMPTY() : new JvmPackagePartProvider(environment);
|
||||||
|
CompilerConfiguration configuration =
|
||||||
|
environment == null ? CompilerConfiguration.EMPTY : environment.getConfiguration();
|
||||||
AnalysisResult analysisResult =
|
AnalysisResult analysisResult =
|
||||||
JvmResolveUtil.analyzeOneFileWithJavaIntegrationAndCheckForErrors(psiFile, new JvmPackagePartProvider(environment));
|
JvmResolveUtil.analyzeAndCheckForErrors(CollectionsKt.first(files).getProject(), files, configuration, packagePartProvider);
|
||||||
return compileFilesGetGenerationState(psiFile.getProject(), analysisResult, Collections.singletonList(psiFile), false, null);
|
return compileFiles(analysisResult, files, false, configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static GenerationState compileManyFilesGetGenerationStateForTest(@NotNull Project project, @NotNull List<KtFile> files) {
|
public static GenerationState compileFiles(
|
||||||
return compileManyFilesGetGenerationStateForTest(project, files, PackagePartProvider.Companion.getEMPTY(), null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static GenerationState compileManyFilesGetGenerationStateForTest(
|
|
||||||
@NotNull Project project,
|
|
||||||
@NotNull List<KtFile> files,
|
|
||||||
@NotNull PackagePartProvider packagePartProvider,
|
|
||||||
@Nullable CompilerConfiguration configuration
|
|
||||||
) {
|
|
||||||
AnalysisResult analysisResult = JvmResolveUtil.analyzeFilesWithJavaIntegrationAndCheckForErrors(
|
|
||||||
project, files, packagePartProvider);
|
|
||||||
return compileFilesGetGenerationState(project, analysisResult, files, false, configuration);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static GenerationState compileFilesGetGenerationState(
|
|
||||||
@NotNull Project project,
|
|
||||||
@NotNull AnalysisResult analysisResult,
|
|
||||||
@NotNull List<KtFile> files,
|
|
||||||
boolean useTypeTableInSerializer
|
|
||||||
) {
|
|
||||||
return compileFilesGetGenerationState(project, analysisResult, files, useTypeTableInSerializer, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static GenerationState compileFilesGetGenerationState(
|
|
||||||
@NotNull Project project,
|
|
||||||
@NotNull AnalysisResult analysisResult,
|
@NotNull AnalysisResult analysisResult,
|
||||||
@NotNull List<KtFile> files,
|
@NotNull List<KtFile> files,
|
||||||
boolean useTypeTableInSerializer,
|
boolean useTypeTableInSerializer,
|
||||||
@Nullable CompilerConfiguration configuration
|
@NotNull CompilerConfiguration configuration
|
||||||
) {
|
) {
|
||||||
analysisResult.throwIfError();
|
analysisResult.throwIfError();
|
||||||
GenerationState state = new GenerationState(
|
GenerationState state = new GenerationState(
|
||||||
project, ClassBuilderFactories.TEST,
|
CollectionsKt.first(files).getProject(), ClassBuilderFactories.TEST,
|
||||||
analysisResult.getModuleDescriptor(), analysisResult.getBindingContext(),
|
analysisResult.getModuleDescriptor(), analysisResult.getBindingContext(),
|
||||||
files,
|
files,
|
||||||
getConfigurationValueOrDefault(configuration, JVMConfigurationKeys.DISABLE_CALL_ASSERTIONS, false),
|
configuration.get(JVMConfigurationKeys.DISABLE_CALL_ASSERTIONS, false),
|
||||||
getConfigurationValueOrDefault(configuration, JVMConfigurationKeys.DISABLE_PARAM_ASSERTIONS, false),
|
configuration.get(JVMConfigurationKeys.DISABLE_PARAM_ASSERTIONS, false),
|
||||||
GenerationState.GenerateClassFilter.GENERATE_ALL,
|
GenerationState.GenerateClassFilter.GENERATE_ALL,
|
||||||
getConfigurationValueOrDefault(configuration, JVMConfigurationKeys.DISABLE_INLINE, false),
|
configuration.get(JVMConfigurationKeys.DISABLE_INLINE, false),
|
||||||
getConfigurationValueOrDefault(configuration, JVMConfigurationKeys.DISABLE_OPTIMIZATION, false),
|
configuration.get(JVMConfigurationKeys.DISABLE_OPTIMIZATION, false),
|
||||||
useTypeTableInSerializer,
|
useTypeTableInSerializer,
|
||||||
getConfigurationValueOrDefault(configuration, JVMConfigurationKeys.INHERIT_MULTIFILE_PARTS, false),
|
configuration.get(JVMConfigurationKeys.INHERIT_MULTIFILE_PARTS, false),
|
||||||
Collections.<FqName>emptySet(),
|
Collections.<FqName>emptySet(),
|
||||||
Collections.<FqName>emptySet(),
|
Collections.<FqName>emptySet(),
|
||||||
null,
|
null,
|
||||||
configuration == null ? null : configuration.get(JVMConfigurationKeys.MODULE_NAME)
|
configuration.get(JVMConfigurationKeys.MODULE_NAME)
|
||||||
);
|
);
|
||||||
KotlinCodegenFacade.compileCorrectFiles(state, CompilationErrorHandler.THROW_EXCEPTION);
|
KotlinCodegenFacade.compileCorrectFiles(state, CompilationErrorHandler.THROW_EXCEPTION);
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T> T getConfigurationValueOrDefault(
|
|
||||||
@Nullable CompilerConfiguration configuration,
|
|
||||||
@NotNull CompilerConfigurationKey<T> key,
|
|
||||||
T defaultValue
|
|
||||||
) {
|
|
||||||
if (configuration == null) return defaultValue;
|
|
||||||
return configuration.get(key, defaultValue);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-11
@@ -54,18 +54,17 @@ import static org.jetbrains.kotlin.test.InTextDirectivesUtils.findStringWithPref
|
|||||||
* FLAGS: ACC_STATIC, ACC_FINAL, ACC_PRIVATE
|
* FLAGS: ACC_STATIC, ACC_FINAL, ACC_PRIVATE
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractWriteFlagsTest extends KtUsefulTestCase {
|
public abstract class AbstractWriteFlagsTest extends KtUsefulTestCase {
|
||||||
|
private KotlinCoreEnvironment environment;
|
||||||
private KotlinCoreEnvironment jetCoreEnvironment;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
jetCoreEnvironment = KotlinTestUtils.createEnvironmentWithMockJdkAndIdeaAnnotations(myTestRootDisposable, ConfigurationKind.JDK_ONLY);
|
environment = KotlinTestUtils.createEnvironmentWithMockJdkAndIdeaAnnotations(myTestRootDisposable, ConfigurationKind.JDK_ONLY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
jetCoreEnvironment = null;
|
environment = null;
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,19 +74,17 @@ public abstract class AbstractWriteFlagsTest extends KtUsefulTestCase {
|
|||||||
|
|
||||||
String fileText = FileUtil.loadFile(ktFile, true);
|
String fileText = FileUtil.loadFile(ktFile, true);
|
||||||
|
|
||||||
KtFile psiFile = KotlinTestUtils.createFile(ktFile.getName(), fileText, jetCoreEnvironment.getProject());
|
KtFile psiFile = KotlinTestUtils.createFile(ktFile.getName(), fileText, environment.getProject());
|
||||||
|
|
||||||
OutputFileCollection outputFiles = GenerationUtils.compileFileGetClassFileFactoryForTest(psiFile, jetCoreEnvironment);
|
OutputFileCollection outputFiles = GenerationUtils.compileFile(psiFile, environment);
|
||||||
|
|
||||||
List<TestedObject> testedObjects = parseExpectedTestedObject(fileText);
|
List<TestedObject> testedObjects = parseExpectedTestedObject(fileText);
|
||||||
for (TestedObject testedObject : testedObjects) {
|
for (TestedObject testedObject : testedObjects) {
|
||||||
String className = null;
|
String className = null;
|
||||||
for (OutputFile outputFile : outputFiles.asList()) {
|
for (OutputFile outputFile : outputFiles.asList()) {
|
||||||
String filePath = outputFile.getRelativePath();
|
String filePath = outputFile.getRelativePath();
|
||||||
if (testedObject.isFullContainingClassName && filePath.equals(testedObject.containingClass + ".class")) {
|
if (testedObject.isFullContainingClassName && filePath.equals(testedObject.containingClass + ".class") ||
|
||||||
className = filePath;
|
!testedObject.isFullContainingClassName && filePath.startsWith(testedObject.containingClass)) {
|
||||||
}
|
|
||||||
else if (!testedObject.isFullContainingClassName && filePath.startsWith(testedObject.containingClass)) {
|
|
||||||
className = filePath;
|
className = filePath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -118,7 +115,7 @@ public abstract class AbstractWriteFlagsTest extends KtUsefulTestCase {
|
|||||||
|
|
||||||
private static List<TestedObject> parseExpectedTestedObject(String testDescription) {
|
private static List<TestedObject> parseExpectedTestedObject(String testDescription) {
|
||||||
String[] testObjectData = testDescription.substring(testDescription.indexOf("// TESTED_OBJECT_KIND")).split("\n\n");
|
String[] testObjectData = testDescription.substring(testDescription.indexOf("// TESTED_OBJECT_KIND")).split("\n\n");
|
||||||
ArrayList<TestedObject> objects = new ArrayList<TestedObject>();
|
List<TestedObject> objects = new ArrayList<TestedObject>();
|
||||||
|
|
||||||
for (String testData : testObjectData) {
|
for (String testData : testObjectData) {
|
||||||
if (testData.isEmpty()) continue;
|
if (testData.isEmpty()) continue;
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import org.jetbrains.kotlin.config.ContentRootsKt;
|
|||||||
import org.jetbrains.kotlin.context.ModuleContext;
|
import org.jetbrains.kotlin.context.ModuleContext;
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||||
|
import org.jetbrains.kotlin.descriptors.ModuleDescriptor;
|
||||||
import org.jetbrains.kotlin.descriptors.PackageViewDescriptor;
|
import org.jetbrains.kotlin.descriptors.PackageViewDescriptor;
|
||||||
import org.jetbrains.kotlin.psi.KtFile;
|
import org.jetbrains.kotlin.psi.KtFile;
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||||
@@ -189,12 +190,10 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
|
|||||||
compilerConfigurationForTests(ConfigurationKind.JDK_ONLY, getJdkKind(), getAnnotationsJar(), libraryOut),
|
compilerConfigurationForTests(ConfigurationKind.JDK_ONLY, getJdkKind(), getAnnotationsJar(), libraryOut),
|
||||||
EnvironmentConfigFiles.JVM_CONFIG_FILES);
|
EnvironmentConfigFiles.JVM_CONFIG_FILES);
|
||||||
|
|
||||||
KtFile jetFile = KotlinTestUtils.createFile(kotlinSrc.getPath(), FileUtil.loadFile(kotlinSrc, true), environment.getProject());
|
KtFile ktFile = KotlinTestUtils.createFile(kotlinSrc.getPath(), FileUtil.loadFile(kotlinSrc, true), environment.getProject());
|
||||||
|
|
||||||
AnalysisResult result = JvmResolveUtil.analyzeFilesWithJavaIntegrationAndCheckForErrors(
|
ModuleDescriptor module = JvmResolveUtil.analyzeAndCheckForErrors(Collections.singleton(ktFile), environment).getModuleDescriptor();
|
||||||
environment.getProject(), Collections.singleton(jetFile)
|
PackageViewDescriptor packageView = module.getPackage(TEST_PACKAGE_FQNAME);
|
||||||
);
|
|
||||||
PackageViewDescriptor packageView = result.getModuleDescriptor().getPackage(TEST_PACKAGE_FQNAME);
|
|
||||||
assertFalse(packageView.isEmpty());
|
assertFalse(packageView.isEmpty());
|
||||||
|
|
||||||
validateAndCompareDescriptorWithFile(packageView, DONT_INCLUDE_METHODS_OF_OBJECT.withValidationStrategy(
|
validateAndCompareDescriptorWithFile(packageView, DONT_INCLUDE_METHODS_OF_OBJECT.withValidationStrategy(
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import org.jetbrains.kotlin.analyzer.AnalysisResult;
|
|||||||
import org.jetbrains.kotlin.cli.common.output.outputUtils.OutputUtilsKt;
|
import org.jetbrains.kotlin.cli.common.output.outputUtils.OutputUtilsKt;
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.CliLightClassGenerationSupport;
|
import org.jetbrains.kotlin.cli.jvm.compiler.CliLightClassGenerationSupport;
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles;
|
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles;
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.JvmPackagePartProvider;
|
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
||||||
import org.jetbrains.kotlin.codegen.GenerationUtils;
|
import org.jetbrains.kotlin.codegen.GenerationUtils;
|
||||||
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime;
|
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime;
|
||||||
@@ -67,12 +66,11 @@ public final class LoadDescriptorUtil {
|
|||||||
@NotNull ConfigurationKind configurationKind,
|
@NotNull ConfigurationKind configurationKind,
|
||||||
boolean useTypeTableInSerializer
|
boolean useTypeTableInSerializer
|
||||||
) {
|
) {
|
||||||
KtFilesAndAnalysisResult
|
KtFilesAndAnalysisResult filesAndResult =
|
||||||
filesAndResult = KtFilesAndAnalysisResult.createJetFilesAndAnalyze(kotlinFiles, disposable, configurationKind);
|
KtFilesAndAnalysisResult.createJetFilesAndAnalyze(kotlinFiles, disposable, configurationKind);
|
||||||
AnalysisResult result = filesAndResult.getAnalysisResult();
|
AnalysisResult result = filesAndResult.getAnalysisResult();
|
||||||
List<KtFile> files = filesAndResult.getKtFiles();
|
GenerationState state = GenerationUtils.compileFiles(
|
||||||
GenerationState state = GenerationUtils.compileFilesGetGenerationState(
|
result, filesAndResult.getKtFiles(), useTypeTableInSerializer, CompilerConfiguration.EMPTY
|
||||||
files.get(0).getProject(), result, files, useTypeTableInSerializer
|
|
||||||
);
|
);
|
||||||
OutputUtilsKt.writeAllTo(state.getFactory(), outDir);
|
OutputUtilsKt.writeAllTo(state.getFactory(), outDir);
|
||||||
return result;
|
return result;
|
||||||
@@ -131,22 +129,22 @@ public final class LoadDescriptorUtil {
|
|||||||
@NotNull Disposable disposable,
|
@NotNull Disposable disposable,
|
||||||
@NotNull ConfigurationKind configurationKind
|
@NotNull ConfigurationKind configurationKind
|
||||||
) {
|
) {
|
||||||
final KotlinCoreEnvironment jetCoreEnvironment = createEnvironmentWithMockJdkAndIdeaAnnotations(disposable, configurationKind);
|
final KotlinCoreEnvironment environment = createEnvironmentWithMockJdkAndIdeaAnnotations(disposable, configurationKind);
|
||||||
List<KtFile> jetFiles = ContainerUtil.map(kotlinFiles, new Function<File, KtFile>() {
|
List<KtFile> ktFiles = ContainerUtil.map(kotlinFiles, new Function<File, KtFile>() {
|
||||||
@Override
|
@Override
|
||||||
public KtFile fun(File kotlinFile) {
|
public KtFile fun(File kotlinFile) {
|
||||||
try {
|
try {
|
||||||
return KotlinTestUtils.createFile(
|
return KotlinTestUtils.createFile(
|
||||||
kotlinFile.getName(), FileUtil.loadFile(kotlinFile, true), jetCoreEnvironment.getProject());
|
kotlinFile.getName(), FileUtil.loadFile(kotlinFile, true), environment.getProject()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
throw new AssertionError(e);
|
throw new AssertionError(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
AnalysisResult result = JvmResolveUtil.analyzeFilesWithJavaIntegrationAndCheckForErrors(
|
AnalysisResult result = JvmResolveUtil.analyzeAndCheckForErrors(ktFiles, environment);
|
||||||
jetCoreEnvironment.getProject(), jetFiles, new JvmPackagePartProvider(jetCoreEnvironment));
|
return new KtFilesAndAnalysisResult(ktFiles, result);
|
||||||
return new KtFilesAndAnalysisResult(jetFiles, result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final List<KtFile> ktFiles;
|
private final List<KtFile> ktFiles;
|
||||||
|
|||||||
+2
-3
@@ -17,7 +17,6 @@
|
|||||||
package org.jetbrains.kotlin.jvm.runtime
|
package org.jetbrains.kotlin.jvm.runtime
|
||||||
|
|
||||||
import com.intellij.openapi.util.io.FileUtil
|
import com.intellij.openapi.util.io.FileUtil
|
||||||
import org.jetbrains.kotlin.cli.common.output.outputUtils.writeAllTo
|
|
||||||
import org.jetbrains.kotlin.codegen.GenerationUtils
|
import org.jetbrains.kotlin.codegen.GenerationUtils
|
||||||
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
|
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
@@ -138,8 +137,8 @@ abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdir() {
|
|||||||
val environment = KotlinTestUtils.createEnvironmentWithJdkAndNullabilityAnnotationsFromIdea(
|
val environment = KotlinTestUtils.createEnvironmentWithJdkAndNullabilityAnnotationsFromIdea(
|
||||||
myTestRootDisposable, ConfigurationKind.ALL, jdkKind
|
myTestRootDisposable, ConfigurationKind.ALL, jdkKind
|
||||||
)
|
)
|
||||||
val jetFile = KotlinTestUtils.createFile(file.path, text, environment.project)
|
val ktFile = KotlinTestUtils.createFile(file.path, text, environment.project)
|
||||||
GenerationUtils.compileFileGetClassFileFactoryForTest(jetFile, environment).writeAllTo(tmpdir)
|
GenerationUtils.compileFileTo(ktFile, environment, tmpdir)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,13 +18,11 @@ package org.jetbrains.kotlin.resolve;
|
|||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import com.intellij.openapi.project.Project;
|
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import com.intellij.psi.PsiQualifiedNamedElement;
|
import com.intellij.psi.PsiQualifiedNamedElement;
|
||||||
import com.intellij.psi.util.PsiTreeUtil;
|
import com.intellij.psi.util.PsiTreeUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.analyzer.AnalysisResult;
|
|
||||||
import org.jetbrains.kotlin.builtins.DefaultBuiltIns;
|
import org.jetbrains.kotlin.builtins.DefaultBuiltIns;
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
||||||
import org.jetbrains.kotlin.descriptors.*;
|
import org.jetbrains.kotlin.descriptors.*;
|
||||||
@@ -139,9 +137,7 @@ public abstract class ExpectedResolveData {
|
|||||||
return BindingContext.EMPTY;
|
return BindingContext.EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
Project project = files.iterator().next().getProject();
|
return JvmResolveUtil.analyze(files, environment).getBindingContext();
|
||||||
AnalysisResult analysisResult = JvmResolveUtil.analyzeFilesWithJavaIntegration(project, files, environment);
|
|
||||||
return analysisResult.getBindingContext();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void checkResult(BindingContext bindingContext) {
|
public final void checkResult(BindingContext bindingContext) {
|
||||||
|
|||||||
+3
-3
@@ -50,10 +50,10 @@ abstract class AbstractResolvedCallsTest : KotlinTestWithEnvironment() {
|
|||||||
fun doTest(filePath: String) {
|
fun doTest(filePath: String) {
|
||||||
val text = KotlinTestUtils.doLoadFile(File(filePath))!!
|
val text = KotlinTestUtils.doLoadFile(File(filePath))!!
|
||||||
|
|
||||||
val jetFile = KtPsiFactory(project).createFile(text.replace("<caret>", ""))
|
val ktFile = KtPsiFactory(project).createFile(text.replace("<caret>", ""))
|
||||||
val bindingContext = JvmResolveUtil.analyzeOneFileWithJavaIntegration(jetFile, environment).bindingContext
|
val bindingContext = JvmResolveUtil.analyze(ktFile, environment).bindingContext
|
||||||
|
|
||||||
val (element, cachedCall) = buildCachedCall(bindingContext, jetFile, text)
|
val (element, cachedCall) = buildCachedCall(bindingContext, ktFile, text)
|
||||||
|
|
||||||
val resolvedCall = if (cachedCall !is VariableAsFunctionResolvedCall) cachedCall
|
val resolvedCall = if (cachedCall !is VariableAsFunctionResolvedCall) cachedCall
|
||||||
else if ("(" == element?.text) cachedCall.functionCall
|
else if ("(" == element?.text) cachedCall.functionCall
|
||||||
|
|||||||
+1
-1
@@ -67,7 +67,7 @@ abstract class AbstractConstraintSystemTest : KotlinTestWithEnvironment() {
|
|||||||
val fileName = "declarations.kt"
|
val fileName = "declarations.kt"
|
||||||
|
|
||||||
val psiFile = KotlinTestUtils.createFile(fileName, KotlinTestUtils.doLoadFile(testDataPath, fileName), project)
|
val psiFile = KotlinTestUtils.createFile(fileName, KotlinTestUtils.doLoadFile(testDataPath, fileName), project)
|
||||||
val bindingContext = JvmResolveUtil.analyzeOneFileWithJavaIntegrationAndCheckForErrors(psiFile).bindingContext
|
val bindingContext = JvmResolveUtil.analyzeAndCheckForErrors(psiFile, environment).bindingContext
|
||||||
return ConstraintSystemTestData(bindingContext, project, typeResolver)
|
return ConstraintSystemTestData(bindingContext, project, typeResolver)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,55 +35,32 @@ public class JvmResolveUtil {
|
|||||||
public static String TEST_MODULE_NAME = "java-integration-test";
|
public static String TEST_MODULE_NAME = "java-integration-test";
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static AnalysisResult analyzeOneFileWithJavaIntegrationAndCheckForErrors(@NotNull KtFile file) {
|
public static AnalysisResult analyzeAndCheckForErrors(@NotNull KtFile file, @NotNull KotlinCoreEnvironment environment) {
|
||||||
return analyzeOneFileWithJavaIntegrationAndCheckForErrors(file, PackagePartProvider.Companion.getEMPTY());
|
return analyzeAndCheckForErrors(Collections.singleton(file), environment);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static AnalysisResult analyzeOneFileWithJavaIntegrationAndCheckForErrors(@NotNull KtFile file, @NotNull PackagePartProvider provider) {
|
public static AnalysisResult analyzeAndCheckForErrors(
|
||||||
AnalyzingUtils.checkForSyntacticErrors(file);
|
@NotNull Collection<KtFile> files,
|
||||||
|
@NotNull KotlinCoreEnvironment environment
|
||||||
AnalysisResult analysisResult = analyzeOneFileWithJavaIntegration(file, provider);
|
|
||||||
|
|
||||||
AnalyzingUtils.throwExceptionOnErrors(analysisResult.getBindingContext());
|
|
||||||
|
|
||||||
return analysisResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static AnalysisResult analyzeOneFileWithJavaIntegration(@NotNull KtFile file, @NotNull KotlinCoreEnvironment environment) {
|
|
||||||
return analyzeOneFileWithJavaIntegration(file, new JvmPackagePartProvider(environment));
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private static AnalysisResult analyzeOneFileWithJavaIntegration(@NotNull KtFile file, @NotNull PackagePartProvider provider) {
|
|
||||||
return analyzeFilesWithJavaIntegration(file.getProject(), Collections.singleton(file), provider);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static AnalysisResult analyzeOneFileWithJavaIntegration(@NotNull KtFile file) {
|
|
||||||
return analyzeOneFileWithJavaIntegration(file, PackagePartProvider.Companion.getEMPTY());
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static AnalysisResult analyzeFilesWithJavaIntegrationAndCheckForErrors(
|
|
||||||
@NotNull Project project,
|
|
||||||
@NotNull Collection<KtFile> files
|
|
||||||
) {
|
) {
|
||||||
return analyzeFilesWithJavaIntegrationAndCheckForErrors(project, files, PackagePartProvider.Companion.getEMPTY());
|
return analyzeAndCheckForErrors(
|
||||||
|
environment.getProject(), files, environment.getConfiguration(), new JvmPackagePartProvider(environment)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static AnalysisResult analyzeFilesWithJavaIntegrationAndCheckForErrors(
|
public static AnalysisResult analyzeAndCheckForErrors(
|
||||||
@NotNull Project project,
|
@NotNull Project project,
|
||||||
@NotNull Collection<KtFile> files,
|
@NotNull Collection<KtFile> files,
|
||||||
|
@NotNull CompilerConfiguration configuration,
|
||||||
@NotNull PackagePartProvider packagePartProvider
|
@NotNull PackagePartProvider packagePartProvider
|
||||||
) {
|
) {
|
||||||
for (KtFile file : files) {
|
for (KtFile file : files) {
|
||||||
AnalyzingUtils.checkForSyntacticErrors(file);
|
AnalyzingUtils.checkForSyntacticErrors(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
AnalysisResult analysisResult = analyzeFilesWithJavaIntegration(project, files, packagePartProvider);
|
AnalysisResult analysisResult = analyze(project, files, configuration, packagePartProvider);
|
||||||
|
|
||||||
AnalyzingUtils.throwExceptionOnErrors(analysisResult.getBindingContext());
|
AnalyzingUtils.throwExceptionOnErrors(analysisResult.getBindingContext());
|
||||||
|
|
||||||
@@ -91,23 +68,25 @@ public class JvmResolveUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static AnalysisResult analyzeFilesWithJavaIntegration(
|
public static AnalysisResult analyze(@NotNull KtFile file, @NotNull KotlinCoreEnvironment environment) {
|
||||||
@NotNull Project project,
|
return analyze(Collections.singleton(file), environment);
|
||||||
@NotNull Collection<KtFile> files,
|
|
||||||
@NotNull KotlinCoreEnvironment environment
|
|
||||||
) {
|
|
||||||
return analyzeFilesWithJavaIntegration(project, files, new JvmPackagePartProvider(environment));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static AnalysisResult analyzeFilesWithJavaIntegration(
|
public static AnalysisResult analyze(@NotNull Collection<KtFile> files, @NotNull KotlinCoreEnvironment environment) {
|
||||||
|
return analyze(environment.getProject(), files, environment.getConfiguration(), new JvmPackagePartProvider(environment));
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private static AnalysisResult analyze(
|
||||||
@NotNull Project project,
|
@NotNull Project project,
|
||||||
@NotNull Collection<KtFile> files,
|
@NotNull Collection<KtFile> files,
|
||||||
|
@NotNull CompilerConfiguration configuration,
|
||||||
@NotNull PackagePartProvider packagePartProvider
|
@NotNull PackagePartProvider packagePartProvider
|
||||||
) {
|
) {
|
||||||
return TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegrationWithCustomContext(
|
return TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegrationWithCustomContext(
|
||||||
TopDownAnalyzerFacadeForJVM.createContextWithSealedModule(project, TEST_MODULE_NAME),
|
TopDownAnalyzerFacadeForJVM.createContextWithSealedModule(project, TEST_MODULE_NAME),
|
||||||
files, new CliLightClassGenerationSupport.CliBindingTrace(), CompilerConfiguration.EMPTY, packagePartProvider
|
files, new CliLightClassGenerationSupport.CliBindingTrace(), configuration, packagePartProvider
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -290,7 +290,7 @@ public class KotlinTestUtils {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static AnalysisResult analyzeFile(@NotNull KtFile file, @NotNull KotlinCoreEnvironment environment) {
|
public static AnalysisResult analyzeFile(@NotNull KtFile file, @NotNull KotlinCoreEnvironment environment) {
|
||||||
return JvmResolveUtil.analyzeOneFileWithJavaIntegration(file, environment);
|
return JvmResolveUtil.analyze(file, environment);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -467,7 +467,7 @@ public class KotlinTestUtils {
|
|||||||
|
|
||||||
JvmContentRootsKt.addJvmClasspathRoots(configuration, classpath);
|
JvmContentRootsKt.addJvmClasspathRoots(configuration, classpath);
|
||||||
|
|
||||||
configuration.put(MODULE_NAME, "compilerConfigurationForTests");
|
configuration.put(MODULE_NAME, JvmResolveUtil.TEST_MODULE_NAME);
|
||||||
|
|
||||||
return configuration;
|
return configuration;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ public class CheckerTestUtilTest extends KotlinTestWithEnvironment {
|
|||||||
|
|
||||||
protected void doTest(TheTest theTest) throws Exception {
|
protected void doTest(TheTest theTest) throws Exception {
|
||||||
String text = KotlinTestUtils.doLoadFile(getTestDataPath(), "test.kt");
|
String text = KotlinTestUtils.doLoadFile(getTestDataPath(), "test.kt");
|
||||||
theTest.test(TestCheckerUtil.createCheckAndReturnPsiFile("test.kt", text, getProject()));
|
theTest.test(TestCheckerUtil.createCheckAndReturnPsiFile("test.kt", text, getProject()), getEnvironment());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testEquals() throws Exception {
|
public void testEquals() throws Exception {
|
||||||
@@ -142,12 +142,14 @@ public class CheckerTestUtilTest extends KotlinTestWithEnvironment {
|
|||||||
this.expected = expectedMessages;
|
this.expected = expectedMessages;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void test(@NotNull PsiFile psiFile) {
|
public void test(@NotNull PsiFile psiFile, @NotNull KotlinCoreEnvironment environment) {
|
||||||
BindingContext bindingContext = JvmResolveUtil.analyzeOneFileWithJavaIntegration(
|
BindingContext bindingContext =
|
||||||
(KtFile) psiFile)
|
JvmResolveUtil.analyze((KtFile) psiFile, environment).getBindingContext();
|
||||||
.getBindingContext();
|
|
||||||
|
|
||||||
String expectedText = CheckerTestUtil.addDiagnosticMarkersToText(psiFile, CheckerTestUtil.getDiagnosticsIncludingSyntaxErrors(bindingContext, psiFile, false, null)).toString();
|
String expectedText = CheckerTestUtil.addDiagnosticMarkersToText(
|
||||||
|
psiFile,
|
||||||
|
CheckerTestUtil.getDiagnosticsIncludingSyntaxErrors(bindingContext, psiFile, false, null)
|
||||||
|
).toString();
|
||||||
|
|
||||||
List<DiagnosedRange> diagnosedRanges = Lists.newArrayList();
|
List<DiagnosedRange> diagnosedRanges = Lists.newArrayList();
|
||||||
CheckerTestUtil.parseDiagnosedRanges(expectedText, diagnosedRanges);
|
CheckerTestUtil.parseDiagnosedRanges(expectedText, diagnosedRanges);
|
||||||
|
|||||||
+1
-1
@@ -81,7 +81,7 @@ public abstract class AbstractCompileJavaAgainstKotlinTest extends TestCaseWithT
|
|||||||
EnvironmentConfigFiles.JVM_CONFIG_FILES
|
EnvironmentConfigFiles.JVM_CONFIG_FILES
|
||||||
);
|
);
|
||||||
|
|
||||||
AnalysisResult exhaust = JvmResolveUtil.analyzeFilesWithJavaIntegration(environment.getProject(), Collections.<KtFile>emptySet(), environment);
|
AnalysisResult exhaust = JvmResolveUtil.analyze(Collections.<KtFile>emptySet(), environment);
|
||||||
PackageViewDescriptor packageView = exhaust.getModuleDescriptor().getPackage(LoadDescriptorUtil.TEST_PACKAGE_FQNAME);
|
PackageViewDescriptor packageView = exhaust.getModuleDescriptor().getPackage(LoadDescriptorUtil.TEST_PACKAGE_FQNAME);
|
||||||
assertFalse("Nothing found in package " + LoadDescriptorUtil.TEST_PACKAGE_FQNAME, packageView.isEmpty());
|
assertFalse("Nothing found in package " + LoadDescriptorUtil.TEST_PACKAGE_FQNAME, packageView.isEmpty());
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import com.google.common.io.Closeables
|
|||||||
import com.google.common.io.Files
|
import com.google.common.io.Files
|
||||||
import com.intellij.openapi.util.Disposer
|
import com.intellij.openapi.util.Disposer
|
||||||
import com.intellij.openapi.util.io.FileUtil
|
import com.intellij.openapi.util.io.FileUtil
|
||||||
import org.jetbrains.kotlin.cli.common.output.outputUtils.writeAllTo
|
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||||
import org.jetbrains.kotlin.codegen.GenerationUtils
|
import org.jetbrains.kotlin.codegen.GenerationUtils
|
||||||
import org.jetbrains.kotlin.test.ConfigurationKind
|
import org.jetbrains.kotlin.test.ConfigurationKind
|
||||||
@@ -36,22 +35,21 @@ import java.nio.charset.Charset
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.regex.MatchResult
|
import java.util.regex.MatchResult
|
||||||
|
|
||||||
|
|
||||||
abstract class AbstractWriteSignatureTest : TestCaseWithTmpdir() {
|
abstract class AbstractWriteSignatureTest : TestCaseWithTmpdir() {
|
||||||
private var jetCoreEnvironment: KotlinCoreEnvironment? = null
|
private var environment: KotlinCoreEnvironment? = null
|
||||||
|
|
||||||
override fun setUp() {
|
override fun setUp() {
|
||||||
super.setUp()
|
super.setUp()
|
||||||
jetCoreEnvironment =
|
environment = KotlinTestUtils.createEnvironmentWithJdkAndNullabilityAnnotationsFromIdea(
|
||||||
KotlinTestUtils.createEnvironmentWithJdkAndNullabilityAnnotationsFromIdea(
|
myTestRootDisposable, ConfigurationKind.ALL, jdkKind
|
||||||
myTestRootDisposable, ConfigurationKind.ALL, jdkKind)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected open val jdkKind: TestJdkKind
|
protected open val jdkKind: TestJdkKind
|
||||||
get() = TestJdkKind.MOCK_JDK
|
get() = TestJdkKind.MOCK_JDK
|
||||||
|
|
||||||
override fun tearDown() {
|
override fun tearDown() {
|
||||||
jetCoreEnvironment = null
|
environment = null
|
||||||
super.tearDown()
|
super.tearDown()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,11 +57,9 @@ abstract class AbstractWriteSignatureTest : TestCaseWithTmpdir() {
|
|||||||
val ktFile = File(ktFileName)
|
val ktFile = File(ktFileName)
|
||||||
val text = FileUtil.loadFile(ktFile, true)
|
val text = FileUtil.loadFile(ktFile, true)
|
||||||
|
|
||||||
val psiFile = KotlinTestUtils.createFile(ktFile.name, text, jetCoreEnvironment!!.project)
|
val psiFile = KotlinTestUtils.createFile(ktFile.name, text, environment!!.project)
|
||||||
|
|
||||||
val outputFiles = GenerationUtils.compileFileGetClassFileFactoryForTest(psiFile, jetCoreEnvironment!!)
|
GenerationUtils.compileFileTo(psiFile, environment!!, tmpdir)
|
||||||
|
|
||||||
outputFiles.writeAllTo(tmpdir)
|
|
||||||
|
|
||||||
Disposer.dispose(myTestRootDisposable)
|
Disposer.dispose(myTestRootDisposable)
|
||||||
|
|
||||||
|
|||||||
+7
-8
@@ -17,7 +17,6 @@
|
|||||||
package org.jetbrains.kotlin.jvm.compiler;
|
package org.jetbrains.kotlin.jvm.compiler;
|
||||||
|
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.intellij.openapi.project.Project;
|
|
||||||
import com.intellij.openapi.util.Ref;
|
import com.intellij.openapi.util.Ref;
|
||||||
import com.intellij.openapi.util.io.FileUtil;
|
import com.intellij.openapi.util.io.FileUtil;
|
||||||
import kotlin.Pair;
|
import kotlin.Pair;
|
||||||
@@ -68,7 +67,7 @@ import static org.jetbrains.kotlin.resolve.DescriptorUtils.isObject;
|
|||||||
import static org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile;
|
import static org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile;
|
||||||
|
|
||||||
public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
|
public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
|
||||||
public static final String TEST_DATA_PATH = "compiler/testData/compileKotlinAgainstCustomBinaries/";
|
private static final String TEST_DATA_PATH = "compiler/testData/compileKotlinAgainstCustomBinaries/";
|
||||||
private static final Pattern JAVA_FILES = Pattern.compile(".*\\.java$");
|
private static final Pattern JAVA_FILES = Pattern.compile(".*\\.java$");
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -107,10 +106,10 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private PackageViewDescriptor analyzeFileToPackageView(@NotNull File... extraClassPath) throws IOException {
|
private PackageViewDescriptor analyzeFileToPackageView(@NotNull File... extraClassPath) throws IOException {
|
||||||
Project project = createEnvironment(Arrays.asList(extraClassPath)).getProject();
|
KotlinCoreEnvironment environment = createEnvironment(Arrays.asList(extraClassPath));
|
||||||
|
|
||||||
AnalysisResult result = JvmResolveUtil.analyzeOneFileWithJavaIntegrationAndCheckForErrors(
|
AnalysisResult result = JvmResolveUtil.analyzeAndCheckForErrors(
|
||||||
KotlinTestUtils.loadJetFile(project, getTestDataFileWithExtension("kt"))
|
KotlinTestUtils.loadJetFile(environment.getProject(), getTestDataFileWithExtension("kt")), environment
|
||||||
);
|
);
|
||||||
|
|
||||||
PackageViewDescriptor packageView = result.getModuleDescriptor().getPackage(LoadDescriptorUtil.TEST_PACKAGE_FQNAME);
|
PackageViewDescriptor packageView = result.getModuleDescriptor().getPackage(LoadDescriptorUtil.TEST_PACKAGE_FQNAME);
|
||||||
@@ -271,10 +270,10 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
|
|||||||
Arrays.asList("-d", tmpdir.getPath())
|
Arrays.asList("-d", tmpdir.getPath())
|
||||||
);
|
);
|
||||||
|
|
||||||
Project project = createEnvironment(Collections.singletonList(tmpdir)).getProject();
|
KotlinCoreEnvironment environment = createEnvironment(Collections.singletonList(tmpdir));
|
||||||
|
|
||||||
AnalysisResult result = JvmResolveUtil.analyzeOneFileWithJavaIntegration(
|
AnalysisResult result = JvmResolveUtil.analyze(
|
||||||
KotlinTestUtils.loadJetFile(project, getTestDataFileWithExtension("kt"))
|
KotlinTestUtils.loadJetFile(environment.getProject(), getTestDataFileWithExtension("kt")), environment
|
||||||
);
|
);
|
||||||
result.throwIfError();
|
result.throwIfError();
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -38,7 +38,7 @@ abstract class AbstractFunctionDescriptorInExpressionRendererTest : KotlinTestWi
|
|||||||
fun doTest(path: String) {
|
fun doTest(path: String) {
|
||||||
val fileText = FileUtil.loadFile(File(path), true)
|
val fileText = FileUtil.loadFile(File(path), true)
|
||||||
val file = KtPsiFactory(project).createFile(fileText)
|
val file = KtPsiFactory(project).createFile(fileText)
|
||||||
val bindingContext = JvmResolveUtil.analyzeOneFileWithJavaIntegration(file).bindingContext
|
val bindingContext = JvmResolveUtil.analyze(file, environment).bindingContext
|
||||||
|
|
||||||
val descriptors = arrayListOf<DeclarationDescriptor>()
|
val descriptors = arrayListOf<DeclarationDescriptor>()
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -51,7 +51,7 @@ class CapturedTypeApproximationTest : KotlinTestWithEnvironment() {
|
|||||||
fun analyzeTestFile(testType: String) = run {
|
fun analyzeTestFile(testType: String) = run {
|
||||||
val test = declarationsText.replace("#TestType#", testType)
|
val test = declarationsText.replace("#TestType#", testType)
|
||||||
val testFile = KtPsiFactory(project).createFile(test)
|
val testFile = KtPsiFactory(project).createFile(test)
|
||||||
val bindingContext = JvmResolveUtil.analyzeOneFileWithJavaIntegration(testFile).bindingContext
|
val bindingContext = JvmResolveUtil.analyze(testFile, environment).bindingContext
|
||||||
val functions = bindingContext.getSliceContents(BindingContext.FUNCTION)
|
val functions = bindingContext.getSliceContents(BindingContext.FUNCTION)
|
||||||
val functionFoo = functions.values.firstOrNull { it.name.asString() == "foo" } ?:
|
val functionFoo = functions.values.firstOrNull { it.name.asString() == "foo" } ?:
|
||||||
throw AssertionError("Function 'foo' is not declared")
|
throw AssertionError("Function 'foo' is not declared")
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ abstract class AbstractTypeBindingTest : KotlinTestWithEnvironment() {
|
|||||||
val testFile = File(path)
|
val testFile = File(path)
|
||||||
val testKtFile = loadJetFile(project, testFile)
|
val testKtFile = loadJetFile(project, testFile)
|
||||||
|
|
||||||
val analyzeResult = JvmResolveUtil.analyzeFilesWithJavaIntegration(project, listOf(testKtFile), environment)
|
val analyzeResult = JvmResolveUtil.analyze(testKtFile, environment)
|
||||||
|
|
||||||
val testDeclaration = testKtFile.declarations.last()!! as KtCallableDeclaration
|
val testDeclaration = testKtFile.declarations.last()!! as KtCallableDeclaration
|
||||||
|
|
||||||
|
|||||||
@@ -85,12 +85,11 @@ public class DefaultModalityModifiersTest extends KotlinTestWithEnvironment {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private LexicalScope createScope(@NotNull MemberScope libraryScope) {
|
private LexicalScope createScope(@NotNull MemberScope libraryScope) {
|
||||||
KtFile file = KtPsiFactoryKt
|
KtFile file =
|
||||||
.KtPsiFactory(getProject()).createFile("abstract class C { abstract fun foo(); abstract val a: Int }");
|
KtPsiFactoryKt.KtPsiFactory(getProject()).createFile("abstract class C { abstract fun foo(); abstract val a: Int }");
|
||||||
List<KtDeclaration> declarations = file.getDeclarations();
|
KtDeclaration aClass = file.getDeclarations().get(0);
|
||||||
KtDeclaration aClass = declarations.get(0);
|
|
||||||
assert aClass instanceof KtClass;
|
assert aClass instanceof KtClass;
|
||||||
AnalysisResult bindingContext = JvmResolveUtil.analyzeOneFileWithJavaIntegrationAndCheckForErrors(file);
|
AnalysisResult bindingContext = JvmResolveUtil.analyzeAndCheckForErrors(file, getEnvironment());
|
||||||
final DeclarationDescriptor classDescriptor = bindingContext.getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, aClass);
|
final DeclarationDescriptor classDescriptor = bindingContext.getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, aClass);
|
||||||
return new LexicalScopeImpl(ScopeUtilsKt.memberScopeAsImportingScope(libraryScope), root, false, null,
|
return new LexicalScopeImpl(ScopeUtilsKt.memberScopeAsImportingScope(libraryScope), root, false, null,
|
||||||
LexicalScopeKind.SYNTHETIC, LocalRedeclarationChecker.DO_NOTHING.INSTANCE,
|
LexicalScopeKind.SYNTHETIC, LocalRedeclarationChecker.DO_NOTHING.INSTANCE,
|
||||||
|
|||||||
@@ -129,13 +129,14 @@ public abstract class AbstractPositionManagerTest extends KotlinLightCodeInsight
|
|||||||
private void performTest() {
|
private void performTest() {
|
||||||
Project project = getProject();
|
Project project = getProject();
|
||||||
List<KtFile> files = new ArrayList<KtFile>(PluginJetFilesProvider.allFilesInProject(project));
|
List<KtFile> files = new ArrayList<KtFile>(PluginJetFilesProvider.allFilesInProject(project));
|
||||||
|
if (files.isEmpty()) return;
|
||||||
|
|
||||||
final List<Breakpoint> breakpoints = Lists.newArrayList();
|
final List<Breakpoint> breakpoints = Lists.newArrayList();
|
||||||
for (KtFile file : files) {
|
for (KtFile file : files) {
|
||||||
breakpoints.addAll(extractBreakpointsInfo(file, file.getText()));
|
breakpoints.addAll(extractBreakpointsInfo(file, file.getText()));
|
||||||
}
|
}
|
||||||
|
|
||||||
GenerationState state = GenerationUtils.compileManyFilesGetGenerationStateForTest(project, files);
|
GenerationState state = GenerationUtils.compileFiles(files, null);
|
||||||
|
|
||||||
Map<String, ReferenceType> referencesByName = getReferenceMap(state.getFactory());
|
Map<String, ReferenceType> referencesByName = getReferenceMap(state.getFactory());
|
||||||
|
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ public abstract class AbstractDiagnosticMessageTest extends KotlinTestWithEnviro
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
protected AnalysisResult analyze(@NotNull KtFile file) {
|
protected AnalysisResult analyze(@NotNull KtFile file) {
|
||||||
return JvmResolveUtil.analyzeOneFileWithJavaIntegration(file);
|
return JvmResolveUtil.analyze(file, getEnvironment());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doTest(String filePath) throws Exception {
|
public void doTest(String filePath) throws Exception {
|
||||||
|
|||||||
+2
-5
@@ -16,10 +16,8 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.lang.resolve.android.test
|
package org.jetbrains.kotlin.lang.resolve.android.test
|
||||||
|
|
||||||
import com.intellij.testFramework.UsefulTestCase
|
|
||||||
import org.jetbrains.kotlin.android.synthetic.res.AndroidPackageFragmentProviderExtension
|
import org.jetbrains.kotlin.android.synthetic.res.AndroidPackageFragmentProviderExtension
|
||||||
import org.jetbrains.kotlin.android.synthetic.res.AndroidSyntheticPackageFragmentProvider
|
import org.jetbrains.kotlin.android.synthetic.res.AndroidSyntheticPackageFragmentProvider
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.JvmPackagePartProvider
|
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||||
import org.jetbrains.kotlin.resolve.MemberComparator
|
import org.jetbrains.kotlin.resolve.MemberComparator
|
||||||
import org.jetbrains.kotlin.resolve.jvm.extensions.PackageFragmentProviderExtension
|
import org.jetbrains.kotlin.resolve.jvm.extensions.PackageFragmentProviderExtension
|
||||||
@@ -32,7 +30,6 @@ import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
abstract class AbstractAndroidSyntheticPropertyDescriptorTest : KtUsefulTestCase() {
|
abstract class AbstractAndroidSyntheticPropertyDescriptorTest : KtUsefulTestCase() {
|
||||||
|
|
||||||
fun doTest(path: String) {
|
fun doTest(path: String) {
|
||||||
val config = KotlinTestUtils.compilerConfigurationForTests(ConfigurationKind.ALL, TestJdkKind.ANDROID_API)
|
val config = KotlinTestUtils.compilerConfigurationForTests(ConfigurationKind.ALL, TestJdkKind.ANDROID_API)
|
||||||
val env = createAndroidTestEnvironment(config, getResPaths(path))
|
val env = createAndroidTestEnvironment(config, getResPaths(path))
|
||||||
@@ -40,7 +37,7 @@ abstract class AbstractAndroidSyntheticPropertyDescriptorTest : KtUsefulTestCase
|
|||||||
|
|
||||||
val ext = PackageFragmentProviderExtension.getInstances(project).first { it is AndroidPackageFragmentProviderExtension }
|
val ext = PackageFragmentProviderExtension.getInstances(project).first { it is AndroidPackageFragmentProviderExtension }
|
||||||
|
|
||||||
val analysisResult = JvmResolveUtil.analyzeFilesWithJavaIntegrationAndCheckForErrors(project, listOf(), JvmPackagePartProvider(env))
|
val analysisResult = JvmResolveUtil.analyzeAndCheckForErrors(listOf(), env)
|
||||||
|
|
||||||
val fragmentProvider = ext.getPackageFragmentProvider(project, analysisResult.moduleDescriptor, LockBasedStorageManager.NO_LOCKS,
|
val fragmentProvider = ext.getPackageFragmentProvider(project, analysisResult.moduleDescriptor, LockBasedStorageManager.NO_LOCKS,
|
||||||
KotlinTestUtils.DUMMY_EXCEPTION_ON_ERROR_TRACE, null) as AndroidSyntheticPackageFragmentProvider
|
KotlinTestUtils.DUMMY_EXCEPTION_ON_ERROR_TRACE, null) as AndroidSyntheticPackageFragmentProvider
|
||||||
@@ -55,4 +52,4 @@ abstract class AbstractAndroidSyntheticPropertyDescriptorTest : KtUsefulTestCase
|
|||||||
|
|
||||||
KotlinTestUtils.assertEqualsToFile(File(path, "result.txt"), expected)
|
KotlinTestUtils.assertEqualsToFile(File(path, "result.txt"), expected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user