From 2ecc4272ac08e97e0314b5bae551b429f5d5b0ed Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Tue, 14 Oct 2014 10:21:26 +0200 Subject: [PATCH] merge unused declaration and unused symbol inspections --- .../daemon/impl/PostHighlightingPass.java | 66 ++++---- .../deadCode/DummyEntryPointsTool.java | 2 +- ...a => UnusedDeclarationInspectionBase.java} | 155 ++++-------------- .../UnusedDeclarationInspectionMerger.java | 94 +++++++++++ .../reference/RefJavaManagerImpl.java | 16 +- .../impl/PostHighlightingPassFactory.java | 8 +- .../deadCode/UnusedDeclarationInspection.java | 146 +++++++++++++++++ .../UnusedDeclarationPresentation.java | 6 +- .../unusedSymbol/OptionsPanel.form | 14 +- .../UnusedSymbolLocalInspection.java | 22 ++- .../suppress15Inspections/after2.java | 2 +- .../suppress15Inspections/after3.java | 2 +- .../suppressNonInspections/after1.java | 2 +- .../suppressNonInspections/after2.java | 2 +- .../daemon/AdvHighlightingTest.java | 12 +- .../daemon/AmbiguousMethodCallTest.java | 9 +- .../daemon/GenericsHighlightingTest.java | 10 +- .../daemon/HighlightSeverityTest.java | 6 +- .../daemon/HighlightStressTest.java | 12 +- .../daemon/LightAdvHighlightingJdk6Test.java | 9 +- .../daemon/LightAdvHighlightingJdk7Test.java | 19 ++- .../daemon/LightAdvHighlightingTest.java | 82 +++++---- .../daemon/SuppressWarningsTest.java | 10 +- .../daemon/UnusedSymbolLocalTest.java | 8 +- ...lExpressionIncompleteHighlightingTest.java | 12 +- .../lambda/GenericsHighlighting8Test.java | 10 +- .../daemon/lambda/LambdaHighlightingTest.java | 12 +- .../lambda/MethodRefHighlightingTest.java | 12 +- .../lambda/MostSpecificResolutionTest.java | 12 +- ...ceCollectingAdditionalConstraintsTest.java | 3 - .../lambda/NewLambdaHighlightingTest.java | 12 +- .../lambda/NewMethodRefHighlightingTest.java | 12 +- .../daemon/lambda/OverloadResolutionTest.java | 12 +- ...eateConstructorParameterFromFieldTest.java | 14 +- .../quickFix/CreateGetterOrSetterTest.java | 10 +- ...tializeFinalFieldInConstructorFixTest.java | 10 +- .../quickFix/RemoveUnusedParameterTest.java | 11 +- .../quickFix/RemoveUnusedVariableTest.java | 10 +- .../quickFix/Suppress15InspectionsTest.java | 5 +- .../quickFix/SuppressNonInspectionsTest.java | 10 +- .../codeInspection/InspectionProfileTest.java | 4 +- .../ChangeSignatureGestureTest.java | 4 +- .../daemon/impl/HighlightInfoType.java | 7 +- .../ex/InspectionElementsMerger.java | 28 ++++ .../ex/InspectionProfileImpl.java | 18 +- .../intellij/codeInspection/ex/ToolsImpl.java | 4 +- .../codeInspection/inspection-black-list.txt | 2 - .../src/META-INF/LangExtensionPoints.xml | 1 + .../DevKitImplicitUsageProviderTest.java | 5 +- .../RegisterExtensionFixProviderTest.java | 5 +- .../local/GroovyPostHighlightingPass.java | 4 +- .../groovy/lang/GppFunctionalTest.groovy | 5 +- .../lang/highlighting/GrUnusedDefTest.groovy | 4 +- .../javaFX/fxml/JavaFXHighlightingTest.java | 6 +- .../javaFX/fxml/JavaFxCoercingTest.java | 2 - .../inspectionDescriptions/UNUSED_SYMBOL.html | 13 -- .../{UnusedDeclaration.html => unused.html} | 3 +- resources/src/META-INF/IdeaPlugin.xml | 6 +- 58 files changed, 579 insertions(+), 423 deletions(-) rename java/java-analysis-impl/src/com/intellij/codeInspection/deadCode/{UnusedDeclarationInspection.java => UnusedDeclarationInspectionBase.java} (85%) create mode 100644 java/java-analysis-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspectionMerger.java create mode 100644 java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspection.java create mode 100644 platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionElementsMerger.java delete mode 100644 resources-en/src/inspectionDescriptions/UNUSED_SYMBOL.html rename resources-en/src/inspectionDescriptions/{UnusedDeclaration.html => unused.html} (60%) diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/PostHighlightingPass.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/PostHighlightingPass.java index 7bbeb1e68a95..c3ddc9e1f877 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/PostHighlightingPass.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/PostHighlightingPass.java @@ -28,7 +28,7 @@ import com.intellij.codeInsight.intention.QuickFixFactory; import com.intellij.codeInspection.InspectionProfile; import com.intellij.codeInspection.InspectionsBundle; import com.intellij.codeInspection.SuppressionUtil; -import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; +import com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionBase; import com.intellij.codeInspection.ex.EntryPointsManagerBase; import com.intellij.codeInspection.reference.UnusedDeclarationFixProvider; import com.intellij.codeInspection.unusedImport.UnusedImportLocalInspection; @@ -92,7 +92,6 @@ public class PostHighlightingPass extends ProgressableTextEditorHighlightingPass private boolean myHasMissortedImports; private static final ImplicitUsageProvider[] ourImplicitUsageProviders = Extensions.getExtensions(ImplicitUsageProvider.EP_NAME); private UnusedSymbolLocalInspectionBase myUnusedSymbolInspection; - private HighlightDisplayKey myUnusedSymbolKey; private boolean myInLibrary; private HighlightDisplayKey myDeadCodeKey; private HighlightInfoType myDeadCodeInfoType; @@ -202,12 +201,15 @@ public class PostHighlightingPass extends ProgressableTextEditorHighlightingPass ApplicationManager.getApplication().assertReadAccessAllowed(); InspectionProfile profile = InspectionProjectProfileManager.getInstance(myProject).getInspectionProfile(); - myUnusedSymbolKey = HighlightDisplayKey.find(UnusedSymbolLocalInspectionBase.SHORT_NAME); - boolean unusedSymbolEnabled = profile.isToolEnabled(myUnusedSymbolKey, myFile); - myUnusedSymbolInspection = (UnusedSymbolLocalInspectionBase)profile.getUnwrappedTool(UnusedSymbolLocalInspectionBase.SHORT_NAME, myFile); - LOG.assertTrue(ApplicationManager.getApplication().isUnitTestMode() || myUnusedSymbolInspection != null); - myDeadCodeKey = HighlightDisplayKey.find(UnusedDeclarationInspection.SHORT_NAME); + myDeadCodeKey = HighlightDisplayKey.find(UnusedDeclarationInspectionBase.SHORT_NAME); + boolean unusedSymbolEnabled = profile.isToolEnabled(myDeadCodeKey, myFile); + + final UnusedDeclarationInspectionBase + unwrappedTool = (UnusedDeclarationInspectionBase)profile.getUnwrappedTool(UnusedDeclarationInspectionBase.SHORT_NAME, myFile); + LOG.assertTrue(ApplicationManager.getApplication().isUnitTestMode() || unwrappedTool != null); + + myUnusedSymbolInspection = unwrappedTool != null ? unwrappedTool.getSharedLocalInspectionTool() : null; HighlightDisplayKey unusedImportKey = HighlightDisplayKey.find(UnusedImportLocalInspection.SHORT_NAME); @@ -305,17 +307,17 @@ public class PostHighlightingPass extends ProgressableTextEditorHighlightingPass if (!myRefCountHolder.isReferenced(variable)) { String message = JavaErrorMessages.message("local.variable.is.never.used", identifier.getText()); - HighlightInfo highlightInfo = createUnusedSymbolInfo(identifier, message, HighlightInfoType.UNUSED_SYMBOL); + HighlightInfo highlightInfo = createUnusedSymbolInfo(identifier, message, myDeadCodeInfoType); IntentionAction fix = variable instanceof PsiResourceVariable ? QuickFixFactory.getInstance().createRenameToIgnoredFix(variable) : QuickFixFactory.getInstance().createRemoveUnusedVariableFix(variable); - QuickFixAction.registerQuickFixAction(highlightInfo, fix, myUnusedSymbolKey); + QuickFixAction.registerQuickFixAction(highlightInfo, fix, myDeadCodeKey); return highlightInfo; } boolean referenced = myRefCountHolder.isReferencedForRead(variable); if (!referenced && !isImplicitRead(myProject, variable, progress)) { String message = JavaErrorMessages.message("local.variable.is.not.used.for.reading", identifier.getText()); - HighlightInfo highlightInfo = createUnusedSymbolInfo(identifier, message, HighlightInfoType.UNUSED_SYMBOL); - QuickFixAction.registerQuickFixAction(highlightInfo, QuickFixFactory.getInstance().createRemoveUnusedVariableFix(variable), myUnusedSymbolKey); + HighlightInfo highlightInfo = createUnusedSymbolInfo(identifier, message, myDeadCodeInfoType); + QuickFixAction.registerQuickFixAction(highlightInfo, QuickFixFactory.getInstance().createRemoveUnusedVariableFix(variable), myDeadCodeKey); return highlightInfo; } @@ -323,8 +325,8 @@ public class PostHighlightingPass extends ProgressableTextEditorHighlightingPass referenced = myRefCountHolder.isReferencedForWrite(variable); if (!referenced && !isImplicitWrite(myProject, variable, progress)) { String message = JavaErrorMessages.message("local.variable.is.not.assigned", identifier.getText()); - final HighlightInfo unusedSymbolInfo = createUnusedSymbolInfo(identifier, message, HighlightInfoType.UNUSED_SYMBOL); - QuickFixAction.registerQuickFixAction(unusedSymbolInfo, new EmptyIntentionAction(UnusedSymbolLocalInspectionBase.DISPLAY_NAME), myUnusedSymbolKey); + final HighlightInfo unusedSymbolInfo = createUnusedSymbolInfo(identifier, message, myDeadCodeInfoType); + QuickFixAction.registerQuickFixAction(unusedSymbolInfo, new EmptyIntentionAction(UnusedSymbolLocalInspectionBase.DISPLAY_NAME), myDeadCodeKey); return unusedSymbolInfo; } } @@ -419,9 +421,9 @@ public class PostHighlightingPass extends ProgressableTextEditorHighlightingPass final boolean writeReferenced = myRefCountHolder.isReferencedForWrite(field); if (!writeReferenced && !isImplicitWrite(project, field, progress)) { String message = JavaErrorMessages.message("private.field.is.not.assigned", identifier.getText()); - final HighlightInfo info = createUnusedSymbolInfo(identifier, message, HighlightInfoType.UNUSED_SYMBOL); + final HighlightInfo info = createUnusedSymbolInfo(identifier, message, myDeadCodeInfoType); - QuickFixAction.registerQuickFixAction(info, QuickFixFactory.getInstance().createCreateGetterOrSetterFix(false, true, field), myUnusedSymbolKey); + QuickFixAction.registerQuickFixAction(info, QuickFixFactory.getInstance().createCreateGetterOrSetterFix(false, true, field), myDeadCodeKey); QuickFixAction.registerQuickFixAction(info, HighlightMethodUtil.getFixRange(field), QuickFixFactory.getInstance().createCreateConstructorParameterFromFieldFix( field)); SpecialAnnotationsUtilBase.createAddToSpecialAnnotationFixes(field, new Processor() { @@ -456,11 +458,11 @@ public class PostHighlightingPass extends ProgressableTextEditorHighlightingPass } private HighlightInfo suggestionsToMakeFieldUsed(@NotNull PsiField field, @NotNull PsiIdentifier identifier, @NotNull String message) { - HighlightInfo highlightInfo = createUnusedSymbolInfo(identifier, message, HighlightInfoType.UNUSED_SYMBOL); - QuickFixAction.registerQuickFixAction(highlightInfo, QuickFixFactory.getInstance().createRemoveUnusedVariableFix(field), myUnusedSymbolKey); - QuickFixAction.registerQuickFixAction(highlightInfo, QuickFixFactory.getInstance().createCreateGetterOrSetterFix(true, false, field), myUnusedSymbolKey); - QuickFixAction.registerQuickFixAction(highlightInfo, QuickFixFactory.getInstance().createCreateGetterOrSetterFix(false, true, field), myUnusedSymbolKey); - QuickFixAction.registerQuickFixAction(highlightInfo, QuickFixFactory.getInstance().createCreateGetterOrSetterFix(true, true, field), myUnusedSymbolKey); + HighlightInfo highlightInfo = createUnusedSymbolInfo(identifier, message, myDeadCodeInfoType); + QuickFixAction.registerQuickFixAction(highlightInfo, QuickFixFactory.getInstance().createRemoveUnusedVariableFix(field), myDeadCodeKey); + QuickFixAction.registerQuickFixAction(highlightInfo, QuickFixFactory.getInstance().createCreateGetterOrSetterFix(true, false, field), myDeadCodeKey); + QuickFixAction.registerQuickFixAction(highlightInfo, QuickFixFactory.getInstance().createCreateGetterOrSetterFix(false, true, field), myDeadCodeKey); + QuickFixAction.registerQuickFixAction(highlightInfo, QuickFixFactory.getInstance().createCreateGetterOrSetterFix(true, true, field), myDeadCodeKey); return highlightInfo; } @@ -498,7 +500,7 @@ public class PostHighlightingPass extends ProgressableTextEditorHighlightingPass else if (declarationScope instanceof PsiForeachStatement && !PsiUtil.isIgnoredName(parameter.getName())) { HighlightInfo highlightInfo = checkUnusedParameter(parameter, identifier, progress); if (highlightInfo != null) { - QuickFixAction.registerQuickFixAction(highlightInfo, QuickFixFactory.getInstance().createRenameToIgnoredFix(parameter), myUnusedSymbolKey); + QuickFixAction.registerQuickFixAction(highlightInfo, QuickFixFactory.getInstance().createRenameToIgnoredFix(parameter), myDeadCodeKey); return highlightInfo; } } @@ -518,7 +520,7 @@ public class PostHighlightingPass extends ProgressableTextEditorHighlightingPass return null; } String message = JavaErrorMessages.message("parameter.is.not.used", identifier.getText()); - return createUnusedSymbolInfo(identifier, message, HighlightInfoType.UNUSED_SYMBOL); + return createUnusedSymbolInfo(identifier, message, myDeadCodeInfoType); } return null; } @@ -530,17 +532,13 @@ public class PostHighlightingPass extends ProgressableTextEditorHighlightingPass @NotNull ProgressIndicator progress, @NotNull GlobalUsageHelper helper) { if (isMethodReferenced(myProject, myFile, method, progress, helper)) return null; - HighlightInfoType highlightInfoType; - HighlightDisplayKey highlightDisplayKey; + final HighlightInfoType highlightInfoType = myDeadCodeInfoType; + final HighlightDisplayKey highlightDisplayKey = myDeadCodeKey; String key; if (method.hasModifierProperty(PsiModifier.PRIVATE)) { - highlightInfoType = HighlightInfoType.UNUSED_SYMBOL; - highlightDisplayKey = myUnusedSymbolKey; key = method.isConstructor() ? "private.constructor.is.not.used" : "private.method.is.not.used"; } else { - highlightInfoType = myDeadCodeInfoType; - highlightDisplayKey = myDeadCodeKey; key = method.isConstructor() ? "constructor.is.not.used" : "method.is.not.used"; } String symbolName = HighlightMessageUtil.getSymbolName(method, PsiSubstitutor.EMPTY); @@ -703,29 +701,21 @@ public class PostHighlightingPass extends ProgressableTextEditorHighlightingPass if (isClassUsed(project, myFile, aClass, progress, helper)) return null; String pattern; - HighlightDisplayKey highlightDisplayKey; - HighlightInfoType highlightInfoType; + HighlightDisplayKey highlightDisplayKey = myDeadCodeKey; + HighlightInfoType highlightInfoType = myDeadCodeInfoType; if (aClass.getContainingClass() != null && aClass.hasModifierProperty(PsiModifier.PRIVATE)) { pattern = aClass.isInterface() ? "private.inner.interface.is.not.used" : "private.inner.class.is.not.used"; - highlightDisplayKey = myUnusedSymbolKey; - highlightInfoType = HighlightInfoType.UNUSED_SYMBOL; } else if (aClass.getParent() instanceof PsiDeclarationStatement) { // local class pattern = "local.class.is.not.used"; - highlightDisplayKey = myUnusedSymbolKey; - highlightInfoType = HighlightInfoType.UNUSED_SYMBOL; } else if (aClass instanceof PsiTypeParameter) { pattern = "type.parameter.is.not.used"; - highlightDisplayKey = myUnusedSymbolKey; - highlightInfoType = HighlightInfoType.UNUSED_SYMBOL; } else { pattern = "class.is.not.used"; - highlightDisplayKey = myDeadCodeKey; - highlightInfoType = myDeadCodeInfoType; } return formatUnusedSymbolHighlightInfo(myProject, pattern, aClass, "classes", highlightDisplayKey, highlightInfoType, identifier); } diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/deadCode/DummyEntryPointsTool.java b/java/java-analysis-impl/src/com/intellij/codeInspection/deadCode/DummyEntryPointsTool.java index 4a49391cdecb..7a99ce8661f9 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/deadCode/DummyEntryPointsTool.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/deadCode/DummyEntryPointsTool.java @@ -27,7 +27,7 @@ import org.jetbrains.annotations.Nullable; /** * @author max */ -public class DummyEntryPointsTool extends UnusedDeclarationInspection { +public class DummyEntryPointsTool extends UnusedDeclarationInspectionBase { public DummyEntryPointsTool() { } diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspection.java b/java/java-analysis-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspectionBase.java similarity index 85% rename from java/java-analysis-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspection.java rename to java/java-analysis-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspectionBase.java index d46ebee90c55..65b529ad4c00 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspection.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspectionBase.java @@ -35,13 +35,14 @@ import com.intellij.codeInspection.ex.EntryPointsManager; import com.intellij.codeInspection.ex.GlobalInspectionContextBase; import com.intellij.codeInspection.ex.JobDescriptor; import com.intellij.codeInspection.reference.*; +import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspectionBase; import com.intellij.codeInspection.util.RefFilter; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.ExtensionPoint; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.project.Project; -import com.intellij.openapi.project.ProjectManager; import com.intellij.openapi.util.InvalidDataException; import com.intellij.openapi.util.WriteExternalException; import com.intellij.psi.*; @@ -55,15 +56,11 @@ import org.jdom.Element; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.TestOnly; -import javax.swing.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.util.*; -import java.util.List; -public class UnusedDeclarationInspection extends GlobalInspectionTool { +public class UnusedDeclarationInspectionBase extends GlobalInspectionTool { public boolean ADD_MAINS_TO_ENTRIES = true; public boolean ADD_APPLET_TO_ENTRIES = true; @@ -73,14 +70,21 @@ public class UnusedDeclarationInspection extends GlobalInspectionTool { private Set myProcessedSuspicious = null; private int myPhase; public static final String DISPLAY_NAME = InspectionsBundle.message("inspection.dead.code.display.name"); - @NonNls public static final String SHORT_NAME = "UnusedDeclaration"; - @NonNls private static final String ALTERNATIVE_ID = "unused"; + @NonNls public static final String SHORT_NAME = "unused"; + @NonNls public static final String ALTERNATIVE_ID = "UnusedDeclaration"; public final EntryPoint[] myExtensions; - private static final Logger LOG = Logger.getInstance("#" + UnusedDeclarationInspection.class.getName()); + private static final Logger LOG = Logger.getInstance("#" + UnusedDeclarationInspectionBase.class.getName()); private GlobalInspectionContext myContext; + protected UnusedSymbolLocalInspectionBase myLocalInspectionBase = createUnusedSymbolLocalInspection(); + private boolean myEnabledInEditor = !ApplicationManager.getApplication().isUnitTestMode(); - public UnusedDeclarationInspection() { + public UnusedDeclarationInspectionBase(boolean enabledInEditor) { + this(); + myEnabledInEditor = enabledInEditor; + } + + public UnusedDeclarationInspectionBase() { ExtensionPoint point = Extensions.getRootArea().getExtensionPoint(ToolExtensionPoints.DEAD_CODE_TOOL); final EntryPoint[] deadCodeAddins = new EntryPoint[point.getExtensions().length]; EntryPoint[] extensions = point.getExtensions(); @@ -102,117 +106,14 @@ public class UnusedDeclarationInspection extends GlobalInspectionTool { myExtensions = deadCodeAddins; } - private GlobalInspectionContext getContext() { + protected UnusedSymbolLocalInspectionBase createUnusedSymbolLocalInspection() { + return new UnusedSymbolLocalInspectionBase(); + } + + protected GlobalInspectionContext getContext() { return myContext; } - private class OptionsPanel extends JPanel { - private final JCheckBox myMainsCheckbox; - private final JCheckBox myAppletToEntries; - private final JCheckBox myServletToEntries; - private final JCheckBox myNonJavaCheckbox; - - private OptionsPanel() { - super(new GridBagLayout()); - GridBagConstraints gc = new GridBagConstraints(); - gc.weightx = 1; - gc.weighty = 0; - gc.insets = new Insets(0, 20, 2, 0); - gc.fill = GridBagConstraints.HORIZONTAL; - gc.anchor = GridBagConstraints.NORTHWEST; - - myMainsCheckbox = new JCheckBox(InspectionsBundle.message("inspection.dead.code.option")); - myMainsCheckbox.setSelected(ADD_MAINS_TO_ENTRIES); - myMainsCheckbox.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - ADD_MAINS_TO_ENTRIES = myMainsCheckbox.isSelected(); - } - }); - - gc.gridy = 0; - add(myMainsCheckbox, gc); - - myAppletToEntries = new JCheckBox(InspectionsBundle.message("inspection.dead.code.option3")); - myAppletToEntries.setSelected(ADD_APPLET_TO_ENTRIES); - myAppletToEntries.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - ADD_APPLET_TO_ENTRIES = myAppletToEntries.isSelected(); - } - }); - gc.gridy++; - add(myAppletToEntries, gc); - - myServletToEntries = new JCheckBox(InspectionsBundle.message("inspection.dead.code.option4")); - myServletToEntries.setSelected(ADD_SERVLET_TO_ENTRIES); - myServletToEntries.addActionListener(new ActionListener(){ - @Override - public void actionPerformed(ActionEvent e) { - ADD_SERVLET_TO_ENTRIES = myServletToEntries.isSelected(); - } - }); - gc.gridy++; - add(myServletToEntries, gc); - - for (final EntryPoint extension : myExtensions) { - if (extension.showUI()) { - final JCheckBox extCheckbox = new JCheckBox(extension.getDisplayName()); - extCheckbox.setSelected(extension.isSelected()); - extCheckbox.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - extension.setSelected(extCheckbox.isSelected()); - } - }); - gc.gridy++; - add(extCheckbox, gc); - } - } - - myNonJavaCheckbox = - new JCheckBox(InspectionsBundle.message("inspection.dead.code.option5")); - myNonJavaCheckbox.setSelected(ADD_NONJAVA_TO_ENTRIES); - myNonJavaCheckbox.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - ADD_NONJAVA_TO_ENTRIES = myNonJavaCheckbox.isSelected(); - } - }); - - gc.gridy++; - add(myNonJavaCheckbox, gc); - - Project project = guessProject(); - JButton configureAnnotations = EntryPointsManager.getInstance(project).createConfigureAnnotationsBtn(); - gc.fill = GridBagConstraints.NONE; - gc.gridy++; - gc.insets.top = 10; - gc.weighty = 1; - - add(configureAnnotations, gc); - } - - } - - private Project guessProject() { - Project project = myContext == null ? null : myContext.getProject(); - - if (project == null) { - Project[] openProjects = ProjectManager.getInstance().getOpenProjects(); - project = openProjects.length == 0 ? ProjectManager.getInstance().getDefaultProject() : openProjects[0]; - } - return project; - } - - @Override - public JComponent createOptionsPanel() { - final JPanel scrollPane = new JPanel(new BorderLayout()); - scrollPane.add(new JLabel("Entry points:"), BorderLayout.NORTH); - scrollPane.add(new OptionsPanel(), BorderLayout.CENTER); - return scrollPane; - } - private boolean isAddMainsEnabled() { return ADD_MAINS_TO_ENTRIES; } @@ -250,6 +151,7 @@ public class UnusedDeclarationInspection extends GlobalInspectionTool { @Override public void readSettings(@NotNull Element node) throws InvalidDataException { super.readSettings(node); + myLocalInspectionBase.readSettings(node); for (EntryPoint extension : myExtensions) { extension.readExternal(node); } @@ -258,6 +160,7 @@ public class UnusedDeclarationInspection extends GlobalInspectionTool { @Override public void writeSettings(@NotNull Element node) throws WriteExternalException { super.writeSettings(node); + myLocalInspectionBase.writeSettings(node); for (EntryPoint extension : myExtensions) { extension.writeExternal(node); } @@ -363,7 +266,7 @@ public class UnusedDeclarationInspection extends GlobalInspectionTool { if (file == null) return; final boolean isSuppressed = refElement.isSuppressed(getShortName(), ALTERNATIVE_ID); - if (isSuppressed || !((GlobalInspectionContextBase)globalContext).isToCheckFile(file, UnusedDeclarationInspection.this)) { + if (isSuppressed || !((GlobalInspectionContextBase)globalContext).isToCheckFile(file, UnusedDeclarationInspectionBase.this)) { if (isSuppressed || !scope.contains(file)) { getEntryPointsManager().addEntryPoint(refElement, false); } @@ -498,9 +401,17 @@ public class UnusedDeclarationInspection extends GlobalInspectionTool { return false; } + public boolean isGlobalEnabledInEditor() { + return myEnabledInEditor; + } + + @TestOnly + public void setEnabledInEditor(boolean enabledInEditor) { + myEnabledInEditor = enabledInEditor; + } private static class StrictUnreferencedFilter extends UnreferencedFilter { - private StrictUnreferencedFilter(@NotNull UnusedDeclarationInspection tool, @NotNull GlobalInspectionContext context) { + private StrictUnreferencedFilter(@NotNull UnusedDeclarationInspectionBase tool, @NotNull GlobalInspectionContext context) { super(tool, context); } @@ -652,7 +563,7 @@ public class UnusedDeclarationInspection extends GlobalInspectionTool { public void visitElement(@NotNull RefEntity refEntity) { if (refEntity instanceof RefJavaElement) { final RefJavaElementImpl refElement = (RefJavaElementImpl)refEntity; - if (!((GlobalInspectionContextBase)context).isToCheckMember(refElement, UnusedDeclarationInspection.this)) return; + if (!((GlobalInspectionContextBase)context).isToCheckMember(refElement, UnusedDeclarationInspectionBase.this)) return; refElement.setReachable(false); } } diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspectionMerger.java b/java/java-analysis-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspectionMerger.java new file mode 100644 index 000000000000..adca66bc6780 --- /dev/null +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspectionMerger.java @@ -0,0 +1,94 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInspection.deadCode; + +import com.intellij.codeInspection.ex.InspectionElementsMerger; +import com.intellij.codeInspection.ex.InspectionProfileImpl; +import com.intellij.codeInspection.ex.ToolsImpl; +import com.intellij.lang.annotation.HighlightSeverity; +import org.jdom.Element; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +public class UnusedDeclarationInspectionMerger extends InspectionElementsMerger { + @Override + public String getNewToolName() { + return UnusedDeclarationInspectionBase.SHORT_NAME; + } + + @Override + public Element merge(Map elements) { + final Element unusedSymbolElement = elements.get("UNUSED_SYMBOL"); + final Element unusedDeclarationElement = elements.get("UnusedDeclaration"); + if (unusedDeclarationElement != null || unusedSymbolElement != null) { + final Element toolElement = new Element(InspectionProfileImpl.INSPECTION_TOOL_TAG); + final LinkedHashMap scopes = new LinkedHashMap(); + final List content = new ArrayList(); + boolean enabled = cloneContent(unusedDeclarationElement, content, scopes); + enabled |= cloneContent(unusedSymbolElement, content, scopes); + + toolElement.setAttribute(InspectionProfileImpl.CLASS_TAG, getNewToolName()); + toolElement.setAttribute(ToolsImpl.ENABLED_ATTRIBUTE, String.valueOf(enabled)); + + String level = getLevel(unusedSymbolElement); + if (level == null) { + level = getLevel(unusedDeclarationElement); + } + + if (level != null) { + toolElement.setAttribute(ToolsImpl.LEVEL_ATTRIBUTE, level); + } + + for (Element scopeEl : scopes.values()) { + toolElement.addContent(scopeEl); + } + for (Element element : content) { + toolElement.addContent(element); + } + return toolElement; + } + return null; + } + + private static String getLevel(Element element) { + return element != null ? element.getAttributeValue(ToolsImpl.LEVEL_ATTRIBUTE) : HighlightSeverity.WARNING.getName(); + } + + protected static boolean cloneContent(Element sourceElement, List elements, Map scopes) { + if (sourceElement != null) { + for (Element element : sourceElement.getChildren()) { + if ("scope".equals(element.getName())) { + String scopeName = element.getAttributeValue("name"); + if (scopes.containsKey(scopeName)) { + Element scopeElement = scopes.get(scopeName); + for (Element scopeEl : element.getChildren()) { + scopeElement.addContent(scopeEl.clone()); + } + } else { + scopes.put(scopeName, element.clone()); + } + continue; + } + elements.add(element.clone()); + } + return Boolean.parseBoolean(sourceElement.getAttributeValue("enabled")); + } + return false; + } +} diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/reference/RefJavaManagerImpl.java b/java/java-analysis-impl/src/com/intellij/codeInspection/reference/RefJavaManagerImpl.java index 4d6507823e17..b03f804fdd45 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/reference/RefJavaManagerImpl.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/reference/RefJavaManagerImpl.java @@ -19,7 +19,7 @@ import com.intellij.codeInspection.BatchSuppressManager; import com.intellij.codeInspection.InspectionProfileEntry; import com.intellij.codeInspection.InspectionsBundle; import com.intellij.codeInspection.SuppressionUtil; -import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; +import com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionBase; import com.intellij.codeInspection.ex.*; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; @@ -102,30 +102,30 @@ public class RefJavaManagerImpl extends RefJavaManager { public boolean isEntryPoint(final RefElement element) { - UnusedDeclarationInspection tool = getDeadCodeTool(element); + UnusedDeclarationInspectionBase tool = getDeadCodeTool(element); return tool != null && tool.isEntryPoint(element); } @Nullable - private UnusedDeclarationInspection getDeadCodeTool(RefElement element) { + private UnusedDeclarationInspectionBase getDeadCodeTool(RefElement element) { PsiFile file = ((RefElementImpl)element).getContainingFile(); if (file == null) return null; return getDeadCodeTool(file); } - private static final UserDataCache, PsiFile, RefManagerImpl> DEAD_CODE_TOOL = new UserDataCache, PsiFile, RefManagerImpl>("DEAD_CODE_TOOL") { + private static final UserDataCache, PsiFile, RefManagerImpl> DEAD_CODE_TOOL = new UserDataCache, PsiFile, RefManagerImpl>("DEAD_CODE_TOOL") { @Override - protected Ref compute(PsiFile file, RefManagerImpl refManager) { - Tools tools = ((GlobalInspectionContextBase)refManager.getContext()).getTools().get(UnusedDeclarationInspection.SHORT_NAME); + protected Ref compute(PsiFile file, RefManagerImpl refManager) { + Tools tools = ((GlobalInspectionContextBase)refManager.getContext()).getTools().get(UnusedDeclarationInspectionBase.SHORT_NAME); InspectionToolWrapper toolWrapper = tools == null ? null : tools.getEnabledTool(file); InspectionProfileEntry tool = toolWrapper == null ? null : toolWrapper.getTool(); - return Ref.create(tool instanceof UnusedDeclarationInspection ? (UnusedDeclarationInspection)tool : null); + return Ref.create(tool instanceof UnusedDeclarationInspectionBase ? (UnusedDeclarationInspectionBase)tool : null); } }; @Nullable - private UnusedDeclarationInspection getDeadCodeTool(PsiElement element) { + private UnusedDeclarationInspectionBase getDeadCodeTool(PsiElement element) { PsiFile file = element.getContainingFile(); return file != null ? DEAD_CODE_TOOL.get(file, myRefManager).get() : null; } diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/PostHighlightingPassFactory.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/PostHighlightingPassFactory.java index de13524ce4e5..e471389866b2 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/PostHighlightingPassFactory.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/PostHighlightingPassFactory.java @@ -22,7 +22,7 @@ import com.intellij.codeHighlighting.TextEditorHighlightingPassRegistrar; import com.intellij.codeInsight.daemon.HighlightDisplayKey; import com.intellij.codeInsight.daemon.impl.analysis.HighlightVisitorImpl; import com.intellij.codeInspection.InspectionProfile; -import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; +import com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionBase; import com.intellij.openapi.components.AbstractProjectComponent; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Document; @@ -87,9 +87,9 @@ public class PostHighlightingPassFactory extends AbstractProjectComponent implem @NotNull Document document, Editor editor, @NotNull HighlightInfoProcessor highlightInfoProcessor) { InspectionProfile profile = InspectionProjectProfileManager.getInstance(file.getProject()).getInspectionProfile(); - final UnusedDeclarationInspection myDeadCodeInspection = (UnusedDeclarationInspection)profile.getUnwrappedTool(UnusedDeclarationInspection.SHORT_NAME, file); - HighlightDisplayKey myDeadCodeKey = HighlightDisplayKey.find(UnusedDeclarationInspection.SHORT_NAME); - final boolean myDeadCodeEnabled = profile.isToolEnabled(myDeadCodeKey, file); + final UnusedDeclarationInspectionBase myDeadCodeInspection = (UnusedDeclarationInspectionBase)profile.getUnwrappedTool(UnusedDeclarationInspectionBase.SHORT_NAME, file); + HighlightDisplayKey myDeadCodeKey = HighlightDisplayKey.find(UnusedDeclarationInspectionBase.SHORT_NAME); + final boolean myDeadCodeEnabled = myDeadCodeInspection != null && profile.isToolEnabled(myDeadCodeKey, file) && myDeadCodeInspection.isGlobalEnabledInEditor(); return new PostHighlightingPass(myProject, file, editor, document, highlightInfoProcessor, new Predicate() { @Override diff --git a/java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspection.java b/java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspection.java new file mode 100644 index 000000000000..ecb0a9b5f18f --- /dev/null +++ b/java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspection.java @@ -0,0 +1,146 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInspection.deadCode; + +import com.intellij.codeInspection.GlobalInspectionContext; +import com.intellij.codeInspection.InspectionsBundle; +import com.intellij.codeInspection.ex.EntryPointsManager; +import com.intellij.codeInspection.reference.EntryPoint; +import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection; +import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspectionBase; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.project.ProjectManager; +import com.intellij.ui.components.JBTabbedPane; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class UnusedDeclarationInspection extends UnusedDeclarationInspectionBase { + @Override + protected UnusedSymbolLocalInspectionBase createUnusedSymbolLocalInspection() { + return new UnusedSymbolLocalInspection(); + } + + @Override + public JComponent createOptionsPanel() { + JTabbedPane tabs = new JBTabbedPane(SwingConstants.TOP); + tabs.add("Entry points", new OptionsPanel()); + tabs.add("On the fly editor settings", myLocalInspectionBase.createOptionsPanel()); + return tabs; + } + + private Project guessProject() { + final GlobalInspectionContext context = getContext(); + Project project = context == null ? null : context.getProject(); + + if (project == null) { + Project[] openProjects = ProjectManager.getInstance().getOpenProjects(); + project = openProjects.length == 0 ? ProjectManager.getInstance().getDefaultProject() : openProjects[0]; + } + return project; + } + + private class OptionsPanel extends JPanel { + private final JCheckBox myMainsCheckbox; + private final JCheckBox myAppletToEntries; + private final JCheckBox myServletToEntries; + private final JCheckBox myNonJavaCheckbox; + + private OptionsPanel() { + super(new GridBagLayout()); + GridBagConstraints gc = new GridBagConstraints(); + gc.weightx = 1; + gc.weighty = 0; + gc.insets = new Insets(0, 20, 2, 0); + gc.fill = GridBagConstraints.HORIZONTAL; + gc.anchor = GridBagConstraints.NORTHWEST; + + myMainsCheckbox = new JCheckBox(InspectionsBundle.message("inspection.dead.code.option")); + myMainsCheckbox.setSelected(ADD_MAINS_TO_ENTRIES); + myMainsCheckbox.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + ADD_MAINS_TO_ENTRIES = myMainsCheckbox.isSelected(); + } + }); + + gc.gridy = 0; + add(myMainsCheckbox, gc); + + myAppletToEntries = new JCheckBox(InspectionsBundle.message("inspection.dead.code.option3")); + myAppletToEntries.setSelected(ADD_APPLET_TO_ENTRIES); + myAppletToEntries.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + ADD_APPLET_TO_ENTRIES = myAppletToEntries.isSelected(); + } + }); + gc.gridy++; + add(myAppletToEntries, gc); + + myServletToEntries = new JCheckBox(InspectionsBundle.message("inspection.dead.code.option4")); + myServletToEntries.setSelected(ADD_SERVLET_TO_ENTRIES); + myServletToEntries.addActionListener(new ActionListener(){ + @Override + public void actionPerformed(ActionEvent e) { + ADD_SERVLET_TO_ENTRIES = myServletToEntries.isSelected(); + } + }); + gc.gridy++; + add(myServletToEntries, gc); + + for (final EntryPoint extension : myExtensions) { + if (extension.showUI()) { + final JCheckBox extCheckbox = new JCheckBox(extension.getDisplayName()); + extCheckbox.setSelected(extension.isSelected()); + extCheckbox.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + extension.setSelected(extCheckbox.isSelected()); + } + }); + gc.gridy++; + add(extCheckbox, gc); + } + } + + myNonJavaCheckbox = + new JCheckBox(InspectionsBundle.message("inspection.dead.code.option5")); + myNonJavaCheckbox.setSelected(ADD_NONJAVA_TO_ENTRIES); + myNonJavaCheckbox.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + ADD_NONJAVA_TO_ENTRIES = myNonJavaCheckbox.isSelected(); + } + }); + + gc.gridy++; + add(myNonJavaCheckbox, gc); + + Project project = guessProject(); + JButton configureAnnotations = EntryPointsManager.getInstance(project).createConfigureAnnotationsBtn(); + gc.fill = GridBagConstraints.NONE; + gc.gridy++; + gc.insets.top = 10; + gc.weighty = 1; + + add(configureAnnotations, gc); + } + + } +} diff --git a/java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationPresentation.java b/java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationPresentation.java index 276bb97e2922..cdc8fdd15c7d 100644 --- a/java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationPresentation.java +++ b/java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationPresentation.java @@ -78,7 +78,7 @@ public class UnusedDeclarationPresentation extends DefaultInspectionToolPresenta return myFilter; } private static class WeakUnreferencedFilter extends UnreferencedFilter { - private WeakUnreferencedFilter(@NotNull UnusedDeclarationInspection tool, @NotNull GlobalInspectionContextImpl context) { + private WeakUnreferencedFilter(@NotNull UnusedDeclarationInspectionBase tool, @NotNull GlobalInspectionContextImpl context) { super(tool, context); } @@ -92,8 +92,8 @@ public class UnusedDeclarationPresentation extends DefaultInspectionToolPresenta } @NotNull - private UnusedDeclarationInspection getTool() { - return (UnusedDeclarationInspection)getToolWrapper().getTool(); + private UnusedDeclarationInspectionBase getTool() { + return (UnusedDeclarationInspectionBase)getToolWrapper().getTool(); } diff --git a/java/java-impl/src/com/intellij/codeInspection/unusedSymbol/OptionsPanel.form b/java/java-impl/src/com/intellij/codeInspection/unusedSymbol/OptionsPanel.form index 93a930895c82..008947c0960c 100644 --- a/java/java-impl/src/com/intellij/codeInspection/unusedSymbol/OptionsPanel.form +++ b/java/java-impl/src/com/intellij/codeInspection/unusedSymbol/OptionsPanel.form @@ -1,12 +1,12 @@
- + - + @@ -46,14 +46,6 @@ - - - - - - - - @@ -72,7 +64,7 @@ - + diff --git a/java/java-impl/src/com/intellij/codeInspection/unusedSymbol/UnusedSymbolLocalInspection.java b/java/java-impl/src/com/intellij/codeInspection/unusedSymbol/UnusedSymbolLocalInspection.java index 961427ff372a..f59f912b7d68 100644 --- a/java/java-impl/src/com/intellij/codeInspection/unusedSymbol/UnusedSymbolLocalInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/unusedSymbol/UnusedSymbolLocalInspection.java @@ -17,19 +17,14 @@ package com.intellij.codeInspection.unusedSymbol; import com.intellij.codeInsight.daemon.GroupNames; -import com.intellij.codeInsight.daemon.impl.HighlightInfoType; import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; -import com.intellij.codeInspection.ex.EntryPointsManager; import com.intellij.codeInspection.ex.PairedUnfairLocalInspectionTool; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.project.ProjectUtil; import org.intellij.lang.annotations.Pattern; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; -import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -38,6 +33,14 @@ import java.awt.event.ActionListener; * Date: 17-Feb-2006 */ public class UnusedSymbolLocalInspection extends UnusedSymbolLocalInspectionBase implements PairedUnfairLocalInspectionTool { + + /** + * use {@link com.intellij.codeInspection.deadCode.UnusedDeclarationInspection} instead + */ + @Deprecated + public UnusedSymbolLocalInspection() { + } + @Override @NotNull public String getGroupDisplayName() { @@ -62,12 +65,12 @@ public class UnusedSymbolLocalInspection extends UnusedSymbolLocalInspectionBase @NotNull @NonNls public String getID() { - return HighlightInfoType.UNUSED_SYMBOL_ID; + return "unused"; } @Override public String getAlternativeID() { - return "unused"; + return UnusedDeclarationInspection.ALTERNATIVE_ID; } @Override @@ -88,7 +91,6 @@ public class UnusedSymbolLocalInspection extends UnusedSymbolLocalInspectionBase private JCheckBox myCheckMethodsCheckBox; private JCheckBox myCheckParametersCheckBox; private JCheckBox myReportUnusedParametersInPublics; - private JPanel myAnnos; private JPanel myPanel; public OptionsPanel() { @@ -120,10 +122,6 @@ public class UnusedSymbolLocalInspection extends UnusedSymbolLocalInspectionBase myCheckClassesCheckBox.addActionListener(listener); myCheckParametersCheckBox.addActionListener(listener); myReportUnusedParametersInPublics.addActionListener(listener); - Project project = ProjectUtil.guessCurrentProject(myPanel); - myAnnos.add(EntryPointsManager.getInstance(project).createConfigureAnnotationsBtn(), - new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, - new Insets(10, 0, 0, 0), 0, 0)); } public JComponent getPanel() { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/suppress15Inspections/after2.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/suppress15Inspections/after2.java index f2a1850d8a71..b73a263add5e 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/suppress15Inspections/after2.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/suppress15Inspections/after2.java @@ -1,6 +1,6 @@ // "Suppress for statement" "true" public class Test { public void run() { - @SuppressWarnings("UnusedDeclaration") int i; + @SuppressWarnings("unused") int i; } } \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/suppress15Inspections/after3.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/suppress15Inspections/after3.java index 127d57d58bf6..b90993f9168c 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/suppress15Inspections/after3.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/suppress15Inspections/after3.java @@ -1,7 +1,7 @@ // "Suppress for statement" "true" public class Test { public void run() { - //noinspection id,UnusedDeclaration + //noinspection id,unused int i; } } \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/suppressNonInspections/after1.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/suppressNonInspections/after1.java index 7b83a8c780b8..f5edd1995d42 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/suppressNonInspections/after1.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/suppressNonInspections/after1.java @@ -1,7 +1,7 @@ // "Suppress for statement" "true" class a { public void run() { -//noinspection UnusedDeclaration +//noinspection unused int i = 0; } } \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/suppressNonInspections/after2.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/suppressNonInspections/after2.java index 70a41fa4e77e..d1203fecd027 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/suppressNonInspections/after2.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/suppressNonInspections/after2.java @@ -1,6 +1,6 @@ // "Suppress for method" "true" class a { -/** @noinspection UnusedDeclaration*/ +/** @noinspection unused*/ private void run() { } } \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/AdvHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/AdvHighlightingTest.java index 154740e6bea2..d38fd2af4dff 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/AdvHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/AdvHighlightingTest.java @@ -18,9 +18,7 @@ package com.intellij.codeInsight.daemon; import com.intellij.analysis.PackagesScopesProvider; import com.intellij.application.options.colors.ScopeAttributesUtil; import com.intellij.codeInsight.daemon.impl.HighlightInfo; -import com.intellij.codeInspection.LocalInspectionTool; -import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; -import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection; +import com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionBase; import com.intellij.openapi.application.ex.PathManagerEx; import com.intellij.openapi.editor.colors.EditorColorsManager; import com.intellij.openapi.editor.colors.EditorColorsScheme; @@ -328,14 +326,8 @@ public class AdvHighlightingTest extends DaemonAnalyzerTestCase { doTest(BASE_PATH + "/publicClassInRightFile/x/Y.java", BASE_PATH + "/publicClassInRightFile", false, false); } - @Override - protected LocalInspectionTool[] configureLocalInspectionTools() { - boolean needUnusedSymbol = getTestName(true).toLowerCase().contains("unused"); - return needUnusedSymbol ? new LocalInspectionTool[]{new UnusedSymbolLocalInspection()} : new LocalInspectionTool[0]; - } - public void testUnusedPublicMethodReferencedViaSubclass() throws Exception { - UnusedDeclarationInspection deadCodeInspection = new UnusedDeclarationInspection(); + UnusedDeclarationInspectionBase deadCodeInspection = new UnusedDeclarationInspectionBase(true); enableInspectionTool(deadCodeInspection); //String ref = getTestDataPath() + BASE_PATH + "/unusedPublicMethodRefViaSubclass/x/X.java"; allowTreeAccessForAllFiles(); diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/AmbiguousMethodCallTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/AmbiguousMethodCallTest.java index f528f8fd8bc6..1635df128db6 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/AmbiguousMethodCallTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/AmbiguousMethodCallTest.java @@ -17,9 +17,9 @@ package com.intellij.codeInsight.daemon; import com.intellij.codeInspection.LocalInspectionTool; import com.intellij.codeInspection.compiler.JavacQuirksInspection; +import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; import com.intellij.codeInspection.redundantCast.RedundantCastInspection; import com.intellij.codeInspection.uncheckedWarnings.UncheckedWarningLocalInspection; -import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection; import com.intellij.pom.java.LanguageLevel; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -31,6 +31,12 @@ import org.jetbrains.annotations.NotNull; public class AmbiguousMethodCallTest extends LightDaemonAnalyzerTestCase { @NonNls static final String BASE_PATH = "/codeInsight/daemonCodeAnalyzer/ambiguousCalls"; + @Override + protected void setUp() throws Exception { + super.setUp(); + enableInspectionTool(new UnusedDeclarationInspection()); + } + private void doTest(boolean checkWarnings, boolean checkInfos) throws Exception { doTest(BASE_PATH + "/" + getTestName(false) + ".java", checkWarnings, checkInfos); } @@ -39,7 +45,6 @@ public class AmbiguousMethodCallTest extends LightDaemonAnalyzerTestCase { @Override protected LocalInspectionTool[] configureLocalInspectionTools() { return new LocalInspectionTool[]{ - new UnusedSymbolLocalInspection(), new UncheckedWarningLocalInspection(), new JavacQuirksInspection(), new RedundantCastInspection() diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java index 3964bad42031..eebb36e0ed09 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java @@ -16,9 +16,9 @@ package com.intellij.codeInsight.daemon; import com.intellij.codeInspection.LocalInspectionTool; +import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; import com.intellij.codeInspection.uncheckedWarnings.UncheckedWarningLocalInspection; import com.intellij.codeInspection.unusedImport.UnusedImportLocalInspection; -import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection; import com.intellij.openapi.projectRoots.JavaSdkVersion; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.roots.LanguageLevelProjectExtension; @@ -32,10 +32,16 @@ import org.jetbrains.annotations.NotNull; public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase { @NonNls private static final String BASE_PATH = "/codeInsight/daemonCodeAnalyzer/genericsHighlighting"; + @Override + protected void setUp() throws Exception { + super.setUp(); + enableInspectionTool(new UnusedDeclarationInspection()); + } + @NotNull @Override protected LocalInspectionTool[] configureLocalInspectionTools() { - return new LocalInspectionTool[]{new UncheckedWarningLocalInspection(), new UnusedSymbolLocalInspection(), new UnusedImportLocalInspection()}; + return new LocalInspectionTool[]{new UncheckedWarningLocalInspection(), new UnusedImportLocalInspection()}; } @Override diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/HighlightSeverityTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/HighlightSeverityTest.java index 898889b34b03..45f31f1587a5 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/HighlightSeverityTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/HighlightSeverityTest.java @@ -16,8 +16,8 @@ package com.intellij.codeInsight.daemon; import com.intellij.codeHighlighting.HighlightDisplayLevel; -import com.intellij.codeInspection.ex.LocalInspectionToolWrapper; -import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection; +import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; +import com.intellij.codeInspection.ex.GlobalInspectionToolWrapper; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -26,7 +26,7 @@ public class HighlightSeverityTest extends LightDaemonAnalyzerTestCase { public void testErrorLikeUnusedSymbol() throws Exception { - enableInspectionTool(new LocalInspectionToolWrapper(new UnusedSymbolLocalInspection()) { + enableInspectionTool(new GlobalInspectionToolWrapper(new UnusedDeclarationInspection()) { @NotNull @Override public HighlightDisplayLevel getDefaultLevel() { diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/HighlightStressTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/HighlightStressTest.java index c593d04464f0..0c14e4acdf2b 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/HighlightStressTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/HighlightStressTest.java @@ -24,11 +24,11 @@ package com.intellij.codeInsight.daemon; import com.intellij.codeInsight.daemon.impl.HighlightInfo; import com.intellij.codeInspection.LocalInspectionTool; +import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; import com.intellij.codeInspection.ex.InspectionToolRegistrar; import com.intellij.codeInspection.ex.InspectionToolWrapper; import com.intellij.codeInspection.ex.LocalInspectionToolWrapper; import com.intellij.codeInspection.unusedImport.UnusedImportLocalInspection; -import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection; import com.intellij.lang.annotation.HighlightSeverity; import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx; @@ -47,11 +47,19 @@ import java.util.*; @SkipSlowTestLocally public class HighlightStressTest extends LightDaemonAnalyzerTestCase { + @Override + protected void setUp() throws Exception { + super.setUp(); + if ("RandomEditingForUnused".equals(getTestName(false))) { + enableInspectionTool(new UnusedDeclarationInspection()); + } + } + @NotNull @Override protected LocalInspectionTool[] configureLocalInspectionTools() { if ("RandomEditingForUnused".equals(getTestName(false))) { - return new LocalInspectionTool[]{new UnusedSymbolLocalInspection(), new UnusedImportLocalInspection(),}; + return new LocalInspectionTool[]{new UnusedImportLocalInspection(),}; } List all = InspectionToolRegistrar.getInstance().createTools(); List locals = new ArrayList(); diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk6Test.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk6Test.java index fa4334a591ee..0ed6303bfdad 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk6Test.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk6Test.java @@ -17,9 +17,9 @@ package com.intellij.codeInsight.daemon; import com.intellij.codeInspection.LocalInspectionTool; import com.intellij.codeInspection.compiler.JavacQuirksInspection; +import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; import com.intellij.codeInspection.redundantCast.RedundantCastInspection; import com.intellij.codeInspection.uncheckedWarnings.UncheckedWarningLocalInspection; -import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection; import com.intellij.openapi.projectRoots.JavaSdkVersion; import com.intellij.pom.java.LanguageLevel; import com.intellij.testFramework.IdeaTestUtil; @@ -33,6 +33,12 @@ import org.jetbrains.annotations.NotNull; public class LightAdvHighlightingJdk6Test extends LightDaemonAnalyzerTestCase { @NonNls static final String BASE_PATH = "/codeInsight/daemonCodeAnalyzer/advHighlighting6"; + @Override + protected void setUp() throws Exception { + super.setUp(); + enableInspectionTool(new UnusedDeclarationInspection()); + } + private void doTest(boolean checkWarnings, boolean checkInfos, Class... classes) { setLanguageLevel(LanguageLevel.JDK_1_6); IdeaTestUtil.setTestVersion(JavaSdkVersion.JDK_1_6, getModule(), myTestRootDisposable); @@ -44,7 +50,6 @@ public class LightAdvHighlightingJdk6Test extends LightDaemonAnalyzerTestCase { @Override protected LocalInspectionTool[] configureLocalInspectionTools() { return new LocalInspectionTool[]{ - new UnusedSymbolLocalInspection(), new UncheckedWarningLocalInspection(), new JavacQuirksInspection(), new RedundantCastInspection() diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk7Test.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk7Test.java index c24366b3d513..e7e236999426 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk7Test.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk7Test.java @@ -17,15 +17,16 @@ package com.intellij.codeInsight.daemon; import com.intellij.ToolExtensionPoints; import com.intellij.codeInsight.daemon.impl.HighlightInfo; +import com.intellij.codeInspection.InspectionProfileEntry; import com.intellij.codeInspection.LocalInspectionTool; import com.intellij.codeInspection.compiler.JavacQuirksInspection; import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; +import com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionBase; import com.intellij.codeInspection.defUse.DefUseInspection; import com.intellij.codeInspection.redundantCast.RedundantCastInspection; import com.intellij.codeInspection.reference.EntryPoint; import com.intellij.codeInspection.reference.RefElement; import com.intellij.codeInspection.uncheckedWarnings.UncheckedWarningLocalInspection; -import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection; import com.intellij.lang.annotation.HighlightSeverity; import com.intellij.openapi.extensions.ExtensionPoint; import com.intellij.openapi.extensions.Extensions; @@ -44,8 +45,13 @@ import java.util.List; */ public class LightAdvHighlightingJdk7Test extends LightDaemonAnalyzerTestCase { private static final String BASE_PATH = "/codeInsight/daemonCodeAnalyzer/advHighlighting7"; + @Override + protected void setUp() throws Exception { + super.setUp(); + enableInspectionTool(new UnusedDeclarationInspection()); + } - private void doTest(boolean checkWarnings, boolean checkInfos, Class... classes) { + private void doTest(boolean checkWarnings, boolean checkInfos, InspectionProfileEntry... classes) { setLanguageLevel(LanguageLevel.JDK_1_7); IdeaTestUtil.setTestVersion(JavaSdkVersion.JDK_1_7, getModule(), myTestRootDisposable); enableInspectionTools(classes); @@ -61,7 +67,6 @@ public class LightAdvHighlightingJdk7Test extends LightDaemonAnalyzerTestCase { @Override protected LocalInspectionTool[] configureLocalInspectionTools() { return new LocalInspectionTool[]{ - new UnusedSymbolLocalInspection(), new UncheckedWarningLocalInspection(), new JavacQuirksInspection(), new RedundantCastInspection() @@ -116,7 +121,7 @@ public class LightAdvHighlightingJdk7Test extends LightDaemonAnalyzerTestCase { @Override public String[] getIgnoreAnnotations() { return new String[]{"MyAnno"}; } }; - UnusedDeclarationInspection deadCodeInspection = new UnusedDeclarationInspection(); + UnusedDeclarationInspectionBase deadCodeInspection = new UnusedDeclarationInspectionBase(true); enableInspectionTool(deadCodeInspection); doTest(true, false); @@ -138,7 +143,7 @@ public class LightAdvHighlightingJdk7Test extends LightDaemonAnalyzerTestCase { public void testNumericLiterals() { doTest(false, false); } public void testMultiCatch() { doTest(false, false); } public void testTryWithResources() { doTest(false, false); } - public void testTryWithResourcesWarn() { doTest(true, false, DefUseInspection.class); } + public void testTryWithResourcesWarn() { doTest(true, false, new DefUseInspection()); } public void testSafeVarargsApplicability() { doTest(true, false); } public void testUncheckedGenericsArrayCreation() { doTest(true, false); } public void testGenericsArrayCreation() { doTest(false, false); } @@ -146,8 +151,8 @@ public class LightAdvHighlightingJdk7Test extends LightDaemonAnalyzerTestCase { public void testImprovedCatchAnalysis() { doTest(true, false); } public void testPolymorphicTypeCast() { doTest(true, false); } public void testTypeCastInInstanceof() { doTest(true, false); } - public void testErasureClashConfusion() { doTest(true, false, UnusedDeclarationInspection.class); } - public void testUnused() { doTest(true, false, UnusedDeclarationInspection.class); } + public void testErasureClashConfusion() { doTest(true, false, new UnusedDeclarationInspectionBase(true)); } + public void testUnused() { doTest(true, false, new UnusedDeclarationInspectionBase(true)); } public void testSuperBound() { doTest(false, false); } public void testExtendsBound() { doTest(false, false); } public void testIDEA84533() { doTest(false, false); } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingTest.java index 5617b002158d..5d26c0e46e6d 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingTest.java @@ -21,6 +21,7 @@ import com.intellij.codeInsight.daemon.impl.HighlightInfo; import com.intellij.codeInspection.LocalInspectionTool; import com.intellij.codeInspection.accessStaticViaInstance.AccessStaticViaInstance; import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; +import com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionBase; import com.intellij.codeInspection.deprecation.DeprecationInspection; import com.intellij.codeInspection.javaDoc.JavaDocLocalInspection; import com.intellij.codeInspection.reference.EntryPoint; @@ -29,7 +30,7 @@ import com.intellij.codeInspection.sillyAssignment.SillyAssignmentInspection; import com.intellij.codeInspection.uncheckedWarnings.UncheckedWarningLocalInspection; import com.intellij.codeInspection.unneededThrows.RedundantThrowsDeclaration; import com.intellij.codeInspection.unusedImport.UnusedImportLocalInspection; -import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection; +import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspectionBase; import com.intellij.lang.Language; import com.intellij.lang.LanguageAnnotators; import com.intellij.lang.annotation.Annotation; @@ -67,8 +68,7 @@ import java.util.List; */ public class LightAdvHighlightingTest extends LightDaemonAnalyzerTestCase { @NonNls static final String BASE_PATH = "/codeInsight/daemonCodeAnalyzer/advHighlighting"; - - private UnusedSymbolLocalInspection myUnusedSymbolLocalInspection; + private UnusedDeclarationInspectionBase myUnusedDeclarationInspection; private void doTest(boolean checkWarnings, boolean checkInfos) { doTest(BASE_PATH + "/" + getTestName(false) + ".java", checkWarnings, checkInfos); @@ -77,6 +77,8 @@ public class LightAdvHighlightingTest extends LightDaemonAnalyzerTestCase { @Override protected void setUp() throws Exception { super.setUp(); + myUnusedDeclarationInspection = new UnusedDeclarationInspection(); + enableInspectionTool(myUnusedDeclarationInspection); setLanguageLevel(LanguageLevel.JDK_1_4); } @@ -88,7 +90,6 @@ public class LightAdvHighlightingTest extends LightDaemonAnalyzerTestCase { new AccessStaticViaInstance(), new DeprecationInspection(), new RedundantThrowsDeclaration(), - myUnusedSymbolLocalInspection = new UnusedSymbolLocalInspection(), new UnusedImportLocalInspection(), new UncheckedWarningLocalInspection() }; @@ -149,7 +150,7 @@ public class LightAdvHighlightingTest extends LightDaemonAnalyzerTestCase { public void testCatchType() { doTest(false, false); } public void testMustBeThrowable() { doTest(false, false); } public void testUnhandledMessingWithFinally() { doTest(false, false); } - public void testSerializableStuff() { enableInspectionTool(new UnusedDeclarationInspection()); doTest(true, false); } + public void testSerializableStuff() { doTest(true, false); } public void testDeprecated() { doTest(true, false); } public void testJavadoc() { enableInspectionTool(new JavaDocLocalInspection()); doTest(true, false); } public void testExpressionsInSwitch () { doTest(false, false); } @@ -214,14 +215,25 @@ public class LightAdvHighlightingTest extends LightDaemonAnalyzerTestCase { public void testInnerClassesShadowing() { doTest(false, false); } public void testUnusedParamsOfPublicMethodDisabled() { - myUnusedSymbolLocalInspection.REPORT_PARAMETER_FOR_PUBLIC_METHODS = false; - doTest(true, false); + final UnusedSymbolLocalInspectionBase localInspectionTool = myUnusedDeclarationInspection.getSharedLocalInspectionTool(); + boolean oldVal = localInspectionTool.REPORT_PARAMETER_FOR_PUBLIC_METHODS; + try { + localInspectionTool.REPORT_PARAMETER_FOR_PUBLIC_METHODS = false; + doTest(true, false); + } + finally { + localInspectionTool.REPORT_PARAMETER_FOR_PUBLIC_METHODS = oldVal; + } } public void testUnusedNonPrivateMembers() { - UnusedDeclarationInspection deadCodeInspection = new UnusedDeclarationInspection(); - enableInspectionTool(deadCodeInspection); - doTest(true, false); + try { + myUnusedDeclarationInspection.setEnabledInEditor(true); + doTest(true, false); + } + finally { + myUnusedDeclarationInspection.setEnabledInEditor(false); + } } public void testUnusedNonPrivateMembers2() { @@ -261,39 +273,41 @@ public class LightAdvHighlightingTest extends LightDaemonAnalyzerTestCase { point.registerExtension(extension); try { - UnusedDeclarationInspection deadCodeInspection = new UnusedDeclarationInspection(); - enableInspectionTool(deadCodeInspection); - + myUnusedDeclarationInspection = new UnusedDeclarationInspectionBase(true); doTest(true, false); } finally { point.unregisterExtension(extension); + myUnusedDeclarationInspection = new UnusedDeclarationInspectionBase(); } } public void testUnusedNonPrivateMembersReferencedFromText() { - UnusedDeclarationInspection deadCodeInspection = new UnusedDeclarationInspection(); - enableInspectionTool(deadCodeInspection); - - doTest(true, false); - WriteCommandAction.runWriteCommandAction(null, new Runnable() { - @Override - public void run() { - PsiDirectory directory = myFile.getParent(); - assertNotNull(myFile.toString(), directory); - PsiFile txt = directory.createFile("x.txt"); - VirtualFile vFile = txt.getVirtualFile(); - assertNotNull(txt.toString(), vFile); - try { - VfsUtil.saveText(vFile, "XXX"); + try { + myUnusedDeclarationInspection.setEnabledInEditor(true); + doTest(true, false); + WriteCommandAction.runWriteCommandAction(null, new Runnable() { + @Override + public void run() { + PsiDirectory directory = myFile.getParent(); + assertNotNull(myFile.toString(), directory); + PsiFile txt = directory.createFile("x.txt"); + VirtualFile vFile = txt.getVirtualFile(); + assertNotNull(txt.toString(), vFile); + try { + VfsUtil.saveText(vFile, "XXX"); + } + catch (IOException e) { + throw new RuntimeException(e); + } } - catch (IOException e) { - throw new RuntimeException(e); - } - } - }); + }); - List infos = doHighlighting(HighlightSeverity.WARNING); - assertEmpty(infos); + List infos = doHighlighting(HighlightSeverity.WARNING); + assertEmpty(infos); + } + finally { + myUnusedDeclarationInspection.setEnabledInEditor(false); + } } public void testNamesHighlighting() { diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/SuppressWarningsTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/SuppressWarningsTest.java index 6e68611e77ff..135ff43ce9b9 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/SuppressWarningsTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/SuppressWarningsTest.java @@ -20,10 +20,8 @@ */ package com.intellij.codeInsight.daemon; -import com.intellij.codeInspection.LocalInspectionTool; -import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection; +import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; public class SuppressWarningsTest extends LightDaemonAnalyzerTestCase { @NonNls private static final String BASE_PATH = "/codeInsight/daemonCodeAnalyzer/advHighlighting"; @@ -32,10 +30,10 @@ public class SuppressWarningsTest extends LightDaemonAnalyzerTestCase { doTest(BASE_PATH + "/" + getTestName(false) + ".java", checkWarnings, false); } - @NotNull @Override - protected LocalInspectionTool[] configureLocalInspectionTools() { - return new LocalInspectionTool[]{new UnusedSymbolLocalInspection()}; + protected void setUp() throws Exception { + super.setUp(); + enableInspectionTool(new UnusedDeclarationInspection()); } public void testSuppressed() throws Exception { diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/UnusedSymbolLocalTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/UnusedSymbolLocalTest.java index 2652f737c190..9fa7c048766b 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/UnusedSymbolLocalTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/UnusedSymbolLocalTest.java @@ -16,8 +16,7 @@ package com.intellij.codeInsight.daemon; import com.intellij.codeInsight.daemon.impl.HighlightInfo; -import com.intellij.codeInspection.LocalInspectionTool; -import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection; +import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; import com.intellij.lang.annotation.HighlightSeverity; import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.editor.Document; @@ -29,8 +28,9 @@ public class UnusedSymbolLocalTest extends DaemonAnalyzerTestCase { private static final String BASE_PATH = "/codeInsight/daemonCodeAnalyzer/unusedDecls"; @Override - protected LocalInspectionTool[] configureLocalInspectionTools() { - return new LocalInspectionTool[]{new UnusedSymbolLocalInspection()}; + protected void setUp() throws Exception { + super.setUp(); + enableInspectionTool(new UnusedDeclarationInspection()); } public void testInnerClass() throws Exception { doTest(); } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/FunctionalExpressionIncompleteHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/FunctionalExpressionIncompleteHighlightingTest.java index 5e34b963e321..66234ca38ca0 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/FunctionalExpressionIncompleteHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/FunctionalExpressionIncompleteHighlightingTest.java @@ -16,22 +16,18 @@ package com.intellij.codeInsight.daemon.lambda; import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase; -import com.intellij.codeInspection.LocalInspectionTool; -import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection; +import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.testFramework.IdeaTestUtil; import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; public class FunctionalExpressionIncompleteHighlightingTest extends LightDaemonAnalyzerTestCase { @NonNls static final String BASE_PATH = "/codeInsight/daemonCodeAnalyzer/lambda/incomplete"; - @NotNull @Override - protected LocalInspectionTool[] configureLocalInspectionTools() { - return new LocalInspectionTool[]{ - new UnusedSymbolLocalInspection(), - }; + protected void setUp() throws Exception { + super.setUp(); + enableInspectionTool(new UnusedDeclarationInspection()); } public void testMissedFunctionalInterfaceMethodReturnType() throws Exception { diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GenericsHighlighting8Test.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GenericsHighlighting8Test.java index fb5046f194e9..3e4e6b55f91a 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GenericsHighlighting8Test.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GenericsHighlighting8Test.java @@ -17,9 +17,9 @@ package com.intellij.codeInsight.daemon.lambda; import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase; import com.intellij.codeInspection.LocalInspectionTool; +import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; import com.intellij.codeInspection.uncheckedWarnings.UncheckedWarningLocalInspection; import com.intellij.codeInspection.unusedImport.UnusedImportLocalInspection; -import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection; import com.intellij.openapi.projectRoots.JavaSdkVersion; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.roots.LanguageLevelProjectExtension; @@ -31,10 +31,16 @@ import org.jetbrains.annotations.NotNull; public class GenericsHighlighting8Test extends LightDaemonAnalyzerTestCase { @NonNls private static final String BASE_PATH = "/codeInsight/daemonCodeAnalyzer/genericsHighlighting8"; + @Override + protected void setUp() throws Exception { + super.setUp(); + enableInspectionTool(new UnusedDeclarationInspection()); + } + @NotNull @Override protected LocalInspectionTool[] configureLocalInspectionTools() { - return new LocalInspectionTool[]{new UncheckedWarningLocalInspection(), new UnusedSymbolLocalInspection(), new UnusedImportLocalInspection()}; + return new LocalInspectionTool[]{new UncheckedWarningLocalInspection(), new UnusedImportLocalInspection()}; } @Override diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/LambdaHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/LambdaHighlightingTest.java index 5ecab96d8926..868982e18bb8 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/LambdaHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/LambdaHighlightingTest.java @@ -16,22 +16,18 @@ package com.intellij.codeInsight.daemon.lambda; import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase; -import com.intellij.codeInspection.LocalInspectionTool; -import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection; +import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.testFramework.IdeaTestUtil; import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; public class LambdaHighlightingTest extends LightDaemonAnalyzerTestCase { @NonNls static final String BASE_PATH = "/codeInsight/daemonCodeAnalyzer/lambda/highlighting"; - @NotNull @Override - protected LocalInspectionTool[] configureLocalInspectionTools() { - return new LocalInspectionTool[]{ - new UnusedSymbolLocalInspection(), - }; + protected void setUp() throws Exception { + super.setUp(); + enableInspectionTool(new UnusedDeclarationInspection()); } public void testStaticAccess() { doTest(); } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/MethodRefHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/MethodRefHighlightingTest.java index d0bed5e9d5df..9b4c44547ed4 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/MethodRefHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/MethodRefHighlightingTest.java @@ -16,23 +16,19 @@ package com.intellij.codeInsight.daemon.lambda; import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase; -import com.intellij.codeInspection.LocalInspectionTool; -import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection; +import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; import com.intellij.openapi.projectRoots.JavaSdkVersion; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.testFramework.IdeaTestUtil; import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; public class MethodRefHighlightingTest extends LightDaemonAnalyzerTestCase { @NonNls static final String BASE_PATH = "/codeInsight/daemonCodeAnalyzer/lambda/methodRef"; - @NotNull @Override - protected LocalInspectionTool[] configureLocalInspectionTools() { - return new LocalInspectionTool[]{ - new UnusedSymbolLocalInspection(), - }; + protected void setUp() throws Exception { + super.setUp(); + enableInspectionTool(new UnusedDeclarationInspection()); } public void testValidContext() { doTest(); } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/MostSpecificResolutionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/MostSpecificResolutionTest.java index 294a3cc8a4f6..8fefdf069e47 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/MostSpecificResolutionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/MostSpecificResolutionTest.java @@ -16,23 +16,19 @@ package com.intellij.codeInsight.daemon.lambda; import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase; -import com.intellij.codeInspection.LocalInspectionTool; -import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection; +import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; import com.intellij.openapi.projectRoots.JavaSdkVersion; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.testFramework.IdeaTestUtil; import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; public class MostSpecificResolutionTest extends LightDaemonAnalyzerTestCase { @NonNls static final String BASE_PATH = "/codeInsight/daemonCodeAnalyzer/lambda/mostSpecific"; - @NotNull @Override - protected LocalInspectionTool[] configureLocalInspectionTools() { - return new LocalInspectionTool[]{ - new UnusedSymbolLocalInspection(), - }; + protected void setUp() throws Exception { + super.setUp(); + enableInspectionTool(new UnusedDeclarationInspection()); } public void testVoidConflict() throws Exception { diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewInferenceCollectingAdditionalConstraintsTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewInferenceCollectingAdditionalConstraintsTest.java index 960185e4b637..e6ddab2d8c06 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewInferenceCollectingAdditionalConstraintsTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewInferenceCollectingAdditionalConstraintsTest.java @@ -16,13 +16,10 @@ package com.intellij.codeInsight.daemon.lambda; import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase; -import com.intellij.codeInspection.LocalInspectionTool; -import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection; import com.intellij.openapi.projectRoots.JavaSdkVersion; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.testFramework.IdeaTestUtil; import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; public class NewInferenceCollectingAdditionalConstraintsTest extends LightDaemonAnalyzerTestCase { @NonNls static final String BASE_PATH = "/codeInsight/daemonCodeAnalyzer/lambda/additionalConstraints"; diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewLambdaHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewLambdaHighlightingTest.java index 0c9d8c65bce5..be6f71ba76fb 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewLambdaHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewLambdaHighlightingTest.java @@ -16,26 +16,22 @@ package com.intellij.codeInsight.daemon.lambda; import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase; -import com.intellij.codeInspection.LocalInspectionTool; -import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection; +import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; import com.intellij.idea.Bombed; import com.intellij.openapi.projectRoots.JavaSdkVersion; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.testFramework.IdeaTestUtil; import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; import java.util.Calendar; public class NewLambdaHighlightingTest extends LightDaemonAnalyzerTestCase { @NonNls static final String BASE_PATH = "/codeInsight/daemonCodeAnalyzer/lambda/newLambda"; - @NotNull @Override - protected LocalInspectionTool[] configureLocalInspectionTools() { - return new LocalInspectionTool[]{ - new UnusedSymbolLocalInspection() - }; + protected void setUp() throws Exception { + super.setUp(); + enableInspectionTool(new UnusedDeclarationInspection()); } public void testIDEA93586() { doTest(); } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewMethodRefHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewMethodRefHighlightingTest.java index eada71123134..281cefa64109 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewMethodRefHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewMethodRefHighlightingTest.java @@ -17,25 +17,27 @@ package com.intellij.codeInsight.daemon.lambda; import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase; import com.intellij.codeInspection.LocalInspectionTool; +import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; import com.intellij.codeInspection.uncheckedWarnings.UncheckedWarningLocalInspection; -import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection; -import com.intellij.idea.Bombed; import com.intellij.openapi.projectRoots.JavaSdkVersion; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.testFramework.IdeaTestUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; -import java.util.Calendar; - public class NewMethodRefHighlightingTest extends LightDaemonAnalyzerTestCase { @NonNls static final String BASE_PATH = "/codeInsight/daemonCodeAnalyzer/lambda/newMethodRef"; + @Override + protected void setUp() throws Exception { + super.setUp(); + enableInspectionTool(new UnusedDeclarationInspection()); + } + @NotNull @Override protected LocalInspectionTool[] configureLocalInspectionTools() { return new LocalInspectionTool[]{ - new UnusedSymbolLocalInspection(), new UncheckedWarningLocalInspection() }; } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/OverloadResolutionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/OverloadResolutionTest.java index 327d54d04260..a1507016f82d 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/OverloadResolutionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/OverloadResolutionTest.java @@ -16,23 +16,19 @@ package com.intellij.codeInsight.daemon.lambda; import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase; -import com.intellij.codeInspection.LocalInspectionTool; -import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection; +import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; import com.intellij.openapi.projectRoots.JavaSdkVersion; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.testFramework.IdeaTestUtil; import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; public class OverloadResolutionTest extends LightDaemonAnalyzerTestCase { @NonNls static final String BASE_PATH = "/codeInsight/daemonCodeAnalyzer/lambda/overloadResolution"; - @NotNull @Override - protected LocalInspectionTool[] configureLocalInspectionTools() { - return new LocalInspectionTool[]{ - new UnusedSymbolLocalInspection(), - }; + protected void setUp() throws Exception { + super.setUp(); + enableInspectionTool(new UnusedDeclarationInspection()); } public void testPertinentToApplicabilityOfExplicitlyTypedLambda() throws Exception { diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/CreateConstructorParameterFromFieldTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/CreateConstructorParameterFromFieldTest.java index d60e87c75b42..6f1c93050e25 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/CreateConstructorParameterFromFieldTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/CreateConstructorParameterFromFieldTest.java @@ -1,21 +1,19 @@ package com.intellij.codeInsight.daemon.quickFix; -import com.intellij.codeInspection.LocalInspectionTool; -import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection; +import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; import com.siyeh.ig.style.MissortedModifiersInspection; import com.siyeh.ig.style.UnqualifiedFieldAccessInspection; -import org.jetbrains.annotations.NotNull; /** * @author cdr */ public class CreateConstructorParameterFromFieldTest extends LightQuickFixParameterizedTestCase { - @NotNull - @Override - protected LocalInspectionTool[] configureLocalInspectionTools() { - return new LocalInspectionTool[]{ new UnusedSymbolLocalInspection(), new MissortedModifiersInspection(), new UnqualifiedFieldAccessInspection()}; - } + @Override + protected void setUp() throws Exception { + super.setUp(); + enableInspectionTools(new UnusedDeclarationInspection(), new MissortedModifiersInspection(), new UnqualifiedFieldAccessInspection()); + } public void test() throws Exception { doAllTests(); } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/CreateGetterOrSetterTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/CreateGetterOrSetterTest.java index 0f673656d9b2..48dfb758ac32 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/CreateGetterOrSetterTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/CreateGetterOrSetterTest.java @@ -15,18 +15,16 @@ */ package com.intellij.codeInsight.daemon.quickFix; -import com.intellij.codeInspection.LocalInspectionTool; -import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection; -import org.jetbrains.annotations.NotNull; +import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; /** * @author Danila Ponomarenko */ public class CreateGetterOrSetterTest extends LightQuickFixParameterizedTestCase { - @NotNull @Override - protected LocalInspectionTool[] configureLocalInspectionTools() { - return new LocalInspectionTool[] {new UnusedSymbolLocalInspection()}; + protected void setUp() throws Exception { + super.setUp(); + enableInspectionTool(new UnusedDeclarationInspection()); } public void test() throws Exception { diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/InitializeFinalFieldInConstructorFixTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/InitializeFinalFieldInConstructorFixTest.java index ac7bba98a7f6..9afb67d72c46 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/InitializeFinalFieldInConstructorFixTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/InitializeFinalFieldInConstructorFixTest.java @@ -1,14 +1,12 @@ package com.intellij.codeInsight.daemon.quickFix; -import com.intellij.codeInspection.LocalInspectionTool; -import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection; -import org.jetbrains.annotations.NotNull; +import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; public class InitializeFinalFieldInConstructorFixTest extends LightQuickFixParameterizedTestCase { - @NotNull @Override - protected LocalInspectionTool[] configureLocalInspectionTools() { - return new LocalInspectionTool[]{ new UnusedSymbolLocalInspection()}; + protected void setUp() throws Exception { + super.setUp(); + enableInspectionTool(new UnusedDeclarationInspection()); } public void test() throws Exception { doAllTests(); } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/RemoveUnusedParameterTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/RemoveUnusedParameterTest.java index 6ca1ef6188e9..6bc3f2933b86 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/RemoveUnusedParameterTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/RemoveUnusedParameterTest.java @@ -1,17 +1,14 @@ package com.intellij.codeInsight.daemon.quickFix; -import com.intellij.codeInspection.LocalInspectionTool; -import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection; -import org.jetbrains.annotations.NotNull; +import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; public class RemoveUnusedParameterTest extends LightQuickFixParameterizedTestCase { - - @NotNull @Override - protected LocalInspectionTool[] configureLocalInspectionTools() { - return new LocalInspectionTool[]{ new UnusedSymbolLocalInspection()}; + protected void setUp() throws Exception { + super.setUp(); + enableInspectionTool(new UnusedDeclarationInspection()); } public void test() throws Exception { doAllTests(); } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/RemoveUnusedVariableTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/RemoveUnusedVariableTest.java index e9c74a04d4ff..c0b1b87f3fd8 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/RemoveUnusedVariableTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/RemoveUnusedVariableTest.java @@ -1,14 +1,12 @@ package com.intellij.codeInsight.daemon.quickFix; -import com.intellij.codeInspection.LocalInspectionTool; -import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection; -import org.jetbrains.annotations.NotNull; +import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; public class RemoveUnusedVariableTest extends LightQuickFixParameterizedTestCase { - @NotNull @Override - protected LocalInspectionTool[] configureLocalInspectionTools() { - return new LocalInspectionTool[]{ new UnusedSymbolLocalInspection()}; + protected void setUp() throws Exception { + super.setUp(); + enableInspectionTool(new UnusedDeclarationInspection()); } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/Suppress15InspectionsTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/Suppress15InspectionsTest.java index c9baaed20115..15bcb730e07a 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/Suppress15InspectionsTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/Suppress15InspectionsTest.java @@ -17,13 +17,13 @@ package com.intellij.codeInsight.daemon.quickFix; import com.intellij.codeInspection.LocalInspectionTool; import com.intellij.codeInspection.accessStaticViaInstance.AccessStaticViaInstance; +import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; import com.intellij.codeInspection.deprecation.DeprecationInspection; import com.intellij.codeInspection.javaDoc.JavaDocReferenceInspection; import com.intellij.codeInspection.sillyAssignment.SillyAssignmentInspection; import com.intellij.codeInspection.uncheckedWarnings.UncheckedWarningLocalInspection; import com.intellij.codeInspection.unneededThrows.RedundantThrowsDeclaration; import com.intellij.codeInspection.unusedParameters.UnusedParametersInspection; -import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection; import org.jetbrains.annotations.NotNull; @@ -31,7 +31,7 @@ public class Suppress15InspectionsTest extends LightQuickFixParameterizedTestCas @Override protected void setUp() throws Exception { super.setUp(); - enableInspectionTool(new UnusedParametersInspection()); + enableInspectionTools(new UnusedParametersInspection(), new UnusedDeclarationInspection()); } @NotNull @@ -43,7 +43,6 @@ public class Suppress15InspectionsTest extends LightQuickFixParameterizedTestCas new AccessStaticViaInstance(), new DeprecationInspection(), new JavaDocReferenceInspection(), - new UnusedSymbolLocalInspection(), new UncheckedWarningLocalInspection() }; } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/SuppressNonInspectionsTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/SuppressNonInspectionsTest.java index 2b69de699961..3384bf6ee73d 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/SuppressNonInspectionsTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/SuppressNonInspectionsTest.java @@ -2,13 +2,12 @@ package com.intellij.codeInsight.daemon.quickFix; import com.intellij.codeInspection.LocalInspectionTool; import com.intellij.codeInspection.accessStaticViaInstance.AccessStaticViaInstance; +import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; import com.intellij.codeInspection.deprecation.DeprecationInspection; import com.intellij.codeInspection.javaDoc.JavaDocReferenceInspection; import com.intellij.codeInspection.sillyAssignment.SillyAssignmentInspection; import com.intellij.codeInspection.uncheckedWarnings.UncheckedWarningLocalInspection; import com.intellij.codeInspection.unneededThrows.RedundantThrowsDeclaration; -import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection; -import com.intellij.openapi.roots.LanguageLevelProjectExtension; import com.intellij.pom.java.LanguageLevel; import org.jetbrains.annotations.NotNull; @@ -19,6 +18,12 @@ public class SuppressNonInspectionsTest extends LightQuickFixParameterizedTestCa return LanguageLevel.JDK_1_3; } + @Override + protected void setUp() throws Exception { + super.setUp(); + enableInspectionTool(new UnusedDeclarationInspection()); + } + @NotNull @Override protected LocalInspectionTool[] configureLocalInspectionTools() { @@ -28,7 +33,6 @@ public class SuppressNonInspectionsTest extends LightQuickFixParameterizedTestCa new AccessStaticViaInstance(), new DeprecationInspection(), new JavaDocReferenceInspection(), - new UnusedSymbolLocalInspection(), new UncheckedWarningLocalInspection() }; } diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/InspectionProfileTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/InspectionProfileTest.java index a84b0703eef8..7901923bca5f 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/InspectionProfileTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/InspectionProfileTest.java @@ -17,7 +17,7 @@ package com.intellij.codeInspection; import com.intellij.codeInsight.daemon.HighlightDisplayKey; import com.intellij.codeInspection.dataFlow.DataFlowInspection; -import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; +import com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionBase; import com.intellij.codeInspection.ex.*; import com.intellij.openapi.util.JDOMUtil; import com.intellij.openapi.util.WriteExternalException; @@ -262,7 +262,7 @@ public class InspectionProfileTest extends LightIdeaTestCase { public void testGlobalInspectionContext() throws Exception { InspectionProfileImpl profile = new InspectionProfileImpl("Foo"); profile.disableAllTools(getProject()); - profile.enableTool(new UnusedDeclarationInspection().getShortName(), getProject()); + profile.enableTool(new UnusedDeclarationInspectionBase(true).getShortName(), getProject()); GlobalInspectionContextImpl context = ((InspectionManagerEx)InspectionManager.getInstance(getProject())).createNewGlobalContext(false); context.setExternalProfile(profile); diff --git a/java/java-tests/testSrc/com/intellij/refactoring/ChangeSignatureGestureTest.java b/java/java-tests/testSrc/com/intellij/refactoring/ChangeSignatureGestureTest.java index 36d7d3974108..f34b14db5cb4 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/ChangeSignatureGestureTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/ChangeSignatureGestureTest.java @@ -17,7 +17,7 @@ package com.intellij.refactoring; import com.intellij.JavaTestUtil; import com.intellij.codeInsight.intention.IntentionAction; -import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection; +import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.editor.CaretModel; @@ -41,7 +41,7 @@ public class ChangeSignatureGestureTest extends LightCodeInsightFixtureTestCase private void doTest(final Runnable run, boolean shouldShow, final String hint) { myFixture.configureByFile("/refactoring/changeSignatureGesture/" + getTestName(false) + ".java"); - myFixture.enableInspections(new UnusedSymbolLocalInspection()); + myFixture.enableInspections(new UnusedDeclarationInspection()); final ChangeSignatureGestureDetector detector = ChangeSignatureGestureDetector.getInstance(getProject()); final EditorEx editor = (EditorEx)myFixture.getEditor(); final Document document = editor.getDocument(); diff --git a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfoType.java b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfoType.java index d1615b93bce6..5ba5e858b0ce 100644 --- a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfoType.java +++ b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfoType.java @@ -37,9 +37,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public interface HighlightInfoType { - @NonNls String UNUSED_SYMBOL_SHORT_NAME = "UNUSED_SYMBOL"; - @NonNls String UNUSED_SYMBOL_DISPLAY_NAME = InspectionsBundle.message("unused.symbol"); - @NonNls String UNUSED_SYMBOL_ID = "UnusedDeclaration"; + @NonNls String UNUSED_SYMBOL_SHORT_NAME = "unused"; + @NonNls String UNUSED_SYMBOL_DISPLAY_NAME = InspectionsBundle.message("inspection.dead.code.display.name"); HighlightInfoType ERROR = new HighlightInfoTypeImpl(HighlightSeverity.ERROR, CodeInsightColors.ERRORS_ATTRIBUTES); HighlightInfoType WARNING = new HighlightInfoTypeImpl(HighlightSeverity.WARNING, CodeInsightColors.WARNINGS_ATTRIBUTES); @@ -55,7 +54,7 @@ public interface HighlightInfoType { HighlightInfoType DUPLICATE_FROM_SERVER = new HighlightInfoTypeImpl(HighlightSeverity.INFORMATION, CodeInsightColors.DUPLICATE_FROM_SERVER); HighlightInfoType UNUSED_SYMBOL = new HighlightInfoTypeSeverityByKey( - HighlightDisplayKey.findOrRegister(UNUSED_SYMBOL_SHORT_NAME, UNUSED_SYMBOL_DISPLAY_NAME, UNUSED_SYMBOL_ID), + HighlightDisplayKey.findOrRegister(UNUSED_SYMBOL_SHORT_NAME, UNUSED_SYMBOL_DISPLAY_NAME, UNUSED_SYMBOL_SHORT_NAME), CodeInsightColors.NOT_USED_ELEMENT_ATTRIBUTES); HighlightInfoType DEPRECATED = new HighlightInfoTypeSeverityByKey( diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionElementsMerger.java b/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionElementsMerger.java new file mode 100644 index 000000000000..be0583eee708 --- /dev/null +++ b/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionElementsMerger.java @@ -0,0 +1,28 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInspection.ex; + +import com.intellij.openapi.extensions.ExtensionPointName; +import org.jdom.Element; + +import java.util.Map; + +public abstract class InspectionElementsMerger { + public static final ExtensionPointName EP_NAME = ExtensionPointName.create("com.intellij.inspectionElementsMerger"); + + public abstract String getNewToolName(); + public abstract Element merge(Map elements); +} diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java b/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java index 346a4446090a..c6b47ffec368 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java +++ b/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java @@ -27,6 +27,7 @@ import com.intellij.ide.plugins.IdeaPluginDescriptorImpl; import com.intellij.lang.annotation.HighlightSeverity; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.options.ExternalInfo; import com.intellij.openapi.options.ExternalizableScheme; import com.intellij.openapi.progress.ProcessCanceledException; @@ -47,7 +48,6 @@ import com.intellij.util.graph.CachingSemiGraph; import com.intellij.util.graph.DFSTBuilder; import com.intellij.util.graph.GraphGenerator; import gnu.trove.THashMap; -import org.jdom.Document; import org.jdom.Element; import org.jdom.JDOMException; import org.jetbrains.annotations.NonNls; @@ -75,9 +75,9 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel, protected InspectionProfileImpl mySource; private InspectionProfileImpl myBaseProfile = null; @NonNls private static final String VERSION_TAG = "version"; - @NonNls private static final String INSPECTION_TOOL_TAG = "inspection_tool"; + @NonNls public static final String INSPECTION_TOOL_TAG = "inspection_tool"; - @NonNls private static final String CLASS_TAG = "class"; + @NonNls public static final String CLASS_TAG = "class"; @NonNls private static final String PROFILE_NAME_TAG = "profile_name"; @NonNls private static final String ROOT_ELEMENT_TAG = "inspections"; @@ -264,6 +264,18 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel, myDeinstalledInspectionsSettings.put(toolClassName, toolElement); } + + for (InspectionElementsMerger merger : Extensions.getExtensions(InspectionElementsMerger.EP_NAME)) { + final String newToolName = merger.getNewToolName(); + final String mergedToolName = newToolName + "Merged"; + if (!myDeinstalledInspectionsSettings.containsKey(mergedToolName)) { + final Element merged = merger.merge(myDeinstalledInspectionsSettings); + if (merged != null) { + myDeinstalledInspectionsSettings.put(newToolName, merged); + myDeinstalledInspectionsSettings.put(mergedToolName, new Element(INSPECTION_TOOL_TAG).setAttribute(CLASS_TAG, mergedToolName)); + } + } + } } @NotNull diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/ex/ToolsImpl.java b/platform/analysis-impl/src/com/intellij/codeInspection/ex/ToolsImpl.java index cfa20b44327b..39a53f30ef4b 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/ex/ToolsImpl.java +++ b/platform/analysis-impl/src/com/intellij/codeInspection/ex/ToolsImpl.java @@ -50,8 +50,8 @@ import java.util.Map; public class ToolsImpl implements Tools { @NonNls private static final String ENABLED_BY_DEFAULT_ATTRIBUTE = "enabled_by_default"; - @NonNls private static final String ENABLED_ATTRIBUTE = "enabled"; - @NonNls private static final String LEVEL_ATTRIBUTE = "level"; + @NonNls public static final String ENABLED_ATTRIBUTE = "enabled"; + @NonNls public static final String LEVEL_ATTRIBUTE = "level"; private final String myShortName; private final ScopeToolState myDefaultState; diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/inspection-black-list.txt b/platform/analysis-impl/src/com/intellij/codeInspection/inspection-black-list.txt index 5b937f501617..093d5a62f335 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/inspection-black-list.txt +++ b/platform/analysis-impl/src/com/intellij/codeInspection/inspection-black-list.txt @@ -1,6 +1,5 @@ com.intellij.codeInspection.canBeFinal.CanBeFinalInspection com.intellij.codeInspection.dataFlow.DataFlowInspection -com.intellij.codeInspection.deadCode.UnusedDeclarationInspection com.intellij.codeInspection.defaultFileTemplateUsage.DefaultFileTemplateUsageInspection com.intellij.codeInspection.defUse.DefUseInspection com.intellij.codeInspection.duplicatePropertyInspection.DuplicatePropertyInspection @@ -17,7 +16,6 @@ com.intellij.codeInspection.miscGenerics.SuspiciousCollectionsMethodCallsInspect com.intellij.codeInspection.nullable.NullableStuffInspection com.intellij.codeInspection.suspiciousNameCombination.SuspiciousNameCombinationInspection com.intellij.codeInspection.uncheckedWarnings.UncheckedWarningLocalInspection -com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection com.intellij.codeInspection.varScopeCanBeNarrowed.FieldCanBeLocalInspection com.intellij.codeInspection.visibility.VisibilityInspection com.intellij.lang.javascript.inspections.JSMismatchedCollectionQueryUpdateInspection diff --git a/platform/platform-resources/src/META-INF/LangExtensionPoints.xml b/platform/platform-resources/src/META-INF/LangExtensionPoints.xml index b16ce3f81509..f6e8ae60daea 100644 --- a/platform/platform-resources/src/META-INF/LangExtensionPoints.xml +++ b/platform/platform-resources/src/META-INF/LangExtensionPoints.xml @@ -817,6 +817,7 @@ + diff --git a/plugins/devkit/testSources/inspections/DevKitImplicitUsageProviderTest.java b/plugins/devkit/testSources/inspections/DevKitImplicitUsageProviderTest.java index a7fedaeaa74d..28e17c379703 100644 --- a/plugins/devkit/testSources/inspections/DevKitImplicitUsageProviderTest.java +++ b/plugins/devkit/testSources/inspections/DevKitImplicitUsageProviderTest.java @@ -15,8 +15,7 @@ */ package org.jetbrains.idea.devkit.inspections; -import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; -import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection; +import com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionBase; import com.intellij.openapi.application.PluginPathManager; import com.intellij.testFramework.TestDataPath; import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase; @@ -52,7 +51,7 @@ public class DevKitImplicitUsageProviderTest extends LightCodeInsightFixtureTest } private void enableImplicitUsageInspections() { - myFixture.enableInspections(new UnusedSymbolLocalInspection(), new UnusedDeclarationInspection()); + myFixture.enableInspections(new UnusedDeclarationInspectionBase(true)); } diff --git a/plugins/devkit/testSources/inspections/quickfix/RegisterExtensionFixProviderTest.java b/plugins/devkit/testSources/inspections/quickfix/RegisterExtensionFixProviderTest.java index 77b7f47594bf..bbf7b3c39670 100644 --- a/plugins/devkit/testSources/inspections/quickfix/RegisterExtensionFixProviderTest.java +++ b/plugins/devkit/testSources/inspections/quickfix/RegisterExtensionFixProviderTest.java @@ -16,8 +16,7 @@ package org.jetbrains.idea.devkit.inspections.quickfix; import com.intellij.codeInsight.intention.IntentionAction; -import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; -import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection; +import com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionBase; import com.intellij.openapi.application.PluginPathManager; import com.intellij.testFramework.TestDataPath; import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase; @@ -32,7 +31,7 @@ public class RegisterExtensionFixProviderTest extends LightCodeInsightFixtureTes @Override public void setUp() throws Exception { super.setUp(); - myFixture.enableInspections(new UnusedDeclarationInspection(), new UnusedSymbolLocalInspection()); + myFixture.enableInspections(new UnusedDeclarationInspectionBase(true)); } public void testCreateLocalInspectionMapping() { diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/local/GroovyPostHighlightingPass.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/local/GroovyPostHighlightingPass.java index 3a8fb591a605..b2cbcae3071e 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/local/GroovyPostHighlightingPass.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/local/GroovyPostHighlightingPass.java @@ -25,7 +25,7 @@ import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.codeInsight.intention.QuickFixFactory; import com.intellij.codeInspection.InspectionProfile; import com.intellij.codeInspection.ProblemHighlightType; -import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; +import com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionBase; import com.intellij.lang.annotation.Annotation; import com.intellij.lang.annotation.AnnotationHolder; import com.intellij.lang.annotation.AnnotationSession; @@ -91,7 +91,7 @@ public class GroovyPostHighlightingPass extends TextEditorHighlightingPass { final InspectionProfile profile = InspectionProjectProfileManager.getInstance(myProject).getInspectionProfile(); final HighlightDisplayKey unusedDefKey = HighlightDisplayKey.find(GroovyUnusedDeclarationInspection.SHORT_NAME); final boolean deadCodeEnabled = profile.isToolEnabled(unusedDefKey, myFile); - final UnusedDeclarationInspection deadCodeInspection = (UnusedDeclarationInspection)profile.getUnwrappedTool(UnusedDeclarationInspection.SHORT_NAME, myFile); + final UnusedDeclarationInspectionBase deadCodeInspection = (UnusedDeclarationInspectionBase)profile.getUnwrappedTool(UnusedDeclarationInspectionBase.SHORT_NAME, myFile); final GlobalUsageHelper usageHelper = new GlobalUsageHelper() { @Override public boolean isCurrentFileAlreadyChecked() { diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GppFunctionalTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GppFunctionalTest.groovy index 3aa643fea676..73806d5896fb 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GppFunctionalTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GppFunctionalTest.groovy @@ -16,7 +16,7 @@ package org.jetbrains.plugins.groovy.lang import com.intellij.codeInsight.lookup.LookupManager -import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection +import com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionBase import com.intellij.openapi.module.Module import com.intellij.openapi.roots.ContentEntry import com.intellij.openapi.roots.ModifiableRootModel @@ -34,6 +34,7 @@ import org.jetbrains.plugins.groovy.codeInspection.assignment.GroovyAssignabilit import org.jetbrains.plugins.groovy.codeInspection.unassignedVariable.UnassignedVariableAccessInspection import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod import org.jetbrains.plugins.groovy.util.TestUtils + /** * @author peter */ @@ -521,7 +522,7 @@ class Bar { } println new Bar().zzz ''' - myFixture.enableInspections(new GroovyUnusedDeclarationInspection(), new UnusedDeclarationInspection()) + myFixture.enableInspections(new GroovyUnusedDeclarationInspection(), new UnusedDeclarationInspectionBase(true)) myFixture.checkHighlighting(true, false, false) } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GrUnusedDefTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GrUnusedDefTest.groovy index 2af888b452ee..462045b9a785 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GrUnusedDefTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GrUnusedDefTest.groovy @@ -16,7 +16,7 @@ package org.jetbrains.plugins.groovy.lang.highlighting import com.intellij.codeInspection.InspectionProfileEntry -import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection +import com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionBase import org.jetbrains.plugins.groovy.codeInspection.GroovyUnusedDeclarationInspection import org.jetbrains.plugins.groovy.codeInspection.assignment.GroovyResultOfAssignmentUsedInspection import org.jetbrains.plugins.groovy.codeInspection.confusing.GrUnusedIncDecInspection @@ -28,7 +28,7 @@ import org.jetbrains.plugins.groovy.codeInspection.unusedDef.UnusedDefInspection class GrUnusedDefTest extends GrHighlightingTestBase { @Override InspectionProfileEntry[] getCustomInspections() { - return [new UnusedDefInspection(), new GrUnusedIncDecInspection(), new GroovyUnusedDeclarationInspection(), new UnusedDeclarationInspection(), new GroovyResultOfAssignmentUsedInspection()] as InspectionProfileEntry[] + return [new UnusedDefInspection(), new GrUnusedIncDecInspection(), new GroovyUnusedDeclarationInspection(), new UnusedDeclarationInspectionBase(true), new GroovyResultOfAssignmentUsedInspection()] as InspectionProfileEntry[] } public void testUnusedVariable() { doTest() } diff --git a/plugins/javaFX/javaFX-CE/testSrc/org/jetbrains/plugins/javaFX/fxml/JavaFXHighlightingTest.java b/plugins/javaFX/javaFX-CE/testSrc/org/jetbrains/plugins/javaFX/fxml/JavaFXHighlightingTest.java index 840151315836..1093083d9de9 100644 --- a/plugins/javaFX/javaFX-CE/testSrc/org/jetbrains/plugins/javaFX/fxml/JavaFXHighlightingTest.java +++ b/plugins/javaFX/javaFX-CE/testSrc/org/jetbrains/plugins/javaFX/fxml/JavaFXHighlightingTest.java @@ -16,9 +16,8 @@ package org.jetbrains.plugins.javaFX.fxml; import com.intellij.codeInsight.daemon.impl.analysis.XmlPathReferenceInspection; -import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; +import com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionBase; import com.intellij.codeInspection.htmlInspections.RequiredAttributesInspection; -import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection; import com.intellij.openapi.application.PluginPathManager; import com.intellij.psi.*; import com.intellij.psi.search.GlobalSearchScope; @@ -353,8 +352,7 @@ public class JavaFXHighlightingTest extends AbstractJavaFXTestCase { protected void enableInspections() { myFixture.enableInspections(new XmlPathReferenceInspection(), new RequiredAttributesInspection(), - new UnusedSymbolLocalInspection(), - new UnusedDeclarationInspection()); + new UnusedDeclarationInspectionBase(true)); } @NotNull diff --git a/plugins/javaFX/javaFX-CE/testSrc/org/jetbrains/plugins/javaFX/fxml/JavaFxCoercingTest.java b/plugins/javaFX/javaFX-CE/testSrc/org/jetbrains/plugins/javaFX/fxml/JavaFxCoercingTest.java index b86409810cfd..f305c88f7e8f 100644 --- a/plugins/javaFX/javaFX-CE/testSrc/org/jetbrains/plugins/javaFX/fxml/JavaFxCoercingTest.java +++ b/plugins/javaFX/javaFX-CE/testSrc/org/jetbrains/plugins/javaFX/fxml/JavaFxCoercingTest.java @@ -18,7 +18,6 @@ package org.jetbrains.plugins.javaFX.fxml; import com.intellij.codeInsight.daemon.impl.analysis.XmlPathReferenceInspection; import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; import com.intellij.codeInspection.htmlInspections.RequiredAttributesInspection; -import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection; import com.intellij.openapi.application.PluginPathManager; import org.jetbrains.annotations.NotNull; @@ -56,7 +55,6 @@ public class JavaFxCoercingTest extends AbstractJavaFXTestCase { protected void enableInspections() { myFixture.enableInspections(new XmlPathReferenceInspection(), new RequiredAttributesInspection(), - new UnusedSymbolLocalInspection(), new UnusedDeclarationInspection()); } diff --git a/resources-en/src/inspectionDescriptions/UNUSED_SYMBOL.html b/resources-en/src/inspectionDescriptions/UNUSED_SYMBOL.html deleted file mode 100644 index 6fde49f37107..000000000000 --- a/resources-en/src/inspectionDescriptions/UNUSED_SYMBOL.html +++ /dev/null @@ -1,13 +0,0 @@ - - - -Detects local variables and private members that are declared but not used, -never accessed for reading or not initialized in a class. -
Can ignore members that are annotated in a special way, for example, by EJB annotation javax.ejb.EJB. - -Additional annotations can be configured below. -
-The Report unused parameters in non-private method setting is used to -detect unused parameters of public/protected/package local methods which are neither overridden nor override other method. - - \ No newline at end of file diff --git a/resources-en/src/inspectionDescriptions/UnusedDeclaration.html b/resources-en/src/inspectionDescriptions/unused.html similarity index 60% rename from resources-en/src/inspectionDescriptions/UnusedDeclaration.html rename to resources-en/src/inspectionDescriptions/unused.html index e5423e0441ad..95d2a15d0ee3 100644 --- a/resources-en/src/inspectionDescriptions/UnusedDeclaration.html +++ b/resources-en/src/inspectionDescriptions/unused.html @@ -1,7 +1,8 @@ This inspection reports classes, methods or fields in the specified inspection scope that -are not used or not reachable from entry points.

+are not used or not reachable from entry points. +In editor, it also detects local variables that are declared but not used as well as private members that are never accessed for reading or not initialized in a class.

Use check boxes in the inspection options below, to specify what should be automatically assumed entry points. You will also have a possibility to add entry points manually when inspection results are ready. diff --git a/resources/src/META-INF/IdeaPlugin.xml b/resources/src/META-INF/IdeaPlugin.xml index 936aa15b61f5..7953b814b56e 100644 --- a/resources/src/META-INF/IdeaPlugin.xml +++ b/resources/src/META-INF/IdeaPlugin.xml @@ -504,8 +504,9 @@ + - @@ -619,9 +620,6 @@ groupName="Declaration redundancy" enabledByDefault="false" level="WARNING" implementationClass="com.intellij.codeInspection.RedundantSuppressInspection"/> -