diff --git a/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/CommonArgumentConstants.java b/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/CommonArgumentConstants.java new file mode 100644 index 00000000000..6f7d85b7ba4 --- /dev/null +++ b/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/CommonArgumentConstants.java @@ -0,0 +1,21 @@ +/* + * Copyright 2010-2013 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.jet.cli.common.arguments; + +public interface CommonArgumentConstants { + String SUPPRESS_WARNINGS = "warnings"; +} diff --git a/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/CommonCompilerArguments.java b/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/CommonCompilerArguments.java index c962a6c486d..7f51e11473c 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/CommonCompilerArguments.java +++ b/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/CommonCompilerArguments.java @@ -18,7 +18,11 @@ package org.jetbrains.jet.cli.common.arguments; import com.sampullara.cli.Argument; +import static org.jetbrains.jet.cli.common.arguments.CommonArgumentConstants.SUPPRESS_WARNINGS; + public abstract class CommonCompilerArguments extends CompilerArguments { + public static final CommonCompilerArguments DUMMY = new DummyImpl(); + @Argument(value = "tags", description = "Demarcate each compilation message (error, warning, etc) with an open and close tag") public boolean tags; @Argument(value = "verbose", description = "Enable verbose logging output") @@ -60,6 +64,14 @@ public abstract class CommonCompilerArguments extends CompilerArguments { @Override public boolean suppressAllWarnings() { - return "warnings".equalsIgnoreCase(suppress); + return SUPPRESS_WARNINGS.equalsIgnoreCase(suppress); + } + + // Used only for serialize and deserialize settings. Don't use in other places! + public static final class DummyImpl extends CommonCompilerArguments { + @Override + public String getSrc() { + return null; + } } } diff --git a/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/K2JSCompilerArguments.java b/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/K2JSCompilerArguments.java index 9ee26bbf5fd..b251305761e 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/K2JSCompilerArguments.java +++ b/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/K2JSCompilerArguments.java @@ -19,6 +19,9 @@ package org.jetbrains.jet.cli.common.arguments; import com.sampullara.cli.Argument; import org.jetbrains.annotations.Nullable; +import static org.jetbrains.jet.cli.common.arguments.K2JsArgumentConstants.CALL; +import static org.jetbrains.jet.cli.common.arguments.K2JsArgumentConstants.NO_CALL; + /** * NOTE: for now K2JSCompiler supports only minimal amount of parameters required to launch it from the plugin. */ @@ -39,7 +42,8 @@ public class K2JSCompilerArguments extends CommonCompilerArguments { public String target; @Nullable - @Argument(value = "main", description = "Whether a main function should be called; either 'call' or 'noCall', default 'call' (main function will be auto detected)") + @Argument(value = "main", description = "Whether a main function should be called; either '" + CALL + + "' or '" + NO_CALL + "', default '" + CALL + "' (main function will be auto detected)") public String main; @Override diff --git a/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/K2JsArgumentConstants.java b/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/K2JsArgumentConstants.java new file mode 100644 index 00000000000..a36419d0715 --- /dev/null +++ b/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/K2JsArgumentConstants.java @@ -0,0 +1,22 @@ +/* + * Copyright 2010-2013 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.jet.cli.common.arguments; + +public interface K2JsArgumentConstants { + String CALL = "call"; + String NO_CALL = "noCall"; +} diff --git a/compiler/cli/src/org/jetbrains/jet/cli/js/K2JSCompiler.java b/compiler/cli/src/org/jetbrains/jet/cli/js/K2JSCompiler.java index 4f2a73f0244..db7500831f2 100644 --- a/compiler/cli/src/org/jetbrains/jet/cli/js/K2JSCompiler.java +++ b/compiler/cli/src/org/jetbrains/jet/cli/js/K2JSCompiler.java @@ -32,6 +32,7 @@ import org.jetbrains.jet.analyzer.AnalyzeExhaust; import org.jetbrains.jet.cli.common.CLICompiler; import org.jetbrains.jet.cli.common.ExitCode; import org.jetbrains.jet.cli.common.arguments.K2JSCompilerArguments; +import org.jetbrains.jet.cli.common.arguments.K2JsArgumentConstants; import org.jetbrains.jet.cli.common.messages.AnalyzerWithCompilerReport; import org.jetbrains.jet.cli.common.messages.CompilerMessageLocation; import org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity; @@ -170,7 +171,7 @@ public class K2JSCompiler extends CLICompiler { } public static MainCallParameters createMainCallParameters(String main) { - if ("noCall".equals(main)) { + if (K2JsArgumentConstants.NO_CALL.equals(main)) { return MainCallParameters.noCall(); } else { diff --git a/ide-compiler-runner/src/org/jetbrains/jet/compiler/SettingConstants.java b/ide-compiler-runner/src/org/jetbrains/jet/compiler/SettingConstants.java new file mode 100644 index 00000000000..2e30058cdaa --- /dev/null +++ b/ide-compiler-runner/src/org/jetbrains/jet/compiler/SettingConstants.java @@ -0,0 +1,30 @@ +/* + * Copyright 2010-2013 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.jet.compiler; + +import static com.intellij.openapi.components.StoragePathMacros.PROJECT_CONFIG_DIR; + +public class SettingConstants { + private SettingConstants() {} + + public static final String KOTLIN_COMMON_COMPILER_SETTINGS_SECTION = "KotlinCommonCompilerSettings"; + public static final String KOTLIN_TO_JS_COMPILER_SETTINGS_SECTION = "Kotlin2JsCompilerSettings"; + public static final String KOTLIN_TO_JVM_COMPILER_SETTINGS_SECTION = "Kotlin2JvmCompilerSettings"; + + public static final String KOTLIN_COMPILER_SETTINGS_FILE = "kotlinc.xml"; + public static final String KOTLIN_COMPILER_SETTINGS_PATH = PROJECT_CONFIG_DIR + "/" + KOTLIN_COMPILER_SETTINGS_FILE; +} diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index 2580c46deab..8eaeb45628b 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -116,6 +116,15 @@ + + + + + + diff --git a/idea/src/org/jetbrains/jet/plugin/compiler/configuration/BaseKotlinCompilerSettings.java b/idea/src/org/jetbrains/jet/plugin/compiler/configuration/BaseKotlinCompilerSettings.java new file mode 100644 index 00000000000..87ae0a0cc05 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/compiler/configuration/BaseKotlinCompilerSettings.java @@ -0,0 +1,71 @@ +/* + * Copyright 2010-2013 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.jet.plugin.compiler.configuration; + +import com.intellij.openapi.components.PersistentStateComponent; +import com.intellij.util.xmlb.SkipDefaultValuesSerializationFilters; +import com.intellij.util.xmlb.XmlSerializer; +import org.jdom.Element; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.cli.common.arguments.CommonCompilerArguments; + +public abstract class BaseKotlinCompilerSettings implements PersistentStateComponent { + + private static final SkipDefaultValuesSerializationFilters SKIP_DEFAULT_VALUES = new SkipDefaultValuesSerializationFilters(); + + protected BaseKotlinCompilerSettings() { + //noinspection AbstractMethodCallInConstructor + this.settings = createSettings(); + } + + @NotNull + private T settings; + + @NotNull + public T getSettings() { + return settings; + } + + @NotNull + protected abstract T createSettings(); + + @Override + public Element getState() { + return XmlSerializer.serialize(settings, SKIP_DEFAULT_VALUES); + } + + @Override + public void loadState(Element state) { + //noinspection unchecked + T newSettings = (T) XmlSerializer.deserialize(state, settings.getClass()); + if (newSettings == null) + newSettings = createSettings(); + + settings = newSettings; + } + + @Override + @Nullable + public Object clone() { + try { + return super.clone(); + } catch (CloneNotSupportedException e) { + return null; + } + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/compiler/configuration/Kotlin2JsCompilerSettings.java b/idea/src/org/jetbrains/jet/plugin/compiler/configuration/Kotlin2JsCompilerSettings.java new file mode 100644 index 00000000000..57435be338d --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/compiler/configuration/Kotlin2JsCompilerSettings.java @@ -0,0 +1,45 @@ +/* + * Copyright 2010-2013 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.jet.plugin.compiler.configuration; + +import com.intellij.openapi.components.*; +import com.intellij.openapi.project.Project; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.cli.common.arguments.K2JSCompilerArguments; + +import static org.jetbrains.jet.compiler.SettingConstants.KOTLIN_COMPILER_SETTINGS_PATH; +import static org.jetbrains.jet.compiler.SettingConstants.KOTLIN_TO_JS_COMPILER_SETTINGS_SECTION; + +@State( + name = KOTLIN_TO_JS_COMPILER_SETTINGS_SECTION, + storages = { + @Storage(file = StoragePathMacros.PROJECT_FILE), + @Storage(file = KOTLIN_COMPILER_SETTINGS_PATH, scheme = StorageScheme.DIRECTORY_BASED) + } +) +public class Kotlin2JsCompilerSettings extends BaseKotlinCompilerSettings { + + @NotNull + @Override + protected K2JSCompilerArguments createSettings() { + return new K2JSCompilerArguments(); + } + + public static Kotlin2JsCompilerSettings getInstance(Project project) { + return ServiceManager.getService(project, Kotlin2JsCompilerSettings.class); + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/compiler/configuration/Kotlin2JvmCompilerSettings.java b/idea/src/org/jetbrains/jet/plugin/compiler/configuration/Kotlin2JvmCompilerSettings.java new file mode 100644 index 00000000000..bd741f9eeea --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/compiler/configuration/Kotlin2JvmCompilerSettings.java @@ -0,0 +1,45 @@ +/* + * Copyright 2010-2013 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.jet.plugin.compiler.configuration; + +import com.intellij.openapi.components.*; +import com.intellij.openapi.project.Project; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments; + +import static org.jetbrains.jet.compiler.SettingConstants.KOTLIN_COMPILER_SETTINGS_PATH; +import static org.jetbrains.jet.compiler.SettingConstants.KOTLIN_TO_JVM_COMPILER_SETTINGS_SECTION; + +@State( + name = KOTLIN_TO_JVM_COMPILER_SETTINGS_SECTION, + storages = { + @Storage(file = StoragePathMacros.PROJECT_FILE), + @Storage(file = KOTLIN_COMPILER_SETTINGS_PATH, scheme = StorageScheme.DIRECTORY_BASED) + } +) +public class Kotlin2JvmCompilerSettings extends BaseKotlinCompilerSettings { + + @NotNull + @Override + protected K2JVMCompilerArguments createSettings() { + return new K2JVMCompilerArguments(); + } + + public static Kotlin2JvmCompilerSettings getInstance(Project project) { + return ServiceManager.getService(project, Kotlin2JvmCompilerSettings.class); + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/compiler/configuration/KotlinCommonCompilerSettings.java b/idea/src/org/jetbrains/jet/plugin/compiler/configuration/KotlinCommonCompilerSettings.java new file mode 100644 index 00000000000..30e0a89e8c8 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/compiler/configuration/KotlinCommonCompilerSettings.java @@ -0,0 +1,45 @@ +/* + * Copyright 2010-2013 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.jet.plugin.compiler.configuration; + +import com.intellij.openapi.components.*; +import com.intellij.openapi.project.Project; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.cli.common.arguments.CommonCompilerArguments; + +import static org.jetbrains.jet.compiler.SettingConstants.KOTLIN_COMMON_COMPILER_SETTINGS_SECTION; +import static org.jetbrains.jet.compiler.SettingConstants.KOTLIN_COMPILER_SETTINGS_PATH; + +@State( + name = KOTLIN_COMMON_COMPILER_SETTINGS_SECTION, + storages = { + @Storage(file = StoragePathMacros.PROJECT_FILE), + @Storage(file = KOTLIN_COMPILER_SETTINGS_PATH, scheme = StorageScheme.DIRECTORY_BASED) + } +) +public class KotlinCommonCompilerSettings extends BaseKotlinCompilerSettings { + + @NotNull + @Override + protected CommonCompilerArguments createSettings() { + return CommonCompilerArguments.DUMMY; + } + + public static KotlinCommonCompilerSettings getInstance(Project project) { + return ServiceManager.getService(project, KotlinCommonCompilerSettings.class); + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/compiler/configuration/KotlinCompilerConfigurableTab.form b/idea/src/org/jetbrains/jet/plugin/compiler/configuration/KotlinCompilerConfigurableTab.form index 33d504de026..dc467bd9cf2 100644 --- a/idea/src/org/jetbrains/jet/plugin/compiler/configuration/KotlinCompilerConfigurableTab.form +++ b/idea/src/org/jetbrains/jet/plugin/compiler/configuration/KotlinCompilerConfigurableTab.form @@ -1,6 +1,6 @@
- + @@ -10,9 +10,18 @@ - + + + + + + + + + + diff --git a/idea/src/org/jetbrains/jet/plugin/compiler/configuration/KotlinCompilerConfigurableTab.java b/idea/src/org/jetbrains/jet/plugin/compiler/configuration/KotlinCompilerConfigurableTab.java index b677bf6f7d3..51b340e7ce2 100644 --- a/idea/src/org/jetbrains/jet/plugin/compiler/configuration/KotlinCompilerConfigurableTab.java +++ b/idea/src/org/jetbrains/jet/plugin/compiler/configuration/KotlinCompilerConfigurableTab.java @@ -16,19 +16,35 @@ package org.jetbrains.jet.plugin.compiler.configuration; +import com.intellij.compiler.options.ComparingUtils; import com.intellij.openapi.options.Configurable; import com.intellij.openapi.options.ConfigurableEP; import com.intellij.openapi.options.ConfigurationException; -import com.intellij.openapi.options.ex.ConfigurableWrapper; +import com.intellij.openapi.options.SearchableConfigurable; +import org.jetbrains.annotations.Nls; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.cli.common.arguments.CommonCompilerArguments; import javax.swing.*; -public class KotlinCompilerConfigurableTab extends ConfigurableWrapper implements Configurable.NoScroll { +import static org.jetbrains.jet.cli.common.arguments.CommonArgumentConstants.SUPPRESS_WARNINGS; + +public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Configurable.NoScroll{ + private final CommonCompilerArguments commonCompilerSettings; + private final ConfigurableEP extPoint; private JPanel contentPane; + private JCheckBox generateNoWarningsCheckBox; public KotlinCompilerConfigurableTab(ConfigurableEP ep) { - super(ep); + this.extPoint = ep; + this.commonCompilerSettings = KotlinCommonCompilerSettings.getInstance(ep.getProject()).getSettings(); + } + + @NotNull + @Override + public String getId() { + return extPoint.id; } @Nullable @@ -45,16 +61,40 @@ public class KotlinCompilerConfigurableTab extends ConfigurableWrapper implement @Override public boolean isModified() { - return false; + return ComparingUtils.isModified(generateNoWarningsCheckBox, isGenerateNoWarnings()); } @Override public void apply() throws ConfigurationException { - // TODO: Do something + setGenerateNoWarnings(generateNoWarningsCheckBox.isSelected()); } @Override public void reset() { - // TODO: Do something + generateNoWarningsCheckBox.setSelected(isGenerateNoWarnings()); + } + + @Override + public void disposeUIResources() { + } + + @Nls + @Override + public String getDisplayName() { + return extPoint.displayName; + } + + @Nullable + @Override + public String getHelpTopic() { + return null; + } + + private boolean isGenerateNoWarnings() { + return SUPPRESS_WARNINGS.equals(commonCompilerSettings.suppress); + } + + private void setGenerateNoWarnings(boolean selected) { + commonCompilerSettings.suppress = selected ? SUPPRESS_WARNINGS : ""; } }