diff --git a/java/execution/impl/src/com/intellij/execution/SingleClassConfiguration.java b/java/execution/impl/src/com/intellij/execution/SingleClassConfiguration.java index 0b0e69ecafaa..2318982f8ec7 100644 --- a/java/execution/impl/src/com/intellij/execution/SingleClassConfiguration.java +++ b/java/execution/impl/src/com/intellij/execution/SingleClassConfiguration.java @@ -1,23 +1,6 @@ -/* - * Copyright 2000-2009 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. - */ +// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.execution; -import com.intellij.execution.configurations.ConfigurationFactory; -import com.intellij.execution.configurations.ModuleBasedConfiguration; -import com.intellij.execution.configurations.RunConfigurationModule; import com.intellij.psi.PsiClass; /** diff --git a/java/execution/impl/src/com/intellij/execution/applet/AppletConfigurable.java b/java/execution/impl/src/com/intellij/execution/applet/AppletConfigurable.java index a4f26ae79e56..fce7ad5a5240 100644 --- a/java/execution/impl/src/com/intellij/execution/applet/AppletConfigurable.java +++ b/java/execution/impl/src/com/intellij/execution/applet/AppletConfigurable.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-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. - */ +// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.execution.applet; import com.intellij.application.options.ModulesComboBox; @@ -206,12 +192,12 @@ public class AppletConfigurable extends SettingsEditor impl return myHtmlFile; } - private String toNull(String s) { + private static String toNull(String s) { s = s.trim(); return s.length() == 0 ? null : s; } - private String toSystemFormat(String s) { + private static String toSystemFormat(String s) { s = s.trim(); return s.length() == 0 ? null : s.replace(File.separatorChar, '/'); } @@ -223,28 +209,29 @@ public class AppletConfigurable extends SettingsEditor impl configuration.setAppletParameters(params); } - public void resetEditorFrom(@NotNull final AppletConfiguration configuration) { - getClassNameComponent().setText(configuration.MAIN_CLASS_NAME); - String presentableHtmlName = configuration.HTML_FILE_NAME; + public void resetEditorFrom(@NotNull AppletConfiguration runConfiguration) { + AppletConfigurationOptions configuration = runConfiguration.getOptions(); + getClassNameComponent().setText(configuration.getMainClassName()); + String presentableHtmlName = configuration.getHtmlFileName(); if (presentableHtmlName != null && !StringUtil.startsWithIgnoreCase(presentableHtmlName, HTTP_PREFIX)) { presentableHtmlName = presentableHtmlName.replace('/', File.separatorChar); } getHtmlPathComponent().setText(presentableHtmlName); - getPolicyFileComponent().setText(configuration.getPolicyFile()); - getVMParametersComponent().setText(configuration.VM_PARAMETERS); - getWidthComponent().setText(Integer.toString(configuration.WIDTH)); - getHeightComponent().setText(Integer.toString(configuration.HEIGHT)); + getPolicyFileComponent().setText(runConfiguration.getPolicyFile()); + getVMParametersComponent().setText(configuration.getVmParameters()); + getWidthComponent().setText(Integer.toString(configuration.getWidth())); + getHeightComponent().setText(Integer.toString(configuration.getHeight())); - (configuration.HTML_USED ? myURL : myMainClass).setSelected(true); + (configuration.getHtmlUsed() ? myURL : myMainClass).setSelected(true); changePanel(); - final AppletConfiguration.AppletParameter[] appletParameters = configuration.getAppletParameters(); + final AppletConfiguration.AppletParameter[] appletParameters = runConfiguration.getAppletParameters(); if (appletParameters != null) { myParameters.setItems(cloneParameters(Arrays.asList(appletParameters))); } - myModuleSelector.reset(configuration); + myModuleSelector.reset(runConfiguration); myJrePathEditor - .setPathOrName(configuration.ALTERNATIVE_JRE_PATH, configuration.ALTERNATIVE_JRE_PATH_ENABLED); + .setPathOrName(configuration.getAlternativeJrePath(), configuration.getAlternativeJrePathEnabled()); } private RawCommandLineEditor getVMParametersComponent() { @@ -261,25 +248,26 @@ public class AppletConfigurable extends SettingsEditor impl return myWholePanel; } - public void checkEditorData(final AppletConfiguration configuration) { - configuration.MAIN_CLASS_NAME = toNull(getClassNameComponent().getText()); - configuration.HTML_FILE_NAME = toSystemFormat(getHtmlPathComponent().getText()); - configuration.VM_PARAMETERS = toNull(getVMParametersComponent().getText()); - configuration.setPolicyFile(getPolicyFileComponent().getText()); - myModuleSelector.applyTo(configuration); + public void checkEditorData(@NotNull AppletConfiguration runConfiguration) { + AppletConfigurationOptions configuration = runConfiguration.getOptions(); + configuration.setMainClassName(getClassNameComponent().getText().trim()); + configuration.setHtmlFileName(toSystemFormat(getHtmlPathComponent().getText())); + configuration.setVmParameters(getVMParametersComponent().getText().trim()); + runConfiguration.setPolicyFile(getPolicyFileComponent().getText()); + myModuleSelector.applyTo(runConfiguration); try { - configuration.WIDTH = Integer.parseInt(getWidthComponent().getText()); + configuration.setWidth(Integer.parseInt(getWidthComponent().getText())); } - catch (NumberFormatException e) { + catch (NumberFormatException ignored) { } try { - configuration.HEIGHT = Integer.parseInt(getHeightComponent().getText()); + configuration.setHeight(Integer.parseInt(getHeightComponent().getText())); } - catch (NumberFormatException e) { + catch (NumberFormatException ignored) { } - configuration.HTML_USED = myURL.isSelected(); - configuration.ALTERNATIVE_JRE_PATH = myJrePathEditor.getJrePathOrName(); - configuration.ALTERNATIVE_JRE_PATH_ENABLED = myJrePathEditor.isAlternativeJreSelected(); + configuration.setHtmlUsed(myURL.isSelected()); + configuration.setAlternativeJrePath(myJrePathEditor.getJrePathOrName()); + configuration.setAlternativeJrePathEnabled(myJrePathEditor.isAlternativeJreSelected()); } private void createUIComponents() { diff --git a/java/execution/impl/src/com/intellij/execution/applet/AppletConfiguration.java b/java/execution/impl/src/com/intellij/execution/applet/AppletConfiguration.java index eddd151304bb..1b49808ef077 100644 --- a/java/execution/impl/src/com/intellij/execution/applet/AppletConfiguration.java +++ b/java/execution/impl/src/com/intellij/execution/applet/AppletConfiguration.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 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. - */ +// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.execution.applet; import com.intellij.execution.*; @@ -23,20 +9,18 @@ import com.intellij.execution.process.ProcessAdapter; import com.intellij.execution.process.ProcessEvent; import com.intellij.execution.runners.ExecutionEnvironment; import com.intellij.execution.util.JavaParametersUtil; +import com.intellij.openapi.components.PersistentStateComponent; import com.intellij.openapi.module.Module; import com.intellij.openapi.options.SettingsEditor; import com.intellij.openapi.project.Project; import com.intellij.openapi.projectRoots.JdkUtil; import com.intellij.openapi.util.Comparing; -import com.intellij.openapi.util.InvalidDataException; -import com.intellij.openapi.util.WriteExternalException; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiElement; import com.intellij.refactoring.listeners.RefactoringElementListener; import com.intellij.util.SmartList; -import com.intellij.util.xmlb.SmartSerializer; import com.intellij.util.xmlb.annotations.Transient; import org.jdom.Element; import org.jetbrains.annotations.NonNls; @@ -50,31 +34,27 @@ import java.net.URL; import java.util.Collection; import java.util.List; -public class AppletConfiguration extends ModuleBasedConfiguration implements SingleClassConfiguration, RefactoringListenerProvider { - public String MAIN_CLASS_NAME; - public String HTML_FILE_NAME; - public boolean HTML_USED; - public int WIDTH; - public int HEIGHT; - public String POLICY_FILE; - public String VM_PARAMETERS; +public class AppletConfiguration extends ModuleBasedConfiguration implements SingleClassConfiguration, RefactoringListenerProvider, + PersistentStateComponent { + private static final String NAME_ATTR = "name"; + private static final String VALUE_ATTR = "value"; + private static final String PARAMETER_ELEMENT_NAME = "parameter"; + private AppletParameter[] myAppletParameters; - public boolean ALTERNATIVE_JRE_PATH_ENABLED; - public String ALTERNATIVE_JRE_PATH; - @NonNls - protected static final String NAME_ATTR = "name"; - @NonNls - protected static final String VALUE_ATTR = "value"; - @NonNls - protected static final String PARAMETER_ELEMENT_NAME = "parameter"; - - private final SmartSerializer mySerializer; - - public AppletConfiguration(@NotNull Project project, ConfigurationFactory factory) { + public AppletConfiguration(@NotNull Project project, @NotNull ConfigurationFactory factory) { super(new JavaRunConfigurationModule(project, false), factory); + } - mySerializer = new SmartSerializer(!project.isDefault(), true); + @NotNull + @Override + protected AppletConfigurationOptions createOptions() { + return new AppletConfigurationOptions(); + } + + @Override + protected AppletConfigurationOptions getOptions() { + return (AppletConfigurationOptions)super.getOptions(); } @Override @@ -94,18 +74,16 @@ public class AppletConfiguration extends ModuleBasedConfiguration 0) { + private String getPolicyFileParameter() { + if (!StringUtil.isEmpty(getOptions().getPolicyFile())) { + //noinspection SpellCheckingInspection return "-Djava.security.policy=" + getPolicyFile(); } return null; @@ -142,11 +121,11 @@ public class AppletConfiguration extends ModuleBasedConfiguration getValidModules() { - return JavaRunConfigurationModule.getModulesForClass(getProject(), MAIN_CLASS_NAME); + return JavaRunConfigurationModule.getModulesForClass(getProject(), getOptions().getMainClassName()); } @Override - public void readExternal(final Element parentNode) throws InvalidDataException { - mySerializer.readExternal(this, parentNode); + public Element getState() { + Element element = new Element("state"); + super.writeState(element); - List paramList = parentNode.getChildren(PARAMETER_ELEMENT_NAME); + if (myAppletParameters != null) { + for (AppletParameter myAppletParameter : myAppletParameters) { + Element parameterElement = new Element(PARAMETER_ELEMENT_NAME); + element.addContent(parameterElement); + parameterElement.setAttribute(NAME_ATTR, myAppletParameter.getName()); + parameterElement.setAttribute(VALUE_ATTR, myAppletParameter.getValue()); + } + } + return element; + } + + @Override + public void loadState(Element element) { + super.readExternal(element); + + List paramList = element.getChildren(PARAMETER_ELEMENT_NAME); if (paramList.isEmpty()) { myAppletParameters = null; } else { List parameters = new SmartList<>(); - for (Element element : paramList) { - parameters.add(new AppletParameter(element.getAttributeValue(NAME_ATTR), element.getAttributeValue(VALUE_ATTR))); + for (Element child : paramList) { + parameters.add(new AppletParameter(child.getAttributeValue(NAME_ATTR), child.getAttributeValue(VALUE_ATTR))); } myAppletParameters = parameters.toArray(new AppletParameter[parameters.size()]); } } - @Override - protected boolean isNewSerializationUsed() { - return true; - } - - @Override - public void writeExternal(final Element parentNode) throws WriteExternalException { - mySerializer.writeExternal(this, parentNode); - if (myAppletParameters != null) { - for (AppletParameter myAppletParameter : myAppletParameters) { - final Element element = new Element(PARAMETER_ELEMENT_NAME); - parentNode.addContent(element); - element.setAttribute(NAME_ATTR, myAppletParameter.getName()); - element.setAttribute(VALUE_ATTR, myAppletParameter.getValue()); - } - } - } - @Override public RefactoringElementListener getRefactoringElementListener(final PsiElement element) { - if (HTML_USED) return null; + if (getOptions().getHtmlUsed()) { + return null; + } return RefactoringListeners.getClassOrPackageListener(element, new RefactoringListeners.SingleClassConfigurationAccessor(this)); } @Override @Transient public PsiClass getMainClass() { - return getConfigurationModule().findClass(MAIN_CLASS_NAME); + return getConfigurationModule().findClass(getOptions().getMainClassName()); } @Override public String suggestedName() { - if (MAIN_CLASS_NAME == null) return null; - return ProgramRunnerUtil.shortenName(JavaExecutionUtil.getShortClassName(MAIN_CLASS_NAME), 0); + if (getOptions().getMainClassName() == null) { + return null; + } + return ProgramRunnerUtil.shortenName(JavaExecutionUtil.getShortClassName(getOptions().getMainClassName()), 0); } @Override public void setMainClassName(final String qualifiedName) { - MAIN_CLASS_NAME = qualifiedName; + getOptions().setMainClassName(qualifiedName); } @Override public void checkConfiguration() throws RuntimeConfigurationException { - if (ALTERNATIVE_JRE_PATH_ENABLED && (StringUtil.isEmptyOrSpaces(ALTERNATIVE_JRE_PATH) || !JdkUtil.checkForJre(ALTERNATIVE_JRE_PATH))) { - throw new RuntimeConfigurationWarning(ExecutionBundle.message("jre.not.valid.error.message", ALTERNATIVE_JRE_PATH)); + if (getOptions().getAlternativeJrePathEnabled() && (StringUtil.isEmptyOrSpaces(getOptions().getAlternativeJrePath()) || !JdkUtil.checkForJre(getOptions().getAlternativeJrePath()))) { + throw new RuntimeConfigurationWarning(ExecutionBundle.message("jre.not.valid.error.message", getOptions().getAlternativeJrePath())); } getConfigurationModule().checkForWarning(); - if (HTML_USED) { - if (HTML_FILE_NAME == null || HTML_FILE_NAME.length() == 0) { + if (getOptions().getHtmlUsed()) { + if (getOptions().getHtmlFileName() == null) { throw new RuntimeConfigurationWarning(ExecutionBundle.message("html.file.not.specified.error.message")); } try { @@ -266,12 +247,12 @@ public class AppletConfiguration extends ModuleBasedConfiguration\n" + "\n" + - "" + MAIN_CLASS_NAME + "\n" + + "" + getOptions().getMainClassName() + "\n" + "\n" + "\n"); final AppletParameter[] appletParameters = getAppletParameters(); if (appletParameters != null) { @@ -355,6 +337,7 @@ public class AppletConfiguration extends ModuleBasedConfiguration() { + @get:OptionTag("MAIN_CLASS_NAME") var mainClassName by string() + @get:OptionTag("HTML_FILE_NAME") var htmlFileName by string() + @get:OptionTag("HTML_USED") var htmlUsed by storedProperty(false) + + @get:OptionTag("WIDTH") var width by storedProperty(300) + @get:OptionTag("HEIGHT") var height by storedProperty(400) + + @get:OptionTag("POLICY_FILE") var policyFile by string() + @get:OptionTag("VM_PARAMETERS") var vmParameters by string() + + @get:OptionTag("ALTERNATIVE_JRE_PATH_ENABLED") var alternativeJrePathEnabled by storedProperty(false) + @get:OptionTag("ALTERNATIVE_JRE_PATH") var alternativeJrePath by string() +} \ No newline at end of file diff --git a/java/execution/impl/src/com/intellij/execution/applet/AppletConfigurationProducer.java b/java/execution/impl/src/com/intellij/execution/applet/AppletConfigurationProducer.java index 94458b9a1a65..dda240bf04ed 100644 --- a/java/execution/impl/src/com/intellij/execution/applet/AppletConfigurationProducer.java +++ b/java/execution/impl/src/com/intellij/execution/applet/AppletConfigurationProducer.java @@ -1,19 +1,4 @@ -/* - * Copyright 2000-2010 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. - */ - +// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.execution.applet; import com.intellij.execution.JavaExecutionUtil; @@ -59,7 +44,7 @@ public class AppletConfigurationProducer extends JavaRuntimeConfigurationProduce if (myPsiClass == null) return null; RunnerAndConfigurationSettings settings = cloneTemplateConfiguration(project, context); final AppletConfiguration configuration = (AppletConfiguration)settings.getConfiguration(); - configuration.MAIN_CLASS_NAME = JavaExecutionUtil.getRuntimeQualifiedName(myPsiClass); + configuration.setMainClassName(JavaExecutionUtil.getRuntimeQualifiedName(myPsiClass)); configuration.setModule(myPsiClass.isValid() ? ModuleUtilCore.findModuleForPsiElement(myPsiClass) : null); configuration.setGeneratedName(); return settings; @@ -112,7 +97,7 @@ public class AppletConfigurationProducer extends JavaRuntimeConfigurationProduce if (aClass != null) { for (RunnerAndConfigurationSettings existingConfiguration : existingConfigurations) { if (Comparing.equal(JavaExecutionUtil.getRuntimeQualifiedName(aClass), - ((AppletConfiguration)existingConfiguration.getConfiguration()).MAIN_CLASS_NAME)) { + ((AppletConfiguration)existingConfiguration.getConfiguration()).getOptions().getMainClassName())) { return existingConfiguration; } } diff --git a/java/execution/impl/src/com/intellij/execution/applet/AppletConfigurationType.java b/java/execution/impl/src/com/intellij/execution/applet/AppletConfigurationType.java index 06e0c14ac89e..f2cb16f05abc 100644 --- a/java/execution/impl/src/com/intellij/execution/applet/AppletConfigurationType.java +++ b/java/execution/impl/src/com/intellij/execution/applet/AppletConfigurationType.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2014 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. - */ +// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.execution.applet; import com.intellij.execution.ExecutionBundle; @@ -27,11 +13,11 @@ import javax.swing.*; public class AppletConfigurationType implements ConfigurationType { private final ConfigurationFactory myFactory; - /**reflection*/ AppletConfigurationType() { myFactory = new ConfigurationFactoryEx(this) { + @NotNull @Override - public RunConfiguration createTemplateConfiguration(Project project) { + public RunConfiguration createTemplateConfiguration(@NotNull Project project) { return new AppletConfiguration(project, this); } diff --git a/java/java-impl/src/com/intellij/ui/EditorTextFieldWithBrowseButton.java b/java/java-impl/src/com/intellij/ui/EditorTextFieldWithBrowseButton.java index 2875b4813796..2f458f8cb08a 100644 --- a/java/java-impl/src/com/intellij/ui/EditorTextFieldWithBrowseButton.java +++ b/java/java-impl/src/com/intellij/ui/EditorTextFieldWithBrowseButton.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2011 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. - */ +// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.ui; import com.intellij.openapi.editor.Document; @@ -21,6 +7,7 @@ import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.ComponentWithBrowseButton; import com.intellij.psi.*; +import org.jetbrains.annotations.NotNull; public class EditorTextFieldWithBrowseButton extends ComponentWithBrowseButton implements TextAccessor { public EditorTextFieldWithBrowseButton(Project project, boolean isClassAccepted) { @@ -73,6 +60,7 @@ public class EditorTextFieldWithBrowseButton extends ComponentWithBrowseButton getOptionsClass() { + return LocatableRunConfigurationOptions.class; + } + @Override @Attribute("nameIsGenerated") public boolean isGeneratedName() { - return myNameIsGenerated && suggestedName() != null; + return getOptions().isNameGenerated() && suggestedName() != null; } /** @@ -50,29 +45,11 @@ public abstract class LocatableConfigurationBase extends RunConfigurationBase im */ public void setGeneratedName() { setName(suggestedName()); - myNameIsGenerated = true; + getOptions().setNameGenerated(true); } public void setNameChangedByUser(boolean nameChangedByUser) { - myNameIsGenerated = !nameChangedByUser; - } - - @Override - public void readExternal(Element element) throws InvalidDataException { - super.readExternal(element); - - if (!isNewSerializationUsed()) { - myNameIsGenerated = "true".equals(element.getAttributeValue(ATTR_NAME_IS_GENERATED)); - } - } - - @Override - public void writeExternal(Element element) throws WriteExternalException { - super.writeExternal(element); - - if (!isNewSerializationUsed() && myNameIsGenerated && suggestedName() != null) { - element.setAttribute(ATTR_NAME_IS_GENERATED, "true"); - } + getOptions().setNameGenerated(!nameChangedByUser); } /** diff --git a/platform/lang-api/src/com/intellij/execution/configurations/ModuleBasedConfiguration.java b/platform/lang-api/src/com/intellij/execution/configurations/ModuleBasedConfiguration.java index e8ca5ae088d6..8a09c4dd5a16 100644 --- a/platform/lang-api/src/com/intellij/execution/configurations/ModuleBasedConfiguration.java +++ b/platform/lang-api/src/com/intellij/execution/configurations/ModuleBasedConfiguration.java @@ -1,19 +1,4 @@ -/* - * Copyright 2000-2017 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. - */ - +// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.execution.configurations; import com.intellij.openapi.application.ReadAction; @@ -24,10 +9,8 @@ import com.intellij.openapi.roots.ModuleRootManager; import com.intellij.openapi.util.InvalidDataException; import com.intellij.openapi.util.WriteExternalException; import com.intellij.util.ArrayUtil; -import com.intellij.util.xmlb.annotations.Property; import gnu.trove.THashSet; import org.jdom.Element; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -40,44 +23,57 @@ import java.util.*; public abstract class ModuleBasedConfiguration extends LocatableConfigurationBase implements Cloneable, ModuleRunConfiguration { private static final Logger LOG = Logger.getInstance("#com.intellij.execution.configurations.ModuleBasedConfiguration"); - @Property(surroundWithTag = false) - private final ConfigurationModule myModule; - - @NonNls protected static final String TO_CLONE_ELEMENT_NAME = "toClone"; - public ModuleBasedConfiguration(final String name, - @NotNull ConfigurationModule configurationModule, @NotNull ConfigurationFactory factory) { + public ModuleBasedConfiguration(String name, @NotNull ConfigurationModule configurationModule, @NotNull ConfigurationFactory factory) { super(configurationModule.getProject(), factory, name); - myModule = configurationModule; + + ModuleBasedConfigurationOptions options = getOptions(); + options.setModule(configurationModule); + options.resetModificationCount(); } - public ModuleBasedConfiguration(final ConfigurationModule configurationModule, final ConfigurationFactory factory) { + @NotNull + @Override + protected ModuleBasedConfigurationOptions createOptions() { + return new ModuleBasedConfigurationOptions<>(); + } + + @Override + protected ModuleBasedConfigurationOptions getOptions() { + //noinspection unchecked + return (ModuleBasedConfigurationOptions)super.getOptions(); + } + + public ModuleBasedConfiguration(@NotNull ConfigurationModule configurationModule, @NotNull ConfigurationFactory factory) { super(configurationModule.getProject(), factory, ""); - myModule = configurationModule; + + ModuleBasedConfigurationOptions options = getOptions(); + options.setModule(configurationModule); + options.resetModificationCount(); } public abstract Collection getValidModules(); public ConfigurationModule getConfigurationModule() { - return myModule; + return getOptions().getModule(); } public void setModule(final Module module) { - myModule.setModule(module); + getConfigurationModule().setModule(module); } public void setModuleName(@Nullable String moduleName) { - myModule.setModuleName(moduleName); + getConfigurationModule().setModuleName(moduleName); } protected void readModule(final Element element) { - myModule.readExternal(element); + getConfigurationModule().readExternal(element); } protected void writeModule(@NotNull Element element) { //if (myModule.getModule() != null) { - myModule.writeExternal(element); + getConfigurationModule().writeExternal(element); //} } @@ -86,16 +82,18 @@ public abstract class ModuleBasedConfiguration configuration = (ModuleBasedConfiguration)getFactory().createTemplateConfiguration(getProject()); configuration.setName(getName()); return configuration; } + @SuppressWarnings("MethodDoesntCallSuperMethod") @Override public ModuleBasedConfiguration clone() { final Element element = new Element(TO_CLONE_ELEMENT_NAME); diff --git a/platform/lang-api/src/com/intellij/execution/configurations/RunConfigurationBase.java b/platform/lang-api/src/com/intellij/execution/configurations/RunConfigurationBase.java index 9bfaea704321..7f53fb5ea82b 100644 --- a/platform/lang-api/src/com/intellij/execution/configurations/RunConfigurationBase.java +++ b/platform/lang-api/src/com/intellij/execution/configurations/RunConfigurationBase.java @@ -1,25 +1,14 @@ -/* - * Copyright 2000-2017 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. - */ +// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.execution.configurations; +import com.intellij.configurationStore.ComponentSerializationUtil; +import com.intellij.configurationStore.XmlSerializer; import com.intellij.diagnostic.logging.LogConsole; import com.intellij.execution.BeforeRunTask; import com.intellij.execution.ExecutionTarget; import com.intellij.execution.process.ProcessHandler; import com.intellij.execution.runners.ProgramRunner; +import com.intellij.openapi.components.PersistentStateComponent; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.InvalidDataException; import com.intellij.openapi.util.JDOMExternalizerUtil; @@ -39,39 +28,41 @@ import java.util.List; /** * Standard base class for run configuration implementations. - * - * @author dyoma */ public abstract class RunConfigurationBase extends UserDataHolderBase implements RunConfiguration, TargetAwareRunProfile { private static final String LOG_FILE = "log_file"; private static final String PREDEFINED_LOG_FILE_ELEMENT = "predefined_log_file"; - private static final String FILE_OUTPUT = "output_file"; - private static final String SAVE = "is_save"; - private static final String OUTPUT_FILE = "path"; private static final String SHOW_CONSOLE_ON_STD_OUT = "show_console_on_std_out"; private static final String SHOW_CONSOLE_ON_STD_ERR = "show_console_on_std_err"; private final ConfigurationFactory myFactory; private final Project myProject; - private String myName = ""; + private String myName; private final Icon myIcon; + private RunConfigurationOptions myOptions = createOptions(); + private List myLogFiles = new SmartList<>(); private List myPredefinedLogFiles = new SmartList<>(); - private boolean mySaveOutput = false; - private boolean myShowConsoleOnStdOut = false; - private boolean myShowConsoleOnStdErr = false; - private String myFileOutputPath = null; private List myBeforeRunTasks = Collections.emptyList(); - protected RunConfigurationBase(@NotNull Project project, @NotNull ConfigurationFactory factory, final String name) { + protected RunConfigurationBase(@NotNull Project project, @NotNull ConfigurationFactory factory, String name) { myProject = project; myFactory = factory; myName = name; myIcon = factory.getIcon(); } + @NotNull + protected RunConfigurationOptions createOptions() { + return new RunConfigurationOptions(); + } + + protected RunConfigurationOptions getOptions() { + return myOptions; + } + @Override @NotNull @Transient @@ -137,10 +128,7 @@ public abstract class RunConfigurationBase extends UserDataHolderBase implements final RunConfigurationBase runConfiguration = (RunConfigurationBase)super.clone(); runConfiguration.myLogFiles = new ArrayList<>(myLogFiles); runConfiguration.myPredefinedLogFiles = new ArrayList<>(myPredefinedLogFiles); - runConfiguration.myFileOutputPath = myFileOutputPath; - runConfiguration.mySaveOutput = mySaveOutput; - runConfiguration.myShowConsoleOnStdOut = myShowConsoleOnStdOut; - runConfiguration.myShowConsoleOnStdErr = myShowConsoleOnStdErr; + runConfiguration.myOptions.copyFrom(myOptions); copyCopyableDataTo(runConfiguration); myBeforeRunTasks = myBeforeRunTasks.isEmpty() ? Collections.emptyList() : new SmartList<>(myBeforeRunTasks); @@ -182,11 +170,12 @@ public abstract class RunConfigurationBase extends UserDataHolderBase implements return myLogFiles; } - public void addLogFile(String file, String alias, boolean checked){ + @SuppressWarnings("unused") + public void addLogFile(String file, String alias, boolean checked) { myLogFiles.add(new LogFileOptions(alias, file, checked, true, false)); } - public void addLogFile(String file, String alias, boolean checked, boolean skipContent, final boolean showAll){ + public void addLogFile(String file, String alias, boolean checked, boolean skipContent, final boolean showAll) { myLogFiles.add(new LogFileOptions(alias, file, checked, skipContent, showAll)); } @@ -216,83 +205,77 @@ public abstract class RunConfigurationBase extends UserDataHolderBase implements logFile.readExternal(fileElement); myPredefinedLogFiles.add(logFile); } - final Element fileOutputElement = element.getChild(FILE_OUTPUT); - if (fileOutputElement != null) { - myFileOutputPath = fileOutputElement.getAttributeValue(OUTPUT_FILE); - String isSave = fileOutputElement.getAttributeValue(SAVE); - mySaveOutput = isSave != null && Boolean.parseBoolean(isSave); - } - if (!isNewSerializationUsed()) { - myShowConsoleOnStdOut = Boolean.parseBoolean(element.getAttributeValue(SHOW_CONSOLE_ON_STD_OUT)); - myShowConsoleOnStdErr = Boolean.parseBoolean(element.getAttributeValue(SHOW_CONSOLE_ON_STD_ERR)); + if (this instanceof PersistentStateComponent) { + PersistentStateComponent instance = (PersistentStateComponent)this; + myOptions = XmlSerializer.deserialize(element, ComponentSerializationUtil.getStateClass(instance.getClass())); } + else { + myOptions = XmlSerializer.deserialize(element, getOptionsClass()); + } + } + + Class getOptionsClass() { + return RunConfigurationOptions.class; } @Override - public void writeExternal(Element element) throws WriteExternalException { - JDOMExternalizerUtil.addChildren(element, LOG_FILE, myLogFiles); - JDOMExternalizerUtil.addChildren(element, PREDEFINED_LOG_FILE_ELEMENT, myPredefinedLogFiles); - - if (myFileOutputPath != null || mySaveOutput) { - Element fileOutputPathElement = new Element(FILE_OUTPUT); - if (myFileOutputPath != null) { - fileOutputPathElement.setAttribute(OUTPUT_FILE, myFileOutputPath); - } - if (mySaveOutput) { - fileOutputPathElement.setAttribute(SAVE, String.valueOf(mySaveOutput)); - } - element.addContent(fileOutputPathElement); - } - - if (!isNewSerializationUsed()) { - if (myShowConsoleOnStdOut) {//default value shouldn't be written - element.setAttribute(SHOW_CONSOLE_ON_STD_OUT, String.valueOf(true)); - } - if (myShowConsoleOnStdErr) {//default value shouldn't be written - element.setAttribute(SHOW_CONSOLE_ON_STD_ERR, String.valueOf(true)); - } - } + public void writeExternal(@NotNull Element element) throws WriteExternalException { + writeState(element); } - protected boolean isNewSerializationUsed() { - return false; + protected void writeState(@NotNull Element element) { + JDOMExternalizerUtil.addChildren(element, LOG_FILE, myLogFiles); + JDOMExternalizerUtil.addChildren(element, PREDEFINED_LOG_FILE_ELEMENT, myPredefinedLogFiles); + XmlSerializer.serializeObjectInto(myOptions, element); } @Transient public boolean isSaveOutputToFile() { - return mySaveOutput; + RunConfigurationOptions.OutputFileOptions fileOutput = myOptions.getFileOutput(); + return fileOutput != null && fileOutput.isSaveOutput(); } public void setSaveOutputToFile(boolean redirectOutput) { - mySaveOutput = redirectOutput; + RunConfigurationOptions.OutputFileOptions fileOutput = myOptions.getFileOutput(); + if (fileOutput == null) { + fileOutput = new RunConfigurationOptions.OutputFileOptions(); + myOptions.setFileOutput(fileOutput); + } + fileOutput.setSaveOutput(redirectOutput); } @Attribute(SHOW_CONSOLE_ON_STD_OUT) public boolean isShowConsoleOnStdOut() { - return myShowConsoleOnStdOut; + return myOptions.isShowConsoleOnStdOut(); } public void setShowConsoleOnStdOut(boolean showConsoleOnStdOut) { - myShowConsoleOnStdOut = showConsoleOnStdOut; + myOptions.setShowConsoleOnStdOut(showConsoleOnStdOut); } @Attribute(SHOW_CONSOLE_ON_STD_ERR) public boolean isShowConsoleOnStdErr() { - return myShowConsoleOnStdErr; + return myOptions.isShowConsoleOnStdErr(); } public void setShowConsoleOnStdErr(boolean showConsoleOnStdErr) { - myShowConsoleOnStdErr = showConsoleOnStdErr; + myOptions.setShowConsoleOnStdErr(showConsoleOnStdErr); } @Transient public String getOutputFilePath() { - return myFileOutputPath; + RunConfigurationOptions.OutputFileOptions output = myOptions.getFileOutput(); + return output == null ? null : output.getFileOutputPath(); } public void setFileOutputPath(String fileOutputPath) { - myFileOutputPath = fileOutputPath; + RunConfigurationOptions.OutputFileOptions fileOutput = myOptions.getFileOutput(); + if (fileOutput == null) { + fileOutput = new RunConfigurationOptions.OutputFileOptions(); + myOptions.setFileOutput(fileOutput); + } + fileOutput.setFileOutputPath(fileOutputPath); } public boolean collectOutputFromProcessHandler() { diff --git a/platform/lang-api/src/com/intellij/execution/configurations/RunConfigurationOptions.kt b/platform/lang-api/src/com/intellij/execution/configurations/RunConfigurationOptions.kt new file mode 100644 index 000000000000..6cefeaaeedf9 --- /dev/null +++ b/platform/lang-api/src/com/intellij/execution/configurations/RunConfigurationOptions.kt @@ -0,0 +1,41 @@ +// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.intellij.execution.configurations + +import com.intellij.openapi.components.BaseState +import com.intellij.util.xmlb.Accessor +import com.intellij.util.xmlb.annotations.Attribute +import com.intellij.util.xmlb.annotations.Property +import com.intellij.util.xmlb.annotations.Tag + +open class RunConfigurationOptions : BaseState() { + @Tag("output_file") + class OutputFileOptions : BaseState() { + @get:Attribute("path") var fileOutputPath by string() + @get:Attribute("is_save") var isSaveOutput by storedProperty(false) + } + + // we use object instead of 2 fields because XML serializer cannot reuse tag for several fields + @get:Property(surroundWithTag = false) var fileOutput by storedProperty() + + @get:Attribute("show_console_on_std_out") var isShowConsoleOnStdOut by storedProperty(false) + @get:Attribute("show_console_on_std_err") var isShowConsoleOnStdErr by storedProperty(false) +} + +open class LocatableRunConfigurationOptions : RunConfigurationOptions() { + @get:Attribute("nameIsGenerated") var isNameGenerated by storedProperty(false) +} + +open class ModuleBasedConfigurationOptions : LocatableRunConfigurationOptions() { + @get:Property(surroundWithTag = false) + var module by storedProperty() + + override fun accepts(accessor: Accessor, bean: Any): Boolean { + if (accessor.name == "module") { + val module = module + return module != null && module.moduleName.isNotEmpty() + } + else { + return super.accepts(accessor, bean) + } + } +} \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/execution/ExternalizablePath.java b/platform/lang-impl/src/com/intellij/execution/ExternalizablePath.java index 84f593513a1a..93a483fb11d6 100644 --- a/platform/lang-impl/src/com/intellij/execution/ExternalizablePath.java +++ b/platform/lang-impl/src/com/intellij/execution/ExternalizablePath.java @@ -1,23 +1,10 @@ -/* - * Copyright 2000-2009 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. - */ +// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.execution; import com.intellij.openapi.util.InvalidDataException; import com.intellij.openapi.util.JDOMExternalizable; import com.intellij.openapi.util.WriteExternalException; +import com.intellij.openapi.util.io.FileUtilRt; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFileManager; @@ -57,6 +44,6 @@ public class ExternalizablePath implements JDOMExternalizable { } public static String localPathValue(@Nullable String url) { - return StringUtil.isEmptyOrSpaces(url) ? "" : VirtualFileManager.extractPath(url.trim()).replace('/', File.separatorChar); + return StringUtil.isEmptyOrSpaces(url) ? "" : FileUtilRt.toSystemDependentName(VirtualFileManager.extractPath(url.trim())); } } diff --git a/platform/lang-impl/src/com/intellij/facet/impl/FacetUtil.java b/platform/lang-impl/src/com/intellij/facet/impl/FacetUtil.java index ec39f06c50a7..c1b40eafa50e 100644 --- a/platform/lang-impl/src/com/intellij/facet/impl/FacetUtil.java +++ b/platform/lang-impl/src/com/intellij/facet/impl/FacetUtil.java @@ -1,26 +1,12 @@ -/* - * Copyright 2000-2015 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. - */ +// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.facet.impl; +import com.intellij.configurationStore.ComponentSerializationUtil; import com.intellij.facet.*; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.Result; import com.intellij.openapi.application.WriteAction; -import com.intellij.openapi.components.ComponentSerializationUtil; import com.intellij.openapi.components.PersistentStateComponent; import com.intellij.openapi.module.Module; import com.intellij.openapi.util.InvalidDataException; diff --git a/platform/platform-api/src/com/intellij/ui/TextAccessor.java b/platform/platform-api/src/com/intellij/ui/TextAccessor.java index d977d8922a69..92b0d2cdc0f8 100644 --- a/platform/platform-api/src/com/intellij/ui/TextAccessor.java +++ b/platform/platform-api/src/com/intellij/ui/TextAccessor.java @@ -1,22 +1,8 @@ -/* - * Copyright 2000-2009 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. - */ - +// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.ui; public interface TextAccessor { void setText(String text); + String getText(); } diff --git a/platform/platform-impl/src/com/intellij/ui/EditorTextField.java b/platform/platform-impl/src/com/intellij/ui/EditorTextField.java index c8908289aa48..07019e7522bf 100644 --- a/platform/platform-impl/src/com/intellij/ui/EditorTextField.java +++ b/platform/platform-impl/src/com/intellij/ui/EditorTextField.java @@ -30,6 +30,7 @@ import com.intellij.openapi.project.ProjectManager; import com.intellij.openapi.project.ProjectManagerListener; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.Key; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.wm.IdeFocusManager; import com.intellij.openapi.wm.ex.AbstractDelegatingToRootTraversalPolicy; import com.intellij.psi.PsiDocumentManager; @@ -138,6 +139,7 @@ public class EditorTextField extends NonOpaquePanel implements DocumentListener, setDocument(myDocument); // reinit editor. } + @NotNull @Override public String getText() { return myDocument.getText(); @@ -233,7 +235,7 @@ public class EditorTextField extends NonOpaquePanel implements DocumentListener, public void setText(@Nullable final String text) { ApplicationManager.getApplication().runWriteAction(() -> CommandProcessor.getInstance().executeCommand(getProject(), () -> { - myDocument.replaceString(0, myDocument.getTextLength(), text == null ? "" : text); + myDocument.replaceString(0, myDocument.getTextLength(), StringUtil.notNullize(text)); if (myEditor != null) { final CaretModel caretModel = myEditor.getCaretModel(); if (caretModel.getOffset() >= myDocument.getTextLength()) { diff --git a/platform/projectModel-impl/src/com/intellij/openapi/components/ComponentSerializationUtil.java b/platform/projectModel-api/src/com/intellij/configurationStore/ComponentSerializationUtil.java similarity index 93% rename from platform/projectModel-impl/src/com/intellij/openapi/components/ComponentSerializationUtil.java rename to platform/projectModel-api/src/com/intellij/configurationStore/ComponentSerializationUtil.java index a8157cbdaaa2..8c6b0395cc82 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/components/ComponentSerializationUtil.java +++ b/platform/projectModel-api/src/com/intellij/configurationStore/ComponentSerializationUtil.java @@ -1,6 +1,7 @@ // Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -package com.intellij.openapi.components; +package com.intellij.configurationStore; +import com.intellij.openapi.components.PersistentStateComponent; import com.intellij.util.ReflectionUtil; import com.intellij.util.xmlb.XmlSerializer; import org.jdom.Element; diff --git a/platform/projectModel-impl/src/com/intellij/configurationStore/xmlSerializer.kt b/platform/projectModel-api/src/com/intellij/configurationStore/xmlSerializer.kt similarity index 87% rename from platform/projectModel-impl/src/com/intellij/configurationStore/xmlSerializer.kt rename to platform/projectModel-api/src/com/intellij/configurationStore/xmlSerializer.kt index 2cfc6b6e074e..be0c6f09ab3e 100644 --- a/platform/projectModel-impl/src/com/intellij/configurationStore/xmlSerializer.kt +++ b/platform/projectModel-api/src/com/intellij/configurationStore/xmlSerializer.kt @@ -1,23 +1,8 @@ -/* - * Copyright 2000-2017 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. - */ +// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. @file:JvmName("XmlSerializer") package com.intellij.configurationStore import com.intellij.openapi.components.BaseState -import com.intellij.openapi.components.ComponentSerializationUtil import com.intellij.openapi.components.PersistentStateComponent import com.intellij.openapi.util.JDOMUtil import com.intellij.reference.SoftReference @@ -123,11 +108,6 @@ fun PersistentStateComponent<*>.serializeStateInto(element: Element) { state?.let { serializeObjectInto(it, element) } } -@Deprecated("") -fun T.serializeInto(target: Element) { - serializeObjectInto(this, target) -} - fun serializeObjectInto(o: Any, target: Element) { if (o is Element) { val iterator = o.children.iterator() @@ -145,10 +125,11 @@ fun serializeObjectInto(o: Any, target: Element) { } val binding = serializer.getClassBinding(o.javaClass) - (binding as BeanBinding).serializeInto(o, target, getDefaultSerializationFilter()) + (binding as BeanBinding).serializeInto(o, target, if (o is BaseState) null else getDefaultSerializationFilter()) } private val serializer = object : XmlSerializerImpl.XmlSerializerBase() { + @Suppress("ObjectPropertyName") private var _bindingCache: SoftReference>? = null private val bindingCache: MutableMap diff --git a/platform/projectModel-api/src/com/intellij/openapi/components/StoredProperty.kt b/platform/projectModel-api/src/com/intellij/openapi/components/StoredProperty.kt index af3fe94e2d43..8d3a6b437eac 100644 --- a/platform/projectModel-api/src/com/intellij/openapi/components/StoredProperty.kt +++ b/platform/projectModel-api/src/com/intellij/openapi/components/StoredProperty.kt @@ -5,6 +5,7 @@ import com.intellij.openapi.diagnostic.logger import com.intellij.openapi.util.ModificationTracker import com.intellij.util.SmartList import com.intellij.util.xmlb.Accessor +import com.intellij.util.xmlb.PropertyAccessor import com.intellij.util.xmlb.SerializationFilter import com.intellij.util.xmlb.annotations.Transient import kotlin.reflect.KProperty @@ -62,8 +63,9 @@ abstract class BaseState : SerializationFilter, ModificationTracker { } override fun accepts(accessor: Accessor, bean: Any): Boolean { + val getterName = (accessor as? PropertyAccessor)?.getterName for (property in properties) { - if (property.name == accessor.name) { + if (property.name == accessor.name || property.name == getterName) { return property.value != property.defaultValue } } diff --git a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/libraries/LibraryImpl.java b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/libraries/LibraryImpl.java index a7a26beeb5fe..f4425bce71a0 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/libraries/LibraryImpl.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/libraries/LibraryImpl.java @@ -1,23 +1,9 @@ -/* - * Copyright 2000-2017 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. - */ +// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.roots.impl.libraries; +import com.intellij.configurationStore.ComponentSerializationUtil; import com.intellij.openapi.Disposable; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.components.ComponentSerializationUtil; import com.intellij.openapi.components.StateSplitterEx; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.module.Module; diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/configuration/RemoteServersManagerImpl.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/configuration/RemoteServersManagerImpl.java index 15513c2a2b7d..0ad0815fa952 100644 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/configuration/RemoteServersManagerImpl.java +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/configuration/RemoteServersManagerImpl.java @@ -1,21 +1,7 @@ -/* - * Copyright 2000-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. - */ +// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.remoteServer.impl.configuration; -import com.intellij.openapi.components.ComponentSerializationUtil; +import com.intellij.configurationStore.ComponentSerializationUtil; import com.intellij.openapi.components.PersistentStateComponent; import com.intellij.openapi.components.State; import com.intellij.openapi.components.Storage; diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/configuration/deployment/DeployToServerRunConfiguration.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/configuration/deployment/DeployToServerRunConfiguration.java index 24abac524028..e3f8cc0420ab 100644 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/configuration/deployment/DeployToServerRunConfiguration.java +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/configuration/deployment/DeployToServerRunConfiguration.java @@ -1,27 +1,13 @@ -/* - * Copyright 2000-2017 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. - */ +// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.remoteServer.impl.configuration.deployment; +import com.intellij.configurationStore.ComponentSerializationUtil; import com.intellij.execution.ExecutionException; import com.intellij.execution.Executor; import com.intellij.execution.configurations.*; import com.intellij.execution.runners.ExecutionEnvironment; import com.intellij.openapi.application.ReadAction; import com.intellij.openapi.application.Result; -import com.intellij.openapi.components.ComponentSerializationUtil; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.options.SettingsEditor; import com.intellij.openapi.options.SettingsEditorGroup; diff --git a/platform/util/src/com/intellij/util/xmlb/PropertyAccessor.java b/platform/util/src/com/intellij/util/xmlb/PropertyAccessor.java index b424cb3fcae3..33acaad9f3e0 100644 --- a/platform/util/src/com/intellij/util/xmlb/PropertyAccessor.java +++ b/platform/util/src/com/intellij/util/xmlb/PropertyAccessor.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 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. - */ +// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.util.xmlb; import com.intellij.util.ExceptionUtil; @@ -28,7 +14,7 @@ import java.lang.reflect.Type; import static com.intellij.util.xmlb.Binding.LOG; -class PropertyAccessor implements MutableAccessor { +public class PropertyAccessor implements MutableAccessor { private final String myName; private final Class myType; private final Method myReadMethod; @@ -53,6 +39,11 @@ class PropertyAccessor implements MutableAccessor { catch (SecurityException ignored) { } } + @NotNull + public String getGetterName() { + return myReadMethod.getName(); + } + @Override public Object read(@NotNull Object o) { try { diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointBase.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointBase.java index 74d0386a9b47..2a17669ffa20 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointBase.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointBase.java @@ -1,24 +1,10 @@ -/* - * Copyright 2000-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. - */ +// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.xdebugger.impl.breakpoints; +import com.intellij.configurationStore.ComponentSerializationUtil; import com.intellij.icons.AllIcons; import com.intellij.openapi.actionSystem.ActionGroup; import com.intellij.openapi.actionSystem.AnAction; -import com.intellij.openapi.components.ComponentSerializationUtil; import com.intellij.openapi.editor.markup.GutterDraggableObject; import com.intellij.openapi.editor.markup.GutterIconRenderer; import com.intellij.openapi.project.DumbAware; diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/settings/XDebuggerSettingManagerImpl.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/settings/XDebuggerSettingManagerImpl.java index 2eec35b47b2e..e0e7c184a4eb 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/settings/XDebuggerSettingManagerImpl.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/settings/XDebuggerSettingManagerImpl.java @@ -1,21 +1,7 @@ -/* - * Copyright 2000-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. - */ +// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.xdebugger.impl.settings; -import com.intellij.openapi.components.ComponentSerializationUtil; +import com.intellij.configurationStore.ComponentSerializationUtil; import com.intellij.openapi.components.PersistentStateComponent; import com.intellij.openapi.components.State; import com.intellij.openapi.components.Storage; diff --git a/plugins/eclipse/src/org/jetbrains/idea/eclipse/conversion/IdeaSpecificSettings.java b/plugins/eclipse/src/org/jetbrains/idea/eclipse/conversion/IdeaSpecificSettings.java index bb6843b1e741..ef39c9fc94a3 100644 --- a/plugins/eclipse/src/org/jetbrains/idea/eclipse/conversion/IdeaSpecificSettings.java +++ b/plugins/eclipse/src/org/jetbrains/idea/eclipse/conversion/IdeaSpecificSettings.java @@ -1,23 +1,9 @@ -/* - * Copyright 2000-2017 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. - */ +// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.idea.eclipse.conversion; +import com.intellij.configurationStore.ComponentSerializationUtil; import com.intellij.configurationStore.XmlSerializer; -import com.intellij.openapi.components.ComponentSerializationUtil; import com.intellij.openapi.components.PathMacroManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.module.Module; diff --git a/python/src/com/jetbrains/PySymbolFieldWithBrowseButton.kt b/python/src/com/jetbrains/PySymbolFieldWithBrowseButton.kt index 4101b487b96a..62ad01fa9f68 100644 --- a/python/src/com/jetbrains/PySymbolFieldWithBrowseButton.kt +++ b/python/src/com/jetbrains/PySymbolFieldWithBrowseButton.kt @@ -1,6 +1,4 @@ -// Copyright 2000-2017 JetBrains s.r.o. -// Use of this source code is governed by the Apache 2.0 license that can be -// found in the LICENSE file. +// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.jetbrains import com.intellij.codeInsight.completion.CompletionResultSet @@ -55,22 +53,21 @@ class PySymbolFieldWithBrowseButton(contextAnchor: ContextAnchor, dialog.showDialog() val element = dialog.selected if (element is PyQualifiedNameOwner) { - childComponent.text = element.qualifiedName + childComponent.setText(element.qualifiedName) } if (element is PyFile) { - childComponent.text = element.getQName()?.toString() + childComponent.setText(element.getQName()?.toString()) } } } override fun setText(text: String?) { - childComponent.text = text + childComponent.setText(text) } - override fun getText() = childComponent.text!! + override fun getText() = childComponent.text } - private fun PyType.getVariants(element: PsiElement): Array = this.getCompletionVariants("", element, ProcessingContext()).filterIsInstance(LookupElement::class.java).toTypedArray() diff --git a/resources/src/idea/RunManager.xml b/resources/src/idea/RunManager.xml index cbcceec7e802..c73ed1a9143f 100644 --- a/resources/src/idea/RunManager.xml +++ b/resources/src/idea/RunManager.xml @@ -11,13 +11,7 @@ -