diff --git a/platform/lang-impl/src/com/intellij/codeInsight/hints/settings/ParameterNameHintsSettings.java b/platform/lang-impl/src/com/intellij/codeInsight/hints/settings/ParameterNameHintsSettings.java index 403151819d38..f6dadaca1ae6 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/hints/settings/ParameterNameHintsSettings.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/hints/settings/ParameterNameHintsSettings.java @@ -22,6 +22,7 @@ import com.intellij.openapi.components.Storage; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.TestOnly; import java.util.List; import java.util.Set; @@ -54,6 +55,12 @@ public class ParameterNameHintsSettings implements PersistentStateComponent defaultIgnoreSet = DEFAULT; + + @TestOnly + protected void setDefaultSet(@NotNull Set ignoreSet) { + defaultIgnoreSet = ignoreSet; + } public static ParameterNameHintsSettings getInstance() { return ServiceManager.getService(ParameterNameHintsSettings.class); @@ -79,7 +86,7 @@ public class ParameterNameHintsSettings implements PersistentStateComponent getIgnorePatternSet() { - Set ignoreSet = ContainerUtil.newHashSet(DEFAULT); + Set ignoreSet = ContainerUtil.newHashSet(defaultIgnoreSet); state.diff.forEach((item) -> { if (item.startsWith("+")) { ignoreSet.add(item.substring(1)); @@ -97,9 +104,9 @@ public class ParameterNameHintsSettings implements PersistentStateComponent updatedBlackList) { Set addedItems = ContainerUtil.newHashSet(updatedBlackList); - DEFAULT.forEach((pattern) -> addedItems.remove(pattern)); + defaultIgnoreSet.forEach((pattern) -> addedItems.remove(pattern)); - Set removedItems = ContainerUtil.newHashSet(DEFAULT); + Set removedItems = ContainerUtil.newHashSet(defaultIgnoreSet); updatedBlackList.forEach((pattern) -> removedItems.remove(pattern)); List diff = ContainerUtil.newArrayList(); diff --git a/platform/lang-impl/testSources/com/intellij/codeInsight/hints/settings/ParameterNameSettingsTest.kt b/platform/lang-impl/testSources/com/intellij/codeInsight/hints/settings/ParameterNameSettingsTest.kt new file mode 100644 index 000000000000..9025764809ed --- /dev/null +++ b/platform/lang-impl/testSources/com/intellij/codeInsight/hints/settings/ParameterNameSettingsTest.kt @@ -0,0 +1,72 @@ +/* + * 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.codeInsight.hints.settings + +import junit.framework.TestCase + +class ParameterNameSettingsTest : TestCase() { + + fun `test deleted value is saved to state`() { + val settings = ParameterNameHintsSettings() + val ignoreSet = settings.ignorePatternSet + + assert(ignoreSet.size > 0) + val first = ignoreSet.first() + ignoreSet.remove(first) + + settings.ignorePatternSet = ignoreSet + + val diff = settings.state!!.diff + assert(diff.size == 1) + assert(diff[0].startsWith("-")) + assert(diff[0].endsWith(first)) + } + + fun `test saved value is saved to state`() { + val settings = ParameterNameHintsSettings() + val newPattern = "java.util.*(*)" + settings.addIgnorePattern(newPattern) + + val diff = settings.state!!.diff + assert(diff.size == 1) + assert(diff[0].startsWith("+")) + assert(diff[0].endsWith(newPattern)) + } + + fun `test on defaults change ensure removed default items remains removed`() { + val settings = ParameterNameHintsSettings() + settings.setDefaultSet(setOf("aaa", "bbb", "ccc")) + + settings.ignorePatternSet = setOf("aaa", "ccc", "zzz") + settings.addIgnorePattern("xxx") + + val savedState = settings.state + + val newSettings = ParameterNameHintsSettings() + newSettings.setDefaultSet(setOf("aaa", "bbb", "ccc", "qqq", "xxx")) + newSettings.loadState(savedState) + + val newIgnoreSet = newSettings.ignorePatternSet + assert(newIgnoreSet.containsAll(setOf("aaa", "ccc", "qqq", "zzz", "xxx"))) + assert(newIgnoreSet.size == 5) + newSettings.ignorePatternSet = newSettings.ignorePatternSet + + val diff = newSettings.state!!.diff + assert(diff.containsAll(setOf("-bbb", "+zzz"))) + assert(diff.size == 2) + } + +} \ No newline at end of file