mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
java completion: put signature suggestions below all types (IDEA-187504, IDEA-CR-28091)
This commit is contained in:
@@ -621,11 +621,7 @@ public class JavaCompletionSorting {
|
||||
@Override
|
||||
public boolean shouldLift(LookupElement shorterElement, LookupElement longerElement) {
|
||||
Object object = shorterElement.getObject();
|
||||
if (!(object instanceof PsiClass)) return false;
|
||||
|
||||
if (longerElement.getUserData(JavaGenerateMemberCompletionContributor.GENERATE_ELEMENT) != null) return true;
|
||||
|
||||
if (longerElement.getObject() instanceof PsiClass) {
|
||||
if (object instanceof PsiClass && longerElement.getObject() instanceof PsiClass) {
|
||||
PsiClass psiClass = (PsiClass)object;
|
||||
PsiFile file = psiClass.getContainingFile();
|
||||
if (file != null) {
|
||||
|
||||
+11
-13
@@ -136,9 +136,9 @@ public class JavaGenerateMemberCompletionContributor {
|
||||
}
|
||||
}
|
||||
|
||||
private static LookupElementBuilder createOverridingLookupElement(boolean implemented,
|
||||
final PsiMethod baseMethod,
|
||||
PsiClass baseClass, PsiSubstitutor substitutor, boolean generateDefaultMethods, PsiClass targetClass) {
|
||||
private static LookupElement createOverridingLookupElement(boolean implemented,
|
||||
PsiMethod baseMethod,
|
||||
PsiClass baseClass, PsiSubstitutor substitutor, boolean generateDefaultMethods, PsiClass targetClass) {
|
||||
|
||||
RowIcon icon = new RowIcon(baseMethod.getIcon(0), implemented ? AllIcons.Gutter.ImplementingMethod : AllIcons.Gutter.OverridingMethod);
|
||||
return createGenerateMethodElement(baseMethod, substitutor, icon, baseClass.getName(), new InsertHandler<LookupElement>() {
|
||||
@@ -186,12 +186,12 @@ public class JavaGenerateMemberCompletionContributor {
|
||||
}
|
||||
}
|
||||
|
||||
private static LookupElementBuilder createGenerateMethodElement(PsiMethod prototype,
|
||||
PsiSubstitutor substitutor,
|
||||
Icon icon,
|
||||
String typeText, InsertHandler<LookupElement> insertHandler,
|
||||
boolean generateDefaultMethod,
|
||||
PsiClass targetClass) {
|
||||
private static LookupElement createGenerateMethodElement(PsiMethod prototype,
|
||||
PsiSubstitutor substitutor,
|
||||
Icon icon,
|
||||
String typeText, InsertHandler<LookupElement> insertHandler,
|
||||
boolean generateDefaultMethod,
|
||||
PsiClass targetClass) {
|
||||
String methodName = prototype.getName();
|
||||
|
||||
String visibility = VisibilityUtil.getVisibilityModifier(prototype.getModifierList());
|
||||
@@ -201,8 +201,7 @@ public class JavaGenerateMemberCompletionContributor {
|
||||
}
|
||||
|
||||
PsiType type = substitutor.substitute(prototype.getReturnType());
|
||||
String typeAndName = (type == null ? "" : type.getPresentableText() + " ") + methodName;
|
||||
String signature = modifiers + typeAndName;
|
||||
String signature = modifiers + (type == null ? "" : type.getPresentableText() + " ") + methodName;
|
||||
|
||||
String parameters = "(" + StringUtil.join(prototype.getParameterList().getParameters(),
|
||||
p -> getShortParameterName(substitutor, p) + " " + p.getName(),
|
||||
@@ -210,14 +209,13 @@ 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()) {
|
||||
element = element.withStrikeoutness(true);
|
||||
}
|
||||
element.putUserData(GENERATE_ELEMENT, true);
|
||||
return element;
|
||||
return PrioritizedLookupElement.withPriority(element, -1);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
class Foo {
|
||||
private boolean zoo;
|
||||
public bool<caret>
|
||||
}
|
||||
+3
-2
@@ -1,4 +1,5 @@
|
||||
class Foo {
|
||||
private String zoo;
|
||||
public Stri<caret>
|
||||
private SomeClass zoo;
|
||||
public SomeCl<caret>
|
||||
}
|
||||
class SomeClass {}
|
||||
+5
-1
@@ -825,7 +825,11 @@ class Foo {
|
||||
}
|
||||
|
||||
void testPreferTypeToGeneratedMethod() {
|
||||
checkPreferredItems 0, 'String', 'public String getZoo', 'public String toString'
|
||||
checkPreferredItems 0, 'SomeClass', 'public SomeClass getZoo'
|
||||
}
|
||||
|
||||
void testPreferPrimitiveTypeToGeneratedMethod() {
|
||||
checkPreferredItems 0, 'boolean', 'public boolean isZoo', 'public boolean equals'
|
||||
}
|
||||
|
||||
void testPreferExceptionsInCatch() {
|
||||
|
||||
+2
-2
@@ -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[1].object
|
||||
PsiClass c1 = items[0].object
|
||||
assert !c1.physical
|
||||
assert CompletionUtil.getOriginalElement(c1)
|
||||
|
||||
getLookup().hide()
|
||||
myFixture.type('x')
|
||||
items = myFixture.completeBasic()
|
||||
PsiClass c2 = items[1].object
|
||||
PsiClass c2 = items[0].object
|
||||
assert !c2.physical
|
||||
assert CompletionUtil.getOriginalElement(c2)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user