mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
unused declaration: merge unused parameters inspection
This commit is contained in:
+3
-2
@@ -31,6 +31,7 @@ import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInsight.intention.IntentionManager;
|
||||
import com.intellij.codeInsight.intention.QuickFixFactory;
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection;
|
||||
import com.intellij.codeInspection.ex.EntryPointsManagerBase;
|
||||
import com.intellij.codeInspection.unusedParameters.UnusedParametersInspection;
|
||||
import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspectionBase;
|
||||
@@ -655,8 +656,8 @@ public class QuickFixFactoryImpl extends QuickFixFactory {
|
||||
public void registerFixesForUnusedParameter(@NotNull PsiParameter parameter, @NotNull Object highlightInfo) {
|
||||
Project myProject = parameter.getProject();
|
||||
InspectionProfile profile = InspectionProjectProfileManager.getInstance(myProject).getCurrentProfile();
|
||||
UnusedParametersInspection unusedParametersInspection =
|
||||
(UnusedParametersInspection)profile.getUnwrappedTool(UnusedSymbolLocalInspectionBase.UNUSED_PARAMETERS_SHORT_NAME, parameter);
|
||||
UnusedDeclarationInspection unusedParametersInspection =
|
||||
(UnusedDeclarationInspection)profile.getUnwrappedTool(UnusedSymbolLocalInspectionBase.SHORT_NAME, parameter);
|
||||
LOG.assertTrue(ApplicationManager.getApplication().isUnitTestMode() || unusedParametersInspection != null);
|
||||
List<IntentionAction> options = new ArrayList<>();
|
||||
HighlightDisplayKey myUnusedSymbolKey = HighlightDisplayKey.find(UnusedSymbolLocalInspectionBase.SHORT_NAME);
|
||||
|
||||
+56
-1
@@ -15,13 +15,20 @@
|
||||
*/
|
||||
package com.intellij.codeInspection.deadCode;
|
||||
|
||||
import com.intellij.codeInspection.InspectionsBundle;
|
||||
import com.intellij.analysis.AnalysisScope;
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.codeInspection.ex.EntryPointsManagerImpl;
|
||||
import com.intellij.codeInspection.reference.EntryPoint;
|
||||
import com.intellij.codeInspection.reference.RefEntity;
|
||||
import com.intellij.codeInspection.reference.RefMethod;
|
||||
import com.intellij.codeInspection.reference.RefVisitor;
|
||||
import com.intellij.codeInspection.unusedParameters.UnusedParametersInspection;
|
||||
import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection;
|
||||
import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspectionBase;
|
||||
import com.intellij.ui.components.JBTabbedPane;
|
||||
import com.intellij.util.ui.JBUI;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -30,6 +37,8 @@ import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class UnusedDeclarationInspection extends UnusedDeclarationInspectionBase {
|
||||
private final UnusedParametersInspection myUnusedParameters = new UnusedParametersInspection();
|
||||
|
||||
public UnusedDeclarationInspection() { }
|
||||
|
||||
@TestOnly
|
||||
@@ -37,6 +46,52 @@ public class UnusedDeclarationInspection extends UnusedDeclarationInspectionBase
|
||||
super(enabledInEditor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runInspection(@NotNull AnalysisScope scope,
|
||||
@NotNull InspectionManager manager,
|
||||
@NotNull GlobalInspectionContext globalContext,
|
||||
@NotNull ProblemDescriptionsProcessor problemDescriptionsProcessor) {
|
||||
if (myLocalInspectionBase.PARAMETER) {
|
||||
globalContext.getRefManager().iterate(new RefVisitor() {
|
||||
@Override public void visitElement(@NotNull RefEntity refEntity) {
|
||||
if (!(refEntity instanceof RefMethod) ||
|
||||
!globalContext.shouldCheck(refEntity, UnusedDeclarationInspection.this) ||
|
||||
!UnusedDeclarationPresentation.compareVisibilities((RefMethod)refEntity, myLocalInspectionBase)) {
|
||||
return;
|
||||
}
|
||||
CommonProblemDescriptor[] descriptors = myUnusedParameters.checkElement(refEntity, scope, manager, globalContext, problemDescriptionsProcessor);
|
||||
if (descriptors != null) {
|
||||
problemDescriptionsProcessor.addProblemElement(refEntity, descriptors);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
super.runInspection(scope, manager, globalContext, problemDescriptionsProcessor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean queryExternalUsagesRequests(@NotNull InspectionManager manager,
|
||||
@NotNull GlobalInspectionContext globalContext,
|
||||
@NotNull ProblemDescriptionsProcessor problemDescriptionsProcessor) {
|
||||
final boolean requests = super.queryExternalUsagesRequests(manager, globalContext, problemDescriptionsProcessor);
|
||||
if (!requests) {
|
||||
myUnusedParameters.queryExternalUsagesRequests(manager, globalContext, problemDescriptionsProcessor);
|
||||
}
|
||||
return requests;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getHint(@NotNull QuickFix fix) {
|
||||
return myUnusedParameters.getHint(fix);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public QuickFix getQuickFix(String hint) {
|
||||
return myUnusedParameters.getQuickFix(hint);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
protected UnusedSymbolLocalInspectionBase createUnusedSymbolLocalInspection() {
|
||||
|
||||
+4
-2
@@ -436,6 +436,7 @@ public class UnusedDeclarationPresentation extends DefaultInspectionToolPresenta
|
||||
}
|
||||
}
|
||||
});
|
||||
updateProblemElements();
|
||||
}
|
||||
|
||||
@PsiModifier.ModifierConstant
|
||||
@@ -464,7 +465,7 @@ public class UnusedDeclarationPresentation extends DefaultInspectionToolPresenta
|
||||
return PsiModifier.PUBLIC;
|
||||
}
|
||||
|
||||
private static boolean compareVisibilities(RefJavaElement listOwner, UnusedSymbolLocalInspectionBase localInspectionTool) {
|
||||
protected static boolean compareVisibilities(RefJavaElement listOwner, UnusedSymbolLocalInspectionBase localInspectionTool) {
|
||||
final String visibility = getAcceptedVisibility(localInspectionTool, listOwner);
|
||||
if (visibility != null) {
|
||||
while (listOwner != null) {
|
||||
@@ -485,7 +486,7 @@ public class UnusedDeclarationPresentation extends DefaultInspectionToolPresenta
|
||||
|
||||
@Override
|
||||
public boolean hasReportedProblems() {
|
||||
return !myContents.isEmpty();
|
||||
return !myContents.isEmpty() || super.hasReportedProblems();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -544,6 +545,7 @@ public class UnusedDeclarationPresentation extends DefaultInspectionToolPresenta
|
||||
if (COMMENT.equals(hint)) {
|
||||
return new CommentOutFix(((ProblemDescriptor)descriptor).getPsiElement());
|
||||
}
|
||||
return super.findQuickFixes(descriptor, hint);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
+4
-1
@@ -164,7 +164,10 @@ public class UnusedParametersInspection extends GlobalJavaBatchInspectionTool {
|
||||
@Override
|
||||
@Nullable
|
||||
public String getHint(@NotNull final QuickFix fix) {
|
||||
return ((AcceptSuggested)fix).getHint();
|
||||
if (fix instanceof AcceptSuggested) {
|
||||
return ((AcceptSuggested)fix).getHint();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
// "Suppress for parameter" "true"
|
||||
public class Test {
|
||||
private void run(@SuppressWarnings("UnusedParameters") String s<caret>ss) {
|
||||
private void run(@SuppressWarnings("unused") String sss) {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ public class Suppress15InspectionsTest extends LightQuickFixParameterizedTestCas
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
enableInspectionTools(new UnusedParametersInspection(), new UnusedDeclarationInspection());
|
||||
enableInspectionTools(new UnusedDeclarationInspection());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
package com.intellij.codeInspection;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInspection.unusedParameters.UnusedParametersInspection;
|
||||
import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection;
|
||||
import com.intellij.testFramework.InspectionTestCase;
|
||||
|
||||
public class UnusedMethodParameterTest extends InspectionTestCase {
|
||||
@@ -20,10 +20,8 @@ public class UnusedMethodParameterTest extends InspectionTestCase {
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/inspection";
|
||||
}
|
||||
|
||||
private final UnusedParametersInspection myTool = new UnusedParametersInspection();
|
||||
|
||||
private void doTest() throws Exception {
|
||||
doTest("unusedMethodParameter/" + getTestName(true), myTool);
|
||||
doTest("unusedMethodParameter/" + getTestName(true), new UnusedDeclarationInspection());
|
||||
}
|
||||
|
||||
public void testFieldInAnonymousClass() throws Exception {
|
||||
@@ -43,7 +41,7 @@ public class UnusedMethodParameterTest extends InspectionTestCase {
|
||||
}
|
||||
|
||||
public void testEntryPointUnusedParameter() throws Exception {
|
||||
doTest("unusedMethodParameter/" + getTestName(true), myTool, true, true);
|
||||
doTest("unusedMethodParameter/" + getTestName(true), new UnusedDeclarationInspection(), true, true);
|
||||
}
|
||||
|
||||
public void testAppMainUnusedParams() throws Exception {
|
||||
|
||||
+4
@@ -578,6 +578,10 @@ public class DefaultInspectionToolPresentation implements ProblemDescriptionsPro
|
||||
public void updateContent() {
|
||||
myContents.clear();
|
||||
myModulesProblems.clear();
|
||||
updateProblemElements();
|
||||
}
|
||||
|
||||
protected void updateProblemElements() {
|
||||
final Set<RefEntity> elements = getProblemElements().keySet();
|
||||
for (RefEntity element : elements) {
|
||||
if (getContext().getUIOptions().FILTER_RESOLVED_ITEMS && getIgnoredElements().containsKey(element)) continue;
|
||||
|
||||
@@ -596,9 +596,6 @@
|
||||
<globalInspection groupPath="Java" language="JAVA" shortName="CanBeFinal" displayName="Declaration can have final modifier" groupKey="group.names.declaration.redundancy" groupBundle="messages.InspectionsBundle"
|
||||
enabledByDefault="true" level="WARNING"
|
||||
implementationClass="com.intellij.codeInspection.canBeFinal.CanBeFinalInspection"/>
|
||||
<globalInspection groupPath="Java" language="JAVA" shortName="UnusedParameters" bundle="messages.InspectionsBundle" key="inspection.unused.parameter.display.name"
|
||||
groupKey="group.names.declaration.redundancy" enabledByDefault="true" level="WARNING"
|
||||
implementationClass="com.intellij.codeInspection.unusedParameters.UnusedParametersInspection"/>
|
||||
<globalInspection groupPath="Java" language="JAVA" shortName="SameParameterValue" bundle="messages.InspectionsBundle" key="inspection.same.parameter.display.name"
|
||||
groupKey="group.names.declaration.redundancy" enabledByDefault="true" level="WARNING"
|
||||
implementationClass="com.intellij.codeInspection.sameParameterValue.SameParameterValueInspection"/>
|
||||
|
||||
Reference in New Issue
Block a user