don't overwrite trailing space in java & groovy keyword completion
authorpeter <peter@jetbrains.com>
Sat, 31 Dec 2011 21:32:24 +0000 (22:32 +0100)
committerpeter <peter@jetbrains.com>
Sun, 1 Jan 2012 22:14:31 +0000 (23:14 +0100)
12 files changed:
java/java-impl/src/com/intellij/codeInsight/completion/Java15CompletionData.java
java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionData.java
java/java-impl/src/com/intellij/codeInsight/completion/JavaDocCompletionContributor.java
java/java-impl/src/com/intellij/codeInsight/completion/JavaSmartCompletionContributor.java
java/java-tests/testData/codeInsight/completion/keywords/ExtendsWithRightContextInClassTypeParameters-out.java
java/java-tests/testData/codeInsight/completion/keywords/extends-8-result.java
java/java-tests/testData/codeInsight/completion/keywords/methodScope-5-out.java
java/java-tests/testData/codeInsight/completion/normal/FieldType_after.java
java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy
platform/lang-api/src/com/intellij/codeInsight/TailType.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java
plugins/groovy/test/org/jetbrains/plugins/groovy/completion/GroovyCompletionTest.groovy

index 0b38361ecc707210fd0de3e924c3ca76be52f738..6559888c789826111beb123a7cda8088477eae57 100644 (file)
@@ -31,7 +31,7 @@ public class Java15CompletionData extends JavaCompletionData {
     //static keyword in static import
     {
       final CompletionVariant variant = new CompletionVariant(PsiImportList.class, new LeftNeighbour(new TextFilter (PsiKeyword.IMPORT)));
-      variant.addCompletion(PsiKeyword.STATIC, TailType.SPACE);
+      variant.addCompletion(PsiKeyword.STATIC, TailType.INSERT_SPACE);
 
       registerVariant(variant);
     }
@@ -46,7 +46,7 @@ public class Java15CompletionData extends JavaCompletionData {
       final CompletionVariant variant = new CompletionVariant(PsiJavaFile.class, position);
       variant.includeScopeClass(PsiClass.class);
 
-      variant.addCompletion(PsiKeyword.INTERFACE, TailType.SPACE);
+      variant.addCompletion(PsiKeyword.INTERFACE, TailType.INSERT_SPACE);
 
       registerVariant(variant);
     }
@@ -55,7 +55,7 @@ public class Java15CompletionData extends JavaCompletionData {
       final CompletionVariant variant = new CompletionVariant(PsiJavaFile.class, CLASS_START);
       variant.includeScopeClass(PsiClass.class);
 
-      variant.addCompletion(PsiKeyword.ENUM, TailType.SPACE);
+      variant.addCompletion(PsiKeyword.ENUM, TailType.INSERT_SPACE);
       registerVariant(variant);
     }
 
@@ -68,8 +68,8 @@ public class Java15CompletionData extends JavaCompletionData {
       final CompletionVariant variant = new CompletionVariant(JavaMemberNameCompletionContributor.INSIDE_TYPE_PARAMS_PATTERN);
       variant.includeScopeClass(PsiVariable.class, true);
       variant.includeScopeClass(PsiExpressionStatement.class, true);
-      variant.addCompletion(PsiKeyword.SUPER, TailType.SPACE);
-      variant.addCompletion(PsiKeyword.EXTENDS, TailType.SPACE);
+      variant.addCompletion(PsiKeyword.SUPER, TailType.INSERT_SPACE);
+      variant.addCompletion(PsiKeyword.EXTENDS, TailType.INSERT_SPACE);
       registerVariant(variant);
     }
   }
index 08d97fcc00e1e4adb8eb05bd8d53a438ed69e684..af1f43bc578abb438befc01844546779e0de5bd9 100644 (file)
@@ -271,7 +271,7 @@ public class JavaCompletionData extends JavaAwareCompletionData{
 // completion
       final CompletionVariant variant = new CompletionVariant(position);
       variant.includeScopeClass(PsiClass.class, true);
-      variant.addCompletion(PsiKeyword.EXTENDS);
+      variant.addCompletion(PsiKeyword.EXTENDS, TailType.INSERT_SPACE);
       variant.excludeScopeClass(PsiAnonymousClass.class);
       variant.excludeScopeClass(PsiTypeParameter.class);
 
@@ -292,7 +292,7 @@ public class JavaCompletionData extends JavaAwareCompletionData{
 // completion
       final CompletionVariant variant = new CompletionVariant(position);
       variant.includeScopeClass(PsiClass.class, true);
-      variant.addCompletion(PsiKeyword.IMPLEMENTS);
+      variant.addCompletion(PsiKeyword.IMPLEMENTS, TailType.INSERT_SPACE);
       variant.excludeScopeClass(PsiAnonymousClass.class);
 
       registerVariant(variant);
@@ -304,7 +304,7 @@ public class JavaCompletionData extends JavaAwareCompletionData{
           psiElement(PsiIdentifier.class).afterLeaf(
             psiElement().withText(string().oneOf(",", "<")).withParent(PsiTypeParameterList.class))));
       //variant.includeScopeClass(PsiClass.class, true);
-      variant.addCompletion(PsiKeyword.EXTENDS, TailType.SPACE);
+      variant.addCompletion(PsiKeyword.EXTENDS, TailType.INSERT_SPACE);
       registerVariant(variant);
     }
   }
