From cee022e257e43ef03eab23f7755b4db7ffb97648 Mon Sep 17 00:00:00 2001 From: peter Date: Fri, 6 Sep 2013 18:30:45 +0200 Subject: [PATCH] IDEA-113013 When insert selected variant is enabled the "generated" code comply with code style --- .../JavaMemberNameCompletionContributor.java | 26 +++++++++++++------ .../completion/VariablesCompletionTest.groovy | 16 ++++++++++++ 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaMemberNameCompletionContributor.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaMemberNameCompletionContributor.java index d995a9e3d475..fc0baa591c30 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaMemberNameCompletionContributor.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaMemberNameCompletionContributor.java @@ -15,6 +15,7 @@ */ package com.intellij.codeInsight.completion; +import com.intellij.codeInsight.TailType; import com.intellij.codeInsight.completion.util.ParenthesesInsertHandler; import com.intellij.codeInsight.lookup.*; import com.intellij.codeInsight.template.impl.TemplateManagerImpl; @@ -121,10 +122,10 @@ public class JavaMemberNameCompletionContributor extends CompletionContributor { addLookupItems(set, suggestedNameInfo, matcher, project, suggestedNames); if (!hasStartMatches(set, matcher)) { if (type.equalsToText(CommonClassNames.JAVA_LANG_OBJECT) && matcher.prefixMatches("object")) { - set.add(LookupElementBuilder.create("object")); + set.add(withInsertHandler(suggestedNameInfo, LookupElementBuilder.create("object"))); } if (type.equalsToText(CommonClassNames.JAVA_LANG_STRING) && matcher.prefixMatches("string")) { - set.add(LookupElementBuilder.create("string")); + set.add(withInsertHandler(suggestedNameInfo, LookupElementBuilder.create("string"))); } } @@ -422,14 +423,23 @@ public class JavaMemberNameCompletionContributor extends CompletionContributor { LookupElement element = PrioritizedLookupElement.withPriority(LookupElementBuilder.create(name).withAutoCompletionPolicy(AutoCompletionPolicy.GIVE_CHANCE_TO_OVERWRITE), -i); if (callback != null) { - element = LookupElementDecorator.withInsertHandler(element, new InsertHandler>() { - @Override - public void handleInsert(InsertionContext context, LookupElementDecorator item) { - callback.nameChosen(item.getLookupString()); - } - }); + element = withInsertHandler(callback, element); } lookupElements.add(element); } } + + private static LookupElementDecorator withInsertHandler(final SuggestedNameInfo callback, LookupElement element) { + return LookupElementDecorator.withInsertHandler(element, new InsertHandler>() { + @Override + public void handleInsert(InsertionContext context, LookupElementDecorator item) { + TailType tailType = LookupItem.getDefaultTailType(context.getCompletionChar()); + if (tailType != null) { + context.setAddCompletionChar(false); + tailType.processTail(context.getEditor(), context.getTailOffset()); + } + callback.nameChosen(item.getLookupString()); + } + }); + } } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/VariablesCompletionTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/VariablesCompletionTest.groovy index 4f40bd5d2ddc..0aea49050443 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/VariablesCompletionTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/VariablesCompletionTest.groovy @@ -201,4 +201,20 @@ public class VariablesCompletionTest extends LightFixtureCompletionTestCase { assertStringItems("pColor"); } + public void "test finish with ="() { + myFixture.configureByText 'a.java', ''' +class FooFoo { + FooFoo f +} +''' + myFixture.completeBasic() + myFixture.assertPreferredCompletionItems 0, 'fooFoo', 'foo' + myFixture.type '=' + myFixture.checkResult ''' +class FooFoo { + FooFoo fooFoo = +} +''' + } + }