From a6dbdbd3e548edcf347b234fcac66da1afae6f03 Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Wed, 26 Oct 2016 14:50:11 +0300 Subject: [PATCH] Refactoring: Move facet configuration classes to idea-jps-common module --- idea/idea-jps-common/idea-jps-common.iml | 2 + .../kotlin/config}/DescriptionAware.kt | 20 +++- .../kotlin/config/KotlinFacetSettings.kt | 103 ++++++++++++++++++ idea/idea-maven/idea-maven.iml | 1 + .../facet/MavenKotlinVersionInfoProvider.kt | 3 +- .../KotlinCompilerConfigurableTab.java | 4 +- .../GradleKotlinVersionInfoProvider.kt | 2 +- ...kLibraryValidatorWithDynamicDescription.kt | 3 + .../idea/facet/KotlinFacetConfiguration.kt | 78 +------------ .../facet/KotlinFacetEditorCompilerTab.kt | 1 + .../idea/facet/KotlinFacetEditorGeneralTab.kt | 4 +- .../idea/facet/KotlinVersionInfoProvider.kt | 1 + .../jetbrains/kotlin/idea/facet/facetUtils.kt | 10 +- 13 files changed, 144 insertions(+), 88 deletions(-) rename idea/{src/org/jetbrains/kotlin/idea/util => idea-jps-common/src/org/jetbrains/kotlin/config}/DescriptionAware.kt (50%) create mode 100644 idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinFacetSettings.kt diff --git a/idea/idea-jps-common/idea-jps-common.iml b/idea/idea-jps-common/idea-jps-common.iml index 8902bc86b9b..914a19b4ad5 100644 --- a/idea/idea-jps-common/idea-jps-common.iml +++ b/idea/idea-jps-common/idea-jps-common.iml @@ -9,5 +9,7 @@ + + \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/util/DescriptionAware.kt b/idea/idea-jps-common/src/org/jetbrains/kotlin/config/DescriptionAware.kt similarity index 50% rename from idea/src/org/jetbrains/kotlin/idea/util/DescriptionAware.kt rename to idea/idea-jps-common/src/org/jetbrains/kotlin/config/DescriptionAware.kt index ed35e497448..346a984832e 100644 --- a/idea/src/org/jetbrains/kotlin/idea/util/DescriptionAware.kt +++ b/idea/idea-jps-common/src/org/jetbrains/kotlin/config/DescriptionAware.kt @@ -14,8 +14,24 @@ * limitations under the License. */ -package org.jetbrains.kotlin.idea.util +/* + * 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.config; interface DescriptionAware { val description: String -} +} \ No newline at end of file diff --git a/idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinFacetSettings.kt b/idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinFacetSettings.kt new file mode 100644 index 00000000000..a2db9376e59 --- /dev/null +++ b/idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinFacetSettings.kt @@ -0,0 +1,103 @@ +/* + * 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. + */ + +/* + * 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.config + +import com.intellij.util.xmlb.annotations.Property +import com.intellij.util.xmlb.annotations.Transient +import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments +import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments + +enum class LanguageLevel(override val description: String) : DescriptionAware { + KOTLIN_1_0("1.0"), + KOTLIN_1_1("1.1") +} + +sealed class TargetPlatformKind( + val version: Version, + val name: String +) : DescriptionAware { + override val description = "$name ${version.description}" + + companion object { + val ALL_PLATFORMS: List> by lazy { JVMPlatform.JVM_PLATFORMS + JSPlatform } + } +} + +object NoVersion : DescriptionAware { + override val description = "" +} + +enum class JVMVersion(override val description: String) : DescriptionAware { + JVM_1_6("1.6"), + JVM_1_8("1.8") +} + +class JVMPlatform(version: JVMVersion) : TargetPlatformKind(version, "JVM") { + companion object { + val JVM_PLATFORMS by lazy { JVMVersion.values().map(::JVMPlatform) } + + operator fun get(version: JVMVersion) = JVM_PLATFORMS[version.ordinal] + } +} + +object JSPlatform : TargetPlatformKind(NoVersion, "JavaScript") + +data class KotlinVersionInfo( + var languageLevel: LanguageLevel? = null, + var apiLevel: LanguageLevel? = null, + @get:Transient var targetPlatformKindKind: TargetPlatformKind<*>? = null +) { + // To be serialized + var targetPlatformName: String + get() = targetPlatformKindKind?.description ?: "" + set(value) { + targetPlatformKindKind = TargetPlatformKind.ALL_PLATFORMS.firstOrNull { it.description == value } + } +} + +class KotlinCompilerInfo { + // To be serialized + @Property private var _commonCompilerArguments: CommonCompilerArguments.DummyImpl? = null + @get:Transient var commonCompilerArguments: CommonCompilerArguments? + get() = _commonCompilerArguments + set(value) { + _commonCompilerArguments = value as? CommonCompilerArguments.DummyImpl + } + var k2jsCompilerArguments: K2JSCompilerArguments? = null + var compilerSettings: CompilerSettings? = null +} + +class KotlinFacetSettings { + var versionInfo = KotlinVersionInfo() + var compilerInfo = KotlinCompilerInfo() +} \ No newline at end of file diff --git a/idea/idea-maven/idea-maven.iml b/idea/idea-maven/idea-maven.iml index 6ed9a20c3ad..e1357912dbe 100644 --- a/idea/idea-maven/idea-maven.iml +++ b/idea/idea-maven/idea-maven.iml @@ -20,5 +20,6 @@ + \ No newline at end of file diff --git a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/facet/MavenKotlinVersionInfoProvider.kt b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/facet/MavenKotlinVersionInfoProvider.kt index 1d73151be9e..5176a1f3429 100644 --- a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/facet/MavenKotlinVersionInfoProvider.kt +++ b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/facet/MavenKotlinVersionInfoProvider.kt @@ -18,9 +18,8 @@ package org.jetbrains.kotlin.idea.maven.facet import com.intellij.openapi.module.Module import org.jetbrains.idea.maven.project.MavenProjectsManager -import org.jetbrains.kotlin.idea.facet.KotlinFacetConfiguration +import org.jetbrains.kotlin.config.TargetPlatformKind import org.jetbrains.kotlin.idea.facet.KotlinVersionInfoProvider -import org.jetbrains.kotlin.idea.facet.TargetPlatformKind import org.jetbrains.kotlin.idea.facet.mavenLibraryId import org.jetbrains.kotlin.idea.maven.configuration.KotlinMavenConfigurator diff --git a/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerConfigurableTab.java b/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerConfigurableTab.java index 3c7cebcd702..ad515b45bf4 100644 --- a/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerConfigurableTab.java +++ b/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerConfigurableTab.java @@ -36,10 +36,10 @@ import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments; import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments; import org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants; import org.jetbrains.kotlin.config.CompilerSettings; +import org.jetbrains.kotlin.config.JSPlatform; +import org.jetbrains.kotlin.config.TargetPlatformKind; import org.jetbrains.kotlin.idea.KotlinBundle; import org.jetbrains.kotlin.idea.PluginStartupComponent; -import org.jetbrains.kotlin.idea.facet.JSPlatform; -import org.jetbrains.kotlin.idea.facet.TargetPlatformKind; import javax.swing.*; import javax.swing.event.ChangeEvent; diff --git a/idea/src/org/jetbrains/kotlin/idea/configuration/GradleKotlinVersionInfoProvider.kt b/idea/src/org/jetbrains/kotlin/idea/configuration/GradleKotlinVersionInfoProvider.kt index b96406b9a94..a87ef3fb46b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/configuration/GradleKotlinVersionInfoProvider.kt +++ b/idea/src/org/jetbrains/kotlin/idea/configuration/GradleKotlinVersionInfoProvider.kt @@ -18,8 +18,8 @@ package org.jetbrains.kotlin.idea.configuration import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil import com.intellij.openapi.module.Module +import org.jetbrains.kotlin.config.TargetPlatformKind import org.jetbrains.kotlin.idea.facet.KotlinVersionInfoProvider -import org.jetbrains.kotlin.idea.facet.TargetPlatformKind import org.jetbrains.kotlin.idea.facet.mavenLibraryId import org.jetbrains.kotlin.idea.inspections.gradle.DifferentKotlinGradleVersionInspection import org.jetbrains.kotlin.idea.inspections.gradle.DifferentStdlibGradleVersionInspection diff --git a/idea/src/org/jetbrains/kotlin/idea/facet/FrameworkLibraryValidatorWithDynamicDescription.kt b/idea/src/org/jetbrains/kotlin/idea/facet/FrameworkLibraryValidatorWithDynamicDescription.kt index a92a5394939..b0614f20b16 100644 --- a/idea/src/org/jetbrains/kotlin/idea/facet/FrameworkLibraryValidatorWithDynamicDescription.kt +++ b/idea/src/org/jetbrains/kotlin/idea/facet/FrameworkLibraryValidatorWithDynamicDescription.kt @@ -25,6 +25,9 @@ import com.intellij.ide.IdeBundle import com.intellij.openapi.roots.ui.configuration.libraries.AddCustomLibraryDialog import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription import com.intellij.openapi.roots.ui.configuration.libraries.LibraryPresentationManager +import org.jetbrains.kotlin.config.JSPlatform +import org.jetbrains.kotlin.config.JVMPlatform +import org.jetbrains.kotlin.config.TargetPlatformKind import org.jetbrains.kotlin.idea.framework.JSLibraryStdDescription import org.jetbrains.kotlin.idea.framework.JavaRuntimeLibraryDescription import javax.swing.JComponent diff --git a/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetConfiguration.kt b/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetConfiguration.kt index 2a61f5472ff..8414e2496fd 100644 --- a/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetConfiguration.kt +++ b/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetConfiguration.kt @@ -21,81 +21,11 @@ import com.intellij.facet.ui.FacetEditorContext import com.intellij.facet.ui.FacetEditorTab import com.intellij.facet.ui.FacetValidatorsManager import com.intellij.openapi.components.PersistentStateComponent -import com.intellij.util.xmlb.annotations.Property -import com.intellij.util.xmlb.annotations.Transient import org.jdom.Element -import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments -import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments -import org.jetbrains.kotlin.config.CompilerSettings -import org.jetbrains.kotlin.idea.util.DescriptionAware +import org.jetbrains.kotlin.config.KotlinFacetSettings -enum class LanguageLevel(override val description: String) : DescriptionAware { - KOTLIN_1_0("1.0"), - KOTLIN_1_1("1.1") -} - -sealed class TargetPlatformKind( - val version: Version, - val name: String -) : DescriptionAware { - override val description = "$name ${version.description}" - - companion object { - val ALL_PLATFORMS: List> by lazy { JVMPlatform.JVM_PLATFORMS + JSPlatform } - } -} - -object NoVersion : DescriptionAware { - override val description = "" -} - -enum class JVMVersion(override val description: String) : DescriptionAware { - JVM_1_6("1.6"), - JVM_1_8("1.8") -} - -class JVMPlatform(version: JVMVersion) : TargetPlatformKind(version, "JVM") { - companion object { - val JVM_PLATFORMS by lazy { JVMVersion.values().map(::JVMPlatform) } - - operator fun get(version: JVMVersion) = JVM_PLATFORMS[version.ordinal] - } -} - -object JSPlatform : TargetPlatformKind(NoVersion, "JavaScript") - -data class KotlinVersionInfo( - var languageLevel: LanguageLevel? = null, - var apiLevel: LanguageLevel? = null, - @get:Transient var targetPlatformKindKind: TargetPlatformKind<*>? = null -) { - // To be serialized - var targetPlatformName: String - get() = targetPlatformKindKind?.description ?: "" - set(value) { - targetPlatformKindKind = TargetPlatformKind.ALL_PLATFORMS.firstOrNull { it.description == value } - } -} - -class KotlinCompilerInfo { - // To be serialized - @Property private var _commonCompilerArguments: CommonCompilerArguments.DummyImpl? = null - @get:Transient var commonCompilerArguments: CommonCompilerArguments? - get() = _commonCompilerArguments - set(value) { - _commonCompilerArguments = value as? CommonCompilerArguments.DummyImpl - } - var k2jsCompilerArguments: K2JSCompilerArguments? = null - var compilerSettings: CompilerSettings? = null -} - -class KotlinFacetConfiguration : FacetConfiguration, PersistentStateComponent { - class Settings { - var versionInfo = KotlinVersionInfo() - var compilerInfo = KotlinCompilerInfo() - } - - private var settings = Settings() +class KotlinFacetConfiguration : FacetConfiguration, PersistentStateComponent { + private var settings = KotlinFacetSettings() @Suppress("OverridingDeprecatedMember") override fun readExternal(element: Element?) { @@ -107,7 +37,7 @@ class KotlinFacetConfiguration : FacetConfiguration, PersistentStateComponent