remove redundant suppressions: allow unrelated comment inside same noinspection comment

This commit is contained in:
Anna.Kozlova
2018-10-11 15:57:00 +02:00
parent 136370b042
commit 6fa0522d1b
3 changed files with 20 additions and 4 deletions
@@ -113,14 +113,25 @@ public class RemoveSuppressWarningAction implements LocalQuickFix {
}
private void removeFromComment(final PsiComment comment) throws IncorrectOperationException {
String commentText = comment.getText();
int secondCommentIdx = commentText.indexOf("//", 2);
String suffix = "";
if (secondCommentIdx > 0) {
suffix = commentText.substring(secondCommentIdx);
}
String newText = removeFromElementText(comment);
if (newText != null) {
if (newText.isEmpty()) {
comment.delete();
if (suffix.isEmpty()) {
comment.delete();
}
else {
comment.replace(JavaPsiFacade.getElementFactory(comment.getProject()).createCommentFromText(suffix, comment));
}
}
else {
PsiComment newComment = JavaPsiFacade.getElementFactory(comment.getProject())
.createCommentFromText("// " + SuppressionUtilCore.SUPPRESS_INSPECTIONS_TAG_NAME +" "+newText, comment);
.createCommentFromText("// " + SuppressionUtilCore.SUPPRESS_INSPECTIONS_TAG_NAME +" "+newText + suffix, comment);
comment.replace(newComment);
}
}
@@ -147,6 +158,10 @@ public class RemoveSuppressWarningAction implements LocalQuickFix {
text += StringUtil.trimStart(element.getText(), "//").trim();
}
text = StringUtil.trimStart(text, "@").trim();
int secondCommentIdx = text.indexOf("//");
if (secondCommentIdx > 0) {
text = text.substring(0, secondCommentIdx);
}
text = StringUtil.trimStart(text, SuppressionUtilCore.SUPPRESS_INSPECTIONS_TAG_NAME).trim();
List<String> ids = StringUtil.split(text, ",");
int i = ArrayUtil.find(ids.toArray(), myID);
@@ -8,7 +8,8 @@ public class Test {
}
void foo() {
List<ArrayList<String>> list = foo(new ArrayList<String>());
//comment1
List<ArrayList<String>> list = foo(new ArrayList<String>());
//noinspection unchecked
ArrayList<String> list = new ArrayList();
@@ -8,7 +8,7 @@ public class Test {
}
void foo() {
//noinspection unche<caret>cked
//noinspection unche<caret>cked //comment1
List<ArrayList<String>> list = foo(new ArrayList<String>());
//noinspection unchecked