void () { String s1 = """ class A { int bbb(int c, int ddd, int eee) { int a = 1; try { int b = 1; } catch(Type t) { a = 2; } catch(Type2 t2) { a = 3; } } }"""; final List<PsiVariable> vars = new ArrayList<>(); @SuppressWarnings("deprecation") final PsiFile file = PsiFileFactory.getInstance(getProject()).createFileFromText("_.java", s1); //noinspection AnonymousInnerClassMayBeStatic file.acceptChildren(new JavaRecursiveElementWalkingVisitor() { @Override public void visitVariable(final @NotNull PsiVariable variable) { super.visitVariable(variable); vars.add(variable); } }); assertEquals(7, vars.size()); MatchOptions options = new MatchOptions(); options.fillSearchCriteria("try { '_st*; } catch('_Type 't+) { '_st2*; }"); options.setFileType(JavaFileType.INSTANCE); List<MatchResult> results = new ArrayList<>(); for(PsiVariable var:vars) { final List<MatchResult> matchResult = new Matcher(getProject(), options).matchByDownUp(var); results.addAll(matchResult); assertTrue((var instanceof PsiParameter && var.getParent() instanceof PsiCatchSection && !matchResult.isEmpty()) || matchResult.isEmpty()); } assertEquals(2, results.size()); MatchResult result = results.get(0); assertEquals("t", result.getMatchImage()); result = results.get(1); assertEquals("t2", result.getMatchImage()); results.clear(); options.fillSearchCriteria("try { '_st*; } catch('Type:Type2 '_t) { '_st2*; }"); for(PsiVariable var:vars) { final PsiTypeElement typeElement = var.getTypeElement(); final List<MatchResult> matchResult = new Matcher(getProject(), options).matchByDownUp(typeElement); results.addAll(matchResult); assertTrue((var instanceof PsiParameter && var.getParent() instanceof PsiCatchSection && !matchResult.isEmpty()) || matchResult.isEmpty()); } assertEquals(1, results.size()); result = results.get(0); assertEquals("Type2", result.getMatchImage()); }