IDEA-80186 Completion for 'continue' always inserts semicolon
authorpeter <peter@jetbrains.com>
Tue, 24 Jan 2012 11:44:16 +0000 (12:44 +0100)
committerpeter <peter@jetbrains.com>
Tue, 24 Jan 2012 12:33:39 +0000 (13:33 +0100)
java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionData.java
java/java-tests/testData/codeInsight/completion/normal/ContinueLabel.java [new file with mode: 0644]
java/java-tests/testData/codeInsight/completion/normal/ContinueLabel_after.java [new file with mode: 0644]
java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy
platform/platform-api/src/com/intellij/patterns/TreeElementPattern.java

index 78d73295c387d5d5813fff51039567e805e91e6b..86d61df0968de2e47252e8750d64c86a1716632b 100644 (file)
@@ -602,12 +602,17 @@ public class JavaCompletionData extends JavaAwareCompletionData{
 
     LookupElement br = createKeyword(position, PsiKeyword.BREAK);
     LookupElement cont = createKeyword(position, PsiKeyword.CONTINUE);
-    if (!psiElement().insideSequence(true, psiElement(PsiLabeledStatement.class),
-                                                  or(psiElement(PsiFile.class), psiElement(PsiMethod.class),
-                                                     psiElement(PsiClassInitializer.class))).accepts(position)) {
-      br = TailTypeDecorator.withTail(br, TailType.SEMICOLON);
-      cont = TailTypeDecorator.withTail(cont, TailType.SEMICOLON);
+    TailType tailType;
+    if (psiElement().insideSequence(true, psiElement(PsiLabeledStatement.class),
+                                    or(psiElement(PsiFile.class), psiElement(PsiMethod.class),
+                                       psiElement(PsiClassInitializer.class))).accepts(position)) {
+      tailType = TailType.HUMBLE_SPACE;
     }
+    else {
+      tailType = TailType.SEMICOLON;
+    }
+    br = TailTypeDecorator.withTail(br, tailType);
+    cont = TailTypeDecorator.withTail(cont, tailType);
 
     if (loop != null && new InsideElementFilter(new ClassFilter(PsiStatement.class)).isAcceptable(position, loop)) {
       result.addElement(br);
diff --git a/java/java-tests/testData/codeInsight/completion/normal/ContinueLabel.java b/java/java-tests/testData/codeInsight/completion/normal/ContinueLabel.java
new file mode 100644 (file)
index 0000000..27341ba
--- /dev/null
@@ -0,0 +1,7 @@
+public class Util {
+  void foo(int a, int b) {
+    Outer: for (int i = 0; i < 239; i++) {
+      conti<caret>
+    }
+  }
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/codeInsight/completion/normal/ContinueLabel_after.java b/java/java-tests/testData/codeInsight/completion/normal/ContinueLabel_after.java
new file mode 100644 (file)
index 0000000..c1b9a66
--- /dev/null
@@ -0,0 +1,7 @@
+public class Util {
+  void foo(int a, int b) {
+    Outer: for (int i = 0; i < 239; i++) {
+      continue <caret>
+    }
+  }
+}
\ No newline at end of file
index 10782dea93135bb9f53f9b7b985a979c95a2c59f..dc148649b4f321f98197714d8e0de93075afce1a 100644 (file)
@@ -520,6 +520,8 @@ public class NormalCompletionTest extends LightFixtureCompletionTestCase {
     checkResult()
   }
 
+  public void testContinueLabel() throws Throwable { doTest(); }
+
   public void testAnonymousProcess() {
     myFixture.addClass 'package java.lang; public class Process {}'
     myFixture.addClass '''
index 050c8c049e34b575baeece73cd4a63b3510b5036..9f843d7cb88c28b78200a96963fc4ff8aa5731d2 100644 (file)
@@ -171,13 +171,13 @@ public abstract class TreeElementPattern<ParentType, T extends ParentType, Self
    * @return Ensures that first elements in hierarchy accepted by patterns appear in specified order
    */
   public Self insideSequence(final boolean strict, @NotNull final ElementPattern<? extends ParentType>... patterns) {
-    return with(new PatternCondition<T>("condInside") {
+    return with(new PatternCondition<T>("insideSequence") {
       public boolean accepts(@NotNull final T t, final ProcessingContext context) {
         int i = 0;
         ParentType element = strict ? getParent(t) : t;
-        while (element != null && i >= patterns.length) {
+        while (element != null && i < patterns.length) {
           for (int j = i; j < patterns.length; j++) {
-            if (patterns[j].getCondition().accepts(t, context)) {
+            if (patterns[j].accepts(element, context)) {
               if (i != j) return false;
               i++;
               break;
@@ -185,7 +185,7 @@ public abstract class TreeElementPattern<ParentType, T extends ParentType, Self
           }
           element = getParent(element);
         }
-        return false;
+        return true;
       }
     });
   }