From 21c6e97731fd94c087a6c96f3a78598fa8d0ac2e Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Tue, 22 Nov 2016 11:48:15 +0300 Subject: [PATCH] Project Settings: Expose JVM target setting in IntelliJ IDEA plugin compiler configuration UI #KT-13811 Fixed --- ChangeLog.md | 2 + .../KotlinCompilerConfigurableTab.form | 20 +++++++++- .../KotlinCompilerConfigurableTab.java | 39 +++++++++++++++++-- .../facet/KotlinFacetEditorCompilerTab.kt | 1 + 4 files changed, 57 insertions(+), 5 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 17bb7d822f0..0411b49d26b 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -326,6 +326,8 @@ These artifacts include extensions for the types available in the latter JDKs, s ### IDE +- [`KT-13811`](https://youtrack.jetbrains.com/issue/KT-13811) Expose JVM target setting in IntelliJ IDEA plugin compiler configuration UI + #### Intention actions, inspections and quickfixes - [`KT-14569`](https://youtrack.jetbrains.com/issue/KT-14569) Convert Property to Function Intention: Search occurrences using progress dialog diff --git a/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerConfigurableTab.form b/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerConfigurableTab.form index 8fb8c165915..21a13c2aa44 100644 --- a/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerConfigurableTab.form +++ b/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerConfigurableTab.form @@ -92,7 +92,7 @@ - + @@ -105,14 +105,30 @@ + + + + + + + + + + - + + + + + + + diff --git a/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerConfigurableTab.java b/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerConfigurableTab.java index 40d586540eb..42e2c532cfe 100644 --- a/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerConfigurableTab.java +++ b/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerConfigurableTab.java @@ -34,8 +34,10 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments; import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments; +import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments; import org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants; import org.jetbrains.kotlin.config.CompilerSettings; +import org.jetbrains.kotlin.config.JvmTarget; import org.jetbrains.kotlin.config.TargetPlatformKind; import org.jetbrains.kotlin.idea.KotlinBundle; import org.jetbrains.kotlin.idea.PluginStartupComponent; @@ -50,6 +52,7 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co private static final Map moduleKindDescriptions = new LinkedHashMap(); private final CommonCompilerArguments commonCompilerArguments; private final K2JSCompilerArguments k2jsCompilerArguments; + private final K2JVMCompilerArguments k2jvmCompilerArguments; private final CompilerSettings compilerSettings; @Nullable private final KotlinCompilerWorkspaceSettings compilerWorkspaceSettings; @@ -75,6 +78,7 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co private JLabel scriptTemplatesClasspathLabel; private JPanel k2jvmPanel; private JPanel k2jsPanel; + private JComboBox jvmVersionComboBox; static { moduleKindDescriptions.put(K2JsArgumentConstants.MODULE_PLAIN, "Plain (put to global scope)"); @@ -88,13 +92,15 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co CommonCompilerArguments commonCompilerArguments, K2JSCompilerArguments k2jsCompilerArguments, CompilerSettings compilerSettings, - @Nullable KotlinCompilerWorkspaceSettings compilerWorkspaceSettings + @Nullable KotlinCompilerWorkspaceSettings compilerWorkspaceSettings, + @Nullable K2JVMCompilerArguments k2jvmCompilerArguments ) { this.project = project; this.commonCompilerArguments = commonCompilerArguments; this.k2jsCompilerArguments = k2jsCompilerArguments; this.compilerSettings = compilerSettings; this.compilerWorkspaceSettings = compilerWorkspaceSettings; + this.k2jvmCompilerArguments = k2jvmCompilerArguments; additionalArgsOptionsField.attachLabel(additionalArgsLabel); @@ -113,6 +119,7 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co }); fillModuleKindList(); + fillJvmVersionList(); if (compilerWorkspaceSettings == null) { keepAliveCheckBox.setVisible(false); @@ -120,6 +127,13 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co } } + @SuppressWarnings("unchecked") + private void fillJvmVersionList() { + for (TargetPlatformKind.Jvm jvm : TargetPlatformKind.Jvm.Companion.getJVM_PLATFORMS()) { + jvmVersionComboBox.addItem(jvm.getVersion().getDescription()); + } + } + public void setTargetPlatform(@Nullable TargetPlatformKind targetPlatform) { k2jsPanel.setVisible(TargetPlatformKind.JavaScript.INSTANCE.equals(targetPlatform)); } @@ -130,7 +144,8 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co KotlinCommonCompilerArgumentsHolder.getInstance(project).getSettings(), Kotlin2JsCompilerArgumentsHolder.getInstance(project).getSettings(), KotlinCompilerSettings.getInstance(project).getSettings(), - ServiceManager.getService(project, KotlinCompilerWorkspaceSettings.class)); + ServiceManager.getService(project, KotlinCompilerWorkspaceSettings.class), + Kotlin2JvmCompilerArgumentsHolder.getInstance(project).getSettings()); } @SuppressWarnings("unchecked") @@ -187,7 +202,8 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co ComparingUtils.isModified(generateSourceMapsCheckBox, k2jsCompilerArguments.sourceMap) || isModified(outputPrefixFile, k2jsCompilerArguments.outputPrefix) || isModified(outputPostfixFile, k2jsCompilerArguments.outputPostfix) || - !getSelectedModuleKind().equals(getModuleKindOrDefault(k2jsCompilerArguments.moduleKind)); + !getSelectedModuleKind().equals(getModuleKindOrDefault(k2jsCompilerArguments.moduleKind)) || + (k2jvmCompilerArguments != null && !getSelectedJvmVersion().equals(getJvmVersionOrDefault(k2jvmCompilerArguments.jvmTarget))); } @NotNull @@ -195,6 +211,11 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co return getModuleKindOrDefault((String) moduleKindComboBox.getSelectedItem()); } + @NotNull + private String getSelectedJvmVersion() { + return getJvmVersionOrDefault((String) jvmVersionComboBox.getSelectedItem()); + } + @Override public void apply() throws ConfigurationException { commonCompilerArguments.suppressWarnings = generateNoWarningsCheckBox.isSelected(); @@ -219,6 +240,10 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co k2jsCompilerArguments.outputPostfix = StringUtil.nullize(outputPostfixFile.getText(), true); k2jsCompilerArguments.moduleKind = getSelectedModuleKind(); + if (k2jvmCompilerArguments != null) { + k2jvmCompilerArguments.jvmTarget = getSelectedJvmVersion(); + } + BuildManager.getInstance().clearState(project); } @@ -230,6 +255,10 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co return moduleKindId; } + private static String getJvmVersionOrDefault(@Nullable String jvmVersion) { + return jvmVersion != null ? jvmVersion : JvmTarget.DEFAULT.getDescription(); + } + @Override public void reset() { generateNoWarningsCheckBox.setSelected(commonCompilerArguments.suppressWarnings); @@ -249,6 +278,10 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co outputPostfixFile.setText(k2jsCompilerArguments.outputPostfix); moduleKindComboBox.setSelectedItem(getModuleKindOrDefault(k2jsCompilerArguments.moduleKind)); + + if (k2jvmCompilerArguments != null) { + jvmVersionComboBox.setSelectedItem(getJvmVersionOrDefault(k2jvmCompilerArguments.jvmTarget)); + } } @Override diff --git a/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetEditorCompilerTab.kt b/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetEditorCompilerTab.kt index 7c159a88531..5a970fecf1a 100644 --- a/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetEditorCompilerTab.kt +++ b/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetEditorCompilerTab.kt @@ -30,6 +30,7 @@ class KotlinFacetEditorCompilerTab( compilerInfo.commonCompilerArguments, compilerInfo.k2jsCompilerArguments, compilerInfo.compilerSettings, + null, null )