mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 07:40:42 +07:00
java completion relevance sorting on the new api, done
This commit is contained in:
@@ -432,75 +432,6 @@ public class JavaCompletionUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int getNameEndMatchingDegree(final String name, ExpectedTypeInfo[] expectedInfos, String prefix) {
|
||||
int res = 0;
|
||||
if (name != null && expectedInfos != null) {
|
||||
if (prefix.equals(name)) {
|
||||
res = Integer.MAX_VALUE;
|
||||
} else {
|
||||
final List<String> words = NameUtil.nameToWordsLowerCase(name);
|
||||
final List<String> wordsNoDigits = NameUtil.nameToWordsLowerCase(truncDigits(name));
|
||||
int max1 = calcMatch(words, 0, expectedInfos);
|
||||
max1 = calcMatch(wordsNoDigits, max1, expectedInfos);
|
||||
res = max1;
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static String truncDigits(String name){
|
||||
int count = name.length() - 1;
|
||||
while (count >= 0) {
|
||||
char c = name.charAt(count);
|
||||
if (!Character.isDigit(c)) break;
|
||||
count--;
|
||||
}
|
||||
return name.substring(0, count + 1);
|
||||
}
|
||||
|
||||
private static int calcMatch(final List<String> words, int max, ExpectedTypeInfo[] myExpectedInfos) {
|
||||
for (ExpectedTypeInfo myExpectedInfo : myExpectedInfos) {
|
||||
String expectedName = ((ExpectedTypeInfoImpl)myExpectedInfo).expectedName;
|
||||
if (expectedName == null) continue;
|
||||
max = calcMatch(expectedName, words, max);
|
||||
max = calcMatch(truncDigits(expectedName), words, max);
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
static int calcMatch(final String expectedName, final List<String> words, int max) {
|
||||
if (expectedName == null) return max;
|
||||
|
||||
String[] expectedWords = NameUtil.nameToWords(expectedName);
|
||||
int limit = Math.min(words.size(), expectedWords.length);
|
||||
for (int i = 0; i < limit; i++) {
|
||||
String word = words.get(words.size() - i - 1);
|
||||
String expectedWord = expectedWords[expectedWords.length - i - 1];
|
||||
if (word.equalsIgnoreCase(expectedWord)) {
|
||||
max = Math.max(max, i + 1);
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static String getLookupObjectName(Object o) {
|
||||
if (o instanceof PsiVariable) {
|
||||
final PsiVariable variable = (PsiVariable)o;
|
||||
JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(variable.getProject());
|
||||
VariableKind variableKind = codeStyleManager.getVariableKind(variable);
|
||||
return codeStyleManager.variableNameToPropertyName(variable.getName(), variableKind);
|
||||
}
|
||||
if (o instanceof PsiMethod) {
|
||||
return ((PsiMethod)o).getName();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiType getLookupElementType(final LookupElement element) {
|
||||
TypedLookupItem typed = element.as(TypedLookupItem.CLASS_CONDITION_KEY);
|
||||
|
||||
Reference in New Issue
Block a user