diff --git a/platform/platform-impl/src/com/intellij/ide/ui/search/SearchableOptionsRegistrarImpl.java b/platform/platform-impl/src/com/intellij/ide/ui/search/SearchableOptionsRegistrarImpl.java index a37f6ebebd8b..dd08b4a5ce92 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/search/SearchableOptionsRegistrarImpl.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/search/SearchableOptionsRegistrarImpl.java @@ -32,6 +32,7 @@ import com.intellij.openapi.util.JDOMUtil; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.ResourceUtil; +import com.intellij.util.SingletonSet; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.StringInterner; import gnu.trove.THashMap; @@ -62,11 +63,10 @@ public class SearchableOptionsRegistrarImpl extends SearchableOptionsRegistrar { @SuppressWarnings({"MismatchedQueryAndUpdateOfCollection"}) private final StringInterner myIdentifierTable = new StringInterner() { + @Override @NotNull - public String intern(@NotNull final String name) { - synchronized (this) { - return super.intern(name); - } + public synchronized String intern(@NotNull final String name) { + return super.intern(name); } }; @@ -163,8 +163,6 @@ public class SearchableOptionsRegistrarImpl extends SearchableOptionsRegistrar { } } } - - } catch (Exception e) { LOG.error(e); @@ -191,16 +189,25 @@ public class SearchableOptionsRegistrarImpl extends SearchableOptionsRegistrar { myId2Name.put(myIdentifierTable.intern(id), myIdentifierTable.intern(groupName)); } + OptionDescription description = + new OptionDescription(null, myIdentifierTable.intern(id).trim(), hit != null ? myIdentifierTable.intern(hit).trim() : null, + path != null ? myIdentifierTable.intern(path).trim() : null); Set configs = myStorage.get(option); if (configs == null) { - configs = new THashSet(3, 0.9f); + configs = new SingletonSet(description); myStorage.put(new String(option), configs); } - - configs.add(new OptionDescription(null, myIdentifierTable.intern(id).trim(), hit != null ? myIdentifierTable.intern(hit).trim() : null, - path != null ? myIdentifierTable.intern(path).trim() : null)); + else if (configs instanceof SingletonSet){ + configs = new THashSet(configs); + configs.add(description); + myStorage.put(new String(option), configs); + } + else { + configs.add(description); + } } + @Override @NotNull public ConfigurableHit getConfigurables(ConfigurableGroup[] groups, final DocumentEvent.EventType type, @@ -313,6 +320,7 @@ public class SearchableOptionsRegistrarImpl extends SearchableOptionsRegistrar { return result; } + @Override @Nullable public String getInnerPath(SearchableConfigurable configurable, @NonNls String option) { loadHugeFilesIfNecessary(); @@ -354,15 +362,18 @@ public class SearchableOptionsRegistrarImpl extends SearchableOptionsRegistrar { } } + @Override public boolean isStopWord(String word) { return myStopWords.contains(word); } + @Override public Set getSynonym(final String option, @NotNull final SearchableConfigurable configurable) { loadHugeFilesIfNecessary(); return myHighlightOption2Synonym.get(Pair.create(option, configurable.getId())); } + @Override public Map> findPossibleExtension(@NotNull String prefix, final Project project) { loadHugeFilesIfNecessary(); final boolean perProject = CodeStyleFacade.getInstance(project).projectUsesOwnSettings(); @@ -399,10 +410,12 @@ public class SearchableOptionsRegistrarImpl extends SearchableOptionsRegistrar { return result; } + @Override public void addOption(String option, String path, final String hit, final String configurableId, final String configurableDisplayName) { putOptionWithHelpId(option, configurableId, configurableDisplayName, hit, path); } + @Override public Set getProcessedWordsWithoutStemming(@NotNull String text) { Set result = new HashSet(); @NonNls final String toLowerCase = text.toLowerCase(); @@ -416,6 +429,7 @@ public class SearchableOptionsRegistrarImpl extends SearchableOptionsRegistrar { return result; } + @Override public Set getProcessedWords(@NotNull String text) { Set result = new HashSet(); @NonNls final String toLowerCase = text.toLowerCase(); @@ -429,6 +443,7 @@ public class SearchableOptionsRegistrarImpl extends SearchableOptionsRegistrar { return result; } + @Override public Set replaceSynonyms(Set options, SearchableConfigurable configurable) { final Set result = new HashSet(options); for (String option : options) { diff --git a/platform/util/src/com/intellij/util/SingletonSet.java b/platform/util/src/com/intellij/util/SingletonSet.java new file mode 100644 index 000000000000..52b5212bb2ea --- /dev/null +++ b/platform/util/src/com/intellij/util/SingletonSet.java @@ -0,0 +1,71 @@ +/* + * Copyright 2000-2012 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.util; + +import com.intellij.openapi.util.Comparing; +import org.jetbrains.annotations.NotNull; + +import java.util.AbstractSet; +import java.util.Iterator; +import java.util.NoSuchElementException; + +/** + * User: cdr + */ +public class SingletonSet extends AbstractSet { + private final E element; + + public SingletonSet(E e) { + element = e; + } + + @NotNull + @Override + public Iterator iterator() { + return new Iterator() { + private boolean hasNext = true; + + @Override + public boolean hasNext() { + return hasNext; + } + + @Override + public E next() { + if (hasNext) { + hasNext = false; + return element; + } + throw new NoSuchElementException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public int size() { + return 1; + } + + @Override + public boolean contains(Object o) { + return Comparing.equal(o, element); + } +}