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.compiler.configuration.KotlinCommonCompilerArgumentsHolder
|
||||
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCompilerSettings
|
||||
import org.jetbrains.kotlin.idea.facet.KotlinFacet
|
||||
import org.jetbrains.kotlin.idea.facet.configureFacet
|
||||
import org.jetbrains.kotlin.idea.facet.getOrCreateFacet
|
||||
import org.jetbrains.kotlin.idea.facet.*
|
||||
import org.jetbrains.kotlin.idea.inspections.UnusedSymbolInspection
|
||||
import org.jetbrains.kotlin.idea.test.CompilerTestDirectives.COMPILER_ARGUMENTS_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 {
|
||||
val removeFacet = !module.hasKotlinFacet()
|
||||
val configured = configureCompilerOptions(fileText, project, module)
|
||||
try {
|
||||
return body()
|
||||
} finally {
|
||||
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)
|
||||
|
||||
val facetSettings = KotlinFacet.get(module)!!.configuration.settings
|
||||
@@ -307,7 +314,6 @@ private fun rollbackCompilerOptions(project: Project, module: Module) {
|
||||
}
|
||||
compilerSettings.additionalArguments = DEFAULT_ADDITIONAL_ARGUMENTS
|
||||
facetSettings.updateMergedArguments()
|
||||
KotlinCompilerSettings.getInstance(project).update { this.additionalArguments = DEFAULT_ADDITIONAL_ARGUMENTS }
|
||||
}
|
||||
|
||||
fun withCustomLanguageAndApiVersion(
|
||||
@@ -317,11 +323,18 @@ fun withCustomLanguageAndApiVersion(
|
||||
apiVersion: String?,
|
||||
body: () -> Unit
|
||||
) {
|
||||
val removeFacet = !module.hasKotlinFacet()
|
||||
configureLanguageAndApiVersion(project, module, languageVersion, apiVersion)
|
||||
try {
|
||||
body()
|
||||
} 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user