mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
redundant suppression: don't delete all same comments/top annotation when one suppress comment is actually to be deleted
This commit is contained in:
+31
-23
@@ -64,29 +64,37 @@ public class RemoveSuppressWarningAction implements LocalQuickFix {
|
||||
PsiElement element = descriptor.getPsiElement();
|
||||
try {
|
||||
if (element != null) {
|
||||
final PsiModifierListOwner commentOwner = PsiTreeUtil.getParentOfType(element, PsiModifierListOwner.class, false);
|
||||
if (commentOwner != null) {
|
||||
final PsiElement psiElement = JavaSuppressionUtil.getElementMemberSuppressedIn(commentOwner, myID);
|
||||
if (psiElement instanceof PsiAnnotation) {
|
||||
removeFromAnnotation((PsiAnnotation)psiElement);
|
||||
} else if (psiElement instanceof PsiDocComment) {
|
||||
removeFromJavaDoc((PsiDocComment)psiElement);
|
||||
} else { //try to remove from all comments
|
||||
final Set<PsiComment> comments = new HashSet<>();
|
||||
commentOwner.accept(new PsiRecursiveElementWalkingVisitor() {
|
||||
@Override public void visitComment(final PsiComment comment) {
|
||||
super.visitComment(comment);
|
||||
if (comment.getText().contains(myID)) {
|
||||
comments.add(comment);
|
||||
if (element instanceof PsiComment) {
|
||||
removeFromComment((PsiComment)element);
|
||||
}
|
||||
else {
|
||||
final PsiModifierListOwner commentOwner = PsiTreeUtil.getParentOfType(element, PsiModifierListOwner.class, false);
|
||||
if (commentOwner != null) {
|
||||
final PsiElement psiElement = JavaSuppressionUtil.getElementMemberSuppressedIn(commentOwner, myID);
|
||||
if (psiElement instanceof PsiAnnotation) {
|
||||
removeFromAnnotation((PsiAnnotation)psiElement);
|
||||
}
|
||||
else if (psiElement instanceof PsiDocComment) {
|
||||
removeFromJavaDoc((PsiDocComment)psiElement);
|
||||
}
|
||||
else { //try to remove from all comments
|
||||
final Set<PsiComment> comments = new HashSet<>();
|
||||
commentOwner.accept(new PsiRecursiveElementWalkingVisitor() {
|
||||
@Override
|
||||
public void visitComment(final PsiComment comment) {
|
||||
super.visitComment(comment);
|
||||
if (comment.getText().contains(myID)) {
|
||||
comments.add(comment);
|
||||
}
|
||||
}
|
||||
});
|
||||
for (PsiComment comment : comments) {
|
||||
try {
|
||||
removeFromComment(comment);
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
for (PsiComment comment : comments) {
|
||||
try {
|
||||
removeFromComment(comment, comments.size() > 1);
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -104,7 +112,7 @@ public class RemoveSuppressWarningAction implements LocalQuickFix {
|
||||
return QuickFixBundle.message("remove.suppression.action.name", myID);
|
||||
}
|
||||
|
||||
private void removeFromComment(final PsiComment comment, final boolean checkLine) throws IncorrectOperationException {
|
||||
private void removeFromComment(final PsiComment comment) throws IncorrectOperationException {
|
||||
String newText = removeFromElementText(comment);
|
||||
if (newText != null) {
|
||||
if (newText.isEmpty()) {
|
||||
|
||||
+3
@@ -9,6 +9,9 @@ public class Test {
|
||||
|
||||
void foo() {
|
||||
List<ArrayList<String>> list = foo(new ArrayList<String>());
|
||||
|
||||
//noinspection unchecked
|
||||
ArrayList<String> list = new ArrayList();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// "Remove 'unchecked' suppression" "true"
|
||||
import java.util.*;
|
||||
|
||||
public class Test {
|
||||
@SafeVarargs
|
||||
static <T> List<T> foo(T... t){
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
void foo() {
|
||||
List<ArrayList<String>> list = foo(new ArrayList<String>());
|
||||
|
||||
ArrayList<String> list = new ArrayList();
|
||||
}
|
||||
}
|
||||
|
||||
+3
@@ -10,6 +10,9 @@ public class Test {
|
||||
void foo() {
|
||||
//noinspection unche<caret>cked
|
||||
List<ArrayList<String>> list = foo(new ArrayList<String>());
|
||||
|
||||
//noinspection unchecked
|
||||
ArrayList<String> list = new ArrayList();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// "Remove 'unchecked' suppression" "true"
|
||||
import java.util.*;
|
||||
|
||||
public class Test {
|
||||
@SafeVarargs
|
||||
static <T> List<T> foo(T... t){
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
void foo() {
|
||||
//noinspection unche<caret>cked
|
||||
List<ArrayList<String>> list = foo(new ArrayList<String>());
|
||||
|
||||
ArrayList<String> list = new ArrayList();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user