[^romka] IDEA-96146 Cannot enter 'final' keyword in try-with-resources

(cherry-picked from acd831e)
This commit is contained in:
peter
2012-11-29 17:00:13 +01:00
parent f22618b2ed
commit ba09e196d3
3 changed files with 13 additions and 2 deletions
@@ -38,7 +38,6 @@ import com.intellij.psi.jsp.JspElementType;
import com.intellij.psi.templateLanguages.OuterLanguageElement;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtil;
import com.intellij.util.Consumer;
import com.intellij.util.ProcessingContext;
import org.jetbrains.annotations.NonNls;
@@ -484,7 +483,9 @@ public class JavaCompletionData extends JavaAwareCompletionData {
}
}
if (isInsideParameterList(position) && !psiElement().afterLeaf(PsiKeyword.FINAL).accepts(position) && !AFTER_DOT.accepts(position)) {
if ((isInsideParameterList(position) || isAtResourceVariableStart(position)) &&
!psiElement().afterLeaf(PsiKeyword.FINAL).accepts(position) &&
!AFTER_DOT.accepts(position)) {
result.addElement(TailTypeDecorator.withTail(createKeyword(position, PsiKeyword.FINAL), TailType.HUMBLE_SPACE_BEFORE_WORD));
}
@@ -632,6 +633,10 @@ public class JavaCompletionData extends JavaAwareCompletionData {
}
}
private static boolean isAtResourceVariableStart(PsiElement position) {
return psiElement().insideStarting(psiElement(PsiTypeElement.class).withParent(PsiResourceList.class)).accepts(position);
}
private static void addBreakContinue(CompletionResultSet result, PsiElement position) {
PsiLoopStatement loop = PsiTreeUtil.getParentOfType(position, PsiLoopStatement.class);
@@ -0,0 +1,5 @@
public class Util {
void foo() {
try (<caret>)
}
}
@@ -108,6 +108,7 @@ 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 testFinalInTryWithResources() throws Exception { doTest(1, "final", "float", "class"); }
public void testClassInMethod() throws Exception { doTest(2, "class", "char"); }
public void testIntInClassArray() throws Throwable { doTest(2, "int", "char", "final"); }
public void testIntInClassArray2() throws Throwable { doTest(2, "int", "char", "final"); }