Clean facet if it wasn't set before test (fix tests on 201)
This commit is contained in:
committed by
Nikolay Krasko
parent
af3b057ba2
commit
19bc39d3ab
+20
-7
@@ -40,9 +40,7 @@ import org.jetbrains.kotlin.config.LanguageVersion
|
|||||||
import org.jetbrains.kotlin.idea.KotlinFileType
|
import org.jetbrains.kotlin.idea.KotlinFileType
|
||||||
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCommonCompilerArgumentsHolder
|
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCommonCompilerArgumentsHolder
|
||||||
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCompilerSettings
|
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCompilerSettings
|
||||||
import org.jetbrains.kotlin.idea.facet.KotlinFacet
|
import org.jetbrains.kotlin.idea.facet.*
|
||||||
import org.jetbrains.kotlin.idea.facet.configureFacet
|
|
||||||
import org.jetbrains.kotlin.idea.facet.getOrCreateFacet
|
|
||||||
import org.jetbrains.kotlin.idea.inspections.UnusedSymbolInspection
|
import org.jetbrains.kotlin.idea.inspections.UnusedSymbolInspection
|
||||||
import org.jetbrains.kotlin.idea.test.CompilerTestDirectives.COMPILER_ARGUMENTS_DIRECTIVE
|
import org.jetbrains.kotlin.idea.test.CompilerTestDirectives.COMPILER_ARGUMENTS_DIRECTIVE
|
||||||
import org.jetbrains.kotlin.idea.test.CompilerTestDirectives.JVM_TARGET_DIRECTIVE
|
import org.jetbrains.kotlin.idea.test.CompilerTestDirectives.JVM_TARGET_DIRECTIVE
|
||||||
@@ -237,12 +235,13 @@ object CompilerTestDirectives {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun <T> withCustomCompilerOptions(fileText: String, project: Project, module: Module, body: () -> T): T {
|
fun <T> withCustomCompilerOptions(fileText: String, project: Project, module: Module, body: () -> T): T {
|
||||||
|
val removeFacet = !module.hasKotlinFacet()
|
||||||
val configured = configureCompilerOptions(fileText, project, module)
|
val configured = configureCompilerOptions(fileText, project, module)
|
||||||
try {
|
try {
|
||||||
return body()
|
return body()
|
||||||
} finally {
|
} finally {
|
||||||
if (configured) {
|
if (configured) {
|
||||||
rollbackCompilerOptions(project, module)
|
rollbackCompilerOptions(project, module, removeFacet)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -296,7 +295,15 @@ fun <T> configureRegistryAndRun(fileText: String, body: () -> T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun rollbackCompilerOptions(project: Project, module: Module) {
|
private fun rollbackCompilerOptions(project: Project, module: Module, removeFacet: Boolean) {
|
||||||
|
KotlinCompilerSettings.getInstance(project).update { this.additionalArguments = DEFAULT_ADDITIONAL_ARGUMENTS }
|
||||||
|
KotlinCommonCompilerArgumentsHolder.getInstance(project).update { this.languageVersion = LanguageVersion.LATEST_STABLE.versionString }
|
||||||
|
|
||||||
|
if (removeFacet) {
|
||||||
|
module.removeKotlinFacet(IdeModifiableModelsProviderImpl(project), commitModel = true)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
configureLanguageAndApiVersion(project, module, LanguageVersion.LATEST_STABLE.versionString)
|
configureLanguageAndApiVersion(project, module, LanguageVersion.LATEST_STABLE.versionString)
|
||||||
|
|
||||||
val facetSettings = KotlinFacet.get(module)!!.configuration.settings
|
val facetSettings = KotlinFacet.get(module)!!.configuration.settings
|
||||||
@@ -307,7 +314,6 @@ private fun rollbackCompilerOptions(project: Project, module: Module) {
|
|||||||
}
|
}
|
||||||
compilerSettings.additionalArguments = DEFAULT_ADDITIONAL_ARGUMENTS
|
compilerSettings.additionalArguments = DEFAULT_ADDITIONAL_ARGUMENTS
|
||||||
facetSettings.updateMergedArguments()
|
facetSettings.updateMergedArguments()
|
||||||
KotlinCompilerSettings.getInstance(project).update { this.additionalArguments = DEFAULT_ADDITIONAL_ARGUMENTS }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun withCustomLanguageAndApiVersion(
|
fun withCustomLanguageAndApiVersion(
|
||||||
@@ -317,11 +323,18 @@ fun withCustomLanguageAndApiVersion(
|
|||||||
apiVersion: String?,
|
apiVersion: String?,
|
||||||
body: () -> Unit
|
body: () -> Unit
|
||||||
) {
|
) {
|
||||||
|
val removeFacet = !module.hasKotlinFacet()
|
||||||
configureLanguageAndApiVersion(project, module, languageVersion, apiVersion)
|
configureLanguageAndApiVersion(project, module, languageVersion, apiVersion)
|
||||||
try {
|
try {
|
||||||
body()
|
body()
|
||||||
} finally {
|
} finally {
|
||||||
configureLanguageAndApiVersion(project, module, LanguageVersion.LATEST_STABLE.versionString, null)
|
if (removeFacet) {
|
||||||
|
KotlinCommonCompilerArgumentsHolder.getInstance(project)
|
||||||
|
.update { this.languageVersion = LanguageVersion.LATEST_STABLE.versionString }
|
||||||
|
module.removeKotlinFacet(IdeModifiableModelsProviderImpl(project), commitModel = true)
|
||||||
|
} else {
|
||||||
|
configureLanguageAndApiVersion(project, module, LanguageVersion.LATEST_STABLE.versionString, null)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.facet
|
package org.jetbrains.kotlin.idea.facet
|
||||||
|
|
||||||
|
import com.intellij.facet.FacetManager
|
||||||
import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider
|
import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider
|
||||||
import com.intellij.openapi.module.Module
|
import com.intellij.openapi.module.Module
|
||||||
import com.intellij.openapi.projectRoots.JavaSdk
|
import com.intellij.openapi.projectRoots.JavaSdk
|
||||||
@@ -133,6 +134,22 @@ fun Module.getOrCreateFacet(
|
|||||||
return facet
|
return facet
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Module.hasKotlinFacet() = FacetManager.getInstance(this).getFacetByType(KotlinFacetType.TYPE_ID) != null
|
||||||
|
|
||||||
|
fun Module.removeKotlinFacet(
|
||||||
|
modelsProvider: IdeModifiableModelsProvider,
|
||||||
|
commitModel: Boolean = false
|
||||||
|
) {
|
||||||
|
val facetModel = modelsProvider.getModifiableFacetModel(this)
|
||||||
|
val facet = facetModel.findFacet(KotlinFacetType.TYPE_ID, KotlinFacetType.INSTANCE.defaultFacetName) ?: return
|
||||||
|
facetModel.removeFacet(facet)
|
||||||
|
if (commitModel) {
|
||||||
|
runWriteAction {
|
||||||
|
facetModel.commit()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//method used for non-mpp modules
|
//method used for non-mpp modules
|
||||||
fun KotlinFacet.configureFacet(
|
fun KotlinFacet.configureFacet(
|
||||||
compilerVersion: String?,
|
compilerVersion: String?,
|
||||||
|
|||||||
Reference in New Issue
Block a user