Commit 37b663ab authored by Tagir Valeev's avatar Tagir Valeev
Browse files

IDEA-182643 Duplicate throws: suppress if both exceptions are documented in JavaDoc

parent df34e38e
Branches unavailable Tags unavailable
No related merge requests found
Showing with 33 additions and 0 deletions
+33 -0
......@@ -6,6 +6,10 @@ import com.intellij.codeInsight.daemon.impl.quickfix.MethodThrowsFix;
import com.intellij.codeInspection.*;
import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel;
import com.intellij.psi.*;
import com.intellij.psi.javadoc.PsiDocComment;
import com.intellij.psi.javadoc.PsiDocTag;
import com.intellij.psi.javadoc.PsiDocTagValue;
import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
......@@ -67,6 +71,16 @@ public class DuplicateThrowsInspection extends AbstractBaseJavaLocalInspectionTo
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.registerProblem(ref, problem, ProblemHighlightType.LIKE_UNUSED_SYMBOL, new MethodThrowsFix(method, type, false, false));
......@@ -77,6 +91,16 @@ public class DuplicateThrowsInspection extends AbstractBaseJavaLocalInspectionTo
};
}
private static boolean refersTo(PsiDocTag[] tags, PsiClassType exceptionType) {
for (PsiDocTag tag : tags) {
PsiDocTagValue element = tag.getValueElement();
if (element == null) continue;
PsiJavaCodeReferenceElement ref = PsiTreeUtil.findChildOfType(element, PsiJavaCodeReferenceElement.class);
if (ref != null && ref.resolve() == exceptionType.resolve()) return true;
}
return false;
}
@Override
public boolean isEnabledByDefault() {
return true;
......
......@@ -21,4 +21,13 @@ class X {
EOFException {
}
/**
* Execute.
*
* @throws IOException if file write is failed
* @throws Throwable if any other problem occurred
*/
void execute() throws IOException, Throwable {
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment