mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-60581 Statement keywords presented when completing inside Java for loop
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
public class Class2 {
|
||||
void foo() {
|
||||
for (int i = 1; <caret>)
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
public class Class2 {
|
||||
void foo() {
|
||||
for (int i = 1; i < 2; <caret>)
|
||||
}
|
||||
}
|
||||
+2
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user