Better exceptions-only completion in catch

This commit is contained in:
Roman Shevchenko
2011-03-10 21:34:36 +01:00
parent 7b05a6c4a9
commit ec147dd31d
16 changed files with 75 additions and 55 deletions
@@ -82,17 +82,20 @@ public class JavaCompletionContributor extends CompletionContributor {
}
})));
private static final ElementPattern<PsiElement> AFTER_NUMBER_LITERAL =
psiElement().afterLeaf(psiElement().withElementType(
elementType().oneOf(JavaTokenType.DOUBLE_LITERAL, JavaTokenType.LONG_LITERAL, JavaTokenType.FLOAT_LITERAL, JavaTokenType.INTEGER_LITERAL)));
private static final PsiJavaElementPattern.Capture<PsiElement> IMPORT_REFERENCE =
psiElement().afterLeaf(psiElement().withElementType(elementType().oneOf(JavaTokenType.DOUBLE_LITERAL, JavaTokenType.LONG_LITERAL,
JavaTokenType.FLOAT_LITERAL, JavaTokenType.INTEGER_LITERAL)));
private static final ElementPattern<PsiElement> IMPORT_REFERENCE =
psiElement().withParent(psiElement(PsiJavaCodeReferenceElement.class).withParent(PsiImportStatementBase.class));
static final PsiJavaElementPattern.Capture<PsiElement> IN_CATCH_TYPE =
psiElement().afterLeaf(psiElement().withText("(").withParent(PsiCatchSection.class));
static final ElementPattern<PsiElement> IN_CATCH_TYPE =
psiElement().withParent(psiElement(PsiJavaCodeReferenceElement.class).
withParent(psiElement(PsiTypeElement.class).
withParent(or(psiElement(PsiCatchSection.class),
psiElement(PsiVariable.class).withParent(PsiCatchSection.class)))));
static final ElementPattern<PsiElement> IN_MULTI_CATCH_TYPE =
or(psiElement().afterLeaf(psiElement().withText("|").withParent(PsiTypeElement.class).withSuperParent(2, PsiCatchSection.class)),
psiElement().afterLeaf(psiElement().withText("|").withParent(PsiTypeElement.class).withSuperParent(2, PsiParameter.class).withSuperParent(3, PsiCatchSection.class)));
static final PsiJavaElementPattern.Capture<PsiElement> INSIDE_METHOD_THROWS_CLAUSE =
static final ElementPattern<PsiElement> INSIDE_METHOD_THROWS_CLAUSE =
psiElement().afterLeaf(PsiKeyword.THROWS, ",").inside(PsiMethod.class).andNot(psiElement().inside(PsiCodeBlock.class)).andNot(psiElement().inside(PsiParameterList.class));
static final ElementPattern<PsiElement> IN_RESOURCE_TYPE =
psiElement().withParent(psiElement(PsiJavaCodeReferenceElement.class).
@@ -66,11 +66,12 @@ public class JavaCompletionData extends JavaAwareCompletionData{
new ParentElementFilter(new AndFilter(
new LeftNeighbour(new TextFilter(PsiKeyword.TRY)),
new ParentElementFilter(new ClassFilter(PsiTryStatement.class)))
)));
)));
public static final PsiJavaElementPattern.Capture<PsiElement> INSIDE_PARAMETER_LIST =
PsiJavaPatterns.psiElement().withParent(
psiElement(PsiJavaCodeReferenceElement.class).withParent(
psiElement(PsiTypeElement.class).withParent(or(psiElement(PsiParameter.class), psiElement(PsiParameterList.class)))));
psiElement(PsiTypeElement.class).withParent(or(psiElement(PsiParameter.class).withParent(PsiParameterList.class),
psiElement(PsiParameterList.class)))));
private static final AndFilter START_OF_CODE_FRAGMENT = new AndFilter(
new ScopeFilter(new AndFilter(
@@ -1,7 +0,0 @@
class MyClass {
static class MyException extends Exception { }
void m() {
try { } catch (MyException<caret>) { }
}
}
@@ -1,7 +0,0 @@
class MyClass {
static class MyException extends Exception { }
void m() {
try { } catch (My<caret>) { }
}
}
@@ -1,7 +0,0 @@
class MyClass {
static class MyException extends Exception { }
void m() {
try { } catch (MyException<caret> e) { }
}
}
@@ -1,7 +0,0 @@
class MyClass {
static class MyException extends Exception { }
void m() {
try { } catch (My<caret> e) { }
}
}
@@ -0,0 +1,8 @@
class AbcdClass {}
class AbcdException extends Throwable {}
class Foo {
{
try { } catch (Abcd<caret> e)
}
}
@@ -0,0 +1,8 @@
class AbcdClass {}
class AbcdException extends Throwable {}
class Foo {
{
try { } catch (AbcdException<caret> e)
}
}
@@ -0,0 +1,8 @@
class AbcdClass {}
class AbcdException extends Throwable {}
class Foo {
{
try { } catch (final Abcd<caret>)
}
}
@@ -0,0 +1,8 @@
class AbcdClass {}
class AbcdException extends Throwable {}
class Foo {
{
try { } catch (final AbcdException<caret>)
}
}
@@ -0,0 +1,8 @@
class AbcdClass {}
class AbcdException extends Throwable {}
class Foo {
{
try { } catch (final Abcd<caret> e)
}
}
@@ -0,0 +1,8 @@
class AbcdClass {}
class AbcdException extends Throwable {}
class Foo {
{
try { } catch (final AbcdException<caret> e)
}
}
@@ -221,10 +221,6 @@ public class ClassNameCompletionTest extends CompletionTestCase {
checkResultByFile(BASE_PATH + "/nameCompletion/java/" + getTestName(false) + "-result.java");
}
public void testInCatchType1() throws Exception { doJavaTest(); }
public void testInCatchType2() throws Exception { doJavaTest(); }
public void testInMultiCatchType1() throws Exception { doJavaTest(); }
public void testInMultiCatchType2() throws Exception { doJavaTest(); }
@@ -236,18 +236,18 @@ public class NormalCompletionTest extends LightFixtureCompletionTestCase {
assertEquals(2, myItems.length);
}
public void testMethodCallBeforeAnotherStatementWithParen() throws Exception {
configureByFile("MethodLookup2.java");
checkResultByFile("MethodLookup2_After.java");
public void testMethodCallBeforeAnotherStatementWithParen() throws Exception {
configureByFile("MethodLookup2.java");
checkResultByFile("MethodLookup2_After.java");
}
public void testMethodCallBeforeAnotherStatementWithParen2() throws Exception {
CodeStyleSettings settings = CodeStyleSettingsManager.getInstance(getProject()).getCurrentSettings();
boolean oldvalue = settings.METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE;
settings.METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE = true;
configureByFile("MethodLookup2.java");
checkResultByFile("MethodLookup2_After2.java");
settings.METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE = oldvalue;
public void testMethodCallBeforeAnotherStatementWithParen2() throws Exception {
CodeStyleSettings settings = CodeStyleSettingsManager.getInstance(getProject()).getCurrentSettings();
boolean oldvalue = settings.METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE;
settings.METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE = true;
configureByFile("MethodLookup2.java");
checkResultByFile("MethodLookup2_After2.java");
settings.METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE = oldvalue;
}
public void testSwitchEnumLabel() throws Exception {
@@ -266,19 +266,16 @@ public class NormalCompletionTest extends LightFixtureCompletionTestCase {
}
public void testMethodInAnnotation3() throws Exception {
configureByFile("Annotation3.java");
checkResultByFile("Annotation3_after.java");
}
public void testMethodInAnnotation5() throws Exception {
configureByFile("Annotation5.java");
checkResultByFile("Annotation5_after.java");
}
public void testMethodInAnnotation7() throws Exception {
configureByFile("Annotation7.java");
selectItem(myItems[0]);
checkResultByFile("Annotation7_after.java");
@@ -824,7 +821,11 @@ public class NormalCompletionTest extends LightFixtureCompletionTestCase {
public void testLiveTemplatePrefixTab() throws Throwable {doTest('\t') }
public void testOnlyAnnotationsAfterAt() throws Throwable { doTest() }
public void testOnlyExceptionsInCatch() throws Throwable { doTest() }
public void testOnlyExceptionsInCatch1() throws Exception { doTest() }
public void testOnlyExceptionsInCatch2() throws Exception { doTest() }
public void testOnlyExceptionsInCatch3() throws Exception { doTest() }
public void testOnlyExceptionsInCatch4() throws Exception { doTest() }
public void testCommaAfterVariable() throws Throwable { doTest(',') }
@@ -958,5 +959,4 @@ public class NormalCompletionTest extends LightFixtureCompletionTestCase {
myFixture.type '*\n'
myFixture.checkResult "import java.lang.*<caret>"
}
}