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