make file structure popup matching use common matchingDegree heuristics

This commit is contained in:
peter
2013-02-15 18:32:53 +01:00
parent 90f9959fe7
commit b3e0176c26
3 changed files with 19 additions and 38 deletions
@@ -1,5 +1,5 @@
-Camel.java
-Camel
[doSomethingWithMyHead(): void]
doSomethingWithMyHead(): void
getSomeArtHeader(): void
getSomeHead(): void
[getSomeHead(): void]
@@ -43,8 +43,16 @@ public class SpeedSearchComparator {
myShouldMatchCamelCase = shouldMatchCamelCase;
}
public int matchingDegree(String pattern, String text) {
return obtainMatcher(pattern).matchingDegree(text);
}
@Nullable
public Iterable<TextRange> matchingFragments(String pattern, String text) {
return obtainMatcher(pattern).matchingFragments(text);
}
private MinusculeMatcher obtainMatcher(String pattern) {
if (myRecentSearchText == null || !myRecentSearchText.equals(pattern)) {
myRecentSearchText = pattern;
if (myShouldMatchCamelCase) {
@@ -55,7 +63,7 @@ public class SpeedSearchComparator {
}
myMinusculeMatcher = new MinusculeMatcher(pattern, NameUtil.MatchingCaseSensitivity.NONE);
}
return myMinusculeMatcher.matchingFragments(text);
return myMinusculeMatcher;
}
public String getRecentSearchText() {
@@ -15,52 +15,25 @@
*/
package com.intellij.ui;
import com.intellij.openapi.util.TextRange;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
/**
* @author Konstantin Bulenkov
*/
public class SpeedSearchObjectWithWeight {
private static final Comparator<TextRange> TEXT_RANGE_COMPARATOR = new Comparator<TextRange>() {
@Override
public int compare(TextRange o1, TextRange o2) {
if (o1.getStartOffset() == o2.getStartOffset()) {
return o2.getEndOffset() - o1.getEndOffset(); //longer is better
}
return o1.getStartOffset() - o2.getStartOffset();
}
};
public final Object node;
final List<TextRange> weights = new ArrayList<TextRange>();
public final int weight;
SpeedSearchObjectWithWeight(Object element, String pattern, SpeedSearchBase speedSearch) {
this.node = element;
final String text = speedSearch.getElementText(element);
if (text != null) {
final Iterable<TextRange> ranges = speedSearch.getComparator().matchingFragments(pattern, text);
if (ranges != null) {
for (TextRange range : ranges) {
weights.add(range);
}
}
}
Collections.sort(weights, TEXT_RANGE_COMPARATOR);
String text = speedSearch.getElementText(element);
this.weight = text == null ? Integer.MIN_VALUE : speedSearch.getComparator().matchingDegree(pattern, text);
}
public int compareWith(SpeedSearchObjectWithWeight obj) {
final List<TextRange> w = obj.weights;
for (int i = 0; i < weights.size(); i++) {
if (i >= w.size()) return 1;
final int result = TEXT_RANGE_COMPARATOR.compare(weights.get(i), w.get(i));
if (result != 0) {
return result;
}
}
return 0;
return weight == obj.weight ? 0 : weight < obj.weight ? 1 : -1;
}
public static List<SpeedSearchObjectWithWeight> findElement(String s, SpeedSearchBase speedSearch) {
@@ -70,7 +43,7 @@ public class SpeedSearchObjectWithWeight {
final ListIterator<Object> it = speedSearch.getElementIterator(0);
while (it.hasNext()) {
final SpeedSearchObjectWithWeight o = new SpeedSearchObjectWithWeight(it.next(), s, speedSearch);
if (!o.weights.isEmpty()) {
if (o.weight != Integer.MIN_VALUE) {
elements.add(o);
}
}