@@ -412,7 +412,7 @@ public class JavaCompletionData extends JavaAwareCompletionData{
           return TailType.SEMICOLON;
         }
 
-        return TailType.SPACE;
+        return TailType.INSERT_SPACE;
       }
       scope = scope.getParent();
     }
@@ -425,12 +425,12 @@ public class JavaCompletionData extends JavaAwareCompletionData{
     variant.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.FOR), TailTypes.FOR_LPARENTH));
     variant.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.IF), TailTypes.IF_LPARENTH));
     variant.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.TRY), TailType.createSimpleTailType('{')));
-    variant.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.THROW), TailType.SPACE));
-    variant.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.NEW), TailType.SPACE));
+    variant.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.THROW), TailType.INSERT_SPACE));
+    variant.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.NEW), TailType.INSERT_SPACE));
     variant.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.SYNCHRONIZED), TailTypes.SYNCHRONIZED_LPARENTH));
 
     if (PsiUtil.getLanguageLevel(position).isAtLeast(LanguageLevel.JDK_1_4)) {
-      variant.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.ASSERT), TailType.SPACE));
+      variant.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.ASSERT), TailType.INSERT_SPACE));
     }
 
     TailType returnTail = getReturnTail(position);
@@ -454,13 +454,13 @@ public class JavaCompletionData extends JavaAwareCompletionData{
     }
     if (statement != null && statement.getTextRange().getStartOffset() == position.getTextRange().getStartOffset()) {
       if (!psiElement().withSuperParent(2, PsiSwitchStatement.class).accepts(statement)) {
-        result.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.FINAL), TailType.SPACE));
+        result.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.FINAL), TailType.INSERT_SPACE));
       }
     }
 
     if (isStatementPosition(position)) {
       if (PsiTreeUtil.getParentOfType(position, PsiSwitchStatement.class, false, PsiMember.class) != null) {
-        result.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.CASE), TailType.SPACE));
+        result.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.CASE), TailType.INSERT_SPACE));
         result.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.DEFAULT), TailType.CASE_COLON));
         if (START_SWITCH.accepts(position)) {
           return;
@@ -499,20 +499,20 @@ public class JavaCompletionData extends JavaAwareCompletionData{
     }
 
     if (EXPR_KEYWORDS.accepts(position)) {
-      result.addElement(TailTypeDecorator.withTail(createKeyword(position, PsiKeyword.NEW), TailType.SPACE));
+      result.addElement(TailTypeDecorator.withTail(createKeyword(position, PsiKeyword.NEW), TailType.INSERT_SPACE));
       result.addElement(createKeyword(position, PsiKeyword.NULL));
       result.addElement(createKeyword(position, PsiKeyword.TRUE));
       result.addElement(createKeyword(position, PsiKeyword.FALSE));
     }
 
     if (INSIDE_PARAMETER_LIST.accepts(position) && !psiElement().afterLeaf(PsiKeyword.FINAL).accepts(position) && !AFTER_DOT.accepts(position)) {
-      result.addElement(TailTypeDecorator.withTail(createKeyword(position, PsiKeyword.FINAL), TailType.SPACE));
+      result.addElement(TailTypeDecorator.withTail(createKeyword(position, PsiKeyword.FINAL), TailType.INSERT_SPACE));
     }
 
     if (CLASS_START.isAcceptable(position, position) &&
         PsiTreeUtil.getNonStrictParentOfType(position, PsiLiteralExpression.class, PsiComment.class) == null) {
       for (String s : ModifierChooser.getKeywords(position)) {
-        result.addElement(new OverrideableSpace(createKeyword(position, s), TailType.SPACE));
+        result.addElement(new OverrideableSpace(createKeyword(position, s), TailType.INSERT_SPACE));
       }
     }
 
@@ -589,11 +589,11 @@ public class JavaCompletionData extends JavaAwareCompletionData{
         isStatementPosition(position)) {
       for (String primitiveType : PRIMITIVE_TYPES) {
         LookupElement keyword = createKeyword(position, primitiveType);
-        result.addElement(inCast ? keyword : new OverrideableSpace(keyword, TailType.SPACE));
+        result.addElement(inCast ? keyword : new OverrideableSpace(keyword, TailType.INSERT_SPACE));
       }
     }
     if (declaration) {
-      result.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.VOID), TailType.SPACE));
+      result.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.VOID), TailType.INSERT_SPACE));
     }
   }
 
