mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-131690 Settings repository plugin: when I merged settings from PyCharm java-related setting was deleted
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -48,11 +48,7 @@ public class JavaCodeStyleSettings extends CustomCodeStyleSettings {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void importLegacySettings() {
|
||||
importLegacyUseFqClassNamesInJavadocSetting();
|
||||
}
|
||||
|
||||
private void importLegacyUseFqClassNamesInJavadocSetting() {
|
||||
protected void importLegacySettings() {
|
||||
CodeStyleSettings settings = getContainer();
|
||||
boolean isDefaultValue = settings.USE_FQ_CLASS_NAMES_IN_JAVADOC;
|
||||
if (!isDefaultValue) {
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.intellij.configurationStore
|
||||
|
||||
import com.intellij.openapi.util.JDOMUtil
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings
|
||||
import com.intellij.testFramework.ProjectRule
|
||||
import com.intellij.util.loadElement
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.jdom.Element
|
||||
import org.junit.ClassRule
|
||||
import org.junit.Test
|
||||
|
||||
class CodeStyleTest {
|
||||
companion object {
|
||||
@JvmField
|
||||
@ClassRule
|
||||
val projectRule = ProjectRule()
|
||||
}
|
||||
|
||||
@Test fun `do not remove unknown`() {
|
||||
val settings = CodeStyleSettings()
|
||||
val loaded = """
|
||||
<code_scheme name="testSchemeName">
|
||||
<UnknownDoNotRemoveMe>
|
||||
<option name="ALIGN_OBJECT_PROPERTIES" value="2" />
|
||||
</UnknownDoNotRemoveMe>
|
||||
<codeStyleSettings language="CoffeeScript">
|
||||
<option name="LINE_COMMENT_AT_FIRST_COLUMN" value="false" />
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="Gherkin">
|
||||
<indentOptions>
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="SQL">
|
||||
<option name="KEEP_LINE_BREAKS" value="false" />
|
||||
<option name="KEEP_BLANK_LINES_IN_CODE" value="10" />
|
||||
</codeStyleSettings>
|
||||
</code_scheme>""".trimIndent()
|
||||
settings.readExternal(loadElement(loaded))
|
||||
|
||||
val serialized = Element("code_scheme").setAttribute("name", "testSchemeName")
|
||||
settings.writeExternal(serialized)
|
||||
assertThat(JDOMUtil.writeElement(serialized)).isEqualTo(loaded)
|
||||
}
|
||||
}
|
||||
@@ -16,5 +16,6 @@
|
||||
<orderEntry type="library" scope="TEST" name="JUnit4" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Mocks" level="project" />
|
||||
<orderEntry type="module" module-name="analysis-api" exported="" />
|
||||
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
package com.intellij.configurationStore
|
||||
|
||||
import gnu.trove.THashMap
|
||||
import gnu.trove.THashSet
|
||||
import org.jdom.Element
|
||||
import java.util.function.Consumer
|
||||
import java.util.function.Function
|
||||
|
||||
// Empty unknown tags supported to simplify client write code (with and without unknown elements)
|
||||
class UnknownElementWriter internal constructor(private val unknownElements: Map<String, Element> = emptyMap()) {
|
||||
companion object {
|
||||
@JvmField
|
||||
val EMPTY = UnknownElementWriter()
|
||||
}
|
||||
|
||||
fun <T> write(outElement: Element, items: Collection<T>, itemToTagName: Function<T, String>, writer: Consumer<T>) {
|
||||
val knownNameToWriter = THashMap<String, T>(items.size)
|
||||
for (item in items) {
|
||||
knownNameToWriter.put(itemToTagName.apply(item), item)
|
||||
}
|
||||
write(outElement, knownNameToWriter, writer)
|
||||
}
|
||||
|
||||
fun <T> write(outElement: Element, knownNameToWriter: Map<String, T>, writer: Consumer<T>) {
|
||||
val names: Set<String>
|
||||
if (unknownElements.isEmpty()) {
|
||||
names = knownNameToWriter.keys
|
||||
}
|
||||
else {
|
||||
names = THashSet<String>(unknownElements.keys)
|
||||
names.addAll(knownNameToWriter.keys)
|
||||
}
|
||||
|
||||
val sortedNames = names.toTypedArray()
|
||||
sortedNames.sort()
|
||||
for (name in sortedNames) {
|
||||
val known = knownNameToWriter.get(name)
|
||||
if (known == null) {
|
||||
outElement.addContent(unknownElements.get(name)!!.clone())
|
||||
}
|
||||
else {
|
||||
writer.accept(known)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class UnknownElementCollector {
|
||||
private val knownTagNames = THashSet<String>()
|
||||
|
||||
fun addKnownName(name: String) {
|
||||
knownTagNames.add(name)
|
||||
}
|
||||
|
||||
fun createWriter(element: Element): UnknownElementWriter? {
|
||||
var unknownElements: MutableMap<String, Element>? = null
|
||||
val iterator = element.children.iterator()
|
||||
for (child in iterator) {
|
||||
if (child.name != "option" && !knownTagNames.contains(child.name)) {
|
||||
if (unknownElements == null) {
|
||||
unknownElements = THashMap()
|
||||
}
|
||||
unknownElements.put(child.name, child)
|
||||
iterator.remove()
|
||||
}
|
||||
}
|
||||
|
||||
return unknownElements?.let { UnknownElementWriter(it) } ?: UnknownElementWriter.EMPTY
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.intellij.psi.codeStyle;
|
||||
|
||||
import com.intellij.configurationStore.UnknownElementCollector;
|
||||
import com.intellij.configurationStore.UnknownElementWriter;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
@@ -57,6 +59,8 @@ public class CodeStyleSettings extends CommonCodeStyleSettings implements Clonea
|
||||
@NonNls private static final String FILETYPE = "fileType";
|
||||
private CommonCodeStyleSettingsManager myCommonSettingsManager = new CommonCodeStyleSettingsManager(this);
|
||||
|
||||
private UnknownElementWriter myUnknownElementWriter = UnknownElementWriter.EMPTY;
|
||||
|
||||
public CodeStyleSettings() {
|
||||
this(true);
|
||||
}
|
||||
@@ -490,11 +494,14 @@ public class CodeStyleSettings extends CommonCodeStyleSettings implements Clonea
|
||||
IMPORT_LAYOUT_TABLE.addEntry(PackageEntry.ALL_OTHER_STATIC_IMPORTS_ENTRY);
|
||||
}
|
||||
}
|
||||
|
||||
UnknownElementCollector unknownElementCollector = new UnknownElementCollector();
|
||||
for (CustomCodeStyleSettings settings : getCustomSettingsValues()) {
|
||||
unknownElementCollector.addKnownName(settings.getTagName());
|
||||
settings.readExternal(element);
|
||||
settings.importLegacySettings();
|
||||
}
|
||||
|
||||
unknownElementCollector.addKnownName(ADDITIONAL_INDENT_OPTIONS);
|
||||
List<Element> list = element.getChildren(ADDITIONAL_INDENT_OPTIONS);
|
||||
if (list != null) {
|
||||
for (Element additionalIndentElement : list) {
|
||||
@@ -512,8 +519,11 @@ public class CodeStyleSettings extends CommonCodeStyleSettings implements Clonea
|
||||
}
|
||||
}
|
||||
|
||||
unknownElementCollector.addKnownName(CommonCodeStyleSettingsManager.COMMON_SETTINGS_TAG);
|
||||
myCommonSettingsManager.readExternal(element);
|
||||
|
||||
myUnknownElementWriter = unknownElementCollector.createWriter(element);
|
||||
|
||||
if (USE_SAME_INDENTS) {
|
||||
IGNORE_SAME_INDENTS_FOR_LANGUAGES = true;
|
||||
}
|
||||
@@ -523,16 +533,14 @@ public class CodeStyleSettings extends CommonCodeStyleSettings implements Clonea
|
||||
public void writeExternal(Element element) throws WriteExternalException {
|
||||
final CodeStyleSettings parentSettings = new CodeStyleSettings();
|
||||
DefaultJDOMExternalizer.writeExternal(this, element, new DifferenceFilter<CodeStyleSettings>(this, parentSettings));
|
||||
List<CustomCodeStyleSettings> customSettings = new ArrayList<CustomCodeStyleSettings>(getCustomSettingsValues());
|
||||
customSettings.sort((o1, o2) -> o1.getTagName().compareTo(o2.getTagName()));
|
||||
|
||||
for (final CustomCodeStyleSettings settings : customSettings) {
|
||||
final CustomCodeStyleSettings parentCustomSettings = parentSettings.getCustomSettings(settings.getClass());
|
||||
myUnknownElementWriter.write(element, getCustomSettingsValues(), CustomCodeStyleSettings::getTagName, settings -> {
|
||||
CustomCodeStyleSettings parentCustomSettings = parentSettings.getCustomSettings(settings.getClass());
|
||||
if (parentCustomSettings == null) {
|
||||
throw new WriteExternalException("Custom settings are null for " + settings.getClass());
|
||||
}
|
||||
settings.writeExternal(element, parentCustomSettings);
|
||||
}
|
||||
});
|
||||
|
||||
final FileType[] fileTypes = myAdditionalIndentOptions.keySet().toArray(new FileType[myAdditionalIndentOptions.keySet().size()]);
|
||||
Arrays.sort(fileTypes, (o1, o2) -> o1.getDefaultExtension().compareTo(o2.getDefaultExtension()));
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ public class CommonCodeStyleSettingsManager {
|
||||
|
||||
@NotNull private final CodeStyleSettings myParentSettings;
|
||||
|
||||
@NonNls private static final String COMMON_SETTINGS_TAG = "codeStyleSettings";
|
||||
@NonNls static final String COMMON_SETTINGS_TAG = "codeStyleSettings";
|
||||
private static final String LANGUAGE_ATTR = "language";
|
||||
|
||||
CommonCodeStyleSettingsManager(@NotNull CodeStyleSettings parentSettings) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -45,7 +45,11 @@ public abstract class CustomCodeStyleSettings implements Cloneable {
|
||||
}
|
||||
|
||||
public void readExternal(Element parentElement) throws InvalidDataException {
|
||||
DefaultJDOMExternalizer.readExternal(this, parentElement.getChild(myTagName));
|
||||
Element child = parentElement.getChild(myTagName);
|
||||
if (child != null) {
|
||||
DefaultJDOMExternalizer.readExternal(this, child);
|
||||
importLegacySettings();
|
||||
}
|
||||
}
|
||||
|
||||
public void writeExternal(Element parentElement, @NotNull final CustomCodeStyleSettings parentSettings) throws WriteExternalException {
|
||||
@@ -69,7 +73,6 @@ public abstract class CustomCodeStyleSettings implements Cloneable {
|
||||
/**
|
||||
* For compatibility with old code style settings stored in CodeStyleSettings.
|
||||
*/
|
||||
public void importLegacySettings() {
|
||||
protected void importLegacySettings() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -19,7 +19,7 @@ package com.intellij.openapi.util;
|
||||
* Throw this exception from {@link JDOMExternalizable#writeExternal(org.jdom.Element)} method if you don't want to store any settings.
|
||||
* If you simply return from the method empty '<component name=... />' tag will be written leading to unneeded modification of configuration files.
|
||||
*/
|
||||
public class WriteExternalException extends Exception {
|
||||
public class WriteExternalException extends RuntimeException {
|
||||
public WriteExternalException() {
|
||||
super();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -54,7 +54,7 @@ public class XmlCodeStyleSettings extends CustomCodeStyleSettings {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void importLegacySettings() {
|
||||
protected void importLegacySettings() {
|
||||
if (!XML_LEGACY_SETTINGS_IMPORTED) {
|
||||
CodeStyleSettings container = getContainer();
|
||||
CodeStyleSettings defaults = new CodeStyleSettings();
|
||||
|
||||
Reference in New Issue
Block a user