This commit is contained in:
Alexey Kudravtsev
2012-10-26 13:10:21 +04:00
parent 57218bb079
commit ee060f5c6c
2 changed files with 96 additions and 10 deletions
@@ -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<OptionDescription> configs = myStorage.get(option);
if (configs == null) {
configs = new THashSet<OptionDescription>(3, 0.9f);
configs = new SingletonSet<OptionDescription>(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<OptionDescription>(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<String> getSynonym(final String option, @NotNull final SearchableConfigurable configurable) {
loadHugeFilesIfNecessary();
return myHighlightOption2Synonym.get(Pair.create(option, configurable.getId()));
}
@Override
public Map<String, Set<String>> 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<String> getProcessedWordsWithoutStemming(@NotNull String text) {
Set<String> result = new HashSet<String>();
@NonNls final String toLowerCase = text.toLowerCase();
@@ -416,6 +429,7 @@ public class SearchableOptionsRegistrarImpl extends SearchableOptionsRegistrar {
return result;
}
@Override
public Set<String> getProcessedWords(@NotNull String text) {
Set<String> result = new HashSet<String>();
@NonNls final String toLowerCase = text.toLowerCase();
@@ -429,6 +443,7 @@ public class SearchableOptionsRegistrarImpl extends SearchableOptionsRegistrar {
return result;
}
@Override
public Set<String> replaceSynonyms(Set<String> options, SearchableConfigurable configurable) {
final Set<String> result = new HashSet<String>(options);
for (String option : options) {
@@ -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<E> extends AbstractSet<E> {
private final E element;
public SingletonSet(E e) {
element = e;
}
@NotNull
@Override
public Iterator<E> iterator() {
return new Iterator<E>() {
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);
}
}