SSR: Match multi-catch correctly

This commit is contained in:
Bas Leijdekkers
2015-04-22 18:57:31 +02:00
parent d966c2eb07
commit 75afac2e7a
2 changed files with 19 additions and 1 deletions

View File

@@ -1614,7 +1614,16 @@ public class JavaMatchingVisitor extends JavaElementVisitor {
myMatchingVisitor.setResult(annotations2 != null && myMatchingVisitor.matchInAnyOrder(annotations, annotations2));
if (!myMatchingVisitor.getResult()) return;
}
myMatchingVisitor.setResult(matchType(typeElement, other));
final PsiTypeElement[] typeElementChildren = PsiTreeUtil.getChildrenOfType(typeElement, PsiTypeElement.class);
if (typeElementChildren != null && typeElementChildren.length > 1) {
// multi catch type element
final PsiTypeElement[] typeElementChildren2 = PsiTreeUtil.getChildrenOfType(other, PsiTypeElement.class);
myMatchingVisitor.setResult(
typeElementChildren2 != null && myMatchingVisitor.matchInAnyOrder(typeElementChildren, typeElementChildren2));
}
else {
myMatchingVisitor.setResult(matchType(typeElement, other));
}
}
@Override

View File

@@ -3223,5 +3223,14 @@ public class StructuralSearchTest extends StructuralSearchTestCase {
String pattern3 = "try { '_St1*; } finally { '_St2*; }";
assertEquals("Find try with finally block", 3, findMatchesCount(source, pattern3));
String pattern4 = "try { '_St1*; } catch (NullPointerException | IllegalArgumentException '_e) { '_St2*; }";
assertEquals("Match multi catch correctly", 0, findMatchesCount(source, pattern4));
String pattern5 = "try { '_St1*; } catch (UnsupportedOperationException | NullPointerException '_e) { '_St2*; }";
assertEquals("Find multi catch", 1, findMatchesCount(source, pattern5));
String pattern6 = "try { '_St1*; } catch ('_E1 | '_E2 '_e) { '_St2*; }";
assertEquals("Find multi catch with variables", 1, findMatchesCount(source, pattern6));
}
}