From 1258c73ef0682c43517bd2fabf6c1fbe26848c61 Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 26 Oct 2015 15:27:32 +0100 Subject: [PATCH] IDEA-130264 Completion for super methods of containing class explicitly qualify lookup item presentation --- .../codeInsight/completion/SuperCalls.java | 22 +++++++++++++------ .../completion/NormalCompletionTest.groovy | 6 ++++- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/SuperCalls.java b/java/java-impl/src/com/intellij/codeInsight/completion/SuperCalls.java index 8f0418668106..dcd34bfa1f22 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/SuperCalls.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/SuperCalls.java @@ -19,6 +19,7 @@ import com.intellij.codeInsight.completion.scope.CompletionElement; import com.intellij.codeInsight.completion.scope.JavaCompletionProcessor; import com.intellij.codeInsight.lookup.LookupElement; import com.intellij.codeInsight.lookup.LookupElementDecorator; +import com.intellij.codeInsight.lookup.LookupElementPresentation; import com.intellij.openapi.util.Condition; import com.intellij.psi.*; import com.intellij.psi.filters.ElementFilter; @@ -48,7 +49,7 @@ class SuperCalls { for (CompletionElement completionElement : superProcessor.getResults()) { for (LookupElement item : JavaCompletionUtil.createLookupElements(completionElement, javaReference)) { - set.add(withQuaifiedSuper(className, item)); + set.add(withQualifiedSuper(className, item)); } } } @@ -56,20 +57,27 @@ class SuperCalls { } @NotNull - private static LookupElementDecorator withQuaifiedSuper(final String className, LookupElement item) { - return LookupElementDecorator.withInsertHandler(item, new InsertHandler>() { + private static LookupElement withQualifiedSuper(final String className, LookupElement item) { + return PrioritizedLookupElement.withExplicitProximity(new LookupElementDecorator(item) { + @Override - public void handleInsert(InsertionContext context, LookupElementDecorator item) { + public void renderElement(LookupElementPresentation presentation) { + super.renderElement(presentation); + presentation.setItemText(className + ".super." + presentation.getItemText()); + } + + @Override + public void handleInsert(InsertionContext context) { context.commitDocument(); PsiJavaCodeReferenceElement ref = PsiTreeUtil .findElementOfClassAtOffset(context.getFile(), context.getStartOffset(), PsiJavaCodeReferenceElement.class, false); if (ref != null) { - context.getDocument().insertString(ref.getTextRange().getStartOffset(), className + "."); + context.getDocument().insertString(ref.getTextRange().getStartOffset(), className + "."); } - item.getDelegate().handleInsert(context); + super.handleInsert(context); } - }); + }, -1); } private static Set getContainingClassNames(PsiElement position) { diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy index 0a36aee54bc6..e317b3237fac 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy @@ -1040,7 +1040,11 @@ public class ListUtils { doTest() } - public void testOuterSuperMethodCall() { doTest('\n') } + public void testOuterSuperMethodCall() { + configure() + assert 'Class2.super.put' == LookupElementPresentation.renderElement(myItems[0]).itemText + type '\n' + checkResult() } public void testTopLevelClassesFromPackaged() throws Throwable { myFixture.addClass "public class Fooooo {}"