Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Intellij Community
Commits
37b663ab
Commit
37b663ab
authored
7 years ago
by
Tagir Valeev
Browse files
Options
Download
Email Patches
Plain Diff
IDEA-182643 Duplicate throws: suppress if both exceptions are documented in JavaDoc
parent
df34e38e
Branches unavailable
Tags unavailable
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
java/java-analysis-impl/src/com/intellij/codeInspection/duplicateThrows/DuplicateThrowsInspection.java
+24
-0
...Inspection/duplicateThrows/DuplicateThrowsInspection.java
java/java-tests/testData/inspection/duplicateThrows/DuplicateThrows.java
+9
-0
.../testData/inspection/duplicateThrows/DuplicateThrows.java
with
33 additions
and
0 deletions
+33
-0
java/java-analysis-impl/src/com/intellij/codeInspection/duplicateThrows/DuplicateThrowsInspection.java
+
24
-
0
View file @
37b663ab
...
...
@@ -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
;
...
...
This diff is collapsed.
Click to expand it.
java/java-tests/testData/inspection/duplicateThrows/DuplicateThrows.java
+
9
-
0
View file @
37b663ab
...
...
@@ -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
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help