KT-36801 IDE: Unsupported language version values

This commit is contained in:
Andrei Klunnyi
2020-06-18 15:04:10 +02:00
parent 2b2fce5949
commit 558dfc6d9a
3 changed files with 43 additions and 8 deletions
@@ -738,6 +738,8 @@ configuration.title.outdated.bundled.kotlin.compiler=Outdated Bundled Kotlin Com
configuration.title.stable=Stable
configuration.warning.text.following.modules.override.project.settings=Following modules override project settings:
configuration.warning.text.modules.override.project.settings={0} modules override project settings
configuration.warning.text.language.version.unsupported=Language version {0} is no longer supported
configuration.warning.text.api.version.unsupported=API version {0} is no longer supported
#Refactoring
0.1.is.never.used={0} ''{1}'' is never used
@@ -299,7 +299,7 @@
<text resource-bundle="messages/KotlinBundle" key="language.version"/>
</properties>
</component>
<component id="d931b" class="javax.swing.JComboBox" binding="languageVersionComboBox">
<component id="d931b" class="javax.swing.JComboBox" binding="languageVersionComboBox" custom-create="true">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
@@ -323,7 +323,7 @@
<text resource-bundle="messages/KotlinBundle" key="api.version"/>
</properties>
</component>
<component id="ab3e4" class="javax.swing.JComboBox" binding="apiVersionComboBox">
<component id="ab3e4" class="javax.swing.JComboBox" binding="apiVersionComboBox" custom-create="true">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
@@ -12,8 +12,8 @@ import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.SearchableConfigurable;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.TextComponentAccessor;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.intellij.openapi.ui.*;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.ui.ListCellRendererWrapper;
import com.intellij.ui.RawCommandLineEditor;
@@ -49,6 +49,7 @@ import org.jetbrains.kotlin.platform.jvm.JdkPlatform;
import javax.swing.*;
import java.util.*;
import java.util.List;
public class KotlinCompilerConfigurableTab implements SearchableConfigurable {
private static final Map<String, String> moduleKindDescriptions = new LinkedHashMap<>();
@@ -324,7 +325,8 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable {
return VersionComparatorUtil.compare(version.getVersionString(), upperBound.getVersionString()) <= 0;
}
public void onLanguageLevelChanged(VersionView languageLevel) {
public void onLanguageLevelChanged(@Nullable VersionView languageLevel) {
if (languageLevel == null) return;
restrictAPIVersions(languageLevel);
coroutinesPanel.setVisible(languageLevel.getVersion().compareTo(LanguageVersion.KOTLIN_1_3) < 0);
}
@@ -587,9 +589,9 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable {
@Override
public void reset() {
reportWarningsCheckBox.setSelected(!commonCompilerArguments.getSuppressWarnings());
languageVersionComboBox.setSelectedItem(KotlinFacetSettingsKt.getLanguageVersionView(commonCompilerArguments));
onLanguageLevelChanged(getSelectedLanguageVersionView());
apiVersionComboBox.setSelectedItem(KotlinFacetSettingsKt.getApiVersionView(commonCompilerArguments));
setSelectedItem(languageVersionComboBox, KotlinFacetSettingsKt.getLanguageVersionView(commonCompilerArguments));
onLanguageLevelChanged((VersionView) languageVersionComboBox.getSelectedItem()); // getSelectedLanguageVersionView() replaces null
setSelectedItem(apiVersionComboBox, KotlinFacetSettingsKt.getApiVersionView(commonCompilerArguments));
coroutineSupportComboBox.setSelectedItem(CoroutineSupport.byCompilerArguments(commonCompilerArguments));
additionalArgsOptionsField.setText(compilerSettings.getAdditionalArguments());
scriptTemplatesField.setText(compilerSettings.getScriptTemplates());
@@ -615,6 +617,15 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable {
jvmVersionComboBox.setSelectedItem(getJvmVersionOrDefault(k2jvmCompilerArguments.getJvmTarget()));
}
private static void setSelectedItem(JComboBox<VersionView> comboBox, VersionView versionView) {
// Imported projects might have outdated language/api versions - we display them as well (see createVersionValidator() for details)
int index = ((DefaultComboBoxModel<VersionView>) comboBox.getModel()).getIndexOf(versionView);
if (index == -1)
comboBox.addItem(versionView);
comboBox.setSelectedItem(versionView);
}
@Override
public void disposeUIResources() {
}
@@ -729,6 +740,13 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable {
}
private void createUIComponents() {
// Explicit use of DefaultComboBoxModel guarantees that setSelectedItem() can make safe cast.
languageVersionComboBox = new ComboBox<>(new DefaultComboBoxModel<>());
apiVersionComboBox = new ComboBox<>(new DefaultComboBoxModel<>());
createVersionValidator(languageVersionComboBox, "configuration.warning.text.language.version.unsupported");
createVersionValidator(apiVersionComboBox, "configuration.warning.text.api.version.unsupported");
// Workaround: ThreeStateCheckBox doesn't send suitable notification on state change
// TODO: replace with PropertyChangerListener after fix is available in IDEA
copyRuntimeFilesCheckBox = new ThreeStateCheckBox() {
@@ -739,4 +757,19 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable {
}
};
}
private static void createVersionValidator(JComboBox<VersionView> component, String messageKey) {
new ComponentValidator(Disposer.newDisposable())
.withValidator(() -> {
VersionView selectedItem = (VersionView) component.getSelectedItem();
if (selectedItem == null) return null;
LanguageVersion version = selectedItem.getVersion();
if (version.isUnsupported())
return new ValidationInfo(KotlinBundle.message(messageKey, version.getVersionString()), component);
return null;
}).installOn(component);
component.addActionListener(e -> ComponentValidator.getInstance(component).ifPresent(ComponentValidator::revalidate));
}
}