mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
prefer better matching constants to methods
This commit is contained in:
@@ -60,7 +60,7 @@ public class JavaCompletionSorting {
|
||||
|
||||
List<LookupElementWeigher> afterNegativeStats = new ArrayList<LookupElementWeigher>();
|
||||
if (!smart) {
|
||||
ContainerUtil.addIfNotNull(afterNegativeStats, preferStatics(position));
|
||||
ContainerUtil.addIfNotNull(afterNegativeStats, preferStatics(position, expectedTypes));
|
||||
}
|
||||
afterNegativeStats.add(new PreferLocalVariablesLiteralsAndAnnoMethodsWeigher(type, position));
|
||||
ContainerUtil.addIfNotNull(afterNegativeStats, recursion(parameters, expectedTypes));
|
||||
@@ -126,7 +126,7 @@ public class JavaCompletionSorting {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static LookupElementWeigher preferStatics(PsiElement position) {
|
||||
private static LookupElementWeigher preferStatics(PsiElement position, final ExpectedTypeInfo[] infos) {
|
||||
if (PsiTreeUtil.getParentOfType(position, PsiDocComment.class) != null) {
|
||||
return null;
|
||||
}
|
||||
@@ -149,7 +149,7 @@ public class JavaCompletionSorting {
|
||||
if (o instanceof PsiKeyword) return -3;
|
||||
if (!(o instanceof PsiMember)) return 0;
|
||||
|
||||
if (((PsiMember)o).hasModifierProperty(PsiModifier.STATIC)) {
|
||||
if (((PsiMember)o).hasModifierProperty(PsiModifier.STATIC) && !hasNonVoid(infos)) {
|
||||
if (o instanceof PsiMethod) return -5;
|
||||
if (o instanceof PsiField) return -4;
|
||||
}
|
||||
@@ -179,14 +179,7 @@ public class JavaCompletionSorting {
|
||||
}
|
||||
}
|
||||
|
||||
boolean hasNonVoid = false;
|
||||
for (ExpectedTypeInfo info : expectedInfos) {
|
||||
if (!PsiType.VOID.equals(info.getType())) {
|
||||
hasNonVoid = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasNonVoid) {
|
||||
if (hasNonVoid(expectedInfos)) {
|
||||
if (item.getObject() instanceof PsiKeyword) {
|
||||
String keyword = ((PsiKeyword)item.getObject()).getText();
|
||||
if (PsiKeyword.NEW.equals(keyword) || PsiKeyword.NULL.equals(keyword)) {
|
||||
@@ -201,6 +194,16 @@ public class JavaCompletionSorting {
|
||||
return ExpectedTypeMatching.normal;
|
||||
}
|
||||
|
||||
private static boolean hasNonVoid(ExpectedTypeInfo[] expectedInfos) {
|
||||
boolean hasNonVoid = false;
|
||||
for (ExpectedTypeInfo info : expectedInfos) {
|
||||
if (!PsiType.VOID.equals(info.getType())) {
|
||||
hasNonVoid = true;
|
||||
}
|
||||
}
|
||||
return hasNonVoid;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String getLookupObjectName(Object o) {
|
||||
if (o instanceof PsiVariable) {
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
class Foo {
|
||||
String s = Util.se<caret>
|
||||
}
|
||||
|
||||
class Util {
|
||||
public static final String serial = "serialVersionUID";
|
||||
|
||||
public static Runnable superExpressionInIllegalContext() {}
|
||||
|
||||
}
|
||||
+5
-1
@@ -87,7 +87,7 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase {
|
||||
final String path = getTestName(false) + ".java";
|
||||
myFixture.configureByFile(path);
|
||||
myFixture.complete(CompletionType.BASIC, 2);
|
||||
assertPreferredItems(0, "booleanMethod", "voidMethod", "registerNatives", "BOOLEAN", "AN_OBJECT");
|
||||
assertPreferredItems(0, "BOOLEAN", "booleanMethod", "AN_OBJECT", "voidMethod", "registerNatives");
|
||||
}
|
||||
|
||||
public void testDispreferDeclared() throws Throwable {
|
||||
@@ -314,4 +314,8 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase {
|
||||
checkPreferredItems 0, 'noo', 'new', 'null', 'noo2', 'notify', 'notifyAll'
|
||||
}
|
||||
|
||||
public void testPreferBetterMatchingConstantToMethods() {
|
||||
checkPreferredItems 0, 'serial', 'superExpressionInIllegalContext'
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user