IDEA: created a infrastructure for saving any compiler settings.
Added "generate no warnings" to Settings.
This commit is contained in:
+21
@@ -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";
|
||||
}
|
||||
+13
-1
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-1
@@ -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
|
||||
|
||||
+22
@@ -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";
|
||||
}
|
||||
@@ -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<K2JSCompilerArguments> {
|
||||
}
|
||||
|
||||
public static MainCallParameters createMainCallParameters(String main) {
|
||||
if ("noCall".equals(main)) {
|
||||
if (K2JsArgumentConstants.NO_CALL.equals(main)) {
|
||||
return MainCallParameters.noCall();
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -116,6 +116,15 @@
|
||||
<projectService serviceInterface="org.jetbrains.jet.plugin.configuration.ModuleTypeCacheManager"
|
||||
serviceImplementation="org.jetbrains.jet.plugin.configuration.ModuleTypeCacheManager"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.jet.plugin.compiler.configuration.KotlinCommonCompilerSettings"
|
||||
serviceImplementation="org.jetbrains.jet.plugin.compiler.configuration.KotlinCommonCompilerSettings"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.jet.plugin.compiler.configuration.Kotlin2JvmCompilerSettings"
|
||||
serviceImplementation="org.jetbrains.jet.plugin.compiler.configuration.Kotlin2JvmCompilerSettings"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.jet.plugin.compiler.configuration.Kotlin2JsCompilerSettings"
|
||||
serviceImplementation="org.jetbrains.jet.plugin.compiler.configuration.Kotlin2JsCompilerSettings"/>
|
||||
|
||||
<errorHandler implementation="org.jetbrains.jet.plugin.reporter.KotlinReportSubmitter"/>
|
||||
|
||||
<internalFileTemplate name="Kotlin File"/>
|
||||
|
||||
+71
@@ -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<T extends CommonCompilerArguments> implements PersistentStateComponent<Element> {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+45
@@ -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<K2JSCompilerArguments> {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected K2JSCompilerArguments createSettings() {
|
||||
return new K2JSCompilerArguments();
|
||||
}
|
||||
|
||||
public static Kotlin2JsCompilerSettings getInstance(Project project) {
|
||||
return ServiceManager.getService(project, Kotlin2JsCompilerSettings.class);
|
||||
}
|
||||
}
|
||||
+45
@@ -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<K2JVMCompilerArguments> {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected K2JVMCompilerArguments createSettings() {
|
||||
return new K2JVMCompilerArguments();
|
||||
}
|
||||
|
||||
public static Kotlin2JvmCompilerSettings getInstance(Project project) {
|
||||
return ServiceManager.getService(project, Kotlin2JvmCompilerSettings.class);
|
||||
}
|
||||
}
|
||||
+45
@@ -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<CommonCompilerArguments> {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected CommonCompilerArguments createSettings() {
|
||||
return CommonCompilerArguments.DUMMY;
|
||||
}
|
||||
|
||||
public static KotlinCommonCompilerSettings getInstance(Project project) {
|
||||
return ServiceManager.getService(project, KotlinCommonCompilerSettings.class);
|
||||
}
|
||||
}
|
||||
+11
-2
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.jetbrains.jet.plugin.compiler.configuration.KotlinCompilerConfigurableTab">
|
||||
<grid id="27dc6" binding="contentPane" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="27dc6" binding="contentPane" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="332" height="102"/>
|
||||
@@ -10,9 +10,18 @@
|
||||
<children>
|
||||
<vspacer id="c5558">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="f842a" class="javax.swing.JCheckBox" binding="generateNoWarningsCheckBox" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<selected value="false"/>
|
||||
<text value="Generate no warnings"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
|
||||
+46
-6
@@ -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 : "";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user