IDEA-154891 IDEA adds unnecessary space/colon on switch case autocompletion
authorpeter <peter@jetbrains.com>
Fri, 29 Apr 2016 18:52:29 +0000 (20:52 +0200)
committerpeter <peter@jetbrains.com>
Fri, 29 Apr 2016 20:56:20 +0000 (22:56 +0200)
java/java-impl/src/com/intellij/codeInsight/lookup/VariableLookupItem.java
java/java-tests/testData/codeInsight/completion/normal/SwitchValueFinishWithColon.java [new file with mode: 0644]
java/java-tests/testData/codeInsight/completion/normal/SwitchValueFinishWithColon_after.java [new file with mode: 0644]
java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy

index 3141112d4488b463b5f1bcf46edcd9f0d19cad33..f76f30b8000a071aaa3f4f38f98a571743e1e8e4 100644 (file)
@@ -203,7 +203,7 @@ public class VariableLookupItem extends LookupItem<PsiVariable> implements Typed
       TailType.COMMA.processTail(context.getEditor(), context.getTailOffset());
       AutoPopupController.getInstance(context.getProject()).autoPopupParameterInfo(context.getEditor(), null);
     }
-    else if (completionChar == ':') {
+    else if (completionChar == ':' && getAttribute(LookupItem.TAIL_TYPE_ATTR) != TailType.UNKNOWN) {
       context.setAddCompletionChar(false);
       TailType.COND_EXPR_COLON.processTail(context.getEditor(), context.getTailOffset());
     }
diff --git a/java/java-tests/testData/codeInsight/completion/normal/SwitchValueFinishWithColon.java b/java/java-tests/testData/codeInsight/completion/normal/SwitchValueFinishWithColon.java
new file mode 100644 (file)
index 0000000..108e2e2
--- /dev/null
@@ -0,0 +1,11 @@
+class Foo {
+  void foo(Constants c) {
+    switch (c) {
+        case B<caret>
+    }
+  }
+}
+
+enum Constants {
+  BAR0, BAR1;
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/codeInsight/completion/normal/SwitchValueFinishWithColon_after.java b/java/java-tests/testData/codeInsight/completion/normal/SwitchValueFinishWithColon_after.java
new file mode 100644 (file)
index 0000000..8047388
--- /dev/null
@@ -0,0 +1,11 @@
+class Foo {
+  void foo(Constants c) {
+    switch (c) {
+        case BAR0:<caret>
+    }
+  }
+}
+
+enum Constants {
+  BAR0, BAR1;
+}
\ No newline at end of file
index 4b4fc9fdf8ac1850224afd048817b763372c0e83..40160c1645bc42f2341e88009c87075c797bb571 100644 (file)
@@ -1045,6 +1045,7 @@ public class ListUtils {
   public void testNoFieldsInImplements() throws Throwable { doTest() }
 
   public void testSwitchConstantsFromReferencedClass() throws Throwable { doTest('\n') }
+  public void testSwitchValueFinishWithColon() throws Throwable { doTest(':') }
 
   public void testUnfinishedMethodTypeParameter() throws Throwable {
     configure()