diff --git a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenImporter.kt b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenImporter.kt index 1cf4ff22905..7ee5b265c60 100644 --- a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenImporter.kt +++ b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenImporter.kt @@ -127,8 +127,8 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_ with(kotlinFacet.configuration.settings) { versionInfo.apiLevel = apiVersion } - parseCompilerArgumentsToFacet(sharedArguments, kotlinFacet) - parseCompilerArgumentsToFacet(executionArguments, kotlinFacet) + parseCompilerArgumentsToFacet(sharedArguments, emptyList(), kotlinFacet) + parseCompilerArgumentsToFacet(executionArguments, emptyList(), kotlinFacet) MavenProjectImportHandler.getInstances(module.project).forEach { it(kotlinFacet, mavenProject) } } diff --git a/idea/kotlin-gradle-tooling/src/KotlinGradleModelBuilder.kt b/idea/kotlin-gradle-tooling/src/KotlinGradleModelBuilder.kt index dec12c0ec14..e010dcdbb52 100644 --- a/idea/kotlin-gradle-tooling/src/KotlinGradleModelBuilder.kt +++ b/idea/kotlin-gradle-tooling/src/KotlinGradleModelBuilder.kt @@ -25,13 +25,15 @@ import java.lang.Exception interface KotlinGradleModel : Serializable { val implements: String? - val serializedCompilerArguments: List? + val currentCompilerArguments: List? + val defaultCompilerArguments: List? val coroutines: String? } class KotlinGradleModelImpl( override val implements: String?, - override val serializedCompilerArguments: List?, + override val currentCompilerArguments: List?, + override val defaultCompilerArguments: List?, override val coroutines: String? ) : KotlinGradleModel @@ -56,11 +58,11 @@ class KotlinGradleModelBuilder : ModelBuilderService { } @Suppress("UNCHECKED_CAST") - private fun getCompilerArguments(project: Project): List? { + private fun getCompilerArguments(project: Project, methodName: String): List? { val compileTask = compileTasks.mapNotNull { project.getTasksByName(it, false).firstOrNull() }.firstOrNull() ?: return null val taskClass = compileTask.javaClass return try { - taskClass.getDeclaredMethod("getSerializedCompilerArguments").invoke(compileTask) as List + taskClass.getDeclaredMethod(methodName).invoke(compileTask) as List } catch (e : NoSuchMethodException) { null @@ -85,5 +87,10 @@ class KotlinGradleModelBuilder : ModelBuilderService { } override fun buildAll(modelName: String?, project: Project) = - KotlinGradleModelImpl(getImplements(project), getCompilerArguments(project), getCoroutines(project)) + KotlinGradleModelImpl( + getImplements(project), + getCompilerArguments(project, "getSerializedCompilerArguments"), + getCompilerArguments(project, "getDefaultSerializedCompilerArguments"), + getCoroutines(project) + ) } diff --git a/idea/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleProjectResolverExtension.kt b/idea/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleProjectResolverExtension.kt index fc92b555526..cda9c71eaf9 100644 --- a/idea/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleProjectResolverExtension.kt +++ b/idea/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleProjectResolverExtension.kt @@ -33,7 +33,8 @@ import org.jetbrains.plugins.gradle.model.data.GradleSourceSetData import org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension import org.jetbrains.plugins.gradle.service.project.GradleProjectResolverUtil.getModuleId -var DataNode.serializedCompilerArguments by UserDataProperty(Key.create>("SERIALIZED_COMPILER_ARGUMENTS")) +var DataNode.currentCompilerArguments by UserDataProperty(Key.create>("CURRENT_COMPILER_ARGUMENTS")) +var DataNode.defaultCompilerArguments by UserDataProperty(Key.create>("DEFAULT_COMPILER_ARGUMENTS")) var DataNode.coroutines by UserDataProperty(Key.create("KOTLIN_COROUTINES")) class KotlinGradleProjectResolverExtension : AbstractProjectResolverExtension() { @@ -60,7 +61,8 @@ class KotlinGradleProjectResolverExtension : AbstractProjectResolverExtension() } } - ideModule.serializedCompilerArguments = gradleModel.serializedCompilerArguments + ideModule.currentCompilerArguments = gradleModel.currentCompilerArguments + ideModule.defaultCompilerArguments = gradleModel.defaultCompilerArguments ideModule.coroutines = gradleModel.coroutines super.populateModuleDependencies(gradleModule, ideModule, ideProject) diff --git a/idea/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleSourceSetDataService.kt b/idea/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleSourceSetDataService.kt index cee06786b42..bd8b563d14d 100644 --- a/idea/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleSourceSetDataService.kt +++ b/idea/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleSourceSetDataService.kt @@ -121,7 +121,11 @@ private fun configureFacetByGradleModule( val kotlinFacet = ideModule.getOrCreateFacet(modelsProvider, false) kotlinFacet.configureFacet(compilerVersion, coroutinesProperty, platformKind, modelsProvider) - moduleNode.serializedCompilerArguments?.let { parseCompilerArgumentsToFacet(it, kotlinFacet) } + val currentCompilerArguments = moduleNode.currentCompilerArguments + val defaultCompilerArguments = moduleNode.defaultCompilerArguments ?: emptyList() + if (currentCompilerArguments != null) { + parseCompilerArgumentsToFacet(currentCompilerArguments, defaultCompilerArguments, kotlinFacet) + } return kotlinFacet } diff --git a/idea/src/org/jetbrains/kotlin/idea/facet/facetUtils.kt b/idea/src/org/jetbrains/kotlin/idea/facet/facetUtils.kt index 21cf66d62d9..1df50c44cb3 100644 --- a/idea/src/org/jetbrains/kotlin/idea/facet/facetUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/facet/facetUtils.kt @@ -35,6 +35,7 @@ import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCompilerSettings import org.jetbrains.kotlin.idea.framework.JSLibraryStdPresentationProvider import org.jetbrains.kotlin.idea.framework.JavaRuntimePresentationProvider import org.jetbrains.kotlin.idea.versions.* +import java.lang.reflect.Field private fun getRuntimeLibraryVersions( module: Module, @@ -207,7 +208,7 @@ private val CommonCompilerArguments.exposedFields: List else -> commonExposedFields } -fun parseCompilerArgumentsToFacet(arguments: List, kotlinFacet: KotlinFacet) { +fun parseCompilerArgumentsToFacet(arguments: List, defaultArguments: List, kotlinFacet: KotlinFacet) { val argumentArray = arguments.toTypedArray() with(kotlinFacet.configuration.settings) { @@ -220,6 +221,9 @@ fun parseCompilerArgumentsToFacet(arguments: List, kotlinFacet: KotlinFa else -> commonCompilerArguments }!! + val defaultCompilerArguments = compilerArguments.javaClass.newInstance() + parseArguments(defaultArguments.toTypedArray(), defaultCompilerArguments, true) + val oldCoroutineSupport = CoroutineSupport.byCompilerArguments(commonCompilerArguments) commonCompilerArguments.coroutinesEnable = false commonCompilerArguments.coroutinesWarn = false @@ -248,15 +252,17 @@ fun parseCompilerArgumentsToFacet(arguments: List, kotlinFacet: KotlinFa val exposedFields = compilerArguments.exposedFields + fun exposeAsAdditionalArgument(field: Field) = field.name !in exposedFields && field.get(compilerArguments) != field.get(defaultCompilerArguments) + val additionalArgumentsString = with(compilerArguments.javaClass.newInstance()) { - copyFieldsSatisfying(compilerArguments, this) { it.name !in exposedFields } + copyFieldsSatisfying(compilerArguments, this, ::exposeAsAdditionalArgument) ArgumentUtils.convertArgumentsToStringList(this).joinToString(separator = " ") } compilerInfo.compilerSettings!!.additionalArguments = if (additionalArgumentsString.isNotEmpty()) additionalArgumentsString else CompilerSettings.DEFAULT_ADDITIONAL_ARGUMENTS with(compilerArguments.javaClass.newInstance()) { - copyFieldsSatisfying(this, compilerArguments) { it.name !in exposedFields } + copyFieldsSatisfying(this, compilerArguments, ::exposeAsAdditionalArgument) } copyInheritedFields(compilerArguments, commonCompilerArguments) diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleFacetImportTest.kt b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleFacetImportTest.kt index 48b4021cf53..60c7b4fae11 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleFacetImportTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleFacetImportTest.kt @@ -28,6 +28,7 @@ class GradleFacetImportTest : GradleImportingTestCase() { private val facetSettings: KotlinFacetSettings get() = KotlinFacet.get(getModule("project_main"))!!.configuration.settings + // TODO: Update this test to 1.1-RC when it's available @Test fun testJvmImport() { createProjectSubFile("build.gradle", """