From d37f6e87c721d7b89f1527939b423bc9567a4c4e Mon Sep 17 00:00:00 2001 From: "Gregory.Shrago" Date: Fri, 10 Mar 2023 15:51:56 +0100 Subject: [PATCH] EA-807031 - REWA: ApplicationImpl.throwThreadAccessException GitOrigin-RevId: 08fe7eeb55f864a27c71d68227a3439e7d7a6cd2 --- .../ui/InspectionResultsView.java | 24 +++++++++++------ .../codeInspection/ui/InspectionTree.java | 26 +++++++++++-------- 2 files changed, 31 insertions(+), 19 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 3c1299aa8c66..2bd6ed72dc34 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java @@ -701,20 +701,28 @@ public class InspectionResultsView extends JPanel implements Disposable, DataPro @Override public Object getData(@NotNull String dataId) { - if (PlatformCoreDataKeys.HELP_ID.is(dataId)) return HELP_ID; - if (DATA_KEY.is(dataId)) return this; - if (ExclusionHandler.EXCLUSION_HANDLER.is(dataId)) return myExclusionHandler; - if (!ApplicationManager.getApplication().isDispatchThread()) return null; - TreePath[] paths = myTree.getSelectionPaths(); - if (paths == null || paths.length == 0) return null; - + if (PlatformCoreDataKeys.HELP_ID.is(dataId)) { + return HELP_ID; + } + if (DATA_KEY.is(dataId)) { + return this; + } + if (ExclusionHandler.EXCLUSION_HANDLER.is(dataId)) { + return myExclusionHandler; + } if (PlatformCoreDataKeys.SELECTED_ITEM.is(dataId)) { + TreePath[] paths = myTree.getSelectionPaths(); + if (paths == null || paths.length == 0) return null; return paths[0].getLastPathComponent(); } if (PlatformCoreDataKeys.SELECTED_ITEMS.is(dataId)) { + TreePath[] paths = myTree.getSelectionPaths(); + if (paths == null || paths.length == 0) return null; return ContainerUtil.map2Array(paths, p -> p.getLastPathComponent()); } if (PlatformCoreDataKeys.BGT_DATA_PROVIDER.is(dataId)) { + TreePath[] paths = myTree.getSelectionPaths(); + if (paths == null || paths.length == 0) return null; return (DataProvider)slowId -> getSlowData(slowId, paths); } return null; @@ -723,7 +731,7 @@ public class InspectionResultsView extends JPanel implements Disposable, DataPro private @Nullable Object getSlowData(@NotNull String dataId, TreePath @NotNull [] paths) { if (paths.length > 1) { if (PlatformCoreDataKeys.PSI_ELEMENT_ARRAY.is(dataId)) { - RefEntity[] refElements = myTree.getSelectedElements(); + RefEntity[] refElements = myTree.getElementsFromSelection(paths); List psiElements = new ArrayList<>(); for (RefEntity refElement : refElements) { PsiElement psiElement = refElement instanceof RefElement ? ((RefElement)refElement).getPsiElement() : null; 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 98fb5c615283..e2b503d3a805 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTree.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTree.java @@ -156,10 +156,13 @@ public class InspectionTree extends Tree { @Nullable public InspectionToolWrapper getSelectedToolWrapper(boolean allowDummy) { + return getSelectedToolWrapper(allowDummy, getSelectionPaths()); + } + + @Nullable InspectionToolWrapper getSelectedToolWrapper(boolean allowDummy, TreePath @Nullable [] paths) { InspectionProfileImpl profile = myView.getCurrentProfile(); if (profile == null) return null; String singleToolName = profile.getSingleTool(); - final TreePath[] paths = getSelectionPaths(); if (paths == null) { if (singleToolName != null) { InspectionToolWrapper tool = profile.getInspectionTool(singleToolName, myView.getProject()); @@ -277,18 +280,19 @@ public class InspectionTree extends Tree { public RefEntity @NotNull [] getSelectedElements() { TreePath[] selectionPaths = getSelectionPaths(); - if (selectionPaths != null) { - InspectionToolWrapper toolWrapper = getSelectedToolWrapper(true); - if (toolWrapper == null) return RefEntity.EMPTY_ELEMENTS_ARRAY; + if (selectionPaths == null) return RefEntity.EMPTY_ELEMENTS_ARRAY; + return getElementsFromSelection(selectionPaths); + } - Set result = new LinkedHashSet<>(); - for (TreePath selectionPath : selectionPaths) { - final InspectionTreeNode node = (InspectionTreeNode)selectionPath.getLastPathComponent(); - addElementsInNode(node, result); - } - return ArrayUtil.reverseArray(result.toArray(RefEntity.EMPTY_ELEMENTS_ARRAY)); + RefEntity @NotNull [] getElementsFromSelection(TreePath @NotNull [] selectionPaths) { + InspectionToolWrapper toolWrapper = getSelectedToolWrapper(true, selectionPaths); + if (toolWrapper == null) return RefEntity.EMPTY_ELEMENTS_ARRAY; + Set result = new LinkedHashSet<>(); + for (TreePath selectionPath : selectionPaths) { + final InspectionTreeNode node = (InspectionTreeNode)selectionPath.getLastPathComponent(); + addElementsInNode(node, result); } - return RefEntity.EMPTY_ELEMENTS_ARRAY; + return ArrayUtil.reverseArray(result.toArray(RefEntity.EMPTY_ELEMENTS_ARRAY)); } @NotNull