mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-65810 Class completion: suggest most probable class in the specific context.
This commit is contained in:
+16
@@ -0,0 +1,16 @@
|
||||
enum Zoo {
|
||||
A,B,C,D,E,F,G,H
|
||||
}
|
||||
|
||||
class Zaa {}
|
||||
class Zab {}
|
||||
class Zac {}
|
||||
class Zad {}
|
||||
class Zae {}
|
||||
|
||||
class Bar {
|
||||
|
||||
{
|
||||
Zoo z = Z<caret>
|
||||
}
|
||||
}
|
||||
+4
@@ -205,4 +205,8 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase {
|
||||
checkPreferredItems(0, "foo", "boo", "doo", "hashCode");
|
||||
}
|
||||
|
||||
public void testPreferClassOverItsStaticMembers() {
|
||||
checkPreferredItems(0, "Zoo");
|
||||
}
|
||||
|
||||
}
|
||||
+14
-5
@@ -19,6 +19,8 @@ import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
@@ -31,14 +33,21 @@ public class PrefixMatchingWeigher extends CompletionWeigher {
|
||||
return 0;
|
||||
}
|
||||
|
||||
final String lookupString = item.getLookupString();
|
||||
final String prefixHumps = StringUtil.capitalsOnly(prefix);
|
||||
final String itemHumps = StringUtil.capitalsOnly(lookupString);
|
||||
final Set<String> strings = item.getAllLookupStrings();
|
||||
|
||||
for (String lookupString : strings) {
|
||||
if (StringUtil.capitalsOnly(lookupString).startsWith(prefixHumps)) return 100;
|
||||
}
|
||||
|
||||
for (String lookupString : strings) {
|
||||
if (lookupString.startsWith(prefix)) return 5;
|
||||
}
|
||||
for (String lookupString : strings) {
|
||||
if (StringUtil.startsWithIgnoreCase(lookupString, prefix)) return 1;
|
||||
}
|
||||
|
||||
if (itemHumps.startsWith(prefixHumps)) return 100;// - itemHumps.length();
|
||||
|
||||
if (lookupString.startsWith(prefix)) return 5;
|
||||
if (StringUtil.startsWithIgnoreCase(lookupString, prefix)) return 1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
+5
-1
@@ -93,7 +93,11 @@ class LiftShorterItemsClassifier extends Classifier<LookupElement> {
|
||||
for (LookupElement shorterElement : myElements.get(prefix)) {
|
||||
if (srcSet.contains(shorterElement) && processed.add(shorterElement)) {
|
||||
lifted.add(shorterElement);
|
||||
group.add(shorterElement);
|
||||
if (group.isEmpty()) {
|
||||
result.add(Collections.singletonList(shorterElement));
|
||||
} else {
|
||||
group.add(shorterElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user