Minor, do not copy CompilerConfiguration in Android codegen tests

This is needed to avoid passing a custom configuration to
GenerationUtils.compileManyFilesGetGenerationStateForTest, but rather take it
from the environment in a future commit
This commit is contained in:
Alexander Udalov
2016-05-19 17:49:48 +03:00
parent 6d6488e795
commit 8a00cabce6
2 changed files with 21 additions and 18 deletions
@@ -69,7 +69,11 @@ internal fun genFiles(file: File, fileContent: String, filesHolder: CodegenTests
}.patchSelfImports(file.newPackage)
}
resultFiles.forEach { resultFile -> filesHolder.addFile(resultFile.name, resultFile.content) }
resultFiles.forEach { resultFile ->
if (resultFile.name.endsWith(".kt") || resultFile.name.endsWith(".kts")) {
filesHolder.addFile(resultFile.name, resultFile.content)
}
}
val boxFiles = resultFiles.filter { hasBoxMethod(it.content) }
if (boxFiles.size != 1) {
@@ -24,6 +24,7 @@ import com.intellij.testFramework.UsefulTestCase;
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;
@@ -142,7 +143,7 @@ public class CodegenTestsOnAndroidGenerator extends UsefulTestCase {
class FilesWriter {
private final boolean isFullJdkAndRuntime;
private boolean inheritMultifileParts;
private final boolean inheritMultifileParts;
public List<KtFile> files = new ArrayList<KtFile>();
private KotlinCoreEnvironment environment;
@@ -150,15 +151,19 @@ public class CodegenTestsOnAndroidGenerator extends UsefulTestCase {
private FilesWriter(boolean isFullJdkAndRuntime, boolean inheritMultifileParts) {
this.isFullJdkAndRuntime = isFullJdkAndRuntime;
this.inheritMultifileParts = inheritMultifileParts;
environment = createEnvironment(isFullJdkAndRuntime);
this.environment = createEnvironment(isFullJdkAndRuntime);
}
private KotlinCoreEnvironment createEnvironment(boolean isFullJdkAndRuntime) {
return isFullJdkAndRuntime ?
KotlinTestUtils.createEnvironmentWithJdkAndNullabilityAnnotationsFromIdea(
myTestRootDisposable, ConfigurationKind.ALL, TestJdkKind.FULL_JDK
) :
KotlinTestUtils.createEnvironmentWithMockJdkAndIdeaAnnotations(myTestRootDisposable, ConfigurationKind.JDK_ONLY);
ConfigurationKind configurationKind = isFullJdkAndRuntime ? ConfigurationKind.ALL : ConfigurationKind.JDK_ONLY;
CompilerConfiguration configuration = KotlinTestUtils.compilerConfigurationForTests(
configurationKind, TestJdkKind.FULL_JDK, KotlinTestUtils.getAnnotationsJar()
);
configuration.put(JVMConfigurationKeys.MODULE_NAME, "android-module-" + MODULE_INDEX++);
if (inheritMultifileParts) {
configuration.put(JVMConfigurationKeys.INHERIT_MULTIFILE_PARTS, true);
}
return KotlinCoreEnvironment.createForTests(myTestRootDisposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES);
}
public boolean shouldWriteFilesOnDisk() {
@@ -180,8 +185,9 @@ public class CodegenTestsOnAndroidGenerator extends UsefulTestCase {
public void addFile(String name, String content) {
try {
files.add(CodegenTestFiles.create(name, content, environment.getProject()).getPsiFile());
} catch (Throwable e) {
new RuntimeException("Problem during creating file " + name + ": \n" + content, e);
}
catch (Throwable e) {
throw new RuntimeException("Problem during creating file " + name + ": \n" + content, e);
}
}
@@ -194,18 +200,11 @@ public class CodegenTestsOnAndroidGenerator extends UsefulTestCase {
: isFullJdkAndRuntime ? " (full jdk and runtime)" : "") + "...");
OutputFileCollection outputFiles;
try {
//hack to pass module name
CompilerConfiguration configuration = environment.getConfiguration().copy();
configuration.put(JVMConfigurationKeys.MODULE_NAME, "android-module-" + MODULE_INDEX++);
if (inheritMultifileParts) {
configuration.put(JVMConfigurationKeys.INHERIT_MULTIFILE_PARTS, true);
}
configuration.setReadOnly(true);
outputFiles = GenerationUtils.compileManyFilesGetGenerationStateForTest(
filesToCompile.iterator().next().getProject(),
filesToCompile,
new JvmPackagePartProvider(environment),
configuration
environment.getConfiguration()
).getFactory();
}
catch (Throwable e) {