IDEA-60581 Statement keywords presented when completing inside Java for loop

This commit is contained in:
peter
2017-07-17 14:14:22 +02:00
parent b48b6362ab
commit 64c770a1f6
4 changed files with 21 additions and 1 deletions
@@ -769,7 +769,7 @@ public class JavaKeywordCompletion {
if (END_OF_BLOCK.getValue().isAcceptable(position, position) &&
PsiTreeUtil.getParentOfType(position, PsiCodeBlock.class, true, PsiMember.class) != null) {
return true;
return !isForLoopMachinery(position);
}
if (psiElement().withParents(PsiReferenceExpression.class, PsiExpressionStatement.class, PsiIfStatement.class).andNot(
@@ -784,6 +784,14 @@ public class JavaKeywordCompletion {
return false;
}
private static boolean isForLoopMachinery(PsiElement position) {
PsiStatement statement = PsiTreeUtil.getParentOfType(position, PsiStatement.class);
if (statement == null) return false;
return statement instanceof PsiForStatement ||
statement.getParent() instanceof PsiForStatement && statement != ((PsiForStatement)statement.getParent()).getBody();
}
private LookupElement createKeyword(String keyword) {
return BasicExpressionCompletionContributor.createKeywordLookupItem(myPosition, keyword);
}
@@ -0,0 +1,5 @@
public class Class2 {
void foo() {
for (int i = 1; <caret>)
}
}
@@ -0,0 +1,5 @@
public class Class2 {
void foo() {
for (int i = 1; i < 2; <caret>)
}
}
@@ -145,6 +145,8 @@ public class KeywordCompletionTest extends LightCompletionTestCase {
public void testIntInGenerics2() { doTest(2, "int", "char", "final"); }
public void testBreakInLabeledBlock() { doTest(1, "break label", "continue"); }
public void testPrimitiveInForLoop() { doTest(1, "int"); }
public void testNoStatementInForLoopCondition() { doTest(0, "synchronized", "if"); }
public void testNoStatementInForLoopUpdate() { doTest(0, "synchronized", "if"); }
public void testPrivateInJava9Interface() { setLanguageLevel(LanguageLevel.JDK_1_9); doTest(); }
public void testOverwriteCatch() {