index bd263b7710c1aeb869c3f7995cade23b97f46599..473b8ead0d8b03652871a6411e48767b6c9f8aef 100644 (file)
@@ -145,7 +145,7 @@ public class JavaDocCompletionContributor extends CompletionContributor {
         if (isInline) {
           result.addElement(TailTypeDecorator.withInsertHandler(LookupElementBuilder.create(s), new InlineInsertHandler()));
         } else {
-          result.addElement(TailTypeDecorator.withTail(LookupElementBuilder.create(s), TailType.SPACE));
+          result.addElement(TailTypeDecorator.withTail(LookupElementBuilder.create(s), TailType.INSERT_SPACE));
         }
       }
     }
index 59d3ee666a4c9d2624827ba71e4b7e6c7e9f112e..511a8529c357cd91895bde1624e25f7f28773817 100644 (file)
@@ -264,7 +264,7 @@ public class JavaSmartCompletionContributor extends CompletionContributor {
           for (PsiClassType ref : method.getThrowsList().getReferencedTypes()) {
             final PsiClass exception = ref.resolve();
             if (exception != null && throwsSet.add(exception)) {
-              result.addElement(TailTypeDecorator.withTail(new JavaPsiClassReferenceElement(exception), TailType.SPACE));
+              result.addElement(TailTypeDecorator.withTail(new JavaPsiClassReferenceElement(exception), TailType.INSERT_SPACE));
             }
           }
         }
@@ -282,7 +282,7 @@ public class JavaSmartCompletionContributor extends CompletionContributor {
         if (tryBlock == null) return;
 
         for (final PsiClassType type : ExceptionUtil.getThrownExceptions(tryBlock.getStatements())) {
-          result.addElement(TailTypeDecorator.withTail(PsiTypeLookupItem.createLookupItem(type, tryBlock).setInsertHandler(new DefaultInsertHandler()), TailType.SPACE));
+          result.addElement(TailTypeDecorator.withTail(PsiTypeLookupItem.createLookupItem(type, tryBlock).setInsertHandler(new DefaultInsertHandler()), TailType.INSERT_SPACE));
         }
       }
     });
index 37a271cd37b6e57fafa619a9ed52daeda16ef861..46fe4caea6dc8b93eda2d95298eff2a0df9e85ab 100644 (file)
@@ -1,4 +1,4 @@
 class AAA{}
 
