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.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 version: TargetPlatformVersion
|
||||
|
||||
abstract fun createArguments(init: Arguments.() -> Unit = {}): Arguments
|
||||
|
||||
val description
|
||||
override val description
|
||||
get() = kind.name + " " + version.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 hashCode(): Int = javaClass.hashCode()
|
||||
|
||||
override fun toString() = name
|
||||
|
||||
companion object {
|
||||
// We can't use the ApplicationExtensionDescriptor class directly because it's missing in the JPS process
|
||||
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.LibraryPresentationManager
|
||||
import org.jetbrains.kotlin.idea.platform.tooling
|
||||
import org.jetbrains.kotlin.platform.IdePlatform
|
||||
import org.jetbrains.kotlin.platform.IdePlatformKind
|
||||
import org.jetbrains.kotlin.platform.impl.isCommon
|
||||
import javax.swing.JComponent
|
||||
@@ -35,7 +36,7 @@ class FrameworkLibraryValidatorWithDynamicDescription(
|
||||
private val context: LibrariesValidatorContext,
|
||||
private val validatorsManager: FacetValidatorsManager,
|
||||
private val libraryCategoryName: String,
|
||||
private val getPlatform: () -> IdePlatformKind<*>
|
||||
private val getPlatform: () -> IdePlatform<*, *>
|
||||
) : FrameworkLibraryValidator() {
|
||||
private val IdePlatformKind<*>.libraryDescription: CustomLibraryDescription
|
||||
get() = this.tooling.getLibraryDescription(context.module.project)
|
||||
@@ -69,9 +70,9 @@ class FrameworkLibraryValidatorWithDynamicDescription(
|
||||
override fun check(): ValidationResult {
|
||||
val targetPlatform = getPlatform()
|
||||
|
||||
if (checkLibraryIsConfigured(targetPlatform)) {
|
||||
if (checkLibraryIsConfigured(targetPlatform.kind)) {
|
||||
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()) {
|
||||
val platformText = conflictingPlatforms.mapTo(LinkedHashSet()) { it.name }.joinToString()
|
||||
@@ -84,7 +85,7 @@ class FrameworkLibraryValidatorWithDynamicDescription(
|
||||
|
||||
return ValidationResult(
|
||||
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.FacetValidatorsManager
|
||||
import org.jetbrains.kotlin.idea.facet.KotlinFacetEditorGeneralTab.EditorComponent
|
||||
import org.jetbrains.kotlin.platform.IdePlatformKind
|
||||
import org.jetbrains.kotlin.platform.IdePlatform
|
||||
|
||||
class KotlinLibraryValidatorCreator : KotlinFacetValidatorCreator() {
|
||||
override fun create(editor: EditorComponent, validatorsManager: FacetValidatorsManager, editorContext: FacetEditorContext): FacetEditorValidator {
|
||||
@@ -29,6 +29,6 @@ class KotlinLibraryValidatorCreator : KotlinFacetValidatorCreator() {
|
||||
DelegatingLibrariesValidatorContext(editorContext),
|
||||
validatorsManager,
|
||||
"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.idea.compiler.configuration.*
|
||||
import org.jetbrains.kotlin.idea.util.onTextChange
|
||||
import org.jetbrains.kotlin.platform.IdePlatform
|
||||
import org.jetbrains.kotlin.platform.IdePlatformKind
|
||||
import org.jetbrains.kotlin.platform.impl.isCommon
|
||||
import org.jetbrains.kotlin.platform.impl.isJavaScript
|
||||
@@ -86,7 +87,7 @@ class KotlinFacetEditorGeneralTab(
|
||||
val useProjectSettingsCheckBox = ThreeStateCheckBox("Use project settings").apply { isThirdStateEnabled = isMultiEditor }
|
||||
|
||||
val targetPlatformComboBox =
|
||||
JComboBox<IdePlatformKind<*>>(IdePlatformKind.ALL_KINDS.toTypedArray()).apply {
|
||||
JComboBox<IdePlatform<*, *>>(IdePlatformKind.All_PLATFORMS.toTypedArray()).apply {
|
||||
setRenderer(DescriptionListCellRenderer())
|
||||
}
|
||||
|
||||
@@ -127,7 +128,7 @@ class KotlinFacetEditorGeneralTab(
|
||||
|
||||
internal fun updateCompilerConfigurable() {
|
||||
val useProjectSettings = useProjectSettingsCheckBox.isSelected
|
||||
compilerConfigurable.setTargetPlatform(chosenPlatform)
|
||||
compilerConfigurable.setTargetPlatform(chosenPlatform?.kind)
|
||||
compilerConfigurable.setEnabled(!useProjectSettings)
|
||||
if (useProjectSettings) {
|
||||
compilerConfigurable.commonCompilerArguments = KotlinCommonCompilerArgumentsHolder.getInstance(project).settings.unfrozen() as CommonCompilerArguments?
|
||||
@@ -144,14 +145,14 @@ class KotlinFacetEditorGeneralTab(
|
||||
compilerConfigurable.reset()
|
||||
}
|
||||
|
||||
private val chosenPlatform: IdePlatformKind<*>?
|
||||
get() = targetPlatformComboBox.selectedItem as IdePlatformKind<*>?
|
||||
private val chosenPlatform: IdePlatform<*, *>?
|
||||
get() = targetPlatformComboBox.selectedItem as IdePlatform<*, *>?
|
||||
}
|
||||
|
||||
inner class ArgumentConsistencyValidator : FacetEditorValidator() {
|
||||
override fun check(): ValidationResult {
|
||||
val platformKind = editor.targetPlatformComboBox.selectedItem as IdePlatformKind<*>? ?: return ValidationResult.OK
|
||||
val primaryArguments = platformKind.defaultPlatform.createArguments().apply {
|
||||
val platform = editor.targetPlatformComboBox.selectedItem as IdePlatform<*, *>? ?: return ValidationResult.OK
|
||||
val primaryArguments = platform.createArguments().apply {
|
||||
editor.compilerConfigurable.applyTo(
|
||||
this,
|
||||
this as? K2JVMCompilerArguments ?: K2JVMCompilerArguments(),
|
||||
@@ -166,9 +167,9 @@ class KotlinFacetEditorGeneralTab(
|
||||
}
|
||||
val emptyArguments = argumentClass.newInstance()
|
||||
val fieldNamesToCheck = when {
|
||||
platformKind.isJvm -> jvmUIExposedFields
|
||||
platformKind.isJavaScript -> jsUIExposedFields
|
||||
platformKind.isCommon -> metadataUIExposedFields
|
||||
platform.isJvm -> jvmUIExposedFields
|
||||
platform.isJavaScript -> jsUIExposedFields
|
||||
platform.isCommon -> metadataUIExposedFields
|
||||
else -> commonUIExposedFields
|
||||
}
|
||||
|
||||
@@ -285,14 +286,14 @@ class KotlinFacetEditorGeneralTab(
|
||||
editor.compilerConfigurable.apply()
|
||||
with(configuration.settings) {
|
||||
useProjectSettings = editor.useProjectSettingsCheckBox.isSelected
|
||||
(editor.targetPlatformComboBox.selectedItem as IdePlatformKind<*>?)?.let {
|
||||
(editor.targetPlatformComboBox.selectedItem as IdePlatform<*, *>?)?.let {
|
||||
if (it != platform) {
|
||||
val platformArguments = when {
|
||||
it.isJvm -> editor.compilerConfigurable.k2jvmCompilerArguments
|
||||
it.isJavaScript -> editor.compilerConfigurable.k2jsCompilerArguments
|
||||
else -> null
|
||||
}
|
||||
compilerArguments = it.defaultPlatform.createArguments {
|
||||
compilerArguments = it.createArguments {
|
||||
if (platformArguments != null) {
|
||||
mergeBeans(platformArguments, this)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user