mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
unused declaration: ensure unused local variables are reported inside entry points; suppress works for locals (IDEA-166622)
This commit is contained in:
+3
-2
@@ -284,7 +284,7 @@ public class UnusedDeclarationInspection extends UnusedDeclarationInspectionBase
|
||||
PsiVariable psiVariable = info.getVariable();
|
||||
|
||||
if (parent instanceof PsiDeclarationStatement || parent instanceof PsiResourceVariable) {
|
||||
if (!info.isRead()) {
|
||||
if (!info.isRead() && !SuppressionUtil.inspectionResultSuppressed(psiVariable, UnusedDeclarationInspection.this)) {
|
||||
descriptors.add(createProblemDescriptor(psiVariable));
|
||||
}
|
||||
}
|
||||
@@ -300,7 +300,8 @@ public class UnusedDeclarationInspection extends UnusedDeclarationInspectionBase
|
||||
|
||||
@Override
|
||||
public void visitLocalVariable(PsiLocalVariable variable) {
|
||||
if (!usedVariables.contains(variable) && variable.getInitializer() == null) {
|
||||
if (!usedVariables.contains(variable) && variable.getInitializer() == null &&
|
||||
!SuppressionUtil.inspectionResultSuppressed(variable, UnusedDeclarationInspection.this)) {
|
||||
descriptors.add(createProblemDescriptor(variable));
|
||||
}
|
||||
}
|
||||
|
||||
+18
@@ -27,6 +27,7 @@ import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.openapi.actionSystem.ActionManager;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ReadAction;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
@@ -528,6 +529,23 @@ public class UnusedDeclarationPresentation extends DefaultInspectionToolPresenta
|
||||
myIgnoreElements.add(refEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ignoreElement(@NotNull RefEntity refEntity) {
|
||||
if (refEntity instanceof RefElement) {
|
||||
final CommonProblemDescriptor[] descriptors = getProblemElements().get(refEntity);
|
||||
if (descriptors != null) {
|
||||
final PsiElement psiElement = ReadAction.compute(() -> ((RefElement)refEntity).getElement());
|
||||
List<CommonProblemDescriptor> foreignDescriptors = new ArrayList<>();
|
||||
for (CommonProblemDescriptor descriptor : descriptors) {
|
||||
if (descriptor instanceof ProblemDescriptor && ReadAction.compute(() -> ((ProblemDescriptor)descriptor).getPsiElement()) == psiElement) continue;
|
||||
foreignDescriptors.add(descriptor);
|
||||
}
|
||||
if (foreignDescriptors.size() == descriptors.length) return;
|
||||
}
|
||||
}
|
||||
super.ignoreElement(refEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void amnesty(RefEntity refEntity) {
|
||||
myIgnoreElements.remove(refEntity);
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems>
|
||||
<problems>
|
||||
<problem>
|
||||
<file>A.java</file>
|
||||
<description>Variable <code>i</code> is never used</description>
|
||||
</problem>
|
||||
</problems>
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
class A {
|
||||
public static void main(String[] args) {
|
||||
int i = 0;
|
||||
@SuppressWarning("unused") int j = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user