IDEA-60822 [IdeaX] code completion for "for(fin" automatically chooses "for(finalize()" instead of "for(final"

This commit is contained in:
peter.gromov
2010-11-11 21:03:29 +03:00
parent 68d0598a76
commit f4fafcbb4b
4 changed files with 21 additions and 1 deletions
@@ -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)
}
}
@@ -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() }