mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
minor
This commit is contained in:
+3
-2
@@ -34,6 +34,7 @@ import com.intellij.psi.WeighingService;
|
||||
import com.intellij.psi.statistics.StatisticsInfo;
|
||||
import com.intellij.psi.statistics.StatisticsManager;
|
||||
import com.intellij.util.Alarm;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import gnu.trove.THashMap;
|
||||
@@ -107,7 +108,7 @@ public class CompletionLookupArranger extends LookupArranger {
|
||||
}
|
||||
Classifier<LookupElement> classifier = myClassifiers.get(sorter);
|
||||
if (classifier != null) {
|
||||
classifier.describeItems(subMap);
|
||||
classifier.describeItems(subMap, new ProcessingContext());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,7 +154,7 @@ public class CompletionLookupArranger extends LookupArranger {
|
||||
|
||||
final List<LookupElement> byRelevance = new ArrayList<LookupElement>();
|
||||
for (CompletionSorterImpl sorter : myClassifiers.keySet()) {
|
||||
ContainerUtil.addAll(byRelevance, myClassifiers.get(sorter).classify((List<LookupElement>)inputBySorter.get(sorter)));
|
||||
ContainerUtil.addAll(byRelevance, myClassifiers.get(sorter).classify(inputBySorter.get(sorter), new ProcessingContext()));
|
||||
}
|
||||
|
||||
LinkedHashSet<LookupElement> model = new LinkedHashSet<LookupElement>();
|
||||
|
||||
+17
-20
@@ -17,6 +17,7 @@ package com.intellij.codeInsight.completion.impl;
|
||||
|
||||
import com.intellij.codeInsight.lookup.Classifier;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import com.intellij.util.SmartList;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
@@ -73,19 +74,25 @@ class LiftShorterItemsClassifier extends Classifier<LookupElement> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<LookupElement> classify(List<LookupElement> source) {
|
||||
return liftShorterElements(source, new THashSet<LookupElement>(TObjectHashingStrategy.IDENTITY));
|
||||
public Iterable<LookupElement> classify(Iterable<LookupElement> source, ProcessingContext context) {
|
||||
return liftShorterElements(source, new THashSet<LookupElement>(TObjectHashingStrategy.IDENTITY), context);
|
||||
}
|
||||
|
||||
private List<LookupElement> liftShorterElements(List<LookupElement> source, THashSet<LookupElement> lifted) {
|
||||
final Set<LookupElement> srcSet = new THashSet<LookupElement>(source, TObjectHashingStrategy.IDENTITY);
|
||||
private List<LookupElement> liftShorterElements(Iterable<LookupElement> source, THashSet<LookupElement> lifted, ProcessingContext context) {
|
||||
final Set<LookupElement> srcSet = new THashSet<LookupElement>(TObjectHashingStrategy.IDENTITY);
|
||||
ContainerUtil.addAll(srcSet, source);
|
||||
final Set<LookupElement> processed = new THashSet<LookupElement>(TObjectHashingStrategy.IDENTITY);
|
||||
|
||||
final List<LookupElement> result = new ArrayList<LookupElement>();
|
||||
for (LookupElement element : myNext.classify(source)) {
|
||||
for (LookupElement element : myNext.classify(source, context)) {
|
||||
assert srcSet.contains(element) : myNext;
|
||||
if (processed.add(element)) {
|
||||
for (String prefix : getSortedPrefixes(element)) {
|
||||
final List<String> prefixes = new SmartList<String>();
|
||||
for (String string : getAllLookupStrings(element)) {
|
||||
prefixes.addAll(myPrefixes.get(string));
|
||||
}
|
||||
Collections.sort(prefixes);
|
||||
for (String prefix : prefixes) {
|
||||
List<LookupElement> shorter = new SmartList<LookupElement>();
|
||||
for (LookupElement shorterElement : myElements.get(prefix)) {
|
||||
if (srcSet.contains(shorterElement) && processed.add(shorterElement)) {
|
||||
@@ -95,7 +102,7 @@ class LiftShorterItemsClassifier extends Classifier<LookupElement> {
|
||||
|
||||
lifted.addAll(shorter);
|
||||
|
||||
ContainerUtil.addAll(result, myNext.classify(shorter));
|
||||
ContainerUtil.addAll(result, myNext.classify(shorter, context));
|
||||
}
|
||||
result.add(element);
|
||||
}
|
||||
@@ -103,24 +110,14 @@ class LiftShorterItemsClassifier extends Classifier<LookupElement> {
|
||||
return result;
|
||||
}
|
||||
|
||||
private String[] getSortedPrefixes(LookupElement element) {
|
||||
final List<String> prefixes = new SmartList<String>();
|
||||
for (String string : getAllLookupStrings(element)) {
|
||||
prefixes.addAll(myPrefixes.get(string));
|
||||
}
|
||||
String[] result = prefixes.toArray(new String[prefixes.size()]);
|
||||
Arrays.sort(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Set<String> getAllLookupStrings(LookupElement element) {
|
||||
return element.getAllLookupStrings();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeItems(LinkedHashMap<LookupElement, StringBuilder> map) {
|
||||
public void describeItems(LinkedHashMap<LookupElement, StringBuilder> map, ProcessingContext context) {
|
||||
final HashSet<LookupElement> lifted = new HashSet<LookupElement>();
|
||||
liftShorterElements(new ArrayList<LookupElement>(map.keySet()), new THashSet<LookupElement>(TObjectHashingStrategy.IDENTITY));
|
||||
liftShorterElements(new ArrayList<LookupElement>(map.keySet()), new THashSet<LookupElement>(TObjectHashingStrategy.IDENTITY), new ProcessingContext());
|
||||
if (!lifted.isEmpty()) {
|
||||
for (LookupElement element : map.keySet()) {
|
||||
final StringBuilder builder = map.get(element);
|
||||
@@ -131,6 +128,6 @@ class LiftShorterItemsClassifier extends Classifier<LookupElement> {
|
||||
builder.append("liftShorter=").append(lifted.contains(element));
|
||||
}
|
||||
}
|
||||
myNext.describeItems(map);
|
||||
myNext.describeItems(map, context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,8 +15,9 @@
|
||||
*/
|
||||
package com.intellij.codeInsight.lookup;
|
||||
|
||||
import com.intellij.util.ProcessingContext;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
@@ -24,8 +25,8 @@ import java.util.List;
|
||||
public abstract class Classifier<T> {
|
||||
public abstract void addElement(T t);
|
||||
|
||||
public abstract Iterable<T> classify(List<T> source);
|
||||
public abstract Iterable<T> classify(Iterable<T> source, ProcessingContext context);
|
||||
|
||||
public abstract void describeItems(LinkedHashMap<T, StringBuilder> map);
|
||||
public abstract void describeItems(LinkedHashMap<T, StringBuilder> map, ProcessingContext context);
|
||||
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.intellij.codeInsight.lookup;
|
||||
|
||||
import com.intellij.util.ProcessingContext;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@@ -40,12 +42,12 @@ public abstract class ClassifierFactory<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<T> classify(List<T> source) {
|
||||
public Iterable<T> classify(Iterable<T> source, ProcessingContext context) {
|
||||
return source;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeItems(LinkedHashMap<T, StringBuilder> map) {
|
||||
public void describeItems(LinkedHashMap<T, StringBuilder> map, ProcessingContext context) {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.intellij.codeInsight.lookup;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import com.intellij.util.SmartList;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -41,7 +42,7 @@ public abstract class ComparingClassifier<T> extends Classifier<T> {
|
||||
myNext.addElement(t);
|
||||
}
|
||||
|
||||
private TreeMap<Comparable, List<T>> groupByWeights(List<T> source) {
|
||||
private TreeMap<Comparable, List<T>> groupByWeights(Iterable<T> source) {
|
||||
TreeMap<Comparable, List<T>> map = new TreeMap<Comparable, List<T>>();
|
||||
for (T t : source) {
|
||||
final Comparable weight = getWeight(t);
|
||||
@@ -55,16 +56,16 @@ public abstract class ComparingClassifier<T> extends Classifier<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<T> classify(List<T> source) {
|
||||
public Iterable<T> classify(Iterable<T> source, ProcessingContext context) {
|
||||
List<T> result = new ArrayList<T>();
|
||||
for (List<T> list : groupByWeights(source).values()) {
|
||||
ContainerUtil.addAll(result, myNext.classify(list));
|
||||
ContainerUtil.addAll(result, myNext.classify(list, context));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeItems(LinkedHashMap<T, StringBuilder> map) {
|
||||
public void describeItems(LinkedHashMap<T, StringBuilder> map, ProcessingContext context) {
|
||||
final TreeMap<Comparable, List<T>> treeMap = groupByWeights(new ArrayList<T>(map.keySet()));
|
||||
if (treeMap.size() > 1 || ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
for (Map.Entry<Comparable, List<T>> entry: treeMap.entrySet()){
|
||||
@@ -78,6 +79,6 @@ public abstract class ComparingClassifier<T> extends Classifier<T> {
|
||||
}
|
||||
}
|
||||
}
|
||||
myNext.describeItems(map);
|
||||
myNext.describeItems(map, context);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user