-class BBB extends AAA implements <caret>{
+class BBB extends AAA implements <caret> {
 }
index 1fdb38929526acb40b1bb71e8c285567aa29f8f9..26fd20c10a04a01cec3a37e711372462f00216c5 100644 (file)
@@ -1,5 +1,5 @@
 public class A{
- public void method(final String){
+ public void method(final <caret> String){
   
  }
 }
index 071e1faf557b0e2baf7857a89b817ccded21354a..a5209a87c6871042b32501c1818e2f78262abfd5 100644 (file)
@@ -1,4 +1,4 @@
 class A {
-    private long <caret>localizedStringManager;
+    private long <caret> localizedStringManager;
 
 }
index 82afed75f69b08fe5bf7b3f7b9759daa3b68012e..061a0b68b492acd7f2bca8eff8d7d66b123df21e 100644 (file)
@@ -720,7 +720,7 @@ class Foo {
     joinAutopopup()
     joinCompletion()
     myFixture.type '\n'
-    myFixture.checkResult(" class Foo { { int newa; new <caret>} } ")
+    myFixture.checkResult(" class Foo { { int newa; new <caret> } } ")
     assert !lookup
   }
 
index 6c47940dbacd9c664dbe14662e56358ea48194a9..cc177dfb0cedb3cb04ac7f214682fb7737d503e8 100644 (file)
@@ -88,6 +88,7 @@ public abstract class TailType {
     }
   };
   public static final TailType SPACE = new CharTailType(' ');
+  public static final TailType INSERT_SPACE = new CharTailType(' ', false);
   public static final TailType DOT = new CharTailType('.');
 
   public static final TailType CASE_COLON = new CharTailType(':');
index 17ab4c1b8616afa2baa5888a4eaf3640c450ffbb..481456ce95c8a9c967210ce229d77c47a2630db6 100644 (file)
@@ -77,15 +77,15 @@ public class GroovyCompletionData {
     
     if (!PlatformPatterns.psiElement().afterLeaf(".", ".&").accepts(position)) {
       if (suggestPackage(position)) {
-        result.addElement(keyword(PsiKeyword.PACKAGE, TailType.SPACE));
+        result.addElement(keyword(PsiKeyword.PACKAGE, TailType.INSERT_SPACE));
       }
       if (suggestImport(position)) {
-        result.addElement(keyword(PsiKeyword.IMPORT, TailType.SPACE));
+        result.addElement(keyword(PsiKeyword.IMPORT, TailType.INSERT_SPACE));
       }
 
       addTypeDefinitionKeywords(result, position);
       for (String keyword : addExtendsImplements(position)) {
-        result.addElement(keyword(keyword, TailType.SPACE));
+        result.addElement(keyword(keyword, TailType.INSERT_SPACE));
       }
 
       registerControlCompletion(position, result);
@@ -144,7 +144,7 @@ public class GroovyCompletionData {
       addKeywords(result, true, PsiKeyword.CLASS, PsiKeyword.INTERFACE, PsiKeyword.ENUM);
     }
     if (afterAtInType(position)) {
-      result.addElement(keyword(PsiKeyword.INTERFACE, TailType.SPACE));
+      result.addElement(keyword(PsiKeyword.INTERFACE, TailType.INSERT_SPACE));
     }
   }
 
@@ -185,7 +185,7 @@ public class GroovyCompletionData {
 
   public static void addKeywords(CompletionResultSet result, boolean space, String... keywords) {
     for (String s : keywords) {
-      result.addElement(keyword(s, space ? TailType.SPACE : TailType.NONE));
+      result.addElement(keyword(s, space ? TailType.INSERT_SPACE : TailType.NONE));
     }
   }
 
@@ -201,7 +201,7 @@ public class GroovyCompletionData {
       addKeywords(result, true, controlKeywords);
     }
     if (inCaseSection(context)) {
-      result.addElement(keyword("case", TailType.SPACE));
+      result.addElement(keyword("case", TailType.INSERT_SPACE));
       result.addElement(keyword("default", TailType.CASE_COLON));
     }
     if (afterTry(context)) {
@@ -217,7 +217,7 @@ public class GroovyCompletionData {
     if (PlatformPatterns.psiElement(GroovyDocTokenTypes.mGDOC_TAG_NAME).andNot(PlatformPatterns.psiElement().afterLeaf(".")).accepts(position)) {
       String[] tags = position.getParent() instanceof GrDocInlinedTag ? INLINED_DOC_TAGS : DOC_TAGS;
       for (String docTag : tags) {
-        result.addElement(TailTypeDecorator.withTail(LookupElementBuilder.create(docTag), TailType.SPACE));
+        result.addElement(TailTypeDecorator.withTail(LookupElementBuilder.create(docTag), TailType.INSERT_SPACE));
       }
     }
   }
index 5048a4c0875698ba17ae281d098b6f1bf8593e79..c14cbc698efeb3680b8a143f77db8eba6853bda7 100644 (file)
@@ -1064,7 +1064,7 @@ class X {
   }
 
   public void testInnerClassStart() {
-    checkSingleItemCompletion 'class Foo { cl<caret> }', 'class Foo { class <caret>}'
+    checkSingleItemCompletion 'class Foo { cl<caret> }', 'class Foo { class <caret> }'
   }
 
   public void testPropertyBeforeAccessor() {
@@ -1114,7 +1114,8 @@ public class KeyVO {
 
   public void testSpaceTail() {
     checkCompletion 'class A <caret> ArrayList {}', ' ', 'class A extends <caret> ArrayList {}'
-    checkCompletion 'class A <caret> ArrayList {}', '\n', 'class A extends <caret>ArrayList {}'
+    checkCompletion 'class A <caret> ArrayList {}', '\n', 'class A extends <caret> ArrayList {}'
+    checkSingleItemCompletion 'class Foo impl<caret> {}', 'class Foo implements <caret> {}'
   }
 
   public void testPreferInterfacesInImplements() {