void (@NotNull PsiClassType type, @NotNull PsiElement place) { place.accept(new JavaRecursiveElementWalkingVisitor() { @Override public void visitReferenceExpression(@NotNull PsiReferenceExpression expression) { visitElement(expression); } @Override public void visitThrowStatement(@NotNull PsiThrowStatement statement) { super.visitThrowStatement(statement); List<PsiClassType> actualTypes = ExceptionUtil.getUnhandledExceptions(statement, place); for (PsiClassType actualType : actualTypes) { if (actualType != null && type.isAssignableFrom(actualType) && myTypeFilter.test(actualType)) { PsiExpression psiExpression = statement.getException(); if (psiExpression instanceof PsiReferenceExpression) { addUsage(psiExpression); } else if (psiExpression instanceof PsiNewExpression) { PsiJavaCodeReferenceElement ref = ((PsiNewExpression)psiExpression).getClassReference(); if (ref != null) { addUsage(ref); } } else { PsiExpression exception = statement.getException(); if (exception != null) { addUsage(exception); } } } } } @Override public void visitMethodCallExpression(@NotNull PsiMethodCallExpression expression) { super.visitMethodCallExpression(expression); PsiReference reference = expression.getMethodExpression().getReference(); if (reference != null) { List<PsiClassType> exceptionTypes = ExceptionUtil.getUnhandledExceptions(expression, place); for (final PsiClassType actualType : exceptionTypes) { if (type.isAssignableFrom(actualType) && myTypeFilter.test(actualType)) { addUsage(expression.getMethodExpression()); break; } } } } @Override public void visitNewExpression(@NotNull PsiNewExpression expression) { super.visitNewExpression(expression); PsiJavaCodeReferenceElement classReference = expression.getClassOrAnonymousClassReference(); if (classReference != null) { List<PsiClassType> exceptionTypes = ExceptionUtil.getUnhandledExceptions(expression, place); for (PsiClassType actualType : exceptionTypes) { if (type.isAssignableFrom(actualType) && myTypeFilter.test(actualType)) { addUsage(classReference); break; } } } } @Override public void visitResourceExpression(@NotNull PsiResourceExpression expression) { super.visitResourceExpression(expression); List<PsiClassType> exceptionTypes = ExceptionUtil.getUnhandledCloserExceptions(expression, place); for (PsiClassType actualType : exceptionTypes) { if (type.isAssignableFrom(actualType) && myTypeFilter.test(actualType)) { addUsage(expression); break; } } } @Override public void visitResourceVariable(@NotNull PsiResourceVariable variable) { super.visitResourceVariable(variable); List<PsiClassType> exceptionTypes = ExceptionUtil.getUnhandledCloserExceptions(variable, place); for (PsiClassType actualType : exceptionTypes) { if (type.isAssignableFrom(actualType) && myTypeFilter.test(actualType)) { PsiIdentifier name = variable.getNameIdentifier(); if (name != null) { addUsage(name); break; } } } } }); }