PsiElementVisitor (@NotNull final ProblemsHolder holder, boolean isOnTheFly) { return new JavaElementVisitor() { @Override public void visitMethod(@NotNull PsiMethod method) { PsiReferenceList throwsList = method.getThrowsList(); PsiJavaCodeReferenceElement[] refs = throwsList.getReferenceElements(); PsiClassType[] types = throwsList.getReferencedTypes(); for (int i = 0; i < types.length; i++) { for (int j = i+1; j < types.length; j++) { PsiClassType type = types[i]; PsiClassType otherType = types[j]; String problem = null; PsiJavaCodeReferenceElement ref = refs[i]; if (type.equals(otherType)) { problem = JavaAnalysisBundle.message("inspection.duplicate.throws.problem"); } else if (!ignoreSubclassing) { if (otherType.isAssignableFrom(type)) { problem = JavaAnalysisBundle.message("inspection.duplicate.throws.more.general.problem", otherType.getCanonicalText()); } else if (type.isAssignableFrom(otherType)) { problem = JavaAnalysisBundle.message("inspection.duplicate.throws.more.general.problem", type.getCanonicalText()); ref = refs[j]; type = otherType; } if (problem != null) { PsiDocComment comment = method.getDocComment(); if (comment != null) { PsiDocTag[] docTags = comment.findTagsByName("throws"); if (docTags.length >= 2 && refersTo(docTags, type) && refersTo(docTags, otherType)) { // Both exceptions are present in JavaDoc: ignore return; } } } } if (problem != null) { holder.problem(ref, problem).fix(new MethodThrowsFix.RemoveFirst(method, type, false)).register(); } } } } }; }