Kotlin Facet: Combine "General" and "Compiler" tabs
This commit is contained in:
+25
-23
@@ -120,20 +120,14 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co
|
||||
this.k2jvmCompilerArguments = k2jvmCompilerArguments;
|
||||
this.isProjectSettings = isProjectSettings;
|
||||
|
||||
if (isProjectSettings) {
|
||||
languageVersionComboBox.addActionListener(
|
||||
new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
restrictAPIVersions();
|
||||
}
|
||||
languageVersionComboBox.addActionListener(
|
||||
new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
restrictAPIVersions();
|
||||
}
|
||||
);
|
||||
}
|
||||
else {
|
||||
languageVersionPanel.setVisible(false);
|
||||
apiVersionPanel.setVisible(false);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
additionalArgsOptionsField.attachLabel(additionalArgsLabel);
|
||||
|
||||
@@ -298,8 +292,8 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co
|
||||
@Override
|
||||
public boolean isModified() {
|
||||
return ComparingUtils.isModified(generateNoWarningsCheckBox, commonCompilerArguments.suppressWarnings) ||
|
||||
(isProjectSettings && !getSelectedLanguageVersion().equals(getLanguageVersionOrDefault(commonCompilerArguments.languageVersion))) ||
|
||||
(isProjectSettings && !getSelectedAPIVersion().equals(getLanguageVersionOrDefault(commonCompilerArguments.apiVersion))) ||
|
||||
!getSelectedLanguageVersion().equals(getLanguageVersionOrDefault(commonCompilerArguments.languageVersion)) ||
|
||||
!getSelectedAPIVersion().equals(getLanguageVersionOrDefault(commonCompilerArguments.apiVersion)) ||
|
||||
!coroutineSupportComboBox.getSelectedItem().equals(CoroutineSupport.byCompilerArguments(commonCompilerArguments)) ||
|
||||
ComparingUtils.isModified(additionalArgsOptionsField, compilerSettings.additionalArguments) ||
|
||||
ComparingUtils.isModified(scriptTemplatesField, compilerSettings.scriptTemplates) ||
|
||||
@@ -340,14 +334,12 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co
|
||||
|
||||
@Override
|
||||
public void apply() throws ConfigurationException {
|
||||
commonCompilerArguments.suppressWarnings = generateNoWarningsCheckBox.isSelected();
|
||||
if (isProjectSettings) {
|
||||
boolean shouldInvalidateCaches =
|
||||
commonCompilerArguments.languageVersion != getSelectedLanguageVersion() ||
|
||||
commonCompilerArguments.apiVersion != getSelectedAPIVersion() ||
|
||||
!coroutineSupportComboBox.getSelectedItem().equals(CoroutineSupport.byCompilerArguments(commonCompilerArguments));
|
||||
commonCompilerArguments.languageVersion = getSelectedLanguageVersion();
|
||||
commonCompilerArguments.apiVersion = getSelectedAPIVersion();
|
||||
|
||||
if (shouldInvalidateCaches) {
|
||||
ApplicationUtilsKt.runWriteAction(
|
||||
new Function0<Object>() {
|
||||
@@ -360,6 +352,10 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
commonCompilerArguments.suppressWarnings = generateNoWarningsCheckBox.isSelected();
|
||||
commonCompilerArguments.languageVersion = getSelectedLanguageVersion();
|
||||
commonCompilerArguments.apiVersion = getSelectedAPIVersion();
|
||||
CoroutineSupport coroutineSupport = (CoroutineSupport) coroutineSupportComboBox.getSelectedItem();
|
||||
commonCompilerArguments.coroutinesEnable = coroutineSupport == CoroutineSupport.ENABLED;
|
||||
commonCompilerArguments.coroutinesWarn = coroutineSupport == CoroutineSupport.ENABLED_WITH_WARNING;
|
||||
@@ -395,11 +391,9 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co
|
||||
@Override
|
||||
public void reset() {
|
||||
generateNoWarningsCheckBox.setSelected(commonCompilerArguments.suppressWarnings);
|
||||
if (isProjectSettings) {
|
||||
languageVersionComboBox.setSelectedItem(getLanguageVersionOrDefault(commonCompilerArguments.languageVersion));
|
||||
apiVersionComboBox.setSelectedItem(getLanguageVersionOrDefault(commonCompilerArguments.apiVersion));
|
||||
restrictAPIVersions();
|
||||
}
|
||||
languageVersionComboBox.setSelectedItem(getLanguageVersionOrDefault(commonCompilerArguments.languageVersion));
|
||||
apiVersionComboBox.setSelectedItem(getLanguageVersionOrDefault(commonCompilerArguments.apiVersion));
|
||||
restrictAPIVersions();
|
||||
coroutineSupportComboBox.setSelectedItem(CoroutineSupport.byCompilerArguments(commonCompilerArguments));
|
||||
additionalArgsOptionsField.setText(compilerSettings.additionalArguments);
|
||||
scriptTemplatesField.setText(compilerSettings.scriptTemplates);
|
||||
@@ -442,4 +436,12 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co
|
||||
public JPanel getContentPane() {
|
||||
return contentPane;
|
||||
}
|
||||
|
||||
public JComboBox getLanguageVersionComboBox() {
|
||||
return languageVersionComboBox;
|
||||
}
|
||||
|
||||
public JComboBox getApiVersionComboBox() {
|
||||
return apiVersionComboBox;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,9 +60,7 @@ class KotlinFacetConfiguration : FacetConfiguration {
|
||||
): Array<FacetEditorTab> {
|
||||
settings.initializeIfNeeded(editorContext.module, editorContext.rootModel)
|
||||
|
||||
val compilerTab = KotlinFacetEditorCompilerTab(settings.compilerInfo, editorContext)
|
||||
val generalTab = KotlinFacetEditorGeneralTab(this, editorContext, validatorsManager, compilerTab)
|
||||
val tabs = arrayListOf(generalTab, compilerTab)
|
||||
val tabs = arrayListOf<FacetEditorTab>(KotlinFacetEditorGeneralTab(this, editorContext, validatorsManager))
|
||||
KotlinFacetConfigurationExtension.EP_NAME.extensions.flatMapTo(tabs) { it.createEditorTabs(editorContext, validatorsManager) }
|
||||
return tabs.toTypedArray()
|
||||
}
|
||||
|
||||
@@ -1,49 +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.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(
|
||||
compilerInfo: KotlinCompilerInfo,
|
||||
editorContext: FacetEditorContext
|
||||
) : FacetEditorTab() {
|
||||
val compilerConfigurable = KotlinCompilerConfigurableTab(
|
||||
editorContext.project,
|
||||
compilerInfo.commonCompilerArguments,
|
||||
compilerInfo.k2jsCompilerArguments,
|
||||
compilerInfo.compilerSettings,
|
||||
null,
|
||||
null,
|
||||
false
|
||||
)
|
||||
|
||||
override fun apply() = compilerConfigurable.apply()
|
||||
|
||||
override fun getDisplayName() = "Compiler"
|
||||
|
||||
override fun createComponent() = compilerConfigurable.createComponent()!!
|
||||
|
||||
override fun disposeUIResources() = compilerConfigurable.disposeUIResources()
|
||||
|
||||
override fun isModified() = compilerConfigurable.isModified
|
||||
|
||||
override fun reset() = compilerConfigurable.reset()
|
||||
}
|
||||
@@ -23,19 +23,21 @@ import com.intellij.util.ui.FormBuilder
|
||||
import com.intellij.util.ui.UIUtil
|
||||
import org.jetbrains.kotlin.config.LanguageVersion
|
||||
import org.jetbrains.kotlin.config.TargetPlatformKind
|
||||
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCompilerConfigurableTab
|
||||
import java.awt.BorderLayout
|
||||
import javax.swing.*
|
||||
|
||||
class KotlinFacetEditorGeneralTab(
|
||||
private val configuration: KotlinFacetConfiguration,
|
||||
private val editorContext: FacetEditorContext,
|
||||
validatorsManager: FacetValidatorsManager,
|
||||
private val compilerTab: KotlinFacetEditorCompilerTab
|
||||
validatorsManager: FacetValidatorsManager
|
||||
) : FacetEditorTab() {
|
||||
inner class VersionValidator : FacetEditorValidator() {
|
||||
override fun check(): ValidationResult {
|
||||
val apiLevel = apiVersionComboBox.selectedItem as? LanguageVersion? ?: return ValidationResult.OK
|
||||
val languageLevel = languageVersionComboBox.selectedItem as? LanguageVersion? ?: return ValidationResult.OK
|
||||
val apiLevel = compilerConfigurable.apiVersionComboBox.selectedItem as? LanguageVersion?
|
||||
?: return ValidationResult.OK
|
||||
val languageLevel = compilerConfigurable.languageVersionComboBox.selectedItem as? LanguageVersion?
|
||||
?: return ValidationResult.OK
|
||||
val targetPlatform = targetPlatformComboBox.selectedItem as TargetPlatformKind<*>?
|
||||
val libraryLevel = getLibraryLanguageLevel(editorContext.module, editorContext.rootModel, targetPlatform)
|
||||
if (languageLevel < apiLevel || libraryLevel < apiLevel) {
|
||||
@@ -45,18 +47,20 @@ class KotlinFacetEditorGeneralTab(
|
||||
}
|
||||
}
|
||||
|
||||
private val compilerConfigurable = with(configuration.settings.compilerInfo) {
|
||||
KotlinCompilerConfigurableTab(
|
||||
editorContext.project,
|
||||
commonCompilerArguments,
|
||||
k2jsCompilerArguments,
|
||||
compilerSettings,
|
||||
null,
|
||||
null,
|
||||
false
|
||||
)
|
||||
}
|
||||
|
||||
private val useProjectSettingsCheckBox = JCheckBox("Use project settings")
|
||||
|
||||
private val languageVersionComboBox =
|
||||
JComboBox<LanguageVersion>(LanguageVersion.values()).apply {
|
||||
setRenderer(DescriptionListCellRenderer())
|
||||
}
|
||||
|
||||
private val apiVersionComboBox =
|
||||
JComboBox<LanguageVersion>(LanguageVersion.values()).apply {
|
||||
setRenderer(DescriptionListCellRenderer())
|
||||
}
|
||||
|
||||
private val targetPlatformComboBox =
|
||||
JComboBox<TargetPlatformKind<*>>(TargetPlatformKind.ALL_PLATFORMS.toTypedArray()).apply {
|
||||
setRenderer(DescriptionListCellRenderer())
|
||||
@@ -76,105 +80,71 @@ class KotlinFacetEditorGeneralTab(
|
||||
validatorsManager.registerValidator(versionValidator)
|
||||
|
||||
useProjectSettingsCheckBox.addActionListener {
|
||||
useProjectSettingsChanged()
|
||||
updateCompilerConfigurable()
|
||||
}
|
||||
|
||||
languageVersionComboBox.addActionListener {
|
||||
compilerConfigurable.languageVersionComboBox.addActionListener {
|
||||
validatorsManager.validate()
|
||||
restrictAPIVersions()
|
||||
}
|
||||
|
||||
apiVersionComboBox.addActionListener {
|
||||
compilerConfigurable.apiVersionComboBox.addActionListener {
|
||||
validatorsManager.validate()
|
||||
}
|
||||
|
||||
targetPlatformComboBox.addActionListener {
|
||||
validatorsManager.validate()
|
||||
updateCompilerTab()
|
||||
updateCompilerConfigurable()
|
||||
}
|
||||
|
||||
updateCompilerTab()
|
||||
updateCompilerConfigurable()
|
||||
|
||||
reset()
|
||||
}
|
||||
|
||||
private fun restrictAPIVersions() {
|
||||
val selectedLanguageVersion = languageVersionComboBox.selectedItem as LanguageVersion? ?: return
|
||||
val selectedAPIVersion = apiVersionComboBox.selectedItem as LanguageVersion?
|
||||
val permittedAPIVersions = LanguageVersion.values().filter { it <= selectedLanguageVersion }
|
||||
apiVersionComboBox.model = DefaultComboBoxModel<LanguageVersion>(permittedAPIVersions.toTypedArray())
|
||||
apiVersionComboBox.selectedItem = if (selectedAPIVersion != null && selectedAPIVersion > selectedLanguageVersion) {
|
||||
selectedLanguageVersion
|
||||
}
|
||||
else {
|
||||
selectedAPIVersion
|
||||
}
|
||||
}
|
||||
|
||||
private fun useProjectSettingsChanged() {
|
||||
val useModuleSpecific = !useProjectSettingsCheckBox.isSelected
|
||||
languageVersionComboBox.isEnabled = useModuleSpecific
|
||||
apiVersionComboBox.isEnabled = useModuleSpecific
|
||||
|
||||
updateCompilerTab()
|
||||
}
|
||||
|
||||
private fun updateCompilerTab() {
|
||||
compilerTab.compilerConfigurable.setTargetPlatform(chosenPlatform)
|
||||
UIUtil.setEnabled(compilerTab.compilerConfigurable.contentPane, !useProjectSettingsCheckBox.isSelected, true)
|
||||
private fun updateCompilerConfigurable() {
|
||||
compilerConfigurable.setTargetPlatform(chosenPlatform)
|
||||
UIUtil.setEnabled(compilerConfigurable.contentPane, !useProjectSettingsCheckBox.isSelected, true)
|
||||
}
|
||||
|
||||
override fun isModified(): Boolean {
|
||||
if (useProjectSettingsCheckBox.isSelected != configuration.settings.useProjectSettings) return true
|
||||
|
||||
return with(configuration.settings.versionInfo) {
|
||||
if (useProjectSettingsCheckBox.isSelected) return targetPlatformComboBox.selectedItem != targetPlatformKind
|
||||
|
||||
languageVersionComboBox.selectedItem != languageLevel
|
||||
|| targetPlatformComboBox.selectedItem != targetPlatformKind
|
||||
|| apiVersionComboBox.selectedItem != apiLevel
|
||||
}
|
||||
if (targetPlatformComboBox.selectedItem != configuration.settings.versionInfo.targetPlatformKind) return true
|
||||
return !useProjectSettingsCheckBox.isSelected && compilerConfigurable.isModified
|
||||
}
|
||||
|
||||
override fun reset() {
|
||||
useProjectSettingsCheckBox.isSelected = configuration.settings.useProjectSettings
|
||||
with(configuration.settings.versionInfo) {
|
||||
languageVersionComboBox.selectedItem = languageLevel
|
||||
apiVersionComboBox.selectedItem = apiLevel
|
||||
targetPlatformComboBox.selectedItem = targetPlatformKind
|
||||
restrictAPIVersions()
|
||||
}
|
||||
useProjectSettingsChanged()
|
||||
targetPlatformComboBox.selectedItem = configuration.settings.versionInfo.targetPlatformKind
|
||||
compilerConfigurable.reset()
|
||||
updateCompilerConfigurable()
|
||||
}
|
||||
|
||||
override fun apply() {
|
||||
configuration.settings.useProjectSettings = useProjectSettingsCheckBox.isSelected
|
||||
with(configuration.settings.versionInfo) {
|
||||
if (!useProjectSettingsCheckBox.isSelected) {
|
||||
languageLevel = languageVersionComboBox.selectedItem as LanguageVersion?
|
||||
apiLevel = apiVersionComboBox.selectedItem as LanguageVersion?
|
||||
}
|
||||
targetPlatformKind = targetPlatformComboBox.selectedItem as TargetPlatformKind<*>?
|
||||
compilerConfigurable.apply()
|
||||
with(configuration.settings) {
|
||||
useProjectSettings = useProjectSettingsCheckBox.isSelected
|
||||
versionInfo.targetPlatformKind = targetPlatformComboBox.selectedItem as TargetPlatformKind<*>?
|
||||
versionInfo.languageLevel = LanguageVersion.fromVersionString(compilerInfo.commonCompilerArguments?.languageVersion)
|
||||
versionInfo.apiLevel = LanguageVersion.fromVersionString(compilerInfo.commonCompilerArguments?.apiVersion)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getDisplayName() = "General"
|
||||
|
||||
override fun createComponent(): JComponent {
|
||||
val mainPanel = JPanel(BorderLayout())
|
||||
val contentPanel = FormBuilder
|
||||
.createFormBuilder()
|
||||
.addComponent(useProjectSettingsCheckBox)
|
||||
.addLabeledComponent("&Language version: ", languageVersionComboBox)
|
||||
.addLabeledComponent("&Standard library API version: ", apiVersionComboBox)
|
||||
.addLabeledComponent("&Target platform: ", targetPlatformComboBox)
|
||||
.panel
|
||||
val mainPanel = JPanel(BorderLayout())
|
||||
val contentPanel = FormBuilder
|
||||
.createFormBuilder()
|
||||
.addComponent(useProjectSettingsCheckBox)
|
||||
.addLabeledComponent("&Target platform: ", targetPlatformComboBox)
|
||||
.addComponent(compilerConfigurable.createComponent()!!)
|
||||
.panel
|
||||
mainPanel.add(contentPanel, BorderLayout.NORTH)
|
||||
return mainPanel
|
||||
}
|
||||
|
||||
override fun disposeUIResources() {
|
||||
|
||||
compilerConfigurable.disposeUIResources()
|
||||
}
|
||||
|
||||
val chosenPlatform: TargetPlatformKind<*>?
|
||||
|
||||
Reference in New Issue
Block a user