java completion: put type above signature containing that type (IDEA-181329)

This commit is contained in:
peter
2017-12-21 13:37:01 +01:00
parent 3c0fdc4e89
commit 5806663661
5 changed files with 18 additions and 4 deletions
@@ -621,7 +621,11 @@ public class JavaCompletionSorting {
@Override
public boolean shouldLift(LookupElement shorterElement, LookupElement longerElement) {
Object object = shorterElement.getObject();
if (object instanceof PsiClass && longerElement.getObject() instanceof PsiClass) {
if (!(object instanceof PsiClass)) return false;
if (longerElement.getUserData(JavaGenerateMemberCompletionContributor.GENERATE_ELEMENT) != null) return true;
if (longerElement.getObject() instanceof PsiClass) {
PsiClass psiClass = (PsiClass)object;
PsiFile file = psiClass.getContainingFile();
if (file != null) {
@@ -201,7 +201,8 @@ public class JavaGenerateMemberCompletionContributor {
}
PsiType type = substitutor.substitute(prototype.getReturnType());
String signature = modifiers + (type == null ? "" : type.getPresentableText() + " ") + methodName;
String typeAndName = (type == null ? "" : type.getPresentableText() + " ") + methodName;
String signature = modifiers + typeAndName;
String parameters = "(" + StringUtil.join(prototype.getParameterList().getParameters(),
p -> getShortParameterName(substitutor, p) + " " + p.getName(),
@@ -209,6 +210,7 @@ public class JavaGenerateMemberCompletionContributor {
String overrideSignature = " @Override " + signature; // leading space to make it a middle match, under all annotation suggestions
LookupElementBuilder element = LookupElementBuilder.create(prototype, signature).withLookupString(methodName).
withLookupString(typeAndName).
withLookupString(signature).withLookupString(overrideSignature).withInsertHandler(insertHandler).
appendTailText(parameters, false).appendTailText(" {...}", true).withTypeText(typeText).withIcon(icon);
if (prototype.isDeprecated()) {
@@ -0,0 +1,4 @@
class Foo {
private String zoo;
public Stri<caret>
}
@@ -824,4 +824,8 @@ class Foo {
myFixture.assertPreferredCompletionItems 0, 'out', 'exit'
}
void testPreferTypeToGeneratedMethod() {
checkPreferredItems 0, 'String', 'public String getZoo', 'public String toString'
}
}
@@ -1662,14 +1662,14 @@ class Bar {
myFixture.configureByText('a.java', 'class Fooxxxxxxxxxx { Fooxxxxx<caret>a f;\n' + 'public void foo() {}\n' * 10000 + '}')
def items = myFixture.completeBasic()
PsiClass c1 = items[0].object
PsiClass c1 = items[1].object
assert !c1.physical
assert CompletionUtil.getOriginalElement(c1)
getLookup().hide()
myFixture.type('x')
items = myFixture.completeBasic()
PsiClass c2 = items[0].object
PsiClass c2 = items[1].object
assert !c2.physical
assert CompletionUtil.getOriginalElement(c2)