[FE] Drop coroutinesState from build configurations plugins
This commit is contained in:
committed by
TeamCityServer
parent
7f4a925b85
commit
df3b12e13b
-2
@@ -45,8 +45,6 @@ interface GradleBuildScriptManipulator<out Psi : PsiFile> {
|
|||||||
|
|
||||||
fun configureProjectBuildScript(kotlinPluginName: String, version: String): Boolean
|
fun configureProjectBuildScript(kotlinPluginName: String, version: String): Boolean
|
||||||
|
|
||||||
fun changeCoroutineConfiguration(coroutineOption: String): PsiElement?
|
|
||||||
|
|
||||||
fun changeLanguageFeatureConfiguration(feature: LanguageFeature, state: LanguageFeature.State, forTests: Boolean): PsiElement?
|
fun changeLanguageFeatureConfiguration(feature: LanguageFeature, state: LanguageFeature.State, forTests: Boolean): PsiElement?
|
||||||
|
|
||||||
fun changeLanguageVersion(version: String, forTests: Boolean): PsiElement?
|
fun changeLanguageVersion(version: String, forTests: Boolean): PsiElement?
|
||||||
|
|||||||
-12
@@ -139,18 +139,6 @@ class GroovyBuildScriptManipulator(
|
|||||||
return oldText != scriptFile.text
|
return oldText != scriptFile.text
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun changeCoroutineConfiguration(coroutineOption: String): PsiElement? {
|
|
||||||
val snippet = "coroutines \"$coroutineOption\""
|
|
||||||
val kotlinBlock = scriptFile.getKotlinBlock()
|
|
||||||
kotlinBlock.getBlockOrCreate("experimental").apply {
|
|
||||||
addOrReplaceExpression(snippet) { stmt ->
|
|
||||||
(stmt as? GrMethodCall)?.invokedExpression?.text == "coroutines"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return kotlinBlock.parent
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun changeLanguageFeatureConfiguration(
|
override fun changeLanguageFeatureConfiguration(
|
||||||
feature: LanguageFeature,
|
feature: LanguageFeature,
|
||||||
state: LanguageFeature.State,
|
state: LanguageFeature.State,
|
||||||
|
|||||||
-3
@@ -100,9 +100,6 @@ class KotlinBuildScriptManipulator(
|
|||||||
return originalText != scriptFile.text
|
return originalText != scriptFile.text
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun changeCoroutineConfiguration(coroutineOption: String): PsiElement? =
|
|
||||||
scriptFile.changeCoroutineConfiguration(coroutineOption)
|
|
||||||
|
|
||||||
override fun changeLanguageFeatureConfiguration(
|
override fun changeLanguageFeatureConfiguration(
|
||||||
feature: LanguageFeature,
|
feature: LanguageFeature,
|
||||||
state: LanguageFeature.State,
|
state: LanguageFeature.State,
|
||||||
|
|||||||
-10
@@ -273,14 +273,9 @@ fun configureFacetByGradleModule(
|
|||||||
// TODO there should be a way to figure out the correct platform version
|
// TODO there should be a way to figure out the correct platform version
|
||||||
val platform = platformKind?.defaultPlatform
|
val platform = platformKind?.defaultPlatform
|
||||||
|
|
||||||
val coroutinesProperty = CoroutineSupport.byCompilerArgument(
|
|
||||||
moduleNode.coroutines ?: findKotlinCoroutinesProperty(ideModule.project)
|
|
||||||
)
|
|
||||||
|
|
||||||
val kotlinFacet = ideModule.getOrCreateFacet(modelsProvider, false, GradleConstants.SYSTEM_ID.id)
|
val kotlinFacet = ideModule.getOrCreateFacet(modelsProvider, false, GradleConstants.SYSTEM_ID.id)
|
||||||
kotlinFacet.configureFacet(
|
kotlinFacet.configureFacet(
|
||||||
compilerVersion,
|
compilerVersion,
|
||||||
coroutinesProperty,
|
|
||||||
platform,
|
platform,
|
||||||
modelsProvider
|
modelsProvider
|
||||||
)
|
)
|
||||||
@@ -338,8 +333,3 @@ internal fun adjustClasspath(kotlinFacet: KotlinFacet, dependencyClasspath: List
|
|||||||
val newClasspath = fullClasspath - dependencyClasspath
|
val newClasspath = fullClasspath - dependencyClasspath
|
||||||
arguments.classpath = if (newClasspath.isNotEmpty()) newClasspath.joinToString(File.pathSeparator) else null
|
arguments.classpath = if (newClasspath.isNotEmpty()) newClasspath.joinToString(File.pathSeparator) else null
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun findKotlinCoroutinesProperty(project: Project): String {
|
|
||||||
return GradlePropertiesFileFacade.forProject(project).readProperty("kotlin.coroutines")
|
|
||||||
?: CoroutineSupport.getCompilerArgument(LanguageFeature.Coroutines.defaultState)
|
|
||||||
}
|
|
||||||
|
|||||||
-6
@@ -18,14 +18,12 @@ import com.intellij.openapi.roots.DependencyScope
|
|||||||
import com.intellij.openapi.roots.ExportableOrderEntry
|
import com.intellij.openapi.roots.ExportableOrderEntry
|
||||||
import com.intellij.openapi.roots.ModifiableRootModel
|
import com.intellij.openapi.roots.ModifiableRootModel
|
||||||
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
|
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
|
||||||
import org.jetbrains.kotlin.config.CoroutineSupport
|
|
||||||
import org.jetbrains.kotlin.config.JvmTarget
|
import org.jetbrains.kotlin.config.JvmTarget
|
||||||
import org.jetbrains.kotlin.config.KotlinModuleKind
|
import org.jetbrains.kotlin.config.KotlinModuleKind
|
||||||
import org.jetbrains.kotlin.gradle.KotlinCompilation
|
import org.jetbrains.kotlin.gradle.KotlinCompilation
|
||||||
import org.jetbrains.kotlin.gradle.KotlinModule
|
import org.jetbrains.kotlin.gradle.KotlinModule
|
||||||
import org.jetbrains.kotlin.gradle.KotlinPlatform
|
import org.jetbrains.kotlin.gradle.KotlinPlatform
|
||||||
import org.jetbrains.kotlin.gradle.KotlinSourceSet
|
import org.jetbrains.kotlin.gradle.KotlinSourceSet
|
||||||
import org.jetbrains.kotlin.idea.configuration.KotlinSourceSetDataService.Companion.isRelevantFor
|
|
||||||
import org.jetbrains.kotlin.idea.facet.*
|
import org.jetbrains.kotlin.idea.facet.*
|
||||||
import org.jetbrains.kotlin.idea.inspections.gradle.findAll
|
import org.jetbrains.kotlin.idea.inspections.gradle.findAll
|
||||||
import org.jetbrains.kotlin.idea.inspections.gradle.findKotlinPluginVersion
|
import org.jetbrains.kotlin.idea.inspections.gradle.findKotlinPluginVersion
|
||||||
@@ -184,9 +182,6 @@ class KotlinSourceSetDataService : AbstractProjectDataService<GradleSourceSetDat
|
|||||||
|
|
||||||
val platform = TargetPlatform(platformKinds)
|
val platform = TargetPlatform(platformKinds)
|
||||||
|
|
||||||
val coroutinesProperty = CoroutineSupport.byCompilerArgument(
|
|
||||||
mainModuleNode.coroutines ?: findKotlinCoroutinesProperty(ideModule.project)
|
|
||||||
)
|
|
||||||
val compilerArguments = kotlinSourceSet.compilerArguments
|
val compilerArguments = kotlinSourceSet.compilerArguments
|
||||||
// Used ID is the same as used in org/jetbrains/kotlin/idea/configuration/KotlinGradleSourceSetDataService.kt:280
|
// Used ID is the same as used in org/jetbrains/kotlin/idea/configuration/KotlinGradleSourceSetDataService.kt:280
|
||||||
// because this DataService was separated from KotlinGradleSourceSetDataService for MPP projects only
|
// because this DataService was separated from KotlinGradleSourceSetDataService for MPP projects only
|
||||||
@@ -194,7 +189,6 @@ class KotlinSourceSetDataService : AbstractProjectDataService<GradleSourceSetDat
|
|||||||
val kotlinFacet = ideModule.getOrCreateFacet(modelsProvider, false, id)
|
val kotlinFacet = ideModule.getOrCreateFacet(modelsProvider, false, id)
|
||||||
kotlinFacet.configureFacet(
|
kotlinFacet.configureFacet(
|
||||||
compilerVersion,
|
compilerVersion,
|
||||||
coroutinesProperty,
|
|
||||||
platform,
|
platform,
|
||||||
modelsProvider,
|
modelsProvider,
|
||||||
mainModuleNode.isHmpp,
|
mainModuleNode.isHmpp,
|
||||||
|
|||||||
+2
-26
@@ -28,13 +28,12 @@ import com.intellij.util.PathUtil
|
|||||||
import org.gradle.util.GradleVersion
|
import org.gradle.util.GradleVersion
|
||||||
import org.jetbrains.annotations.NonNls
|
import org.jetbrains.annotations.NonNls
|
||||||
import org.jetbrains.kotlin.config.ApiVersion
|
import org.jetbrains.kotlin.config.ApiVersion
|
||||||
import org.jetbrains.kotlin.config.CoroutineSupport
|
|
||||||
import org.jetbrains.kotlin.config.LanguageFeature
|
import org.jetbrains.kotlin.config.LanguageFeature
|
||||||
import org.jetbrains.kotlin.idea.KotlinIdeaGradleBundle
|
import org.jetbrains.kotlin.idea.KotlinIdeaGradleBundle
|
||||||
import org.jetbrains.kotlin.idea.facet.getRuntimeLibraryVersion
|
import org.jetbrains.kotlin.idea.facet.getRuntimeLibraryVersion
|
||||||
import org.jetbrains.kotlin.idea.facet.toApiVersion
|
import org.jetbrains.kotlin.idea.facet.toApiVersion
|
||||||
import org.jetbrains.kotlin.idea.framework.ui.ConfigureDialogWithModulesAndVersion
|
import org.jetbrains.kotlin.idea.framework.ui.ConfigureDialogWithModulesAndVersion
|
||||||
import org.jetbrains.kotlin.idea.quickfix.ChangeCoroutineSupportFix
|
import org.jetbrains.kotlin.idea.quickfix.AbstractChangeFeatureSupportLevelFix
|
||||||
import org.jetbrains.kotlin.idea.util.application.executeCommand
|
import org.jetbrains.kotlin.idea.util.application.executeCommand
|
||||||
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
|
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
|
||||||
import org.jetbrains.kotlin.idea.util.application.runReadAction
|
import org.jetbrains.kotlin.idea.util.application.runReadAction
|
||||||
@@ -244,25 +243,6 @@ abstract class KotlinWithGradleConfigurator : KotlinProjectConfigurator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun changeCoroutineConfiguration(module: Module, state: LanguageFeature.State) {
|
|
||||||
val runtimeUpdateRequired = state != LanguageFeature.State.DISABLED &&
|
|
||||||
getRuntimeLibraryVersion(module).toApiVersion() == ApiVersion.KOTLIN_1_0
|
|
||||||
|
|
||||||
if (runtimeUpdateRequired) {
|
|
||||||
Messages.showErrorDialog(
|
|
||||||
module.project,
|
|
||||||
KotlinIdeaGradleBundle.message("error.text.coroutines.support.requires.version.1.1.or.later.of.the.kotlin.runtime.library"),
|
|
||||||
ChangeCoroutineSupportFix.getFixText(state)
|
|
||||||
)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
val element = changeCoroutineConfiguration(module, CoroutineSupport.getCompilerArgument(state))
|
|
||||||
if (element != null) {
|
|
||||||
OpenFileDescriptor(module.project, element.containingFile.virtualFile, element.textRange.startOffset).navigate(true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun changeGeneralFeatureConfiguration(
|
override fun changeGeneralFeatureConfiguration(
|
||||||
module: Module,
|
module: Module,
|
||||||
feature: LanguageFeature,
|
feature: LanguageFeature,
|
||||||
@@ -275,7 +255,7 @@ abstract class KotlinWithGradleConfigurator : KotlinProjectConfigurator {
|
|||||||
Messages.showErrorDialog(
|
Messages.showErrorDialog(
|
||||||
module.project,
|
module.project,
|
||||||
KotlinIdeaGradleBundle.message("error.text.support.requires.version", feature.presentableName, sinceVersion),
|
KotlinIdeaGradleBundle.message("error.text.support.requires.version", feature.presentableName, sinceVersion),
|
||||||
ChangeCoroutineSupportFix.getFixText(state)
|
AbstractChangeFeatureSupportLevelFix.getFixText(state, feature.presentableName)
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -345,10 +325,6 @@ abstract class KotlinWithGradleConfigurator : KotlinProjectConfigurator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun changeCoroutineConfiguration(module: Module, coroutineOption: String): PsiElement? = changeBuildGradle(module) {
|
|
||||||
getManipulator(it).changeCoroutineConfiguration(coroutineOption)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun changeFeatureConfiguration(
|
fun changeFeatureConfiguration(
|
||||||
module: Module,
|
module: Module,
|
||||||
feature: LanguageFeature,
|
feature: LanguageFeature,
|
||||||
|
|||||||
-53
@@ -398,59 +398,6 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testAddCoroutinesSupport() {
|
|
||||||
val files = importProjectFromTestData()
|
|
||||||
|
|
||||||
runInEdtAndWait {
|
|
||||||
myTestFixture.project.executeWriteCommand("") {
|
|
||||||
KotlinWithGradleConfigurator.changeCoroutineConfiguration(myTestFixture.module, "enable")
|
|
||||||
}
|
|
||||||
|
|
||||||
checkFiles(files)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testAddCoroutinesSupportGSK() {
|
|
||||||
val files = importProjectFromTestData()
|
|
||||||
|
|
||||||
runInEdtAndWait {
|
|
||||||
myTestFixture.project.executeWriteCommand("") {
|
|
||||||
KotlinWithGradleConfigurator.changeCoroutineConfiguration(myTestFixture.module, "enable")
|
|
||||||
}
|
|
||||||
|
|
||||||
checkFiles(files)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testChangeCoroutinesSupport() {
|
|
||||||
val files = importProjectFromTestData()
|
|
||||||
|
|
||||||
runInEdtAndWait {
|
|
||||||
myTestFixture.project.executeWriteCommand("") {
|
|
||||||
KotlinWithGradleConfigurator.changeCoroutineConfiguration(myTestFixture.module, "enable")
|
|
||||||
}
|
|
||||||
|
|
||||||
checkFiles(files)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@TargetVersions("4.4+")
|
|
||||||
@Test
|
|
||||||
fun testChangeCoroutinesSupportGSK49() {
|
|
||||||
val files = importProjectFromTestData()
|
|
||||||
|
|
||||||
runInEdtAndWait {
|
|
||||||
myTestFixture.project.executeWriteCommand("") {
|
|
||||||
KotlinWithGradleConfigurator.changeCoroutineConfiguration(myTestFixture.module, "enable")
|
|
||||||
}
|
|
||||||
|
|
||||||
checkFiles(files)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testAddLanguageVersion() {
|
fun testAddLanguageVersion() {
|
||||||
val files = importProjectFromTestData()
|
val files = importProjectFromTestData()
|
||||||
|
|||||||
@@ -48,29 +48,6 @@ sealed class TargetPlatformKind<out Version : TargetPlatformVersion>(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
object CoroutineSupport {
|
|
||||||
@JvmStatic
|
|
||||||
fun byCompilerArguments(arguments: CommonCompilerArguments?): LanguageFeature.State =
|
|
||||||
byCompilerArgumentsOrNull(arguments) ?: LanguageFeature.Coroutines.defaultState
|
|
||||||
|
|
||||||
fun byCompilerArgumentsOrNull(arguments: CommonCompilerArguments?): LanguageFeature.State? = when (arguments?.coroutinesState) {
|
|
||||||
CommonCompilerArguments.ENABLE -> LanguageFeature.State.ENABLED
|
|
||||||
CommonCompilerArguments.WARN, CommonCompilerArguments.DEFAULT -> LanguageFeature.State.ENABLED_WITH_WARNING
|
|
||||||
CommonCompilerArguments.ERROR -> LanguageFeature.State.ENABLED_WITH_ERROR
|
|
||||||
else -> null
|
|
||||||
}
|
|
||||||
|
|
||||||
fun byCompilerArgument(argument: String): LanguageFeature.State =
|
|
||||||
LanguageFeature.State.values().find { getCompilerArgument(it).equals(argument, ignoreCase = true) }
|
|
||||||
?: LanguageFeature.Coroutines.defaultState
|
|
||||||
|
|
||||||
fun getCompilerArgument(state: LanguageFeature.State): String = when (state) {
|
|
||||||
LanguageFeature.State.ENABLED -> "enable"
|
|
||||||
LanguageFeature.State.ENABLED_WITH_WARNING -> "warn"
|
|
||||||
LanguageFeature.State.ENABLED_WITH_ERROR, LanguageFeature.State.DISABLED -> "error"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sealed class VersionView : DescriptionAware {
|
sealed class VersionView : DescriptionAware {
|
||||||
abstract val version: LanguageVersion
|
abstract val version: LanguageVersion
|
||||||
|
|
||||||
|
|||||||
@@ -70,8 +70,6 @@ interface KotlinProjectConfigurator {
|
|||||||
forTests: Boolean
|
forTests: Boolean
|
||||||
)
|
)
|
||||||
|
|
||||||
fun changeCoroutineConfiguration(module: Module, state: LanguageFeature.State)
|
|
||||||
|
|
||||||
fun changeGeneralFeatureConfiguration(
|
fun changeGeneralFeatureConfiguration(
|
||||||
module: Module,
|
module: Module,
|
||||||
feature: LanguageFeature,
|
feature: LanguageFeature,
|
||||||
|
|||||||
-17
@@ -346,23 +346,6 @@ abstract class KotlinWithLibraryConfigurator protected constructor() : KotlinPro
|
|||||||
return module.getBuildSystemType() == BuildSystemType.JPS
|
return module.getBuildSystemType() == BuildSystemType.JPS
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun changeCoroutineConfiguration(module: Module, state: LanguageFeature.State) {
|
|
||||||
val runtimeUpdateRequired = state != LanguageFeature.State.DISABLED &&
|
|
||||||
getRuntimeLibraryVersion(module).toApiVersion() == ApiVersion.KOTLIN_1_0
|
|
||||||
|
|
||||||
if (runtimeUpdateRequired && !askUpdateRuntime(module, LanguageFeature.Coroutines.sinceApiVersion)) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
val facetSettings = KotlinFacetSettingsProvider.getInstance(module.project)?.getInitializedSettings(module)
|
|
||||||
if (facetSettings != null) {
|
|
||||||
ModuleRootModificationUtil.updateModel(module) {
|
|
||||||
facetSettings.apiLevel = LanguageVersion.KOTLIN_1_1
|
|
||||||
facetSettings.languageLevel = LanguageVersion.KOTLIN_1_1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun changeGeneralFeatureConfiguration(
|
override fun changeGeneralFeatureConfiguration(
|
||||||
module: Module,
|
module: Module,
|
||||||
feature: LanguageFeature,
|
feature: LanguageFeature,
|
||||||
|
|||||||
@@ -1,78 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2000-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.idea.quickfix
|
|
||||||
|
|
||||||
import com.intellij.codeInsight.intention.IntentionAction
|
|
||||||
import com.intellij.openapi.editor.Editor
|
|
||||||
import com.intellij.openapi.module.ModuleUtilCore
|
|
||||||
import com.intellij.openapi.project.Project
|
|
||||||
import com.intellij.psi.PsiElement
|
|
||||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
|
||||||
import org.jetbrains.kotlin.config.LanguageFeature
|
|
||||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
|
||||||
import org.jetbrains.kotlin.idea.KotlinJvmBundle
|
|
||||||
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCommonCompilerArgumentsHolder
|
|
||||||
import org.jetbrains.kotlin.idea.configuration.findApplicableConfigurator
|
|
||||||
import org.jetbrains.kotlin.idea.roots.invalidateProjectRoots
|
|
||||||
import org.jetbrains.kotlin.psi.KtFile
|
|
||||||
|
|
||||||
sealed class ChangeCoroutineSupportFix(
|
|
||||||
element: PsiElement,
|
|
||||||
coroutineSupport: LanguageFeature.State
|
|
||||||
) : AbstractChangeFeatureSupportLevelFix(element, LanguageFeature.Coroutines, coroutineSupport, shortFeatureName) {
|
|
||||||
|
|
||||||
class InModule(element: PsiElement, coroutineSupport: LanguageFeature.State) : ChangeCoroutineSupportFix(element, coroutineSupport) {
|
|
||||||
override fun getText() = KotlinJvmBundle.message("fix.0.in.current.module", super.getText())
|
|
||||||
|
|
||||||
override fun invoke(project: Project, editor: Editor?, file: KtFile) {
|
|
||||||
val module = ModuleUtilCore.findModuleForPsiElement(file) ?: return
|
|
||||||
|
|
||||||
findApplicableConfigurator(module).changeCoroutineConfiguration(module, featureSupport)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class InProject(element: PsiElement, coroutineSupport: LanguageFeature.State) : ChangeCoroutineSupportFix(element, coroutineSupport) {
|
|
||||||
override fun getText() = KotlinJvmBundle.message("fix.0.in.the.project", super.getText())
|
|
||||||
|
|
||||||
override fun invoke(project: Project, editor: Editor?, file: KtFile) {
|
|
||||||
if (featureSupportEnabled) {
|
|
||||||
if (!checkUpdateRuntime(project, LanguageFeature.Coroutines.sinceApiVersion)) return
|
|
||||||
}
|
|
||||||
|
|
||||||
KotlinCommonCompilerArgumentsHolder.getInstance(project).update {
|
|
||||||
coroutinesState = when (featureSupport) {
|
|
||||||
LanguageFeature.State.ENABLED -> CommonCompilerArguments.ENABLE
|
|
||||||
LanguageFeature.State.ENABLED_WITH_WARNING -> CommonCompilerArguments.WARN
|
|
||||||
LanguageFeature.State.ENABLED_WITH_ERROR, LanguageFeature.State.DISABLED -> CommonCompilerArguments.ERROR
|
|
||||||
}
|
|
||||||
}
|
|
||||||
project.invalidateProjectRoots()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object : FeatureSupportIntentionActionsFactory() {
|
|
||||||
private val shortFeatureName get() = KotlinJvmBundle.message("short.feature.name.coroutine")
|
|
||||||
|
|
||||||
fun getFixText(state: LanguageFeature.State) = getFixText(state, shortFeatureName)
|
|
||||||
|
|
||||||
override fun doCreateActions(diagnostic: Diagnostic): List<IntentionAction> {
|
|
||||||
val module = ModuleUtilCore.findModuleForPsiElement(diagnostic.psiElement) ?: return emptyList()
|
|
||||||
|
|
||||||
return doCreateActions(
|
|
||||||
diagnostic, LanguageFeature.Coroutines, allowWarningAndErrorMode = true,
|
|
||||||
quickFixConstructor = if (shouldConfigureInProject(module)) { element, _, coroutineSupport ->
|
|
||||||
InProject(
|
|
||||||
element,
|
|
||||||
coroutineSupport
|
|
||||||
)
|
|
||||||
} else { element, _, coroutineSupport ->
|
|
||||||
InModule(element, coroutineSupport)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -33,9 +33,6 @@ class JvmQuickFixRegistrar : QuickFixContributor {
|
|||||||
|
|
||||||
UNSUPPORTED_FEATURE.registerFactory(EnableUnsupportedFeatureFix)
|
UNSUPPORTED_FEATURE.registerFactory(EnableUnsupportedFeatureFix)
|
||||||
|
|
||||||
EXPERIMENTAL_FEATURE_ERROR.registerFactory(ChangeCoroutineSupportFix)
|
|
||||||
EXPERIMENTAL_FEATURE_WARNING.registerFactory(ChangeCoroutineSupportFix)
|
|
||||||
|
|
||||||
EXPERIMENTAL_FEATURE_ERROR.registerFactory(ChangeGeneralLanguageFeatureSupportFix)
|
EXPERIMENTAL_FEATURE_ERROR.registerFactory(ChangeGeneralLanguageFeatureSupportFix)
|
||||||
EXPERIMENTAL_FEATURE_WARNING.registerFactory(ChangeGeneralLanguageFeatureSupportFix)
|
EXPERIMENTAL_FEATURE_WARNING.registerFactory(ChangeGeneralLanguageFeatureSupportFix)
|
||||||
|
|
||||||
|
|||||||
-46
@@ -30,14 +30,12 @@ import org.jetbrains.idea.maven.model.MavenId
|
|||||||
import org.jetbrains.idea.maven.project.MavenProjectsManager
|
import org.jetbrains.idea.maven.project.MavenProjectsManager
|
||||||
import org.jetbrains.idea.maven.utils.MavenArtifactScope
|
import org.jetbrains.idea.maven.utils.MavenArtifactScope
|
||||||
import org.jetbrains.kotlin.config.ApiVersion
|
import org.jetbrains.kotlin.config.ApiVersion
|
||||||
import org.jetbrains.kotlin.config.CoroutineSupport
|
|
||||||
import org.jetbrains.kotlin.config.LanguageFeature
|
import org.jetbrains.kotlin.config.LanguageFeature
|
||||||
import org.jetbrains.kotlin.idea.configuration.*
|
import org.jetbrains.kotlin.idea.configuration.*
|
||||||
import org.jetbrains.kotlin.idea.facet.getRuntimeLibraryVersion
|
import org.jetbrains.kotlin.idea.facet.getRuntimeLibraryVersion
|
||||||
import org.jetbrains.kotlin.idea.facet.toApiVersion
|
import org.jetbrains.kotlin.idea.facet.toApiVersion
|
||||||
import org.jetbrains.kotlin.idea.framework.ui.ConfigureDialogWithModulesAndVersion
|
import org.jetbrains.kotlin.idea.framework.ui.ConfigureDialogWithModulesAndVersion
|
||||||
import org.jetbrains.kotlin.idea.maven.*
|
import org.jetbrains.kotlin.idea.maven.*
|
||||||
import org.jetbrains.kotlin.idea.quickfix.ChangeCoroutineSupportFix
|
|
||||||
import org.jetbrains.kotlin.idea.quickfix.ChangeGeneralLanguageFeatureSupportFix
|
import org.jetbrains.kotlin.idea.quickfix.ChangeGeneralLanguageFeatureSupportFix
|
||||||
import org.jetbrains.kotlin.idea.util.application.runReadAction
|
import org.jetbrains.kotlin.idea.util.application.runReadAction
|
||||||
import org.jetbrains.kotlin.idea.versions.LibraryJarDescriptor
|
import org.jetbrains.kotlin.idea.versions.LibraryJarDescriptor
|
||||||
@@ -249,28 +247,6 @@ protected constructor(
|
|||||||
JavaProjectModelModificationService.getInstance(module.project).addDependency(module, library, scope)
|
JavaProjectModelModificationService.getInstance(module.project).addDependency(module, library, scope)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun changeCoroutineConfiguration(module: Module, state: LanguageFeature.State) {
|
|
||||||
val runtimeUpdateRequired = state != LanguageFeature.State.DISABLED &&
|
|
||||||
getRuntimeLibraryVersion(module).toApiVersion() == ApiVersion.KOTLIN_1_0
|
|
||||||
|
|
||||||
val messageTitle = ChangeCoroutineSupportFix.getFixText(state)
|
|
||||||
if (runtimeUpdateRequired) {
|
|
||||||
Messages.showErrorDialog(
|
|
||||||
module.project,
|
|
||||||
KotlinMavenBundle.message("update.language.version.coroutines"),
|
|
||||||
messageTitle
|
|
||||||
)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
val element = changeMavenCoroutineConfiguration(module, CoroutineSupport.getCompilerArgument(state), messageTitle)
|
|
||||||
|
|
||||||
if (element != null) {
|
|
||||||
OpenFileDescriptor(module.project, element.containingFile.virtualFile, element.textRange.startOffset).navigate(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun changeGeneralFeatureConfiguration(
|
override fun changeGeneralFeatureConfiguration(
|
||||||
module: Module,
|
module: Module,
|
||||||
feature: LanguageFeature,
|
feature: LanguageFeature,
|
||||||
@@ -299,28 +275,6 @@ protected constructor(
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun changeMavenCoroutineConfiguration(
|
|
||||||
module: Module,
|
|
||||||
value: String,
|
|
||||||
messageTitle: String
|
|
||||||
): PsiElement? {
|
|
||||||
fun doChangeMavenCoroutineConfiguration(): PsiElement? {
|
|
||||||
val psi = findModulePomFile(module) as? XmlFile ?: return null
|
|
||||||
val pom = PomFile.forFileOrNull(psi) ?: return null
|
|
||||||
return pom.changeCoroutineConfiguration(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
val element = doChangeMavenCoroutineConfiguration()
|
|
||||||
if (element == null) {
|
|
||||||
Messages.showErrorDialog(
|
|
||||||
module.project,
|
|
||||||
KotlinMavenBundle.message("error.failed.update.pom"),
|
|
||||||
messageTitle
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return element
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun changeMavenFeatureConfiguration(
|
private fun changeMavenFeatureConfiguration(
|
||||||
module: Module,
|
module: Module,
|
||||||
feature: LanguageFeature,
|
feature: LanguageFeature,
|
||||||
|
|||||||
@@ -153,16 +153,14 @@ fun Module.removeKotlinFacet(
|
|||||||
//method used for non-mpp modules
|
//method used for non-mpp modules
|
||||||
fun KotlinFacet.configureFacet(
|
fun KotlinFacet.configureFacet(
|
||||||
compilerVersion: String?,
|
compilerVersion: String?,
|
||||||
coroutineSupport: LanguageFeature.State,
|
|
||||||
platform: TargetPlatform?,
|
platform: TargetPlatform?,
|
||||||
modelsProvider: IdeModifiableModelsProvider
|
modelsProvider: IdeModifiableModelsProvider
|
||||||
) {
|
) {
|
||||||
configureFacet(compilerVersion, coroutineSupport, platform, modelsProvider, false, emptyList(), emptyList())
|
configureFacet(compilerVersion, platform, modelsProvider, false, emptyList(), emptyList())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun KotlinFacet.configureFacet(
|
fun KotlinFacet.configureFacet(
|
||||||
compilerVersion: String?,
|
compilerVersion: String?,
|
||||||
coroutineSupport: LanguageFeature.State,
|
|
||||||
platform: TargetPlatform?, // if null, detect by module dependencies
|
platform: TargetPlatform?, // if null, detect by module dependencies
|
||||||
modelsProvider: IdeModifiableModelsProvider,
|
modelsProvider: IdeModifiableModelsProvider,
|
||||||
hmppEnabled: Boolean,
|
hmppEnabled: Boolean,
|
||||||
|
|||||||
@@ -214,7 +214,6 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest {
|
|||||||
assertEquals(JvmPlatforms.INSTANCE.getJvm18(), settings.getTargetPlatform());
|
assertEquals(JvmPlatforms.INSTANCE.getJvm18(), settings.getTargetPlatform());
|
||||||
assertEquals("1.1", arguments.getLanguageVersion());
|
assertEquals("1.1", arguments.getLanguageVersion());
|
||||||
assertEquals("1.0", arguments.getApiVersion());
|
assertEquals("1.0", arguments.getApiVersion());
|
||||||
assertEquals(LanguageFeature.State.ENABLED_WITH_WARNING, CoroutineSupport.byCompilerArguments(arguments));
|
|
||||||
assertEquals("1.7", arguments.getJvmTarget());
|
assertEquals("1.7", arguments.getJvmTarget());
|
||||||
assertEquals("-version -Xallow-kotlin-package -Xskip-metadata-version-check", settings.getCompilerSettings().getAdditionalArguments());
|
assertEquals("-version -Xallow-kotlin-package -Xskip-metadata-version-check", settings.getCompilerSettings().getAdditionalArguments());
|
||||||
}
|
}
|
||||||
@@ -229,7 +228,6 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest {
|
|||||||
assertEquals(JsPlatforms.INSTANCE.getDefaultJsPlatform(), settings.getTargetPlatform());
|
assertEquals(JsPlatforms.INSTANCE.getDefaultJsPlatform(), settings.getTargetPlatform());
|
||||||
assertEquals("1.1", arguments.getLanguageVersion());
|
assertEquals("1.1", arguments.getLanguageVersion());
|
||||||
assertEquals("1.0", arguments.getApiVersion());
|
assertEquals("1.0", arguments.getApiVersion());
|
||||||
assertEquals(LanguageFeature.State.ENABLED_WITH_WARNING, CoroutineSupport.byCompilerArguments(arguments));
|
|
||||||
assertEquals("amd", arguments.getModuleKind());
|
assertEquals("amd", arguments.getModuleKind());
|
||||||
assertEquals("-version -meta-info", settings.getCompilerSettings().getAdditionalArguments());
|
assertEquals("-version -meta-info", settings.getCompilerSettings().getAdditionalArguments());
|
||||||
}
|
}
|
||||||
@@ -244,7 +242,6 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest {
|
|||||||
assertEquals(JvmPlatforms.INSTANCE.getJvm18(), settings.getTargetPlatform());
|
assertEquals(JvmPlatforms.INSTANCE.getJvm18(), settings.getTargetPlatform());
|
||||||
assertEquals("1.1", arguments.getLanguageVersion());
|
assertEquals("1.1", arguments.getLanguageVersion());
|
||||||
assertEquals("1.0", arguments.getApiVersion());
|
assertEquals("1.0", arguments.getApiVersion());
|
||||||
assertEquals(LanguageFeature.State.ENABLED, CoroutineSupport.byCompilerArguments(arguments));
|
|
||||||
assertEquals("1.7", arguments.getJvmTarget());
|
assertEquals("1.7", arguments.getJvmTarget());
|
||||||
assertEquals("-version -Xallow-kotlin-package -Xskip-metadata-version-check", settings.getCompilerSettings().getAdditionalArguments());
|
assertEquals("-version -Xallow-kotlin-package -Xskip-metadata-version-check", settings.getCompilerSettings().getAdditionalArguments());
|
||||||
}
|
}
|
||||||
@@ -259,7 +256,6 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest {
|
|||||||
assertEquals(JsPlatforms.INSTANCE.getDefaultJsPlatform(), settings.getTargetPlatform());
|
assertEquals(JsPlatforms.INSTANCE.getDefaultJsPlatform(), settings.getTargetPlatform());
|
||||||
assertEquals("1.1", arguments.getLanguageVersion());
|
assertEquals("1.1", arguments.getLanguageVersion());
|
||||||
assertEquals("1.0", arguments.getApiVersion());
|
assertEquals("1.0", arguments.getApiVersion());
|
||||||
assertEquals(LanguageFeature.State.ENABLED_WITH_ERROR, CoroutineSupport.byCompilerArguments(arguments));
|
|
||||||
assertEquals("amd", arguments.getModuleKind());
|
assertEquals("amd", arguments.getModuleKind());
|
||||||
assertEquals("-version -meta-info", settings.getCompilerSettings().getAdditionalArguments());
|
assertEquals("-version -meta-info", settings.getCompilerSettings().getAdditionalArguments());
|
||||||
}
|
}
|
||||||
@@ -274,7 +270,6 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest {
|
|||||||
assertEquals(JvmPlatforms.INSTANCE.getJvm18(), settings.getTargetPlatform());
|
assertEquals(JvmPlatforms.INSTANCE.getJvm18(), settings.getTargetPlatform());
|
||||||
assertEquals("1.1", arguments.getLanguageVersion());
|
assertEquals("1.1", arguments.getLanguageVersion());
|
||||||
assertEquals("1.0", arguments.getApiVersion());
|
assertEquals("1.0", arguments.getApiVersion());
|
||||||
assertEquals(LanguageFeature.State.ENABLED, CoroutineSupport.byCompilerArguments(arguments));
|
|
||||||
assertEquals("1.7", arguments.getJvmTarget());
|
assertEquals("1.7", arguments.getJvmTarget());
|
||||||
assertEquals("-version -Xallow-kotlin-package -Xskip-metadata-version-check", settings.getCompilerSettings().getAdditionalArguments());
|
assertEquals("-version -Xallow-kotlin-package -Xskip-metadata-version-check", settings.getCompilerSettings().getAdditionalArguments());
|
||||||
}
|
}
|
||||||
|
|||||||
-52
@@ -1,52 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2016 JetBrains s.r.o.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.gradle
|
|
||||||
|
|
||||||
import org.junit.Test
|
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
class CoroutinesIT : BaseGradleIT() {
|
|
||||||
@Test
|
|
||||||
fun testCoroutinesJvmDefault() {
|
|
||||||
jvmProject.doTest("default", null)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testCoroutinesJsDefault() {
|
|
||||||
jsProject.doTest("default", null)
|
|
||||||
}
|
|
||||||
|
|
||||||
// todo: replace with project that actually uses coroutines after their syntax is finalized
|
|
||||||
private val jvmProject: Project
|
|
||||||
get() = Project("kotlinProject")
|
|
||||||
|
|
||||||
private val jsProject: Project
|
|
||||||
get() = Project("kotlin2JsProject")
|
|
||||||
|
|
||||||
private fun Project.doTest(coroutineSupport: String, propertyFileName: String?) {
|
|
||||||
if (propertyFileName != null) {
|
|
||||||
setupWorkingDir()
|
|
||||||
val propertyFile = File(projectDir, propertyFileName)
|
|
||||||
val coroutinesProperty = "kotlin.coroutines=$coroutineSupport"
|
|
||||||
propertyFile.writeText(coroutinesProperty)
|
|
||||||
}
|
|
||||||
|
|
||||||
build("build") {
|
|
||||||
assertContains("args.coroutinesState=$coroutineSupport")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-4
@@ -441,10 +441,6 @@ public abstract class KotlinCompileMojoBase<A extends CommonCompilerArguments> e
|
|||||||
arguments.setApiVersion(apiVersion);
|
arguments.setApiVersion(apiVersion);
|
||||||
arguments.setMultiPlatform(multiPlatform);
|
arguments.setMultiPlatform(multiPlatform);
|
||||||
|
|
||||||
if (experimentalCoroutines != null) {
|
|
||||||
arguments.setCoroutinesState(experimentalCoroutines);
|
|
||||||
}
|
|
||||||
|
|
||||||
configureSpecificCompilerArguments(arguments, sourceRoots);
|
configureSpecificCompilerArguments(arguments, sourceRoots);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user