From f03375a38b2f3692ad7216c7230bf4e86f1f4907 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Fri, 14 Jun 2013 18:11:42 +0400 Subject: [PATCH] cleanup, notnull --- .../deadCode/UnusedDeclarationInspection.java | 3 ++- .../codeInspection/reference/RefEntity.java | 2 ++ .../ex/DescriptorProviderInspection.java | 9 ++++--- .../ex/LocalQuickFixWrapper.java | 10 ++++--- .../codeInspection/ex/QuickFixAction.java | 27 +++++++++++-------- .../intellij/codeInspection/ui/Browser.java | 2 +- .../codeInspection/ui/InspectionTree.java | 5 ++-- 7 files changed, 34 insertions(+), 24 deletions(-) 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 fa341a05bd20..633a6089d6e2 100644 --- a/java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspection.java @@ -1100,8 +1100,9 @@ public class UnusedDeclarationInspection extends FilteringInspectionTool { super.updateContent(); } + @NotNull @Override - public InspectionNode createToolNode(@NotNull final InspectionRVContentProvider provider, final InspectionTreeNode parentNode, final boolean showStructure) { + public InspectionNode createToolNode(@NotNull final InspectionRVContentProvider provider, @NotNull final InspectionTreeNode parentNode, final boolean showStructure) { final InspectionNode toolNode = super.createToolNode(provider, parentNode, showStructure); final EntryPointsNode entryPointsNode = new EntryPointsNode(this); provider.appendToolNodeContent(entryPointsNode, toolNode, showStructure); diff --git a/platform/analysis-api/src/com/intellij/codeInspection/reference/RefEntity.java b/platform/analysis-api/src/com/intellij/codeInspection/reference/RefEntity.java index 0b3923abc2b3..3c7d66018e1b 100644 --- a/platform/analysis-api/src/com/intellij/codeInspection/reference/RefEntity.java +++ b/platform/analysis-api/src/com/intellij/codeInspection/reference/RefEntity.java @@ -30,6 +30,8 @@ import java.util.List; * @see RefManager */ public interface RefEntity extends UserDataHolder { + RefEntity[] EMPTY_ELEMENTS_ARRAY = new RefEntity[0]; + /** * Returns the name of the node. * diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ex/DescriptorProviderInspection.java b/platform/lang-impl/src/com/intellij/codeInspection/ex/DescriptorProviderInspection.java index 4995cb63b2db..e64487f36697 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/DescriptorProviderInspection.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/DescriptorProviderInspection.java @@ -407,13 +407,14 @@ public abstract class DescriptorProviderInspection extends InspectionTool implem } @Override + @Nullable public QuickFixAction[] getQuickFixes(@NotNull final RefEntity[] refElements) { return extractActiveFixes(refElements, getQuickFixActions()); } - public QuickFixAction[] extractActiveFixes(final RefEntity[] refElements, @NotNull Map> actions) { - if (refElements == null) return null; - Map result = new java.util.HashMap(); + @Nullable + public QuickFixAction[] extractActiveFixes(@NotNull RefEntity[] refElements, @NotNull Map> actions) { + Map result = new HashMap(); for (RefEntity refElement : refElements) { final Set localQuickFixes = actions.get(refElement); if (localQuickFixes == null) continue; @@ -445,7 +446,7 @@ public abstract class DescriptorProviderInspection extends InspectionTool implem return getProblemToElements().get(descriptor); } - public void ignoreProblem(final CommonProblemDescriptor descriptor, final QuickFix fix) { + public void ignoreProblem(@NotNull CommonProblemDescriptor descriptor, @NotNull QuickFix fix) { RefEntity refElement = getProblemToElements().get(descriptor); if (refElement != null) { final QuickFix[] fixes = descriptor.getFixes(); diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ex/LocalQuickFixWrapper.java b/platform/lang-impl/src/com/intellij/codeInspection/ex/LocalQuickFixWrapper.java index e3f43ca7ab88..a67cac8a13f4 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/LocalQuickFixWrapper.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/LocalQuickFixWrapper.java @@ -73,11 +73,11 @@ public class LocalQuickFixWrapper extends QuickFixAction { } @Nullable - protected QuickFix getWorkingQuickFix(QuickFix[] fixes) { + protected QuickFix getWorkingQuickFix(@NotNull QuickFix[] fixes) { for (QuickFix fix : fixes) { if (!myFix.getClass().isInstance(fix)) continue; if (myFix instanceof IntentionWrapper && fix instanceof IntentionWrapper && - !(((IntentionWrapper)myFix).getAction().getClass().isInstance(((IntentionWrapper)fix).getAction()))) { + !((IntentionWrapper)myFix).getAction().getClass().isInstance(((IntentionWrapper)fix).getAction())) { continue; } return fix; @@ -91,7 +91,9 @@ public class LocalQuickFixWrapper extends QuickFixAction { } @Override - protected void applyFix(final Project project, final CommonProblemDescriptor[] descriptors, final Set ignoredElements) { + protected void applyFix(@NotNull final Project project, + @NotNull final CommonProblemDescriptor[] descriptors, + @NotNull final Set ignoredElements) { final PsiModificationTracker tracker = PsiManager.getInstance(project).getModificationTracker(); if (myFix instanceof BatchQuickFix) { final ArrayList collectedElementsToIgnore = new ArrayList(); @@ -139,7 +141,7 @@ public class LocalQuickFixWrapper extends QuickFixAction { } } - private void ignore(Set ignoredElements, CommonProblemDescriptor descriptor, QuickFix fix) { + private void ignore(@NotNull Set ignoredElements, @NotNull CommonProblemDescriptor descriptor, @Nullable QuickFix fix) { if (fix != null) { ((DescriptorProviderInspection)myTool).ignoreProblem(descriptor, fix); } diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ex/QuickFixAction.java b/platform/lang-impl/src/com/intellij/codeInspection/ex/QuickFixAction.java index dd88d8569520..a575e90ede4c 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/QuickFixAction.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/QuickFixAction.java @@ -117,9 +117,12 @@ public class QuickFixAction extends AnAction { } - protected void applyFix(Project project, CommonProblemDescriptor[] descriptors, Set ignoredElements) {} - private void doApplyFix(final Project project, - final CommonProblemDescriptor[] descriptors) { + protected void applyFix(@NotNull Project project, + @NotNull CommonProblemDescriptor[] descriptors, + @NotNull Set ignoredElements) { + } + + private void doApplyFix(@NotNull final Project project, @NotNull final CommonProblemDescriptor[] descriptors) { final Set readOnlyFiles = new THashSet(); for (CommonProblemDescriptor descriptor : descriptors) { final PsiElement psiElement = descriptor instanceof ProblemDescriptor ? ((ProblemDescriptor)descriptor).getPsiElement() : null; @@ -133,7 +136,7 @@ public class QuickFixAction extends AnAction { if (operationStatus.hasReadonlyFiles()) return; } - final RefManagerImpl refManager = ((RefManagerImpl)myTool.getContext().getRefManager()); + final RefManagerImpl refManager = (RefManagerImpl)myTool.getContext().getRefManager(); final boolean initial = refManager.isInProcess(); @@ -167,7 +170,7 @@ public class QuickFixAction extends AnAction { } public void doApplyFix(final RefElement[] refElements, InspectionResultsView view) { - final RefManagerImpl refManager = ((RefManagerImpl)myTool.getContext().getRefManager()); + final RefManagerImpl refManager = (RefManagerImpl)myTool.getContext().getRefManager(); final boolean initial = refManager.isInProcess(); @@ -294,19 +297,21 @@ public class QuickFixAction extends AnAction { } private class PerformFixesTask implements SequentialTask { + @NotNull private final Project myProject; private final CommonProblemDescriptor[] myDescriptors; + @NotNull private final Set myIgnoredElements; private final SequentialModalProgressTask myTask; private int myCount = 0; - public PerformFixesTask(Project project, - CommonProblemDescriptor[] descriptors, - Set elements, - SequentialModalProgressTask task) { + public PerformFixesTask(@NotNull Project project, + @NotNull CommonProblemDescriptor[] descriptors, + @NotNull Set ignoredElements, + @NotNull SequentialModalProgressTask task) { myProject = project; myDescriptors = descriptors; - myIgnoredElements = elements; + myIgnoredElements = ignoredElements; myTask = task; } @@ -324,7 +329,7 @@ public class QuickFixAction extends AnAction { final CommonProblemDescriptor descriptor = myDescriptors[myCount++]; ProgressIndicator indicator = myTask.getIndicator(); if (indicator != null) { - indicator.setFraction(((double)myCount) / myDescriptors.length); + indicator.setFraction((double)myCount / myDescriptors.length); if (descriptor instanceof ProblemDescriptor) { final PsiElement psiElement = ((ProblemDescriptor)descriptor).getPsiElement(); if (psiElement != null) { diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/Browser.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/Browser.java index 34aebc94d1fe..cc823882ab0a 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/Browser.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/Browser.java @@ -512,7 +512,7 @@ class Browser extends JPanel { //CCE here means QuickFix was incorrectly inherited fix.applyFix(myView.getProject(), descriptor); if (startCount != tracker.getModificationCount()) { - final DescriptorProviderInspection tool = ((DescriptorProviderInspection)myView.getTree().getSelectedTool()); + final DescriptorProviderInspection tool = (DescriptorProviderInspection)myView.getTree().getSelectedTool(); if (tool != null) { tool.ignoreProblem(element, descriptor, idx); } diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTree.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTree.java index d8b2c07e49b7..237601917684 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTree.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTree.java @@ -59,7 +59,6 @@ import java.util.*; public class InspectionTree extends Tree { private final HashSet myExpandedUserObjects; private SelectionPath mySelectionPath; - private static final RefEntity[] EMPTY_ELEMENTS_ARRAY = new RefEntity[0]; private static final ProblemDescriptor[] EMPTY_DESCRIPTORS = new ProblemDescriptor[0]; public InspectionTree(final Project project) { @@ -130,7 +129,7 @@ public class InspectionTree extends Tree { TreePath[] selectionPaths = getSelectionPaths(); if (selectionPaths != null) { final InspectionTool selectedTool = getSelectedTool(); - if (selectedTool == null) return EMPTY_ELEMENTS_ARRAY; + if (selectedTool == null) return RefEntity.EMPTY_ELEMENTS_ARRAY; List result = new ArrayList(); for (TreePath selectionPath : selectionPaths) { @@ -139,7 +138,7 @@ public class InspectionTree extends Tree { } return result.toArray(new RefEntity[result.size()]); } - return EMPTY_ELEMENTS_ARRAY; + return RefEntity.EMPTY_ELEMENTS_ARRAY; } private static void addElementsInNode(InspectionTreeNode node, List out) {