mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-04-04 08:31:30 +00:00
Refactoring: Move facet configuration classes to idea-jps-common module
This commit is contained in:
@@ -9,5 +9,7 @@
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="kotlin-runtime" level="project" />
|
||||
<orderEntry type="library" name="kotlin-reflect" level="project" />
|
||||
<orderEntry type="library" name="intellij-core" level="project" />
|
||||
<orderEntry type="module" module-name="cli-common" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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<out Version : DescriptionAware>(
|
||||
val version: Version,
|
||||
val name: String
|
||||
) : DescriptionAware {
|
||||
override val description = "$name ${version.description}"
|
||||
|
||||
companion object {
|
||||
val ALL_PLATFORMS: List<TargetPlatformKind<*>> 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<JVMVersion>(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>(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()
|
||||
}
|
||||
@@ -20,5 +20,6 @@
|
||||
<orderEntry type="module" module-name="frontend.java" />
|
||||
<orderEntry type="library" scope="TEST" name="kotlin-reflect" level="project" />
|
||||
<orderEntry type="module" module-name="tests-common" scope="TEST" />
|
||||
<orderEntry type="module" module-name="idea-jps-common" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<out Version : DescriptionAware>(
|
||||
val version: Version,
|
||||
val name: String
|
||||
) : DescriptionAware {
|
||||
override val description = "$name ${version.description}"
|
||||
|
||||
companion object {
|
||||
val ALL_PLATFORMS: List<TargetPlatformKind<*>> 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<JVMVersion>(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>(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<KotlinFacetConfiguration.Settings> {
|
||||
class Settings {
|
||||
var versionInfo = KotlinVersionInfo()
|
||||
var compilerInfo = KotlinCompilerInfo()
|
||||
}
|
||||
|
||||
private var settings = Settings()
|
||||
class KotlinFacetConfiguration : FacetConfiguration, PersistentStateComponent<KotlinFacetSettings> {
|
||||
private var settings = KotlinFacetSettings()
|
||||
|
||||
@Suppress("OverridingDeprecatedMember")
|
||||
override fun readExternal(element: Element?) {
|
||||
@@ -107,7 +37,7 @@ class KotlinFacetConfiguration : FacetConfiguration, PersistentStateComponent<Ko
|
||||
|
||||
}
|
||||
|
||||
override fun loadState(state: Settings) {
|
||||
override fun loadState(state: KotlinFacetSettings) {
|
||||
this.settings = state
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.idea.facet
|
||||
|
||||
import com.intellij.facet.ui.FacetEditorContext
|
||||
import com.intellij.facet.ui.FacetEditorTab
|
||||
import org.jetbrains.kotlin.config.KotlinCompilerInfo
|
||||
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCompilerConfigurableTab
|
||||
|
||||
class KotlinFacetEditorCompilerTab(
|
||||
|
||||
@@ -20,7 +20,9 @@ import com.intellij.facet.impl.ui.libraries.DelegatingLibrariesValidatorContext
|
||||
import com.intellij.facet.ui.*
|
||||
import com.intellij.facet.ui.libraries.FrameworkLibraryValidator
|
||||
import com.intellij.util.ui.FormBuilder
|
||||
import org.jetbrains.kotlin.idea.util.DescriptionAware
|
||||
import org.jetbrains.kotlin.config.DescriptionAware
|
||||
import org.jetbrains.kotlin.config.LanguageLevel
|
||||
import org.jetbrains.kotlin.config.TargetPlatformKind
|
||||
import java.awt.BorderLayout
|
||||
import java.awt.Component
|
||||
import javax.swing.*
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.idea.facet
|
||||
|
||||
import com.intellij.openapi.extensions.ExtensionPointName
|
||||
import com.intellij.openapi.module.Module
|
||||
import org.jetbrains.kotlin.config.TargetPlatformKind
|
||||
|
||||
interface KotlinVersionInfoProvider {
|
||||
companion object {
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.facet
|
||||
|
||||
import com.intellij.openapi.components.ServiceManager
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.projectRoots.JavaSdk
|
||||
import com.intellij.openapi.projectRoots.JavaSdkVersion
|
||||
@@ -24,11 +23,10 @@ import com.intellij.openapi.roots.LibraryOrderEntry
|
||||
import com.intellij.openapi.roots.ModuleRootManager
|
||||
import com.intellij.openapi.roots.ModuleRootModel
|
||||
import com.intellij.util.text.VersionComparatorUtil
|
||||
import org.jetbrains.kotlin.config.CompilerSettings
|
||||
import org.jetbrains.kotlin.config.*
|
||||
import org.jetbrains.kotlin.idea.compiler.configuration.Kotlin2JsCompilerArgumentsHolder
|
||||
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCommonCompilerArgumentsHolder
|
||||
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCompilerSettings
|
||||
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCompilerWorkspaceSettings
|
||||
import org.jetbrains.kotlin.idea.framework.JSLibraryStdPresentationProvider
|
||||
import org.jetbrains.kotlin.idea.framework.JavaRuntimePresentationProvider
|
||||
import org.jetbrains.kotlin.idea.framework.getLibraryProperties
|
||||
@@ -98,7 +96,7 @@ internal fun getLibraryLanguageLevel(
|
||||
return getDefaultLanguageLevel(module, minVersion)
|
||||
}
|
||||
|
||||
internal fun KotlinFacetConfiguration.Settings.initializeIfNeeded(module: Module, rootModel: ModuleRootModel?) {
|
||||
internal fun KotlinFacetSettings.initializeIfNeeded(module: Module, rootModel: ModuleRootModel?) {
|
||||
val project = module.project
|
||||
|
||||
with(versionInfo) {
|
||||
@@ -130,8 +128,8 @@ internal fun KotlinFacetConfiguration.Settings.initializeIfNeeded(module: Module
|
||||
}
|
||||
}
|
||||
|
||||
internal fun Module.getKotlinSettings(rootModel: ModuleRootModel? = null): KotlinFacetConfiguration.Settings {
|
||||
val settings = KotlinFacet.get(this)?.configuration?.state ?: KotlinFacetConfiguration.Settings()
|
||||
internal fun Module.getKotlinSettings(rootModel: ModuleRootModel? = null): KotlinFacetSettings {
|
||||
val settings = KotlinFacet.get(this)?.configuration?.state ?: KotlinFacetSettings()
|
||||
settings.initializeIfNeeded(this, rootModel)
|
||||
return settings
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user