ElementFilter (PsiElement element, boolean allowRecursion) { //throw foo if (psiElement().withParent(psiElement(PsiReferenceExpression.class).withParent(PsiThrowStatement.class)).accepts(element)) { return TrueFilter.INSTANCE; } if (psiElement().inside(StandardPatterns.or(psiElement(PsiAnnotationParameterList.class), JavaCompletionContributor.IN_SWITCH_LABEL)).accepts(element)) { return new ElementExtractorFilter(new AndFilter( new ClassFilter(PsiField.class), new ModifierFilter(PsiKeyword.STATIC, PsiKeyword.FINAL) )); } final PsiForeachStatement foreach = PsiTreeUtil.getParentOfType(element, PsiForeachStatement.class); if (foreach != null && !PsiTreeUtil.isAncestor(foreach.getBody(), element, false)) { return new ElementExtractorFilter(new ElementFilter() { @Override public boolean isAcceptable(Object element, @Nullable PsiElement context) { return element != foreach.getIterationParameter(); } @Override public boolean isClassAcceptable(Class hintClass) { return true; } }); } if (!allowRecursion) { final ElementFilter filter = RecursionWeigher.recursionFilter(element); if (filter != null) { return new ElementExtractorFilter(filter); } } return TrueFilter.INSTANCE; }