IDEA-80186 Completion for 'continue' always inserts semicolon

This commit is contained in:
peter
2012-01-24 13:33:39 +01:00
parent 134ef93313
commit 2dd04b9c01
5 changed files with 30 additions and 9 deletions
@@ -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);
@@ -0,0 +1,7 @@
public class Util {
void foo(int a, int b) {
Outer: for (int i = 0; i < 239; i++) {
conti<caret>
}
}
}
@@ -0,0 +1,7 @@
public class Util {
void foo(int a, int b) {
Outer: for (int i = 0; i < 239; i++) {
continue <caret>
}
}
}
@@ -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 '''
@@ -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;
}
});
}