IDEA-128971 Java auto-completion does not offer "final" keyword for exception variable in "catch" clause

This commit is contained in:
peter
2014-08-26 14:32:22 +02:00
parent 22058565a7
commit 6564528108
5 changed files with 23 additions and 3 deletions
@@ -484,7 +484,7 @@ public class JavaCompletionData extends JavaAwareCompletionData {
}
}
if ((isInsideParameterList(position) || isAtResourceVariableStart(position)) &&
if ((isInsideParameterList(position) || isAtResourceVariableStart(position) || isAtCatchVariableStart(position)) &&
!psiElement().afterLeaf(PsiKeyword.FINAL).accepts(position) &&
!AFTER_DOT.accepts(position)) {
result.addElement(TailTypeDecorator.withTail(createKeyword(position, PsiKeyword.FINAL), TailType.HUMBLE_SPACE_BEFORE_WORD));
@@ -673,6 +673,10 @@ public class JavaCompletionData extends JavaAwareCompletionData {
return psiElement().insideStarting(psiElement(PsiTypeElement.class).withParent(PsiResourceList.class)).accepts(position);
}
private static boolean isAtCatchVariableStart(PsiElement position) {
return psiElement().insideStarting(psiElement(PsiTypeElement.class).withParent(PsiCatchSection.class)).accepts(position);
}
private static void addBreakContinue(CompletionResultSet result, PsiElement position) {
PsiLoopStatement loop = PsiTreeUtil.getParentOfType(position, PsiLoopStatement.class);
@@ -0,0 +1,7 @@
public class StructuredConfigKey {
{
try {
} catch (<caret>)
}
}
@@ -0,0 +1,7 @@
public class StructuredConfigKey {
{
try {
} catch (<caret>)
}
}
@@ -106,7 +106,9 @@ public class KeywordCompletionTest extends LightCompletionTestCase {
public void testReturnInTernary() throws Exception { doTest(1, "return"); }
public void testFinalAfterParameterAnno() throws Exception { doTest(2, "final", "float", "class"); }
public void testFinalAfterParameterAnno2() throws Exception { doTest(2, "final", "float", "class"); }
public void testFinalAfterCase() throws Exception { doTest(3, "final", "float", "class"); }
public void testFinalAfterCase() { doTest(3, "final", "float", "class"); }
public void testFinalInCatch() { doTest(1, "final"); }
public void testFinalInIncompleteCatch() { doTest(1, "final"); }
public void testFinalInTryWithResources() throws Exception { doTest(1, "final", "float", "class"); }
public void testNoFinalAfterTryBody() throws Exception { doTest(1, "final", "finally"); }
public void testClassInMethod() throws Exception { doTest(2, "class", "char"); }
@@ -638,7 +638,7 @@ interface TxANotAnno {}
}
public void testPreferThrownExceptionsInCatch() {
checkPreferredItems 0, 'FileNotFoundException', 'File'
checkPreferredItems 0, 'final', 'FileNotFoundException', 'File'
}
public void testHonorFirstLetterCase() {