mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 21:55:01 +07:00
IDEA-60822 [IdeaX] code completion for "for(fin" automatically chooses "for(finalize()" instead of "for(final"
This commit is contained in:
@@ -119,6 +119,10 @@ public class JavaCompletionContributor extends CompletionContributor {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (JavaCompletionData.START_FOR.accepts(position)) {
|
||||
return ElementClassFilter.VARIABLE;
|
||||
}
|
||||
|
||||
if (psiElement().afterLeaf(psiElement().withText("(").withParent(PsiTryStatement.class)).accepts(position)) {
|
||||
return new OrFilter(new ThisOrAnyInnerFilter(new AssignableFromFilter(CommonClassNames.JAVA_LANG_THROWABLE)), ElementClassFilter.PACKAGE_FILTER);
|
||||
}
|
||||
|
||||
@@ -137,6 +137,8 @@ public class JavaCompletionData extends JavaAwareCompletionData{
|
||||
final static ElementFilter CLASS_BODY = new OrFilter(
|
||||
new AfterElementFilter(new TextFilter("{")),
|
||||
new ScopeFilter(new ClassFilter(JspClassLevelDeclarationStatement.class)));
|
||||
public static final ElementPattern<PsiElement> START_FOR =
|
||||
psiElement().afterLeaf(psiElement().withText("(").afterLeaf("for")).withParents(PsiJavaCodeReferenceElement.class, PsiExpressionStatement.class, PsiForStatement.class);
|
||||
|
||||
public JavaCompletionData(){
|
||||
declareCompletionSpaces();
|
||||
@@ -592,11 +594,12 @@ public class JavaCompletionData extends JavaAwareCompletionData{
|
||||
result.addElement(createKeyword(position, PsiKeyword.FALSE));
|
||||
}
|
||||
|
||||
if (psiElement().withParents(PsiJavaCodeReferenceElement.class, PsiExpressionStatement.class, PsiForStatement.class).accepts(position)) {
|
||||
if (START_FOR.accepts(position)) {
|
||||
for (String primitiveType : PRIMITIVE_TYPES) {
|
||||
if (!PsiKeyword.VOID.equals(primitiveType)) {
|
||||
result.addElement(TailTypeDecorator.withTail(createKeyword(position, primitiveType), TailType.SPACE));
|
||||
}
|
||||
result.addElement(TailTypeDecorator.withTail(createKeyword(position, PsiKeyword.FINAL), TailType.SPACE));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
public class Foooo {
|
||||
|
||||
{
|
||||
for (fin<caret>x)
|
||||
}
|
||||
|
||||
}
|
||||
+6
@@ -613,6 +613,12 @@ public class NormalCompletionTest extends LightFixtureCompletionTestCase {
|
||||
configureByFile(getTestName(false) + ".java")
|
||||
}
|
||||
|
||||
public void testFinalInForLoop() throws Throwable {
|
||||
configure()
|
||||
checkResultByFile(getTestName(false) + ".java")
|
||||
assertOrderedEquals myFixture.lookupElementStrings, 'final'
|
||||
}
|
||||
|
||||
public void testPrimitiveTypesInForLoop() throws Throwable { doPrimitiveTypeTest() }
|
||||
public void testPrimitiveTypesInForLoop2() throws Throwable { doPrimitiveTypeTest() }
|
||||
public void testPrimitiveTypesInForLoop3() throws Throwable { doPrimitiveTypeTest() }
|
||||
|
||||
Reference in New Issue
Block a user