From 92047f763daff287b4b1b0d5d5c223497d875e58 Mon Sep 17 00:00:00 2001 From: "Gregory.Shrago" Date: Mon, 1 Jul 2024 17:44:57 +0400 Subject: [PATCH] migrate `getData` to `uiDataSnapshot`: java GitOrigin-RevId: 6917901f5fe425ee883779c2fc1775960c2af540 --- .../view/InternalCompilerRefServiceView.java | 29 +++++------- .../debugger/ui/impl/DebuggerTreePanel.java | 12 ++--- .../debugger/ui/impl/ThreadsPanel.java | 13 ++---- .../debugger/ui/impl/watch/DebuggerTree.java | 13 ++---- .../debugger/ui/overhead/OverheadView.java | 27 +++-------- .../actions/DiscoveredTestsTree.java | 33 ++++--------- .../roots/ui/configuration/ModuleEditor.java | 12 ++--- .../ProjectStructureConfigurable.java | 14 ++---- .../artifacts/ArtifactEditorImpl.java | 12 ++--- .../ModuleStructureConfigurable.java | 22 ++++----- .../extractMethod/preview/PreviewPanel.java | 46 ++++++++----------- .../typeMigration/ui/MigrationPanel.java | 29 +++++------- .../ui/CyclicDependenciesPanel.java | 10 ++-- .../intellij/unscramble/ThreadDumpPanel.java | 10 ++-- .../config/ui/MethodParameterPanel.java | 14 +++--- 15 files changed, 108 insertions(+), 188 deletions(-) diff --git a/java/compiler/impl/src/com/intellij/compiler/backwardRefs/view/InternalCompilerRefServiceView.java b/java/compiler/impl/src/com/intellij/compiler/backwardRefs/view/InternalCompilerRefServiceView.java index 0cef7a5b5eb3..f45a3afcc56e 100644 --- a/java/compiler/impl/src/com/intellij/compiler/backwardRefs/view/InternalCompilerRefServiceView.java +++ b/java/compiler/impl/src/com/intellij/compiler/backwardRefs/view/InternalCompilerRefServiceView.java @@ -2,7 +2,8 @@ package com.intellij.compiler.backwardRefs.view; import com.intellij.openapi.actionSystem.CommonDataKeys; -import com.intellij.openapi.actionSystem.DataProvider; +import com.intellij.openapi.actionSystem.DataSink; +import com.intellij.openapi.actionSystem.UiDataProvider; import com.intellij.openapi.compiler.JavaCompilerBundle; import com.intellij.openapi.fileEditor.OpenFileDescriptor; import com.intellij.openapi.project.Project; @@ -22,8 +23,8 @@ import com.intellij.ui.SimpleTextAttributes; import com.intellij.ui.components.JBScrollPane; import com.intellij.ui.content.impl.ContentImpl; import com.intellij.ui.treeStructure.Tree; +import com.intellij.util.ui.tree.TreeUtil; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.tree.DefaultMutableTreeNode; @@ -31,7 +32,7 @@ import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreePath; import java.awt.*; -public class InternalCompilerRefServiceView extends JPanel implements DataProvider { +public class InternalCompilerRefServiceView extends JPanel implements UiDataProvider { private static final String TOOL_WINDOW_ID = "Compiler Reference View"; private final Tree myTree; private final Project myProject; @@ -73,22 +74,14 @@ public class InternalCompilerRefServiceView extends JPanel implements DataProvid add(new JBScrollPane(myTree)); } - @Nullable @Override - public Object getData(@NotNull String dataId) { - if (CommonDataKeys.NAVIGATABLE.is(dataId)) { - final TreePath path = myTree.getSelectionPath(); - if (path != null) { - final Object usrObject = ((DefaultMutableTreeNode)path.getLastPathComponent()).getUserObject(); - if (usrObject instanceof VirtualFile) { - return new OpenFileDescriptor(myProject, (VirtualFile)usrObject); - } - else if (usrObject instanceof NavigatablePsiElement) { - return usrObject; - } - } - } - return null; + public void uiDataSnapshot(@NotNull DataSink sink) { + TreePath path = myTree.getSelectionPath(); + Object usrObject = TreeUtil.getLastUserObject(path); + sink.lazy(CommonDataKeys.NAVIGATABLE, () -> { + return usrObject instanceof VirtualFile o ? new OpenFileDescriptor(myProject, o) : + usrObject instanceof NavigatablePsiElement o ? o : null; + }); } public static void showFindUsages(CompilerReferenceFindUsagesTestInfo info, PsiElement element) { diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/impl/DebuggerTreePanel.java b/java/debugger/impl/src/com/intellij/debugger/ui/impl/DebuggerTreePanel.java index 90810fb8c866..a72699500fd9 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/impl/DebuggerTreePanel.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/impl/DebuggerTreePanel.java @@ -12,7 +12,8 @@ import com.intellij.debugger.ui.impl.watch.DebuggerTree; import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.ActionPopupMenu; import com.intellij.openapi.actionSystem.DataKey; -import com.intellij.openapi.actionSystem.DataProvider; +import com.intellij.openapi.actionSystem.DataSink; +import com.intellij.openapi.actionSystem.UiDataProvider; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.wm.IdeFocusManager; @@ -27,7 +28,7 @@ import org.jetbrains.annotations.Nullable; import java.awt.*; -public abstract class DebuggerTreePanel extends UpdatableDebuggerView implements DataProvider, Disposable { +public abstract class DebuggerTreePanel extends UpdatableDebuggerView implements UiDataProvider, Disposable { public static final DataKey DATA_KEY = DataKey.create("DebuggerPanel"); private final SingleAlarm myRebuildAlarm = new SingleAlarm(() -> { @@ -124,11 +125,8 @@ public abstract class DebuggerTreePanel extends UpdatableDebuggerView implements } @Override - public Object getData(@NotNull String dataId) { - if (DATA_KEY.is(dataId)) { - return this; - } - return null; + public void uiDataSnapshot(@NotNull DataSink sink) { + sink.set(DATA_KEY, this); } @Override diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/impl/ThreadsPanel.java b/java/debugger/impl/src/com/intellij/debugger/ui/impl/ThreadsPanel.java index 4eeea4970727..bfdaf3ce73ce 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/impl/ThreadsPanel.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/impl/ThreadsPanel.java @@ -13,10 +13,7 @@ import com.intellij.debugger.ui.impl.watch.DebuggerTree; import com.intellij.debugger.ui.impl.watch.DebuggerTreeNodeImpl; import com.intellij.ide.DataManager; import com.intellij.openapi.Disposable; -import com.intellij.openapi.actionSystem.ActionManager; -import com.intellij.openapi.actionSystem.ActionPopupMenu; -import com.intellij.openapi.actionSystem.DefaultActionGroup; -import com.intellij.openapi.actionSystem.PlatformCoreDataKeys; +import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Disposer; @@ -158,11 +155,9 @@ public class ThreadsPanel extends DebuggerTreePanel { } @Override - public Object getData(@NotNull String dataId) { - if (PlatformCoreDataKeys.HELP_ID.is(dataId)) { - return HELP_ID; - } - return super.getData(dataId); + public void uiDataSnapshot(@NotNull DataSink sink) { + super.uiDataSnapshot(sink); + sink.set(PlatformCoreDataKeys.HELP_ID, HELP_ID); } public ThreadsDebuggerTree getThreadsTree() { diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/DebuggerTree.java b/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/DebuggerTree.java index f6f7ab4c0f69..821a198c0ed7 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/DebuggerTree.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/DebuggerTree.java @@ -25,7 +25,8 @@ import com.intellij.debugger.ui.impl.tree.TreeBuilderNode; import com.intellij.ide.dnd.aware.DnDAwareTree; import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.DataKey; -import com.intellij.openapi.actionSystem.DataProvider; +import com.intellij.openapi.actionSystem.DataSink; +import com.intellij.openapi.actionSystem.UiDataProvider; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Key; @@ -45,7 +46,7 @@ import java.util.Enumeration; import java.util.LinkedList; import java.util.List; -public abstract class DebuggerTree extends DnDAwareTree implements DataProvider, Disposable { +public abstract class DebuggerTree extends DnDAwareTree implements UiDataProvider, Disposable { private static final Logger LOG = Logger.getInstance(DebuggerTree.class); protected static final Key VISIBLE_RECT = Key.create("VISIBLE_RECT"); @@ -114,14 +115,10 @@ public abstract class DebuggerTree extends DnDAwareTree implements DataProvider, } @Override - public Object getData(@NotNull String dataId) { - if (DATA_KEY.is(dataId)) { - return this; - } - return null; + public void uiDataSnapshot(@NotNull DataSink sink) { + sink.set(DATA_KEY, this); } - private void buildNode(final DebuggerTreeNodeImpl node) { if (node == null || node.getDescriptor() == null) { return; diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/overhead/OverheadView.java b/java/debugger/impl/src/com/intellij/debugger/ui/overhead/OverheadView.java index 567425527aa4..708e93414429 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/overhead/OverheadView.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/overhead/OverheadView.java @@ -23,7 +23,6 @@ import com.intellij.util.ui.update.Update; import com.intellij.xdebugger.breakpoints.XBreakpoint; import com.intellij.xdebugger.impl.ui.DebuggerUIUtil; import one.util.streamex.StreamEx; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -39,7 +38,7 @@ import java.util.function.Function; import static com.intellij.util.containers.ContainerUtil.getFirstItem; import static com.intellij.util.containers.ContainerUtil.mapNotNull; -public class OverheadView extends BorderLayoutPanel implements Disposable, DataProvider { +public class OverheadView extends BorderLayoutPanel implements Disposable, UiDataProvider { @NotNull private final DebugProcessImpl myProcess; static final EnabledColumnInfo ENABLED_COLUMN = new EnabledColumnInfo(); @@ -143,25 +142,13 @@ public class OverheadView extends BorderLayoutPanel implements Disposable, DataP return myTable; } - @Nullable @Override - public Object getData(@NotNull String dataId) { - if (PlatformCoreDataKeys.BGT_DATA_PROVIDER.is(dataId)) { - var selectedBreakpoints = getSelectedBreakpoints(); // gather in EDT - return (DataProvider)realDataId -> getSlowData(selectedBreakpoints, realDataId); - } - return null; - } - - @Nullable - private static Object getSlowData(@NotNull List selected, @NonNls String dataId) { - if (CommonDataKeys.NAVIGATABLE_ARRAY.is(dataId)) { - List navigatables = mapNotNull(selected, XBreakpoint::getNavigatable); - if (!navigatables.isEmpty()) { - return navigatables.toArray(Navigatable.EMPTY_NAVIGATABLE_ARRAY); - } - } - return null; + public void uiDataSnapshot(@NotNull DataSink sink) { + var selection = getSelectedBreakpoints(); + sink.lazy(CommonDataKeys.NAVIGATABLE_ARRAY, () -> { + List navigatables = mapNotNull(selection, XBreakpoint::getNavigatable); + return navigatables.isEmpty() ? null : navigatables.toArray(Navigatable.EMPTY_NAVIGATABLE_ARRAY); + }); } private static class EnabledColumnInfo extends ColumnInfo { diff --git a/java/execution/impl/src/com/intellij/execution/testDiscovery/actions/DiscoveredTestsTree.java b/java/execution/impl/src/com/intellij/execution/testDiscovery/actions/DiscoveredTestsTree.java index 4caac892fb65..7714072e1f51 100644 --- a/java/execution/impl/src/com/intellij/execution/testDiscovery/actions/DiscoveredTestsTree.java +++ b/java/execution/impl/src/com/intellij/execution/testDiscovery/actions/DiscoveredTestsTree.java @@ -5,10 +5,7 @@ import com.intellij.execution.ExecutionBundle; import com.intellij.ide.CommonActionsManager; import com.intellij.ide.DefaultTreeExpander; import com.intellij.openapi.Disposable; -import com.intellij.openapi.actionSystem.CommonDataKeys; -import com.intellij.openapi.actionSystem.DataProvider; -import com.intellij.openapi.actionSystem.LangDataKeys; -import com.intellij.openapi.actionSystem.PlatformCoreDataKeys; +import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.compiler.JavaCompilerBundle; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleUtilCore; @@ -42,7 +39,7 @@ import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; -class DiscoveredTestsTree extends Tree implements DataProvider, Disposable { +class DiscoveredTestsTree extends Tree implements UiDataProvider, Disposable { private final DiscoveredTestsTreeModel myModel; DiscoveredTestsTree(String title) { @@ -155,25 +152,16 @@ class DiscoveredTestsTree extends Tree implements DataProvider, Disposable { return myModel.getTestClassesCount(); } - @Nullable @Override - public Object getData(@NotNull String dataId) { - if (PlatformCoreDataKeys.BGT_DATA_PROVIDER.is(dataId)) { - TreePath[] paths = getSelectionPaths(); - return (DataProvider)slowId -> getSlowData(slowId, paths); - } - else if (LangDataKeys.POSITION_ADJUSTER_POPUP.is(dataId)) { - return PopupUtil.getPopupContainerFor(this); - } - return null; - } + public void uiDataSnapshot(@NotNull DataSink sink) { + TreePath[] paths = getSelectionPaths(); + sink.set(LangDataKeys.POSITION_ADJUSTER_POPUP, PopupUtil.getPopupContainerFor(this)); - private @Nullable Object getSlowData(@NotNull String dataId, TreePath @Nullable [] paths) { - if (paths == null || paths.length == 0) return null; - if (CommonDataKeys.PSI_ELEMENT.is(dataId)) { + if (paths == null || paths.length == 0) return; + sink.lazy(CommonDataKeys.PSI_ELEMENT, () -> { return obj2psi(paths[0].getLastPathComponent()); - } - else if (PlatformCoreDataKeys.PSI_ELEMENT_ARRAY.is(dataId)) { + }); + sink.lazy(PlatformCoreDataKeys.PSI_ELEMENT_ARRAY, () -> { List result = new SmartList<>(); TreeModel model = getModel(); for (TreePath p : paths) { @@ -195,7 +183,6 @@ class DiscoveredTestsTree extends Tree implements DataProvider, Disposable { } } return result.toArray(PsiElement.EMPTY_ARRAY); - } - return null; + }); } } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ModuleEditor.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ModuleEditor.java index 194d398e106b..e810dc0f235e 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ModuleEditor.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ModuleEditor.java @@ -4,8 +4,9 @@ package com.intellij.openapi.roots.ui.configuration; import com.intellij.facet.impl.ProjectFacetsConfigurator; import com.intellij.ide.JavaUiBundle; import com.intellij.openapi.Disposable; -import com.intellij.openapi.actionSystem.DataProvider; +import com.intellij.openapi.actionSystem.DataSink; import com.intellij.openapi.actionSystem.LangDataKeys; +import com.intellij.openapi.actionSystem.UiDataProvider; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.openapi.module.Module; @@ -547,17 +548,14 @@ public abstract class ModuleEditor implements Place.Navigator, Disposable { updateImportedModelWarning(); } - private class ModuleEditorPanel extends JPanel implements DataProvider{ + private class ModuleEditorPanel extends JPanel implements UiDataProvider { ModuleEditorPanel() { super(new BorderLayout()); } @Override - public Object getData(@NotNull String dataId) { - if (LangDataKeys.MODULE_CONTEXT.is(dataId)) { - return getModule(); - } - return null; + public void uiDataSnapshot(@NotNull DataSink sink) { + sink.set(LangDataKeys.MODULE_CONTEXT, getModule()); } } } \ No newline at end of file diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectStructureConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectStructureConfigurable.java index 6ef861231bdb..6b2c9b6f0d81 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectStructureConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectStructureConfigurable.java @@ -615,21 +615,15 @@ public class ProjectStructureConfigurable implements SearchableConfigurable, Pla return myContext; } - private class MyPanel extends JPanel implements DataProvider { + private class MyPanel extends JPanel implements UiDataProvider { MyPanel() { super(new BorderLayout()); } @Override - @Nullable - public Object getData(@NotNull @NonNls final String dataId) { - if (KEY.is(dataId)) { - return ProjectStructureConfigurable.this; - } else if (History.KEY.is(dataId)) { - return getHistory(); - } else { - return null; - } + public void uiDataSnapshot(@NotNull DataSink sink) { + sink.set(KEY, ProjectStructureConfigurable.this); + sink.set(History.KEY, getHistory()); } @Override diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactEditorImpl.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactEditorImpl.java index 2731a42c9045..233c3d24aa5d 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactEditorImpl.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactEditorImpl.java @@ -58,7 +58,7 @@ import java.util.Collections; import java.util.List; import java.util.Objects; -public class ArtifactEditorImpl implements ArtifactEditorEx, DataProvider { +public class ArtifactEditorImpl implements ArtifactEditorEx, UiDataProvider { private JPanel myMainPanel; private JCheckBox myBuildOnMakeCheckBox; private TextFieldWithBrowseButton myOutputDirectoryField; @@ -189,7 +189,7 @@ public class ArtifactEditorImpl implements ArtifactEditorEx, DataProvider { public JComponent createMainComponent() { myLayoutTreeComponent.initTree(); - DataManager.registerDataProvider(myMainPanel, this); + DataManager.registerDataProvider(myMainPanel, (EdtNoGetDataProvider)this::uiDataSnapshot); myErrorPanelPlace.add(myValidationManager.getMainErrorPanel(), BorderLayout.CENTER); @@ -549,13 +549,9 @@ public class ArtifactEditorImpl implements ArtifactEditorEx, DataProvider { return helpId != null ? helpId : "reference.settingsdialog.project.structure.artifacts"; } - @Nullable @Override - public Object getData(@NotNull String dataId) { - if (ARTIFACTS_EDITOR_KEY.is(dataId)) { - return this; - } - return null; + public void uiDataSnapshot(@NotNull DataSink sink) { + sink.set(ARTIFACTS_EDITOR_KEY, this); } } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureConfigurable.java index f48fb3de4ab6..5bd35e2e59c5 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureConfigurable.java @@ -38,7 +38,10 @@ import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ModuleProj import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureDaemonAnalyzer; import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElement; import com.intellij.openapi.ui.*; -import com.intellij.openapi.util.*; +import com.intellij.openapi.util.ActionCallback; +import com.intellij.openapi.util.Comparing; +import com.intellij.openapi.util.NullableComputable; +import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.io.NioFiles; import com.intellij.openapi.util.text.StringUtil; @@ -803,24 +806,21 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple } } - private class MyDataProviderWrapper extends JPanel implements DataProvider { + private class MyDataProviderWrapper extends JPanel implements UiDataProvider { MyDataProviderWrapper(final JComponent component) { super(new BorderLayout()); add(component, BorderLayout.CENTER); } @Override - @Nullable - public Object getData(@NotNull @NonNls String dataId) { - return ValueKey.match(dataId) - .ifEq(LangDataKeys.MODULE_CONTEXT_ARRAY).thenGet(this::getModuleContexts) - .ifEq(LangDataKeys.MODULE_CONTEXT).thenGet(() -> getSelectedModule()) - .ifEq(LangDataKeys.MODIFIABLE_MODULE_MODEL).thenGet(() -> myContext.myModulesConfigurator.getModuleModel()) - .ifEq(PlatformCoreDataKeys.SELECTED_ITEM).thenGet(() -> getSelectedObject()) - .orNull(); + public void uiDataSnapshot(@NotNull DataSink sink) { + sink.set(LangDataKeys.MODULE_CONTEXT_ARRAY, getModuleContexts()); + sink.set(LangDataKeys.MODULE_CONTEXT, getSelectedModule()); + sink.set(LangDataKeys.MODIFIABLE_MODULE_MODEL, myContext.myModulesConfigurator.getModuleModel()); + sink.set(PlatformCoreDataKeys.SELECTED_ITEM, getSelectedObject()); } - private Module[] getModuleContexts() { + private Module @Nullable [] getModuleContexts() { final TreePath[] paths = myTree.getSelectionPaths(); Set modules = new LinkedHashSet<>(); if (paths != null) { diff --git a/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/preview/PreviewPanel.java b/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/preview/PreviewPanel.java index a21387b8a9b6..7cd875e1c9c3 100644 --- a/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/preview/PreviewPanel.java +++ b/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/preview/PreviewPanel.java @@ -6,7 +6,8 @@ import com.intellij.ide.actions.exclusion.ExclusionHandler; import com.intellij.java.refactoring.JavaRefactoringBundle; import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.CommonDataKeys; -import com.intellij.openapi.actionSystem.DataProvider; +import com.intellij.openapi.actionSystem.DataSink; +import com.intellij.openapi.actionSystem.UiDataProvider; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.DumbService; import com.intellij.openapi.project.Project; @@ -26,7 +27,6 @@ import com.intellij.util.ui.DialogUtil; import com.intellij.util.ui.components.BorderLayoutPanel; import one.util.streamex.StreamEx; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.tree.DefaultMutableTreeNode; @@ -34,7 +34,7 @@ import java.awt.*; import java.util.List; import java.util.Optional; -class PreviewPanel extends BorderLayoutPanel implements Disposable, DataProvider { +class PreviewPanel extends BorderLayoutPanel implements Disposable, UiDataProvider { private final Project myProject; private final PreviewTree myTree; private final ExclusionHandler myExclusionHandler; @@ -74,31 +74,23 @@ class PreviewPanel extends BorderLayoutPanel implements Disposable, DataProvider Disposer.register(this, myDiffPanel); } - @Nullable @Override - public Object getData(@NotNull String dataId) { - if (ExclusionHandler.EXCLUSION_HANDLER.is(dataId)) { - return myExclusionHandler; - } - if (CommonDataKeys.NAVIGATABLE.is(dataId)) { - List selectedNodes = myTree.getSelectedNodes(); - if (selectedNodes.size() == 1) { - return Optional.ofNullable(selectedNodes.get(0)) - .map(FragmentNode::getNavigatable) - .map(n -> new Navigatable[]{n}) - .orElse(null); - } - } - if (CommonDataKeys.NAVIGATABLE_ARRAY.is(dataId)) { - List selectedNodes = myTree.getSelectedNodes(); - if (!selectedNodes.isEmpty()) { - return StreamEx.of(selectedNodes) - .map(FragmentNode::getNavigatable) - .nonNull() - .toArray(Navigatable[]::new); - } - } - return null; + public void uiDataSnapshot(@NotNull DataSink sink) { + List selectedNodes = myTree.getSelectedNodes(); + sink.set(ExclusionHandler.EXCLUSION_HANDLER, myExclusionHandler); + sink.lazy(CommonDataKeys.NAVIGATABLE, () -> { + if (selectedNodes.size() != 1) return null; + return Optional.ofNullable(selectedNodes.get(0)) + .map(FragmentNode::getNavigatable) + .orElse(null); + }); + sink.lazy(CommonDataKeys.NAVIGATABLE_ARRAY, () -> { + if (selectedNodes.isEmpty()) return null; + return StreamEx.of(selectedNodes) + .map(FragmentNode::getNavigatable) + .nonNull() + .toArray(Navigatable[]::new); + }); } public void setContent(Content content) { diff --git a/java/java-impl-refactorings/src/com/intellij/refactoring/typeMigration/ui/MigrationPanel.java b/java/java-impl-refactorings/src/com/intellij/refactoring/typeMigration/ui/MigrationPanel.java index 12b6eb706819..acf5c4914566 100644 --- a/java/java-impl-refactorings/src/com/intellij/refactoring/typeMigration/ui/MigrationPanel.java +++ b/java/java-impl-refactorings/src/com/intellij/refactoring/typeMigration/ui/MigrationPanel.java @@ -41,7 +41,6 @@ import com.intellij.usages.UsagePresentation; import com.intellij.util.EditSourceOnDoubleClickHandler; import com.intellij.util.ui.JBUI; import com.intellij.util.ui.tree.TreeUtil; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -266,7 +265,7 @@ public final class MigrationPanel extends JPanel implements Disposable { Disposer.register(content, this); } - private static final class MyTree extends Tree implements DataProvider { + private static final class MyTree extends Tree implements UiDataProvider { @Override protected void paintComponent(final Graphics g) { DuplicateNodeRenderer.paintDuplicateNodesBackground(g, this); @@ -274,24 +273,18 @@ public final class MigrationPanel extends JPanel implements Disposable { } @Override - public Object getData(@NotNull @NonNls final String dataId) { - if (PlatformCoreDataKeys.BGT_DATA_PROVIDER.is(dataId)) { - final DefaultMutableTreeNode[] selectedNodes = getSelectedNodes(DefaultMutableTreeNode.class, null); - if (selectedNodes.length == 1 && selectedNodes[0].getUserObject() instanceof MigrationNode node) { - return (DataProvider)slowId -> CommonDataKeys.PSI_ELEMENT.is(dataId) ? node.getInfo().getElement() : null; + public void uiDataSnapshot(@NotNull DataSink sink) { + DefaultMutableTreeNode[] selectedNodes = getSelectedNodes(DefaultMutableTreeNode.class, null); + if (selectedNodes.length == 1 && selectedNodes[0].getUserObject() instanceof MigrationNode node) { + sink.lazy(CommonDataKeys.PSI_ELEMENT, () -> node.getInfo().getElement()); + } + Set usageInfos = new HashSet<>(); + for (DefaultMutableTreeNode selectedNode : selectedNodes) { + if (selectedNode.getUserObject() instanceof MigrationNode node) { + collectInfos(usageInfos, node); } } - if (MIGRATION_USAGES_KEY.is(dataId)) { - DefaultMutableTreeNode[] selectedNodes = getSelectedNodes(DefaultMutableTreeNode.class, null); - final Set usageInfos = new HashSet<>(); - for (DefaultMutableTreeNode selectedNode : selectedNodes) { - if (selectedNode.getUserObject() instanceof MigrationNode node) { - collectInfos(usageInfos, node); - } - } - return usageInfos.toArray(new TypeMigrationUsageInfo[0]); - } - return null; + sink.set(MIGRATION_USAGES_KEY, usageInfos.toArray(new TypeMigrationUsageInfo[0])); } private static void collectInfos(final Set usageInfos, final MigrationNode currentNode) { diff --git a/java/java-impl/src/com/intellij/cyclicDependencies/ui/CyclicDependenciesPanel.java b/java/java-impl/src/com/intellij/cyclicDependencies/ui/CyclicDependenciesPanel.java index 16c2edd87380..61221512cd8b 100644 --- a/java/java-impl/src/com/intellij/cyclicDependencies/ui/CyclicDependenciesPanel.java +++ b/java/java-impl/src/com/intellij/cyclicDependencies/ui/CyclicDependenciesPanel.java @@ -25,7 +25,6 @@ import com.intellij.ui.content.Content; import com.intellij.ui.treeStructure.Tree; import com.intellij.util.EditSourceOnDoubleClickHandler; import com.intellij.util.ui.tree.TreeUtil; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -38,7 +37,7 @@ import java.awt.*; import java.util.List; import java.util.*; -public final class CyclicDependenciesPanel extends JPanel implements Disposable, DataProvider { +public final class CyclicDependenciesPanel extends JPanel implements Disposable, UiDataProvider { private static final Set EMPTY_FILE_SET = new HashSet<>(0); private final HashMap>> myDependencies; @@ -337,11 +336,8 @@ public final class CyclicDependenciesPanel extends JPanel implements Disposable, } @Override - public @Nullable @NonNls Object getData(@NotNull @NonNls String dataId) { - if (PlatformCoreDataKeys.HELP_ID.is(dataId)) { - return "dependency.viewer.tool.window"; - } - return null; + public void uiDataSnapshot(@NotNull DataSink sink) { + sink.set(PlatformCoreDataKeys.HELP_ID, "dependency.viewer.tool.window"); } private class MyTreeCellRenderer extends ColoredTreeCellRenderer { diff --git a/java/java-impl/src/com/intellij/unscramble/ThreadDumpPanel.java b/java/java-impl/src/com/intellij/unscramble/ThreadDumpPanel.java index 554d8e53cd50..6d4cae9e9aca 100644 --- a/java/java-impl/src/com/intellij/unscramble/ThreadDumpPanel.java +++ b/java/java-impl/src/com/intellij/unscramble/ThreadDumpPanel.java @@ -32,7 +32,6 @@ import com.intellij.util.PlatformIcons; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.event.DocumentEvent; @@ -51,7 +50,7 @@ import static com.intellij.icons.AllIcons.Debugger.ThreadStates.*; * @author Jeka * @author Konstantin Bulenkov */ -public final class ThreadDumpPanel extends JPanel implements DataProvider { +public final class ThreadDumpPanel extends JPanel implements UiDataProvider { private static final Icon PAUSE_ICON_DAEMON = LayeredIcon.layeredIcon(() -> new Icon[]{AllIcons.Actions.Pause, Daemon_sign}); private static final Icon LOCKED_ICON_DAEMON = LayeredIcon.layeredIcon(() -> new Icon[]{AllIcons.Debugger.MuteBreakpoints, Daemon_sign}); private static final Icon RUNNING_ICON_DAEMON = LayeredIcon.layeredIcon(() -> new Icon[]{AllIcons.Actions.Resume, Daemon_sign}); @@ -163,11 +162,8 @@ public final class ThreadDumpPanel extends JPanel implements DataProvider { } @Override - public @Nullable Object getData(@NotNull @NonNls String dataId) { - if (PlatformDataKeys.EXPORTER_TO_TEXT_FILE.is(dataId)) { - return myExporterToTextFile; - } - return null; + public void uiDataSnapshot(@NotNull DataSink sink) { + sink.set(PlatformDataKeys.EXPORTER_TO_TEXT_FILE, myExporterToTextFile); } private void updateThreadList() { diff --git a/plugins/IntelliLang/java-support/org/intellij/plugins/intelliLang/inject/config/ui/MethodParameterPanel.java b/plugins/IntelliLang/java-support/org/intellij/plugins/intelliLang/inject/config/ui/MethodParameterPanel.java index dd565c05de19..63dd3d8d3a37 100644 --- a/plugins/IntelliLang/java-support/org/intellij/plugins/intelliLang/inject/config/ui/MethodParameterPanel.java +++ b/plugins/IntelliLang/java-support/org/intellij/plugins/intelliLang/inject/config/ui/MethodParameterPanel.java @@ -373,19 +373,17 @@ public final class MethodParameterPanel extends AbstractInjectionPanel { + return userObject instanceof PsiElement o ? o : null; + }); } }