From 8201756a4c77888764fd68c08346b1d6b033d33d Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Mon, 21 Jan 2019 13:13:54 +0300 Subject: [PATCH] Use correct project for settings.gradle manipulations #KT-29333 Fixed Otherwise we get an error "Element from alien project". See details in added comment. --- .../idea/configuration/gradleModuleBuilderUtils.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/gradleModuleBuilderUtils.kt b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/gradleModuleBuilderUtils.kt index 73a70b99d02..8ca094c3e30 100644 --- a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/gradleModuleBuilderUtils.kt +++ b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/gradleModuleBuilderUtils.kt @@ -9,6 +9,7 @@ import com.intellij.framework.addSupport.FrameworkSupportInModuleConfigurable import com.intellij.ide.util.frameworkSupport.FrameworkSupportModel import com.intellij.openapi.externalSystem.model.project.ProjectId import com.intellij.openapi.module.Module +import com.intellij.openapi.project.ProjectCoreUtil import com.intellij.openapi.roots.ModifiableModelsProvider import com.intellij.openapi.roots.ModifiableRootModel import com.intellij.openapi.util.Key @@ -132,7 +133,13 @@ internal fun flushSettingsGradleCopy(module: Module) { val settingsFile = findSettingsGradleFile(module) val settingsScriptBuilder = module.settingsScriptBuilder if (settingsScriptBuilder != null && settingsFile != null) { - val project = module.project + // The module.project is not opened yet. + // Due to optimization in ASTDelegatePsiElement.getManager() and relevant ones, + // we have to take theOnlyOpenProject() for manipulations with tmp file + // (otherwise file will have one parent project and its elements will have other parent project, + // and we will get KT-29333 problem). + // TODO: get rid of file manipulations until project is opened + val project = ProjectCoreUtil.theOnlyOpenProject() ?: module.project val tmpFile = GroovyPsiElementFactory .getInstance(project)