IDEA-162844 more correct fix
authorVladimir Krivosheev <vladimir.krivosheev@jetbrains.com>
Fri, 28 Oct 2016 12:36:35 +0000 (14:36 +0200)
committerVladimir Krivosheev <vladimir.krivosheev@jetbrains.com>
Fri, 28 Oct 2016 12:46:46 +0000 (14:46 +0200)
STR: https://youtrack.jetbrains.com/issue/IDEA-162774#comment=27-1678789)

platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/impl/AbstractColorsScheme.java
platform/platform-tests/testSrc/com/intellij/openapi/editor/colors/EditorColorSchemeTest.kt
platform/testFramework/testSrc/com/intellij/openapi/editor/colors/editorColorScheme.kt [new file with mode: 0644]

index 28fc81473e6eecf8192d2b31663bf37a25895479..60672f8bf92c90475114826fdaee42a0d3edfb16 100644 (file)
@@ -623,6 +623,12 @@ public abstract class AbstractColorsScheme implements EditorColorsScheme, Serial
     }
   }
 
+  private boolean isParentOverwritingInheritance(@NotNull TextAttributesKey key) {
+    TextAttributes parentAttributes =
+      myParentScheme instanceof AbstractColorsScheme ? ((AbstractColorsScheme)myParentScheme).getDirectlyDefinedAttributes(key) : null;
+    return parentAttributes != null && parentAttributes != USE_INHERITED_MARKER;
+  }
+
   private void writeAttributes(@NotNull Element attrElements) throws WriteExternalException {
     List<TextAttributesKey> list = new ArrayList<>(myAttributesMap.keySet());
     list.sort(null);
@@ -630,7 +636,8 @@ public abstract class AbstractColorsScheme implements EditorColorsScheme, Serial
       TextAttributes attributes = myAttributesMap.get(key);
       TextAttributesKey baseKey = key.getFallbackAttributeKey();
       if (attributes == USE_INHERITED_MARKER) {
-        if (baseKey != null) {
+        // do not store if  inheritance = on in the parent scheme (https://youtrack.jetbrains.com/issue/IDEA-162774)
+        if (baseKey != null && isParentOverwritingInheritance(key)) {
           attrElements.addContent(new Element(OPTION_ELEMENT)
                                     .setAttribute(NAME_ATTR, key.getExternalName())
                                     .setAttribute(BASE_ATTRIBUTES_ATTR, baseKey.getExternalName()));
index 0a16a493729acf8216f74e6aac44e746f1775586..dacc78257b15dec672b36bc8b3537a85533ee89e 100644 (file)
@@ -17,6 +17,7 @@ package com.intellij.openapi.editor.colors
 
 import com.intellij.configurationStore.SchemeManagerFactoryBase
 import com.intellij.openapi.editor.colors.ex.DefaultColorSchemesManager
+import com.intellij.openapi.editor.colors.impl.AbstractColorsScheme
 import com.intellij.openapi.editor.colors.impl.EditorColorsManagerImpl
 import com.intellij.testFramework.InMemoryFsRule
 import com.intellij.testFramework.ProjectRule
@@ -43,15 +44,9 @@ class EditorColorSchemeTest {
     val schemeFile = fsRule.fs.getPath("colors/Foo.icls")
     val schemeData = """
     <scheme name="Foo" version="142" parent_scheme="Default">
-      <metaInfo>
-        <property name="created">2016-09-29T12:13:05</property>
-        <property name="ide">idea</property>
-        <property name="ideVersion">2016.3.0.0</property>
-        <property name="modified">2016-09-29T12:14:54</property>
-        <property name="originalScheme">Default</property>
-      </metaInfo>
       <option name="EDITOR_FONT_SIZE" value="12" />
       <option name="EDITOR_FONT_NAME" value="Menlo" />
+      <option name="JAVA_NUMBER" baseAttributes="DEFAULT_NUMBER" />
     </scheme>""".trimIndent()
     schemeFile.write(schemeData)
     val schemeManagerFactory = SchemeManagerFactoryBase.TestSchemeManagerFactory(fsRule.fs.getPath(""))
@@ -60,9 +55,16 @@ class EditorColorSchemeTest {
     val scheme = manager.getScheme("Foo")
     assertThat(scheme.name).isEqualTo("Foo")
 
+    (scheme as AbstractColorsScheme).isSaveNeeded = true
+
     schemeManagerFactory.save()
 
-    assertThat(schemeFile.readText()).isEqualTo(schemeData)
+    // JAVA_NUMBER is removed - see isParentOverwritingInheritance
+    assertThat(removeSchemeMetaInfo(schemeFile.readText())).isEqualTo("""
+    <scheme name="Foo" version="142" parent_scheme="Default">
+      <option name="EDITOR_FONT_SIZE" value="12" />
+      <option name="EDITOR_FONT_NAME" value="Menlo" />
+    </scheme>""".trimIndent())
     assertThat(schemeFile.parent).hasChildren("Foo.icls")
   }
 }
diff --git a/platform/testFramework/testSrc/com/intellij/openapi/editor/colors/editorColorScheme.kt b/platform/testFramework/testSrc/com/intellij/openapi/editor/colors/editorColorScheme.kt
new file mode 100644 (file)
index 0000000..08b20e3
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * 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.openapi.editor.colors
+
+import java.util.regex.Pattern
+
+fun removeSchemeMetaInfo(result: String): String {
+  val matcher = Pattern.compile("\\s+<metaInfo>.*</metaInfo>", Pattern.DOTALL).matcher(result)
+  if (!matcher.find()) {
+    return result
+  }
+
+  val builder = StringBuffer()
+  matcher.appendReplacement(builder, "")
+  matcher.appendTail(builder)
+  return builder.toString()
+}
\ No newline at end of file