From 9c61f65c0f0a250dc3d20a02609294e264b30bae Mon Sep 17 00:00:00 2001 From: Dmitry Savvinov Date: Tue, 19 Jun 2018 18:43:46 +0300 Subject: [PATCH] Support internal compiler flags (-XX) in facets importing --- .../kotlin/compilerRunner/ArgumentUtils.java | 1 + .../gradle/GradleFacetImportTest.kt | 48 +++++++++++++++ .../idea/maven/KotlinMavenImporterTest.kt | 58 +++++++++++++++++++ 3 files changed, 107 insertions(+) diff --git a/build-common/src/org/jetbrains/kotlin/compilerRunner/ArgumentUtils.java b/build-common/src/org/jetbrains/kotlin/compilerRunner/ArgumentUtils.java index 0c4d6bc86ba..8ce73120707 100644 --- a/build-common/src/org/jetbrains/kotlin/compilerRunner/ArgumentUtils.java +++ b/build-common/src/org/jetbrains/kotlin/compilerRunner/ArgumentUtils.java @@ -46,6 +46,7 @@ public class ArgumentUtils { Class argumentsClass = arguments.getClass(); convertArgumentsToStringList(arguments, argumentsClass.newInstance(), JvmClassMappingKt.getKotlinClass(argumentsClass), result); result.addAll(arguments.getFreeArgs()); + result.addAll(arguments.getInternalArguments()); return result; } diff --git a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleFacetImportTest.kt b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleFacetImportTest.kt index 988c7f69de3..a5f2a46e817 100644 --- a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleFacetImportTest.kt +++ b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleFacetImportTest.kt @@ -40,6 +40,7 @@ import org.jetbrains.kotlin.idea.facet.KotlinFacet import org.jetbrains.kotlin.idea.framework.CommonLibraryKind import org.jetbrains.kotlin.idea.framework.JSLibraryKind import org.jetbrains.kotlin.idea.framework.KotlinSdkType +import org.jetbrains.kotlin.idea.project.languageVersionSettings import org.jetbrains.kotlin.idea.util.projectStructure.allModules import org.jetbrains.kotlin.idea.util.projectStructure.sdk import org.jetbrains.kotlin.test.KotlinTestUtils @@ -2102,6 +2103,53 @@ compileTestKotlin { ) } + @Test + fun testInternalArgumentsFacetImporting() { + createProjectSubFile( + "build.gradle", """ + buildscript { + repositories { + mavenCentral() + } + + dependencies { + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.50") + } + } + + apply plugin: 'kotlin' + + repositories { + mavenCentral() + } + + dependencies { + compile "org.jetbrains.kotlin:kotlin-stdlib:1.2.50" + } + + compileKotlin { + kotlinOptions.freeCompilerArgs = ["-XXLanguage:+InlineClasses"] + kotlinOptions.languageVersion = "1.2" + } + """ + ) + importProject() + + // Version is indeed 1.2 + Assert.assertEquals(LanguageVersion.KOTLIN_1_2, facetSettings.languageLevel) + + // We haven't lost internal argument during importing to facet + Assert.assertEquals("-XXLanguage:+InlineClasses", facetSettings.compilerSettings?.additionalArguments) + + // Inline classes are enabled even though LV = 1.2 + Assert.assertEquals( + LanguageFeature.State.ENABLED, + getModule("project_main").languageVersionSettings.getFeatureSupport(LanguageFeature.InlineClasses) + ) + + assertAllModulesConfigured() + } + private fun assertAllModulesConfigured() { runReadAction { for (moduleGroup in ModuleSourceRootMap(myProject).groupByBaseModules(myProject.allModules())) { diff --git a/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/KotlinMavenImporterTest.kt b/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/KotlinMavenImporterTest.kt index 588e0d9b019..fbeb5ddb110 100644 --- a/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/KotlinMavenImporterTest.kt +++ b/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/KotlinMavenImporterTest.kt @@ -36,6 +36,7 @@ import org.jetbrains.kotlin.idea.facet.KotlinFacet import org.jetbrains.kotlin.idea.framework.CommonLibraryKind import org.jetbrains.kotlin.idea.framework.JSLibraryKind import org.jetbrains.kotlin.idea.framework.KotlinSdkType +import org.jetbrains.kotlin.idea.project.languageVersionSettings import org.jetbrains.kotlin.idea.refactoring.toPsiFile import org.jetbrains.kotlin.psi.KtFile import org.junit.Assert @@ -2716,6 +2717,63 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { } } + fun testInternalArgumentsFacetImporting() { + importProject( + """ + test + project + 1.0.0 + + + + org.jetbrains.kotlin + kotlin-stdlib + $kotlinVersion + + + + + src/main/kotlin + + + + org.jetbrains.kotlin + kotlin-maven-plugin + + + + compile + compile + + compile + + + + + 1.2 + + -XXLanguage:+InlineClasses + + 1.8 + + + + + """ + ) + + assertImporterStatePresent() + + // Check that we haven't lost internal argument during importing to facet + Assert.assertEquals("-XXLanguage:+InlineClasses", facetSettings.compilerSettings?.additionalArguments) + + // Check that internal argument influenced LanguageVersionSettings correctly + Assert.assertEquals( + LanguageFeature.State.ENABLED, + getModule("project").languageVersionSettings.getFeatureSupport(LanguageFeature.InlineClasses) + ) + } + private fun assertImporterStatePresent() { assertNotNull("Kotlin importer component is not present", myTestFixture.module.getComponent(KotlinImporterComponent::class.java)) }