Use IdePlatform instead of IdePlatformKind in 'Kotlin Facet' project structure tab
This commit is contained in:
@@ -7,14 +7,15 @@ package org.jetbrains.kotlin.platform
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
||||||
import org.jetbrains.kotlin.config.TargetPlatformVersion
|
import org.jetbrains.kotlin.config.TargetPlatformVersion
|
||||||
|
import org.jetbrains.kotlin.utils.DescriptionAware
|
||||||
|
|
||||||
abstract class IdePlatform<Kind : IdePlatformKind<Kind>, Arguments : CommonCompilerArguments> {
|
abstract class IdePlatform<Kind : IdePlatformKind<Kind>, Arguments : CommonCompilerArguments> : DescriptionAware {
|
||||||
abstract val kind: Kind
|
abstract val kind: Kind
|
||||||
abstract val version: TargetPlatformVersion
|
abstract val version: TargetPlatformVersion
|
||||||
|
|
||||||
abstract fun createArguments(init: Arguments.() -> Unit = {}): Arguments
|
abstract fun createArguments(init: Arguments.() -> Unit = {}): Arguments
|
||||||
|
|
||||||
val description
|
override val description
|
||||||
get() = kind.name + " " + version.description
|
get() = kind.name + " " + version.description
|
||||||
|
|
||||||
override fun toString() = description
|
override fun toString() = description
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ abstract class IdePlatformKind<Kind : IdePlatformKind<Kind>> {
|
|||||||
override fun equals(other: Any?): Boolean = javaClass == other?.javaClass
|
override fun equals(other: Any?): Boolean = javaClass == other?.javaClass
|
||||||
override fun hashCode(): Int = javaClass.hashCode()
|
override fun hashCode(): Int = javaClass.hashCode()
|
||||||
|
|
||||||
|
override fun toString() = name
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
// We can't use the ApplicationExtensionDescriptor class directly because it's missing in the JPS process
|
// We can't use the ApplicationExtensionDescriptor class directly because it's missing in the JPS process
|
||||||
private val extension = ApplicationManager.getApplication()?.let {
|
private val extension = ApplicationManager.getApplication()?.let {
|
||||||
|
|||||||
+5
-4
@@ -26,6 +26,7 @@ import com.intellij.openapi.roots.ui.configuration.libraries.AddCustomLibraryDia
|
|||||||
import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription
|
import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription
|
||||||
import com.intellij.openapi.roots.ui.configuration.libraries.LibraryPresentationManager
|
import com.intellij.openapi.roots.ui.configuration.libraries.LibraryPresentationManager
|
||||||
import org.jetbrains.kotlin.idea.platform.tooling
|
import org.jetbrains.kotlin.idea.platform.tooling
|
||||||
|
import org.jetbrains.kotlin.platform.IdePlatform
|
||||||
import org.jetbrains.kotlin.platform.IdePlatformKind
|
import org.jetbrains.kotlin.platform.IdePlatformKind
|
||||||
import org.jetbrains.kotlin.platform.impl.isCommon
|
import org.jetbrains.kotlin.platform.impl.isCommon
|
||||||
import javax.swing.JComponent
|
import javax.swing.JComponent
|
||||||
@@ -35,7 +36,7 @@ class FrameworkLibraryValidatorWithDynamicDescription(
|
|||||||
private val context: LibrariesValidatorContext,
|
private val context: LibrariesValidatorContext,
|
||||||
private val validatorsManager: FacetValidatorsManager,
|
private val validatorsManager: FacetValidatorsManager,
|
||||||
private val libraryCategoryName: String,
|
private val libraryCategoryName: String,
|
||||||
private val getPlatform: () -> IdePlatformKind<*>
|
private val getPlatform: () -> IdePlatform<*, *>
|
||||||
) : FrameworkLibraryValidator() {
|
) : FrameworkLibraryValidator() {
|
||||||
private val IdePlatformKind<*>.libraryDescription: CustomLibraryDescription
|
private val IdePlatformKind<*>.libraryDescription: CustomLibraryDescription
|
||||||
get() = this.tooling.getLibraryDescription(context.module.project)
|
get() = this.tooling.getLibraryDescription(context.module.project)
|
||||||
@@ -69,9 +70,9 @@ class FrameworkLibraryValidatorWithDynamicDescription(
|
|||||||
override fun check(): ValidationResult {
|
override fun check(): ValidationResult {
|
||||||
val targetPlatform = getPlatform()
|
val targetPlatform = getPlatform()
|
||||||
|
|
||||||
if (checkLibraryIsConfigured(targetPlatform)) {
|
if (checkLibraryIsConfigured(targetPlatform.kind)) {
|
||||||
val conflictingPlatforms = IdePlatformKind.ALL_KINDS
|
val conflictingPlatforms = IdePlatformKind.ALL_KINDS
|
||||||
.filter { !it.isCommon && it.name != targetPlatform.name && checkLibraryIsConfigured(it) }
|
.filter { !it.isCommon && it.name != targetPlatform.kind.name && checkLibraryIsConfigured(it) }
|
||||||
|
|
||||||
if (conflictingPlatforms.isNotEmpty()) {
|
if (conflictingPlatforms.isNotEmpty()) {
|
||||||
val platformText = conflictingPlatforms.mapTo(LinkedHashSet()) { it.name }.joinToString()
|
val platformText = conflictingPlatforms.mapTo(LinkedHashSet()) { it.name }.joinToString()
|
||||||
@@ -84,7 +85,7 @@ class FrameworkLibraryValidatorWithDynamicDescription(
|
|||||||
|
|
||||||
return ValidationResult(
|
return ValidationResult(
|
||||||
IdeBundle.message("label.missed.libraries.text", libraryCategoryName),
|
IdeBundle.message("label.missed.libraries.text", libraryCategoryName),
|
||||||
LibrariesQuickFix(targetPlatform.libraryDescription)
|
LibrariesQuickFix(targetPlatform.kind.libraryDescription)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import com.intellij.facet.ui.FacetEditorContext
|
|||||||
import com.intellij.facet.ui.FacetEditorValidator
|
import com.intellij.facet.ui.FacetEditorValidator
|
||||||
import com.intellij.facet.ui.FacetValidatorsManager
|
import com.intellij.facet.ui.FacetValidatorsManager
|
||||||
import org.jetbrains.kotlin.idea.facet.KotlinFacetEditorGeneralTab.EditorComponent
|
import org.jetbrains.kotlin.idea.facet.KotlinFacetEditorGeneralTab.EditorComponent
|
||||||
import org.jetbrains.kotlin.platform.IdePlatformKind
|
import org.jetbrains.kotlin.platform.IdePlatform
|
||||||
|
|
||||||
class KotlinLibraryValidatorCreator : KotlinFacetValidatorCreator() {
|
class KotlinLibraryValidatorCreator : KotlinFacetValidatorCreator() {
|
||||||
override fun create(editor: EditorComponent, validatorsManager: FacetValidatorsManager, editorContext: FacetEditorContext): FacetEditorValidator {
|
override fun create(editor: EditorComponent, validatorsManager: FacetValidatorsManager, editorContext: FacetEditorContext): FacetEditorValidator {
|
||||||
@@ -29,6 +29,6 @@ class KotlinLibraryValidatorCreator : KotlinFacetValidatorCreator() {
|
|||||||
DelegatingLibrariesValidatorContext(editorContext),
|
DelegatingLibrariesValidatorContext(editorContext),
|
||||||
validatorsManager,
|
validatorsManager,
|
||||||
"kotlin"
|
"kotlin"
|
||||||
) { editor.targetPlatformComboBox.selectedItem as IdePlatformKind<*> }
|
) { editor.targetPlatformComboBox.selectedItem as IdePlatform<*, *> }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.cli.common.arguments.*
|
|||||||
import org.jetbrains.kotlin.config.*
|
import org.jetbrains.kotlin.config.*
|
||||||
import org.jetbrains.kotlin.idea.compiler.configuration.*
|
import org.jetbrains.kotlin.idea.compiler.configuration.*
|
||||||
import org.jetbrains.kotlin.idea.util.onTextChange
|
import org.jetbrains.kotlin.idea.util.onTextChange
|
||||||
|
import org.jetbrains.kotlin.platform.IdePlatform
|
||||||
import org.jetbrains.kotlin.platform.IdePlatformKind
|
import org.jetbrains.kotlin.platform.IdePlatformKind
|
||||||
import org.jetbrains.kotlin.platform.impl.isCommon
|
import org.jetbrains.kotlin.platform.impl.isCommon
|
||||||
import org.jetbrains.kotlin.platform.impl.isJavaScript
|
import org.jetbrains.kotlin.platform.impl.isJavaScript
|
||||||
@@ -86,7 +87,7 @@ class KotlinFacetEditorGeneralTab(
|
|||||||
val useProjectSettingsCheckBox = ThreeStateCheckBox("Use project settings").apply { isThirdStateEnabled = isMultiEditor }
|
val useProjectSettingsCheckBox = ThreeStateCheckBox("Use project settings").apply { isThirdStateEnabled = isMultiEditor }
|
||||||
|
|
||||||
val targetPlatformComboBox =
|
val targetPlatformComboBox =
|
||||||
JComboBox<IdePlatformKind<*>>(IdePlatformKind.ALL_KINDS.toTypedArray()).apply {
|
JComboBox<IdePlatform<*, *>>(IdePlatformKind.All_PLATFORMS.toTypedArray()).apply {
|
||||||
setRenderer(DescriptionListCellRenderer())
|
setRenderer(DescriptionListCellRenderer())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,7 +128,7 @@ class KotlinFacetEditorGeneralTab(
|
|||||||
|
|
||||||
internal fun updateCompilerConfigurable() {
|
internal fun updateCompilerConfigurable() {
|
||||||
val useProjectSettings = useProjectSettingsCheckBox.isSelected
|
val useProjectSettings = useProjectSettingsCheckBox.isSelected
|
||||||
compilerConfigurable.setTargetPlatform(chosenPlatform)
|
compilerConfigurable.setTargetPlatform(chosenPlatform?.kind)
|
||||||
compilerConfigurable.setEnabled(!useProjectSettings)
|
compilerConfigurable.setEnabled(!useProjectSettings)
|
||||||
if (useProjectSettings) {
|
if (useProjectSettings) {
|
||||||
compilerConfigurable.commonCompilerArguments = KotlinCommonCompilerArgumentsHolder.getInstance(project).settings.unfrozen() as CommonCompilerArguments?
|
compilerConfigurable.commonCompilerArguments = KotlinCommonCompilerArgumentsHolder.getInstance(project).settings.unfrozen() as CommonCompilerArguments?
|
||||||
@@ -144,14 +145,14 @@ class KotlinFacetEditorGeneralTab(
|
|||||||
compilerConfigurable.reset()
|
compilerConfigurable.reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
private val chosenPlatform: IdePlatformKind<*>?
|
private val chosenPlatform: IdePlatform<*, *>?
|
||||||
get() = targetPlatformComboBox.selectedItem as IdePlatformKind<*>?
|
get() = targetPlatformComboBox.selectedItem as IdePlatform<*, *>?
|
||||||
}
|
}
|
||||||
|
|
||||||
inner class ArgumentConsistencyValidator : FacetEditorValidator() {
|
inner class ArgumentConsistencyValidator : FacetEditorValidator() {
|
||||||
override fun check(): ValidationResult {
|
override fun check(): ValidationResult {
|
||||||
val platformKind = editor.targetPlatformComboBox.selectedItem as IdePlatformKind<*>? ?: return ValidationResult.OK
|
val platform = editor.targetPlatformComboBox.selectedItem as IdePlatform<*, *>? ?: return ValidationResult.OK
|
||||||
val primaryArguments = platformKind.defaultPlatform.createArguments().apply {
|
val primaryArguments = platform.createArguments().apply {
|
||||||
editor.compilerConfigurable.applyTo(
|
editor.compilerConfigurable.applyTo(
|
||||||
this,
|
this,
|
||||||
this as? K2JVMCompilerArguments ?: K2JVMCompilerArguments(),
|
this as? K2JVMCompilerArguments ?: K2JVMCompilerArguments(),
|
||||||
@@ -166,9 +167,9 @@ class KotlinFacetEditorGeneralTab(
|
|||||||
}
|
}
|
||||||
val emptyArguments = argumentClass.newInstance()
|
val emptyArguments = argumentClass.newInstance()
|
||||||
val fieldNamesToCheck = when {
|
val fieldNamesToCheck = when {
|
||||||
platformKind.isJvm -> jvmUIExposedFields
|
platform.isJvm -> jvmUIExposedFields
|
||||||
platformKind.isJavaScript -> jsUIExposedFields
|
platform.isJavaScript -> jsUIExposedFields
|
||||||
platformKind.isCommon -> metadataUIExposedFields
|
platform.isCommon -> metadataUIExposedFields
|
||||||
else -> commonUIExposedFields
|
else -> commonUIExposedFields
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -285,14 +286,14 @@ class KotlinFacetEditorGeneralTab(
|
|||||||
editor.compilerConfigurable.apply()
|
editor.compilerConfigurable.apply()
|
||||||
with(configuration.settings) {
|
with(configuration.settings) {
|
||||||
useProjectSettings = editor.useProjectSettingsCheckBox.isSelected
|
useProjectSettings = editor.useProjectSettingsCheckBox.isSelected
|
||||||
(editor.targetPlatformComboBox.selectedItem as IdePlatformKind<*>?)?.let {
|
(editor.targetPlatformComboBox.selectedItem as IdePlatform<*, *>?)?.let {
|
||||||
if (it != platform) {
|
if (it != platform) {
|
||||||
val platformArguments = when {
|
val platformArguments = when {
|
||||||
it.isJvm -> editor.compilerConfigurable.k2jvmCompilerArguments
|
it.isJvm -> editor.compilerConfigurable.k2jvmCompilerArguments
|
||||||
it.isJavaScript -> editor.compilerConfigurable.k2jsCompilerArguments
|
it.isJavaScript -> editor.compilerConfigurable.k2jsCompilerArguments
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
compilerArguments = it.defaultPlatform.createArguments {
|
compilerArguments = it.createArguments {
|
||||||
if (platformArguments != null) {
|
if (platformArguments != null) {
|
||||||
mergeBeans(platformArguments, this)
|
mergeBeans(platformArguments, this)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user