From f1bbf359c767a94904bfd50633e2a42cc94b0bbb Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Tue, 16 May 2017 14:11:09 +0300 Subject: [PATCH] cleanup --- .../ui/InspectionResultsView.java | 46 ++++++++----------- .../intellij/util/containers/FactoryMap.java | 43 ++++++++++------- 2 files changed, 44 insertions(+), 45 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java index 25accd099333..3ca05fd45a1e 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java @@ -78,8 +78,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; -import javax.swing.event.TreeSelectionEvent; -import javax.swing.event.TreeSelectionListener; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreeNode; @@ -132,7 +130,6 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren private InspectionTreeLoadingProgressAware myLoadingProgressPreview; private final ExcludedInspectionTreeNodesManager myExcludedInspectionTreeNodesManager; private final FactoryMap> mySuppressedNodes = new FactoryMap>() { - @Nullable @Override protected Set create(String key) { return new THashSet<>(); @@ -276,7 +273,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren } } - public void profileChanged() { + void profileChanged() { myTree.revalidate(); myTree.repaint(); syncRightPanel(); @@ -286,14 +283,11 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren if (ApplicationManager.getApplication().isUnitTestMode()) { return; } - myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() { - @Override - public void valueChanged(TreeSelectionEvent e) { - if (myTree.isUnderQueueUpdate()) return; - syncRightPanel(); - if (isAutoScrollMode()) { - OpenSourceUtil.openSourcesFrom(DataManager.getInstance().getDataContext(InspectionResultsView.this), false); - } + myTree.getSelectionModel().addTreeSelectionListener(e -> { + if (myTree.isUnderQueueUpdate()) return; + syncRightPanel(); + if (isAutoScrollMode()) { + OpenSourceUtil.openSourcesFrom(DataManager.getInstance().getDataContext(this), false); } }); @@ -378,7 +372,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren add(westPanel, BorderLayout.WEST); } - @SuppressWarnings({"NonStaticInitializer"}) + @SuppressWarnings("NonStaticInitializer") private JComponent createRightActionsToolbar() { DefaultActionGroup specialGroup = new DefaultActionGroup(); specialGroup.add(myGlobalInspectionContext.getUIOptions().createGroupBySeverityAction(this)); @@ -489,7 +483,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren syncRightPanel(); } - public void openRightPanelIfNeed() { + void openRightPanelIfNeed() { if (mySplitter.getSecondComponent() == null) { syncRightPanel(); } @@ -652,10 +646,10 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren myPreviewEditor.getComponent().setBorder(IdeBorderFactory.createEmptyBorder()); return Pair.create(myPreviewEditor.getComponent(), myPreviewEditor); } - else if (selectedEntity == null) { + if (selectedEntity == null) { return Pair.create(new InspectionNodeInfo(myTree, myProject), null); } - else if (selectedEntity.isValid()) { + if (selectedEntity.isValid()) { return Pair.create(InspectionResultsViewUtil.getPreviewIsNotAvailable(selectedEntity), null); } return Pair.create(InspectionResultsViewUtil.getInvalidEntityLabel(selectedEntity), null); @@ -693,7 +687,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren @NotNull public Set getSuppressActions(InspectionToolWrapper wrapper) { - return mySuppressActions.computeIfAbsent(wrapper.getShortName(), (w) -> { + return mySuppressActions.computeIfAbsent(wrapper.getShortName(), __ -> { final SuppressIntentionAction[] actions = InspectionManagerEx.getSuppressActions(wrapper); return actions == null ? Collections.emptySet() : ContainerUtil.newLinkedHashSet(actions); }); @@ -717,29 +711,24 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren return myInspectionProfile; } - public void addProblemDescriptors(InspectionToolWrapper wrapper, RefEntity refElement, CommonProblemDescriptor[] descriptors) { + void addProblemDescriptors(InspectionToolWrapper wrapper, RefEntity refElement, CommonProblemDescriptor[] descriptors) { myTreeUpdater.submit((Runnable)() -> ReadAction.run(() -> { if (!isDisposed()) { ApplicationManager.getApplication().assertReadAccessAllowed(); synchronized (myTreeStructureUpdateLock) { - final InspectionNode toolNode; final AnalysisUIOptions uiOptions = myGlobalInspectionContext.getUIOptions(); final InspectionToolPresentation presentation = myGlobalInspectionContext.getPresentation(wrapper); if (presentation.getToolNode() == null) { addTool(wrapper, HighlightDisplayLevel.find(presentation.getSeverity((RefElement)refElement)), uiOptions.GROUP_BY_SEVERITY, isSingleInspectionRun()); } - toolNode = presentation.getToolNode(); + final InspectionNode toolNode = presentation.getToolNode(); LOG.assertTrue(toolNode != null); final Map problems = new HashMap<>(); problems.put(refElement, descriptors); final Map> contents = new HashMap<>(); final String groupName = refElement.getRefManager().getGroupName((RefElement)refElement); - Set content = contents.get(groupName); - if (content == null) { - content = new HashSet<>(); - contents.put(groupName, content); - } + Set content = contents.computeIfAbsent(groupName, __ -> new HashSet<>()); content.add(refElement); getProvider().appendToolNodeContent(myGlobalInspectionContext, @@ -1007,7 +996,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren return null; } - public void resetTree() { + void resetTree() { try { myTree.setQueueUpdate(true); final TreePath[] selectionPath = myTree.getSelectionPaths(); @@ -1015,7 +1004,8 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren ((DefaultTreeModel)myTree.getModel()).reload(); TreeUtil.restoreExpandedPaths(myTree, expandedPaths); myTree.setSelectionPaths(selectionPath); - } finally { + } + finally { myTree.setQueueUpdate(false); } } @@ -1165,7 +1155,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren } private class RerunAction extends AnAction { - public RerunAction(JComponent comp) { + RerunAction(JComponent comp) { super(InspectionsBundle.message("inspection.action.rerun"), InspectionsBundle.message("inspection.action.rerun"), AllIcons.Actions.Rerun); registerCustomShortcutSet(CommonShortcuts.getRerun(), comp); diff --git a/platform/util/src/com/intellij/util/containers/FactoryMap.java b/platform/util/src/com/intellij/util/containers/FactoryMap.java index 9ce70a794962..8f472a6d6db2 100644 --- a/platform/util/src/com/intellij/util/containers/FactoryMap.java +++ b/platform/util/src/com/intellij/util/containers/FactoryMap.java @@ -25,8 +25,6 @@ import org.jetbrains.annotations.Nullable; import java.util.*; -import static com.intellij.util.ObjectUtils.NULL; - /** * @author peter */ @@ -34,6 +32,7 @@ public abstract class FactoryMap implements Map { private static final RecursionGuard ourGuard = RecursionManager.createGuard("factoryMap"); protected Map myMap; + @NotNull protected Map createMap() { return new THashMap(); } @@ -51,37 +50,47 @@ public abstract class FactoryMap implements Map { @Override public V get(Object key) { final Map map = getMap(); - V value = map.get(getKey(key)); + K k = notNull(key); + V value = map.get(k); if (value == null) { RecursionGuard.StackStamp stamp = ourGuard.markStack(); value = create((K)key); if (stamp.mayCacheNow()) { - map.put((K)getKey(key), value == null ? (V)NULL : value); + V v = notNull(value); + map.put(k, v); } } - return value == NULL ? null : value; + return value == FAKE_NULL() ? null : value; } - private static K getKey(final K key) { - return key == null ? (K)NULL : key; + private static T FAKE_NULL() { + //noinspection unchecked + return (T)ObjectUtils.NULL; + } + + private static T notNull(final Object key) { + //noinspection unchecked + return key == null ? FactoryMap.FAKE_NULL() : (T)key; } @Override public final boolean containsKey(Object key) { - return myMap != null && myMap.containsKey(getKey(key)); + return myMap != null && myMap.containsKey(notNull(key)); } @Override public V put(K key, V value) { - V v = getMap().put(getKey(key), value == null ? (V)NULL : value); - return v == NULL ? null : v; + K k = notNull(key); + V v = notNull(value); + v = getMap().put(k, v); + return v == FAKE_NULL() ? null : v; } @Override public V remove(Object key) { if (myMap == null) return null; V v = myMap.remove(key); - return v == NULL ? null : v; + return v == FAKE_NULL() ? null : v; } @NotNull @@ -89,22 +98,22 @@ public abstract class FactoryMap implements Map { public Set keySet() { if (myMap == null) return Collections.emptySet(); final Set ts = myMap.keySet(); - //noinspection SuspiciousMethodCalls - if (ts.contains(NULL)) { + K nullKey = FAKE_NULL(); + if (ts.contains(nullKey)) { final HashSet hashSet = new HashSet(ts); - //noinspection SuspiciousMethodCalls - hashSet.remove(NULL); + hashSet.remove(nullKey); hashSet.add(null); return hashSet; } return ts; } + @NotNull public Collection notNullValues() { if (myMap == null) return Collections.emptyList(); final Collection values = ContainerUtil.newArrayList(myMap.values()); for (Iterator iterator = values.iterator(); iterator.hasNext();) { - if (iterator.next() == NULL) { + if (iterator.next() == FAKE_NULL()) { iterator.remove(); } } @@ -113,7 +122,7 @@ public abstract class FactoryMap implements Map { public boolean removeValue(Object value) { if (myMap == null) return false; - Object t = ObjectUtils.notNull(value, NULL); + Object t = ObjectUtils.notNull(value, FAKE_NULL()); //noinspection SuspiciousMethodCalls return myMap.values().remove(t); }