From 4cac3b6b7801ec77351000b3cac58f942f4d3abc Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 4 Nov 2015 16:51:15 +0100 Subject: [PATCH] IDEA-147313 Adding @NotNull in front of a method parameter and finishing lookup with Space inserts 2 spaces --- .../completion/JavaClassNameInsertHandler.java | 11 +++++++---- .../AnnotationBeforeIdentifierFinishWithSpace.java | 5 +++++ ...notationBeforeIdentifierFinishWithSpace_after.java | 5 +++++ .../completion/NormalCompletionTest.groovy | 1 + 4 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/completion/normal/AnnotationBeforeIdentifierFinishWithSpace.java create mode 100644 java/java-tests/testData/codeInsight/completion/normal/AnnotationBeforeIdentifierFinishWithSpace_after.java diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaClassNameInsertHandler.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaClassNameInsertHandler.java index 7f354bc6266e..da7259999894 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaClassNameInsertHandler.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaClassNameInsertHandler.java @@ -18,6 +18,7 @@ package com.intellij.codeInsight.completion; import com.intellij.codeInsight.AutoPopupController; import com.intellij.codeInsight.ExpectedTypeInfo; import com.intellij.codeInsight.ExpectedTypesProvider; +import com.intellij.codeInsight.lookup.Lookup; import com.intellij.codeInsight.lookup.LookupElement; import com.intellij.codeInsight.lookup.PsiTypeLookupItem; import com.intellij.openapi.editor.Editor; @@ -112,10 +113,12 @@ class JavaClassNameInsertHandler implements InsertHandler tail && Character.isLetter(text.charAt(tail))) { - context.getDocument().insertString(tail, " "); + if (context.getCompletionChar() == Lookup.NORMAL_SELECT_CHAR || context.getCompletionChar() == Lookup.COMPLETE_STATEMENT_SELECT_CHAR) { + CharSequence text = context.getDocument().getCharsSequence(); + int tail = context.getTailOffset(); + if (text.length() > tail && Character.isLetter(text.charAt(tail))) { + context.getDocument().insertString(tail, " "); + } } } diff --git a/java/java-tests/testData/codeInsight/completion/normal/AnnotationBeforeIdentifierFinishWithSpace.java b/java/java-tests/testData/codeInsight/completion/normal/AnnotationBeforeIdentifierFinishWithSpace.java new file mode 100644 index 000000000000..b22b28430c1d --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/normal/AnnotationBeforeIdentifierFinishWithSpace.java @@ -0,0 +1,5 @@ +@interface AbcdAnno {} + +class Foo { + void foo(@AbcFoo f) {} +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/normal/AnnotationBeforeIdentifierFinishWithSpace_after.java b/java/java-tests/testData/codeInsight/completion/normal/AnnotationBeforeIdentifierFinishWithSpace_after.java new file mode 100644 index 000000000000..e206c6bcdcbe --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/normal/AnnotationBeforeIdentifierFinishWithSpace_after.java @@ -0,0 +1,5 @@ +@interface AbcdAnno {} + +class Foo { + void foo(@AbcdAnno Foo f) {} +} \ No newline at end of file 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 e317b3237fac..d836f4a658e3 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy @@ -999,6 +999,7 @@ public class ListUtils { public void testOnlyAnnotationsAfterAt() throws Throwable { doTest() } public void testOnlyAnnotationsAfterAt2() throws Throwable { doTest('\n') } public void testAnnotationBeforeIdentifier() { doTest('\n') } + public void testAnnotationBeforeIdentifierFinishWithSpace() { doTest(' ') } public void testOnlyExceptionsInCatch1() throws Exception { doTest('\n') } public void testOnlyExceptionsInCatch2() throws Exception { doTest('\n') }