suggest 'final' in for-in loop clause (IDEA-67249)

This commit is contained in:
peter
2011-03-30 15:13:51 +02:00
parent 4b5428e738
commit 68d8890b7f
3 changed files with 21 additions and 5 deletions

View File

@@ -526,9 +526,12 @@ public class JavaCompletionData extends JavaAwareCompletionData{
return;
}
final PsiExpressionStatement expressionStatement = PsiTreeUtil.getParentOfType(position, PsiExpressionStatement.class);
if (expressionStatement != null && expressionStatement.getTextRange().getStartOffset() == position.getTextRange().getStartOffset()) {
if (!psiElement().withSuperParent(2, PsiSwitchStatement.class).accepts(expressionStatement)) {
PsiStatement statement = PsiTreeUtil.getParentOfType(position, PsiExpressionStatement.class);
if (statement == null) {
statement = PsiTreeUtil.getParentOfType(position, PsiDeclarationStatement.class);
}
if (statement != null && statement.getTextRange().getStartOffset() == position.getTextRange().getStartOffset()) {
if (!psiElement().withSuperParent(2, PsiSwitchStatement.class).accepts(statement)) {
result.addElement(createKeyword(position, PsiKeyword.FINAL));
}
}

View File

@@ -0,0 +1,9 @@
import java.util.ArrayList;
public class Foooo {
{
for (fin<caret> Object o : new ArrayList())
}
}

View File

@@ -709,8 +709,12 @@ public class NormalCompletionTest extends LightFixtureCompletionTestCase {
public void testFinalInForLoop() throws Throwable {
configure()
checkResultByFile(getTestName(false) + ".java")
assertOrderedEquals myFixture.lookupElementStrings, 'final'
assertStringItems 'final'
}
public void testFinalInForLoop2() throws Throwable {
configure()
assertStringItems 'final', 'finalize'
}
public void testPrimitiveTypesInForLoop() throws Throwable { doPrimitiveTypeTest() }