IDEA-75812 IDEA doesn't suggest keyword 'break' in switch structure

This commit is contained in:
peter
2011-10-21 19:10:09 +02:00
parent a39d2ac2dc
commit 36cc99ea9a
5 changed files with 25 additions and 20 deletions

View File

@@ -131,7 +131,7 @@ public class JavaCompletionContributor extends CompletionContributor {
}
if (JavaCompletionData.AFTER_TRY_BLOCK.isAcceptable(position, position) ||
JavaCompletionData.START_SWITCH.isAcceptable(position, position) ||
JavaCompletionData.START_SWITCH.accepts(position) ||
JavaCompletionData.INSTANCEOF_PLACE.isAcceptable(position, position) ||
JavaCompletionData.isAfterPrimitiveOrArrayType(position)) {
return null;

View File

@@ -108,27 +108,13 @@ public class JavaCompletionData extends JavaAwareCompletionData{
START_OF_CODE_FRAGMENT
);
static final AndFilter START_SWITCH = new AndFilter(END_OF_BLOCK, new LeftNeighbour(
new AndFilter(new TextFilter("{"), new ParentElementFilter(new ClassFilter(PsiSwitchStatement.class), 2))));
static final OrFilter INSIDE_SWITCH = new OrFilter(START_SWITCH,
new AndFilter(
END_OF_BLOCK,
new NotFilter(START_SWITCH),
new OrFilter(
new ParentElementFilter(new ClassFilter(PsiSwitchLabelStatement.class)),
new LeftNeighbour(new OrFilter(
new ParentElementFilter(new ClassFilter(PsiSwitchStatement.class), 2),
new AndFilter(new TextFilter(";", ":"), new ParentElementFilter(
new ClassFilter(PsiSwitchStatement.class), 3)),
new AndFilter(new TextFilter("}"), new ParentElementFilter(
new ClassFilter(PsiSwitchStatement.class), 4))
)))));
static final ElementPattern<PsiElement> START_SWITCH = psiElement().afterLeaf(psiElement().withText("{").withParents(PsiCodeBlock.class, PsiSwitchStatement.class));
private static final ElementPattern<Object> SUPER_OR_THIS_PATTERN =
private static final ElementPattern<PsiElement> SUPER_OR_THIS_PATTERN =
and(JavaSmartCompletionContributor.INSIDE_EXPRESSION,
not(psiElement().afterLeaf(PsiKeyword.CASE)),
not(psiElement().afterLeaf(psiElement().withText(".").afterLeaf(PsiKeyword.THIS, PsiKeyword.SUPER))),
not(new FilterPattern(START_SWITCH)));
not(START_SWITCH));
public static final AndFilter CLASS_START = new AndFilter(
@@ -472,10 +458,10 @@ public class JavaCompletionData extends JavaAwareCompletionData{
}
if (isStatementPosition(position)) {
if (INSIDE_SWITCH.isAcceptable(position, 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.DEFAULT), TailType.CASE_COLON));
if (!psiElement().afterLeaf(psiElement().withText(":").withParent(PsiSwitchLabelStatement.class)).accepts(position)) {
if (START_SWITCH.accepts(position)) {
return;
}
}

View File

@@ -0,0 +1,9 @@
public class ConstConfig {
{
switch (x) {
case 1:
println(1);
brea<caret>
}
}
}

View File

@@ -0,0 +1,9 @@
public class ConstConfig {
{
switch (x) {
case 1:
println(1);
break;<caret>
}
}
}

View File

@@ -639,6 +639,7 @@ public class NormalCompletionTest extends LightFixtureCompletionTestCase {
public void testFieldNegation() throws Throwable { doTest('!');}
public void testDefaultInSwitch() throws Throwable { doTest()}
public void testBreakInSwitch() throws Throwable { doTest() }
public void testSuperInConstructor() throws Throwable {
doTest();