From fa488d75f00520385988aa38f5ef1ffe3c7c2590 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Fri, 11 Nov 2016 16:49:49 +0300 Subject: [PATCH] cleanup --- .../UnusedDeclarationInspectionBase.java | 50 ++++++----------- .../deadCode/UnusedDeclarationInspection.java | 55 ++++--------------- .../codeInspection/GlobalInspectionTool.java | 3 +- .../InspectionProfileEntry.java | 24 +++----- 4 files changed, 39 insertions(+), 93 deletions(-) diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspectionBase.java b/java/java-analysis-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspectionBase.java index 8d2b4ede119e..389d4ee0588f 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspectionBase.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspectionBase.java @@ -65,7 +65,7 @@ public class UnusedDeclarationInspectionBase extends GlobalInspectionTool { public boolean ADD_APPLET_TO_ENTRIES = true; public boolean ADD_SERVLET_TO_ENTRIES = true; public boolean ADD_NONJAVA_TO_ENTRIES = true; - protected boolean TEST_ENTRY_POINTS = true; + private boolean TEST_ENTRY_POINTS = true; public static final String DISPLAY_NAME = InspectionsBundle.message("inspection.dead.code.display.name"); public static final String SHORT_NAME = HighlightInfoType.UNUSED_SYMBOL_SHORT_NAME; @@ -290,7 +290,6 @@ public class UnusedDeclarationInspectionBase extends GlobalInspectionTool { if (isSuppressed || !scope.contains(file)) { getEntryPointsManager(globalContext).addEntryPoint(refElement, false); } - return; } } } @@ -323,12 +322,9 @@ public class UnusedDeclarationInspectionBase extends GlobalInspectionTool { String qualifiedName = psiClass != null ? psiClass.getQualifiedName() : null; if (qualifiedName != null) { final GlobalSearchScope projectScope = GlobalSearchScope.projectScope(globalContext.getProject()); - final PsiNonJavaFileReferenceProcessor processor = new PsiNonJavaFileReferenceProcessor() { - @Override - public boolean process(PsiFile file, int startOffset, int endOffset) { - getEntryPointsManager(globalContext).addEntryPoint(refElement, false); - return false; - } + final PsiNonJavaFileReferenceProcessor processor = (file, startOffset, endOffset) -> { + getEntryPointsManager(globalContext).addEntryPoint(refElement, false); + return false; }; final DelegatingGlobalSearchScope globalSearchScope = new DelegatingGlobalSearchScope(projectScope) { @Override @@ -450,9 +446,9 @@ public class UnusedDeclarationInspectionBase extends GlobalInspectionTool { checkForReachableRefs(globalContext); final RefFilter filter = myPhase == 1 ? new StrictUnreferencedFilter(this, globalContext) : new RefUnreachableFilter(this, globalContext); - final boolean[] requestAdded = {false}; LOG.assertTrue(myProcessedSuspicious != null, "phase: " + myPhase); + final boolean[] requestAdded = {false}; globalContext.getRefManager().iterate(new RefJavaVisitor() { @Override public void visitElement(@NotNull RefEntity refEntity) { @@ -469,12 +465,9 @@ public class UnusedDeclarationInspectionBase extends GlobalInspectionTool { getEntryPointsManager(globalContext).addEntryPoint(refField, false); } else { - globalContext.getExtension(GlobalJavaInspectionContext.CONTEXT).enqueueFieldUsagesProcessor(refField, new GlobalJavaInspectionContext.UsagesProcessor() { - @Override - public boolean process(PsiReference psiReference) { - getEntryPointsManager(globalContext).addEntryPoint(refField, false); - return false; - } + globalContext.getExtension(GlobalJavaInspectionContext.CONTEXT).enqueueFieldUsagesProcessor(refField, psiReference -> { + getEntryPointsManager(globalContext).addEntryPoint(refField, false); + return false; }); requestAdded[0] = true; } @@ -506,20 +499,14 @@ public class UnusedDeclarationInspectionBase extends GlobalInspectionTool { public void visitClass(@NotNull final RefClass refClass) { myProcessedSuspicious.add(refClass); if (!refClass.isAnonymous()) { - globalContext.getExtension(GlobalJavaInspectionContext.CONTEXT).enqueueDerivedClassesProcessor(refClass, new GlobalJavaInspectionContext.DerivedClassesProcessor() { - @Override - public boolean process(PsiClass inheritor) { - getEntryPointsManager(globalContext).addEntryPoint(refClass, false); - return false; - } + globalContext.getExtension(GlobalJavaInspectionContext.CONTEXT).enqueueDerivedClassesProcessor(refClass, inheritor -> { + getEntryPointsManager(globalContext).addEntryPoint(refClass, false); + return false; }); - globalContext.getExtension(GlobalJavaInspectionContext.CONTEXT).enqueueClassUsagesProcessor(refClass, new GlobalJavaInspectionContext.UsagesProcessor() { - @Override - public boolean process(PsiReference psiReference) { - getEntryPointsManager(globalContext).addEntryPoint(refClass, false); - return false; - } + globalContext.getExtension(GlobalJavaInspectionContext.CONTEXT).enqueueClassUsagesProcessor(refClass, psiReference -> { + getEntryPointsManager(globalContext).addEntryPoint(refClass, false); + return false; }); requestAdded[0] = true; } @@ -549,12 +536,9 @@ public class UnusedDeclarationInspectionBase extends GlobalInspectionTool { private static void enqueueMethodUsages(GlobalInspectionContext globalContext, final RefMethod refMethod) { if (refMethod.getSuperMethods().isEmpty()) { - globalContext.getExtension(GlobalJavaInspectionContext.CONTEXT).enqueueMethodUsagesProcessor(refMethod, new GlobalJavaInspectionContext.UsagesProcessor() { - @Override - public boolean process(PsiReference psiReference) { - getEntryPointsManager(globalContext).addEntryPoint(refMethod, false); - return false; - } + globalContext.getExtension(GlobalJavaInspectionContext.CONTEXT).enqueueMethodUsagesProcessor(refMethod, psiReference -> { + getEntryPointsManager(globalContext).addEntryPoint(refMethod, false); + return false; }); } else { diff --git a/java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspection.java b/java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspection.java index 98b0b6423a9d..f6fcde195ba3 100644 --- a/java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspection.java @@ -25,7 +25,6 @@ import com.intellij.codeInspection.reference.*; import com.intellij.codeInspection.ui.InspectionToolPresentation; import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection; import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspectionBase; -import com.intellij.openapi.ui.VerticalFlowLayout; import com.intellij.psi.*; import com.intellij.psi.controlFlow.DefUseUtil; import com.intellij.ui.ScrollPaneFactory; @@ -34,7 +33,6 @@ import com.intellij.ui.components.JBLabel; import com.intellij.ui.components.JBRadioButton; import com.intellij.ui.components.JBTabbedPane; import com.intellij.util.ObjectUtils; -import com.intellij.util.ui.JBInsets; import com.intellij.util.ui.JBUI; import gnu.trove.THashSet; import org.jetbrains.annotations.NotNull; @@ -43,10 +41,11 @@ 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.ArrayList; import java.util.List; +import java.util.Map; +import java.util.Set; public class UnusedDeclarationInspection extends UnusedDeclarationInspectionBase { private final UnusedParametersInspection myUnusedParameters = new UnusedParametersInspection(); @@ -155,12 +154,7 @@ public class UnusedDeclarationInspection extends UnusedDeclarationInspectionBase final ButtonGroup group = new ButtonGroup(); group.add(asEntryPoint); group.add(asUnused); - final ActionListener listener = new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - setTestEntryPoints(asEntryPoint.isSelected()); - } - }; + final ActionListener listener = e -> setTestEntryPoints(asEntryPoint.isSelected()); asEntryPoint.addActionListener(listener); asUnused.addActionListener(listener); @@ -187,12 +181,7 @@ public class UnusedDeclarationInspection extends UnusedDeclarationInspectionBase myMainsCheckbox = new JCheckBox(InspectionsBundle.message("inspection.dead.code.option.main")); myMainsCheckbox.setSelected(ADD_MAINS_TO_ENTRIES); - myMainsCheckbox.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - ADD_MAINS_TO_ENTRIES = myMainsCheckbox.isSelected(); - } - }); + myMainsCheckbox.addActionListener(e -> ADD_MAINS_TO_ENTRIES = myMainsCheckbox.isSelected()); add(myMainsCheckbox, gc); @@ -200,23 +189,13 @@ public class UnusedDeclarationInspection extends UnusedDeclarationInspectionBase myAppletToEntries = new JCheckBox(InspectionsBundle.message("inspection.dead.code.option.applet")); myAppletToEntries.setSelected(ADD_APPLET_TO_ENTRIES); - myAppletToEntries.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - ADD_APPLET_TO_ENTRIES = myAppletToEntries.isSelected(); - } - }); + myAppletToEntries.addActionListener(e -> ADD_APPLET_TO_ENTRIES = myAppletToEntries.isSelected()); add(myAppletToEntries, gc); gc.gridy++; myServletToEntries = new JCheckBox(InspectionsBundle.message("inspection.dead.code.option.servlet")); myServletToEntries.setSelected(ADD_SERVLET_TO_ENTRIES); - myServletToEntries.addActionListener(new ActionListener(){ - @Override - public void actionPerformed(ActionEvent e) { - ADD_SERVLET_TO_ENTRIES = myServletToEntries.isSelected(); - } - }); + myServletToEntries.addActionListener(e -> ADD_SERVLET_TO_ENTRIES = myServletToEntries.isSelected()); add(myServletToEntries, gc); gc.gridy++; @@ -224,12 +203,7 @@ public class UnusedDeclarationInspection extends UnusedDeclarationInspectionBase 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()); - } - }); + extCheckbox.addActionListener(e -> extension.setSelected(extCheckbox.isSelected())); add(extCheckbox, gc); gc.gridy++; } @@ -238,12 +212,7 @@ public class UnusedDeclarationInspection extends UnusedDeclarationInspectionBase myNonJavaCheckbox = new JCheckBox(InspectionsBundle.message("inspection.dead.code.option.external")); myNonJavaCheckbox.setSelected(ADD_NONJAVA_TO_ENTRIES); - myNonJavaCheckbox.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - ADD_NONJAVA_TO_ENTRIES = myNonJavaCheckbox.isSelected(); - } - }); + myNonJavaCheckbox.addActionListener(e -> ADD_NONJAVA_TO_ENTRIES = myNonJavaCheckbox.isSelected()); gc.weighty = 1; add(myNonJavaCheckbox, gc); @@ -267,10 +236,10 @@ public class UnusedDeclarationInspection extends UnusedDeclarationInspectionBase private class UnusedVariablesGraphAnnotator extends RefGraphAnnotator { private final InspectionManager myInspectionManager; - private GlobalInspectionContextImpl myContext; - private Map myTools; + private final GlobalInspectionContextImpl myContext; + private final Map myTools; - public UnusedVariablesGraphAnnotator(InspectionManager inspectionManager, RefManager refManager) { + UnusedVariablesGraphAnnotator(InspectionManager inspectionManager, RefManager refManager) { myInspectionManager = inspectionManager; myContext = (GlobalInspectionContextImpl)((RefManagerImpl)refManager).getContext(); myTools = myContext.getTools(); diff --git a/platform/analysis-api/src/com/intellij/codeInspection/GlobalInspectionTool.java b/platform/analysis-api/src/com/intellij/codeInspection/GlobalInspectionTool.java index a40f7a06e91a..259b41260452 100644 --- a/platform/analysis-api/src/com/intellij/codeInspection/GlobalInspectionTool.java +++ b/platform/analysis-api/src/com/intellij/codeInspection/GlobalInspectionTool.java @@ -148,7 +148,7 @@ public abstract class GlobalInspectionTool extends InspectionProfileEntry { * usages of the same classes and methods, usage searches are not performed directly, but * instead are queued for batch processing through * {@link GlobalJavaInspectionContext#enqueueClassUsagesProcessor} and similar methods. The method - * can add new problems to problemDescriptionsProcessor or remove some of the problems + * can add new problems to {@code problemDescriptionsProcessor} or remove some of the problems * collected by {@link #runInspection(AnalysisScope, InspectionManager, GlobalInspectionContext, ProblemDescriptionsProcessor)} * by calling {@link ProblemDescriptionsProcessor#ignoreElement(RefEntity)}. * @@ -207,7 +207,6 @@ public abstract class GlobalInspectionTool extends InspectionProfileEntry { * @return JobDescriptors array to show inspection progress correctly. TotalAmount should be set (e.g. in * {@link #runInspection(AnalysisScope, InspectionManager, GlobalInspectionContext, ProblemDescriptionsProcessor)}) * ProgressIndicator should progress with {@link GlobalInspectionContext#incrementJobDoneAmount(JobDescriptor, String)} - * @param context */ @Nullable public JobDescriptor[] getAdditionalJobs(GlobalInspectionContext context) { diff --git a/platform/analysis-api/src/com/intellij/codeInspection/InspectionProfileEntry.java b/platform/analysis-api/src/com/intellij/codeInspection/InspectionProfileEntry.java index a1686cf42941..d2d041879c76 100644 --- a/platform/analysis-api/src/com/intellij/codeInspection/InspectionProfileEntry.java +++ b/platform/analysis-api/src/com/intellij/codeInspection/InspectionProfileEntry.java @@ -311,8 +311,8 @@ public abstract class InspectionProfileEntry implements BatchSuppressableTool { /** * Read in settings from XML config. - * Default implementation uses XmlSerializer so you may use public fields (like int TOOL_OPTION) - * and bean-style getters/setters (like int getToolOption(), void setToolOption(int)) to store your options. + * Default implementation uses XmlSerializer so you may use public fields (like {@code int TOOL_OPTION}) + * and bean-style getters/setters (like {@code int getToolOption(), void setToolOption(int)}) to store your options. * * @param node to read settings from. * @throws InvalidDataException if the loaded data was not valid. @@ -334,8 +334,8 @@ public abstract class InspectionProfileEntry implements BatchSuppressableTool { /** * Store current settings in XML config. - * Default implementation uses XmlSerializer so you may use public fields (like int TOOL_OPTION) - * and bean-style getters/setters (like int getToolOption(), void setToolOption(int)) to store your options. + * Default implementation uses XmlSerializer so you may use public fields (like {@code int TOOL_OPTION}) + * and bean-style getters/setters (like {@code int getToolOption(), void setToolOption(int)}) to store your options. * * @param node to store settings to. * @throws WriteExternalException if no data should be saved for this component. @@ -366,17 +366,11 @@ public abstract class InspectionProfileEntry implements BatchSuppressableTool { return; } - try { - final BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream())); - try { - String line; - while ((line = reader.readLine()) != null) { - line = line.trim(); - if (!line.isEmpty()) ourBlackList.add(line); - } - } - finally { - reader.close(); + try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()))) { + String line; + while ((line = reader.readLine()) != null) { + line = line.trim(); + if (!line.isEmpty()) ourBlackList.add(line); } } catch (IOException e) {