diff --git a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/ArrayAction.java b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/ArrayAction.java index 06ad3d7d16..f610233737 100644 --- a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/ArrayAction.java +++ b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/ArrayAction.java @@ -40,8 +40,8 @@ import java.util.List; public abstract class ArrayAction extends DebuggerAction { - @RequiredUIAccess @Override + @RequiredUIAccess public void actionPerformed(@Nonnull AnActionEvent e) { DebuggerContextImpl debuggerContext = DebuggerAction.getDebuggerContext(e.getDataContext()); @@ -55,7 +55,7 @@ public void actionPerformed(@Nonnull AnActionEvent e) { return; } - final XValueNode node = tree.getSelectedNode(); + XValueNode node = tree.getSelectedNode(); if (node == null) { return; } @@ -69,13 +69,22 @@ public void actionPerformed(@Nonnull AnActionEvent e) { //String label = selectedNode.toString(); //int index = label.indexOf('='); //if (index > 0) { - // title = title + " " + label.substring(index); + // title = title + " " + label.substring(index); //} - createNewRenderer(node, renderer, debuggerContext, node.getName()).doWhenDone(newRenderer -> setArrayRenderer(newRenderer, node, debuggerContext)); + createNewRenderer(node, renderer, debuggerContext, node.getName()).doWhenDone(newRenderer -> setArrayRenderer( + newRenderer, + node, + debuggerContext + )); } @Nonnull - protected abstract AsyncResult createNewRenderer(XValueNode node, ArrayRenderer original, @Nonnull DebuggerContextImpl debuggerContext, String title); + protected abstract AsyncResult createNewRenderer( + XValueNode node, + ArrayRenderer original, + @Nonnull DebuggerContextImpl debuggerContext, + String title + ); @RequiredUIAccess @Override @@ -90,20 +99,19 @@ public void update(@Nonnull AnActionEvent e) { @Nullable public static ArrayRenderer getArrayRenderer(XValue value) { - if (value instanceof JavaValue) { - ValueDescriptorImpl descriptor = ((JavaValue) value).getDescriptor(); + if (value instanceof JavaValue javaValue) { + ValueDescriptorImpl descriptor = javaValue.getDescriptor(); Renderer lastRenderer = descriptor.getLastRenderer(); - if (lastRenderer instanceof CompoundNodeRenderer) { - ChildrenRenderer childrenRenderer = ((CompoundNodeRenderer) lastRenderer).getChildrenRenderer(); - if (childrenRenderer instanceof ExpressionChildrenRenderer) { - lastRenderer = ExpressionChildrenRenderer.getLastChildrenRenderer(descriptor); - if (lastRenderer == null) { - lastRenderer = ((ExpressionChildrenRenderer) childrenRenderer).getPredictedRenderer(); - } + if (lastRenderer instanceof CompoundNodeRenderer compoundNodeRenderer + && compoundNodeRenderer.getChildrenRenderer() instanceof ExpressionChildrenRenderer expressionChildrenRenderer) { + lastRenderer = ExpressionChildrenRenderer.getLastChildrenRenderer(descriptor); + if (lastRenderer == null) { + lastRenderer = expressionChildrenRenderer.getPredictedRenderer(); } } - if (lastRenderer instanceof ArrayRenderer) { - return (ArrayRenderer) lastRenderer; + + if (lastRenderer instanceof ArrayRenderer arrayRenderer) { + return arrayRenderer; } } return null; @@ -117,24 +125,22 @@ public static void setArrayRenderer(ArrayRenderer newRenderer, @Nonnull XValueNo return; } - ValueDescriptorImpl descriptor = ((JavaValue) container).getDescriptor(); + ValueDescriptorImpl descriptor = ((JavaValue)container).getDescriptor(); DebugProcessImpl debugProcess = debuggerContext.getDebugProcess(); if (debugProcess != null) { debugProcess.getManagerThread().schedule(new SuspendContextCommandImpl(debuggerContext.getSuspendContext()) { @Override public void contextAction(@Nonnull SuspendContextImpl suspendContext) throws Exception { - final Renderer lastRenderer = descriptor.getLastRenderer(); + Renderer lastRenderer = descriptor.getLastRenderer(); if (lastRenderer instanceof ArrayRenderer) { - ((JavaValue) container).setRenderer(newRenderer, node); + ((JavaValue)container).setRenderer(newRenderer, node); Application.get().invokeLater(() -> node.getTree().expand(node)); } - else if (lastRenderer instanceof CompoundNodeRenderer) { - final CompoundNodeRenderer compoundRenderer = (CompoundNodeRenderer) lastRenderer; - final ChildrenRenderer childrenRenderer = compoundRenderer.getChildrenRenderer(); - if (childrenRenderer instanceof ExpressionChildrenRenderer) { + else if (lastRenderer instanceof CompoundNodeRenderer compoundRenderer) { + if (compoundRenderer.getChildrenRenderer() instanceof ExpressionChildrenRenderer) { ExpressionChildrenRenderer.setPreferableChildrenRenderer(descriptor, newRenderer); - ((JavaValue) container).reBuild(node); + ((JavaValue)container).reBuild(node); } } } @@ -146,7 +152,7 @@ private static String createNodeTitle(String prefix, DebuggerTreeNodeImpl node) if (node != null) { DebuggerTreeNodeImpl parent = node.getParent(); NodeDescriptorImpl descriptor = parent.getDescriptor(); - if (descriptor instanceof ValueDescriptorImpl && ((ValueDescriptorImpl) descriptor).isArray()) { + if (descriptor instanceof ValueDescriptorImpl valueDescriptor && valueDescriptor.isArray()) { int index = parent.getIndex(node); return createNodeTitle(prefix, parent) + "[" + index + "]"; } @@ -179,13 +185,19 @@ public static class AdjustArrayRangeAction extends ArrayAction { @Nonnull @Override @RequiredUIAccess - protected AsyncResult createNewRenderer(XValueNode node, ArrayRenderer original, @Nonnull DebuggerContextImpl debuggerContext, String title) { + protected AsyncResult createNewRenderer( + XValueNode node, + ArrayRenderer original, + @Nonnull DebuggerContextImpl debuggerContext, + String title + ) { ArrayRenderer clonedRenderer = original.clone(); clonedRenderer.setForced(true); AsyncResult result = AsyncResult.undefined(); - AsyncResult showResult = ShowSettingsUtil.getInstance().editConfigurable(debuggerContext.getProject(), new NamedArrayConfigurable(title, clonedRenderer)); + AsyncResult showResult = ShowSettingsUtil.getInstance() + .editConfigurable(debuggerContext.getProject(), new NamedArrayConfigurable(title, clonedRenderer)); showResult.doWhenDone(() -> result.setDone(clonedRenderer)); - showResult.doWhenRejected((Runnable) result::setRejected); + showResult.doWhenRejected((Runnable)result::setRejected); return result; } } @@ -193,7 +205,12 @@ protected AsyncResult createNewRenderer(XValueNode node, ArrayRen public static class FilterArrayAction extends ArrayAction { @Nonnull @Override - protected AsyncResult createNewRenderer(XValueNode node, ArrayRenderer original, @Nonnull DebuggerContextImpl debuggerContext, String title) { + protected AsyncResult createNewRenderer( + XValueNode node, + ArrayRenderer original, + @Nonnull DebuggerContextImpl debuggerContext, + String title + ) { //TODO [VISTALL] ArrayFilterInplaceEditor.editParent(node); return AsyncResult.rejected(); } diff --git a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/AutoRendererAction.java b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/AutoRendererAction.java index f1224678b0..957a3e5899 100644 --- a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/AutoRendererAction.java +++ b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/AutoRendererAction.java @@ -15,32 +15,33 @@ */ package com.intellij.java.debugger.impl.actions; -import com.intellij.java.debugger.impl.engine.events.DebuggerContextCommandImpl; import com.intellij.java.debugger.impl.DebuggerContextImpl; +import com.intellij.java.debugger.impl.engine.events.DebuggerContextCommandImpl; import com.intellij.java.debugger.impl.ui.impl.watch.DebuggerTreeNodeImpl; -import com.intellij.java.debugger.impl.ui.impl.watch.NodeDescriptorImpl; import com.intellij.java.debugger.impl.ui.impl.watch.ValueDescriptorImpl; +import consulo.ui.annotation.RequiredUIAccess; import consulo.ui.ex.action.AnAction; import consulo.ui.ex.action.AnActionEvent; -public class AutoRendererAction extends AnAction{ - public void actionPerformed(AnActionEvent e) { - final DebuggerContextImpl debuggerContext = DebuggerAction.getDebuggerContext(e.getDataContext()); - final DebuggerTreeNodeImpl[] selectedNodes = DebuggerAction.getSelectedNodes(e.getDataContext()); +public class AutoRendererAction extends AnAction { + @Override + @RequiredUIAccess + public void actionPerformed(AnActionEvent e) { + DebuggerContextImpl debuggerContext = DebuggerAction.getDebuggerContext(e.getDataContext()); + DebuggerTreeNodeImpl[] selectedNodes = DebuggerAction.getSelectedNodes(e.getDataContext()); - if(debuggerContext != null && debuggerContext.getDebugProcess() != null) { - debuggerContext.getDebugProcess().getManagerThread().schedule(new DebuggerContextCommandImpl(debuggerContext) { - public void threadAction() { - for (int i = 0; i < selectedNodes.length; i++) { - DebuggerTreeNodeImpl selectedNode = selectedNodes[i]; - NodeDescriptorImpl descriptor = selectedNode.getDescriptor(); - if (descriptor instanceof ValueDescriptorImpl) { - ((ValueDescriptorImpl) descriptor).setRenderer(null); - selectedNode.calcRepresentation(); - } - } - } - }); + if (debuggerContext != null && debuggerContext.getDebugProcess() != null) { + debuggerContext.getDebugProcess().getManagerThread().schedule(new DebuggerContextCommandImpl(debuggerContext) { + @Override + public void threadAction() { + for (DebuggerTreeNodeImpl selectedNode : selectedNodes) { + if (selectedNode.getDescriptor() instanceof ValueDescriptorImpl valueDescriptor) { + valueDescriptor.setRenderer(null); + selectedNode.calcRepresentation(); + } + } + } + }); + } } - } } diff --git a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/CreateRendererAction.java b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/CreateRendererAction.java index 3ddabd549c..412f4384af 100644 --- a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/CreateRendererAction.java +++ b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/CreateRendererAction.java @@ -15,7 +15,6 @@ */ package com.intellij.java.debugger.impl.actions; -import com.intellij.java.debugger.DebuggerBundle; import com.intellij.java.debugger.impl.DebuggerContextImpl; import com.intellij.java.debugger.impl.engine.DebugProcessImpl; import com.intellij.java.debugger.impl.engine.JavaValue; @@ -23,72 +22,81 @@ import com.intellij.java.debugger.impl.settings.NodeRendererSettings; import com.intellij.java.debugger.impl.settings.UserRenderersConfigurable; import com.intellij.java.debugger.impl.ui.tree.render.NodeRenderer; +import com.intellij.java.debugger.localize.JavaDebuggerLocalize; import consulo.application.Application; import consulo.configurable.IdeaConfigurableBase; import consulo.ide.impl.idea.openapi.options.ex.SingleConfigurableEditor; import consulo.internal.com.sun.jdi.Type; import consulo.project.Project; +import consulo.ui.annotation.RequiredUIAccess; import consulo.ui.ex.action.AnAction; import consulo.ui.ex.action.AnActionEvent; import consulo.util.lang.StringUtil; - import jakarta.annotation.Nonnull; + import java.util.List; public class CreateRendererAction extends AnAction { - @Override - public void update(AnActionEvent e) { - final List values = ViewAsGroup.getSelectedValues(e); - if (values.size() != 1) { - e.getPresentation().setEnabledAndVisible(false); + @Override + @RequiredUIAccess + public void update(@Nonnull AnActionEvent e) { + List values = ViewAsGroup.getSelectedValues(e); + if (values.size() != 1) { + e.getPresentation().setEnabledAndVisible(false); + } } - } - public void actionPerformed(@Nonnull final AnActionEvent event) { - final DebuggerContextImpl debuggerContext = DebuggerAction.getDebuggerContext(event.getDataContext()); - final List values = ViewAsGroup.getSelectedValues(event); - if (values.size() != 1) { - return; - } + @Override + @RequiredUIAccess + public void actionPerformed(@Nonnull AnActionEvent event) { + DebuggerContextImpl debuggerContext = DebuggerAction.getDebuggerContext(event.getDataContext()); + List values = ViewAsGroup.getSelectedValues(event); + if (values.size() != 1) { + return; + } - final JavaValue javaValue = values.get(0); + JavaValue javaValue = values.get(0); - final DebugProcessImpl process = debuggerContext.getDebugProcess(); - if (process == null) { - return; - } + DebugProcessImpl process = debuggerContext.getDebugProcess(); + if (process == null) { + return; + } - final Project project = event.getData(Project.KEY); + Project project = event.getData(Project.KEY); - process.getManagerThread().schedule(new DebuggerContextCommandImpl(debuggerContext) { - public void threadAction() { - Type type = javaValue.getDescriptor().getType(); - final String name = type != null ? type.name() : null; - Application.get().invokeLater(() -> - { - final UserRenderersConfigurable ui = new UserRenderersConfigurable(); - IdeaConfigurableBase configurable = new IdeaConfigurableBase("reference.idesettings" + - ".debugger.typerenderers", DebuggerBundle.message("user.renderers.configurable.display.name"), "reference.idesettings.debugger.typerenderers") { - @Nonnull + process.getManagerThread().schedule(new DebuggerContextCommandImpl(debuggerContext) { @Override - protected NodeRendererSettings getSettings() { - return NodeRendererSettings.getInstance(); - } + public void threadAction() { + Type type = javaValue.getDescriptor().getType(); + String name = type != null ? type.name() : null; + Application.get().invokeLater(() -> { + UserRenderersConfigurable ui = new UserRenderersConfigurable(); + IdeaConfigurableBase configurable = new IdeaConfigurableBase<>( + "reference.idesettings.debugger.typerenderers", + JavaDebuggerLocalize.userRenderersConfigurableDisplayName().get(), + "reference.idesettings.debugger.typerenderers" + ) { + @Nonnull + @Override + protected NodeRendererSettings getSettings() { + return NodeRendererSettings.getInstance(); + } - @Override - protected UserRenderersConfigurable createUi() { - return ui; + @Override + protected UserRenderersConfigurable createUi() { + return ui; + } + }; + SingleConfigurableEditor editor = new SingleConfigurableEditor(project, configurable); + if (name != null) { + NodeRenderer renderer = + NodeRendererSettings.getInstance().createCompoundTypeRenderer(StringUtil.getShortName(name), name, null, null); + renderer.setEnabled(true); + ui.addRenderer(renderer); + } + editor.show(); + }); } - }; - SingleConfigurableEditor editor = new SingleConfigurableEditor(project, configurable); - if (name != null) { - NodeRenderer renderer = NodeRendererSettings.getInstance().createCompoundTypeRenderer(StringUtil.getShortName(name), name, null, null); - renderer.setEnabled(true); - ui.addRenderer(renderer); - } - editor.show(); }); - } - }); - } + } } diff --git a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/CustomizeContextViewAction.java b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/CustomizeContextViewAction.java index 9c602c781f..307d96d03c 100644 --- a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/CustomizeContextViewAction.java +++ b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/CustomizeContextViewAction.java @@ -15,10 +15,10 @@ */ package com.intellij.java.debugger.impl.actions; -import com.intellij.java.debugger.DebuggerBundle; import com.intellij.java.debugger.impl.engine.JavaDebugProcess; import com.intellij.java.debugger.impl.settings.JavaDebuggerSettings; import com.intellij.java.debugger.impl.settings.NodeRendererSettings; +import com.intellij.java.debugger.localize.JavaDebuggerLocalize; import consulo.configurable.Configurable; import consulo.configurable.ConfigurationException; import consulo.disposer.Disposable; @@ -38,58 +38,62 @@ import java.util.List; public class CustomizeContextViewAction extends DumbAwareAction { - @Override - public void actionPerformed(AnActionEvent e) { - final Project project = e.getData(Project.KEY); - Disposable disposable = Disposable.newDisposable(); - SingleConfigurableEditor editor = new SingleConfigurableEditor(project, new TabbedConfigurable(disposable) { - @Override - protected List createConfigurables() { - return JavaDebuggerSettings.createDataViewsConfigurable(); - } + @Override + @RequiredUIAccess + public void actionPerformed(AnActionEvent e) { + Project project = e.getData(Project.KEY); + Disposable disposable = Disposable.newDisposable(); + SingleConfigurableEditor editor = new SingleConfigurableEditor(project, new TabbedConfigurable(disposable) { + @Override + protected List createConfigurables() { + return JavaDebuggerSettings.createDataViewsConfigurable(); + } - @Override - @RequiredUIAccess - public void apply() throws ConfigurationException { - super.apply(); - NodeRendererSettings.getInstance().fireRenderersChanged(); - } + @Override + @RequiredUIAccess + public void apply() throws ConfigurationException { + super.apply(); + NodeRendererSettings.getInstance().fireRenderersChanged(); + } - @Override - public String getDisplayName() { - return DebuggerBundle.message("title.customize.data.views"); - } + @Override + public String getDisplayName() { + return JavaDebuggerLocalize.titleCustomizeDataViews().get(); + } - @Override - public String getHelpTopic() { - return "reference.debug.customize.data.view"; - } + @Override + public String getHelpTopic() { + return "reference.debug.customize.data.view"; + } - @Override - protected void createConfigurableTabs() { - for (Configurable configurable : getConfigurables()) { - JComponent component = configurable.createComponent(); - assert component != null; - component.setBorder(new EmptyBorder(8, 8, 8, 8)); - myTabbedPane.addTab(configurable.getDisplayName(), component); - } - } - }); - Disposer.register(editor.getDisposable(), disposable); - editor.show(); - } + @Override + @RequiredUIAccess + protected void createConfigurableTabs() { + for (Configurable configurable : getConfigurables()) { + JComponent component = configurable.createComponent(); + assert component != null; + component.setBorder(new EmptyBorder(8, 8, 8, 8)); + myTabbedPane.addTab(configurable.getDisplayName(), component); + } + } + }); + Disposer.register(editor.getDisposable(), disposable); + editor.show(); + } - @Override - public void update(AnActionEvent e) { - e.getPresentation().setTextValue(ActionLocalize.actionDebuggerCustomizecontextviewText()); + @Override + @RequiredUIAccess + public void update(AnActionEvent e) { + e.getPresentation().setTextValue(ActionLocalize.actionDebuggerCustomizecontextviewText()); - Project project = e.getData(Project.KEY); - final XDebuggerManager debuggerManager = project == null ? null : XDebuggerManager.getInstance(project); - final XDebugSession currentSession = debuggerManager == null ? null : debuggerManager.getCurrentSession(); - if (currentSession != null) { - e.getPresentation().setEnabledAndVisible(currentSession.getDebugProcess() instanceof JavaDebugProcess); - } else { - e.getPresentation().setEnabledAndVisible(false); + Project project = e.getData(Project.KEY); + XDebuggerManager debuggerManager = project == null ? null : XDebuggerManager.getInstance(project); + XDebugSession currentSession = debuggerManager == null ? null : debuggerManager.getCurrentSession(); + if (currentSession != null) { + e.getPresentation().setEnabledAndVisible(currentSession.getDebugProcess() instanceof JavaDebugProcess); + } + else { + e.getPresentation().setEnabledAndVisible(false); + } } - } } diff --git a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/CustomizeThreadsViewAction.java b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/CustomizeThreadsViewAction.java index 041f83860b..fd51e114b4 100644 --- a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/CustomizeThreadsViewAction.java +++ b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/CustomizeThreadsViewAction.java @@ -15,8 +15,8 @@ */ package com.intellij.java.debugger.impl.actions; -import com.intellij.java.debugger.DebuggerBundle; import com.intellij.java.debugger.impl.settings.ThreadsViewSettings; +import com.intellij.java.debugger.localize.JavaDebuggerLocalize; import consulo.ide.setting.ShowSettingsUtil; import consulo.java.debugger.impl.settings.ThreadsViewConfigurable; import consulo.platform.base.localize.ActionLocalize; @@ -26,30 +26,26 @@ import jakarta.annotation.Nonnull; /** - * User: lex - * Date: Sep 26, 2003 - * Time: 4:40:12 PM + * @author lex + * @since 2003-09-26 */ -public class CustomizeThreadsViewAction extends DebuggerAction -{ - @RequiredUIAccess - @Override - public void actionPerformed(@Nonnull AnActionEvent e) - { - Project project = e.getData(Project.KEY); +public class CustomizeThreadsViewAction extends DebuggerAction { + @Override + @RequiredUIAccess + public void actionPerformed(@Nonnull AnActionEvent e) { + Project project = e.getData(Project.KEY); - ShowSettingsUtil.getInstance().editConfigurable( - DebuggerBundle.message("threads.view.configurable.display.name"), - project, - new ThreadsViewConfigurable(ThreadsViewSettings::getInstance) - ); - } + ShowSettingsUtil.getInstance().editConfigurable( + JavaDebuggerLocalize.threadsViewConfigurableDisplayName().get(), + project, + new ThreadsViewConfigurable(ThreadsViewSettings::getInstance) + ); + } - @RequiredUIAccess - @Override - public void update(@Nonnull AnActionEvent e) - { - e.getPresentation().setVisible(true); - e.getPresentation().setTextValue(ActionLocalize.actionDebuggerCustomizethreadsviewText()); - } + @Override + @RequiredUIAccess + public void update(@Nonnull AnActionEvent e) { + e.getPresentation().setVisible(true); + e.getPresentation().setTextValue(ActionLocalize.actionDebuggerCustomizethreadsviewText()); + } } diff --git a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/DebuggerAction.java b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/DebuggerAction.java index b4336e7e27..4cf8c165c3 100644 --- a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/DebuggerAction.java +++ b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/DebuggerAction.java @@ -13,14 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/* - * Class DebuggerAction - * @author Jeka - */ package com.intellij.java.debugger.impl.actions; - import com.intellij.java.debugger.impl.DebuggerContextImpl; import com.intellij.java.debugger.impl.DebuggerManagerEx; import com.intellij.java.debugger.impl.DebuggerStateManager; @@ -31,7 +25,6 @@ import consulo.dataContext.DataContext; import consulo.dataContext.DataManager; import consulo.disposer.Disposable; -import consulo.execution.debug.XDebugProcess; import consulo.execution.debug.XDebugSession; import consulo.execution.debug.frame.XValueNode; import consulo.execution.debug.ui.XValueTree; @@ -50,6 +43,11 @@ import java.util.ArrayList; import java.util.List; +/** + * Class DebuggerAction + * + * @author Jeka + */ public abstract class DebuggerAction extends AnAction { private static final DebuggerTreeNodeImpl[] EMPTY_TREE_NODE_ARRAY = new DebuggerTreeNodeImpl[0]; @@ -78,10 +76,7 @@ public static DebuggerTreeNodeImpl getSelectedNode(DataContext dataContext) { return null; } Object component = path.getLastPathComponent(); - if (!(component instanceof DebuggerTreeNodeImpl)) { - return null; - } - return (DebuggerTreeNodeImpl) component; + return component instanceof DebuggerTreeNodeImpl debuggerTreeNode ? debuggerTreeNode : null; } @Nullable @@ -128,8 +123,8 @@ public static boolean isContextView(AnActionEvent e) { DebuggerActions.INSPECT_PANEL_POPUP.equals(e.getPlace()); } - public static Disposable installEditAction(final JTree tree, String actionName) { - final DoubleClickListener listener = new DoubleClickListener() { + public static Disposable installEditAction(JTree tree, String actionName) { + DoubleClickListener listener = new DoubleClickListener() { @Override protected boolean onDoubleClick(MouseEvent e) { if (tree.getPathForLocation(e.getX(), e.getY()) == null) { @@ -142,7 +137,7 @@ protected boolean onDoubleClick(MouseEvent e) { }; listener.installOn(tree); - final AnAction action = ActionManager.getInstance().getAction(actionName); + AnAction action = ActionManager.getInstance().getAction(actionName); action.registerCustomShortcutSet(CommonShortcuts.getEditSource(), tree); return () -> { @@ -151,7 +146,7 @@ protected boolean onDoubleClick(MouseEvent e) { }; } - public static boolean isFirstStart(final AnActionEvent event) { + public static boolean isFirstStart(AnActionEvent event) { //noinspection HardCodedStringLiteral String key = "initalized"; if (event.getPresentation().getClientProperty(key) != null) { @@ -162,7 +157,7 @@ public static boolean isFirstStart(final AnActionEvent event) { return true; } - public static void enableAction(final AnActionEvent event, final boolean enable) { + public static void enableAction(AnActionEvent event, boolean enable) { SwingUtilities.invokeLater(() -> { event.getPresentation().setEnabled(enable); event.getPresentation().setVisible(true); @@ -178,8 +173,7 @@ public static void refreshViews(@Nonnull XValueNode node) { public static void refreshViews(@Nullable XDebugSession session) { if (session != null) { - XDebugProcess process = session.getDebugProcess(); - if (process instanceof JavaDebugProcess debugProcess) { + if (session.getDebugProcess() instanceof JavaDebugProcess debugProcess) { debugProcess.saveNodeHistory(); } session.rebuildViews(); diff --git a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/DebuggerActions.java b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/DebuggerActions.java index d5bdc57c89..a7feeea1cd 100644 --- a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/DebuggerActions.java +++ b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/DebuggerActions.java @@ -13,31 +13,28 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/* - * Interface DebuggerActions - * @author Jeka - */ package com.intellij.java.debugger.impl.actions; import consulo.execution.debug.XDebuggerActions; -import org.jetbrains.annotations.NonNls; +/** + * @author Jeka + */ public interface DebuggerActions extends XDebuggerActions { - @NonNls String POP_FRAME = "Debugger.PopFrame"; - @NonNls String EVALUATION_DIALOG_POPUP = "Debugger.EvaluationDialogPopup"; - @NonNls String FRAME_PANEL_POPUP = "Debugger.FramePanelPopup"; - @NonNls String INSPECT_PANEL_POPUP = "Debugger.InspectPanelPopup"; - @NonNls String THREADS_PANEL_POPUP = "Debugger.ThreadsPanelPopup"; - @NonNls String WATCH_PANEL_POPUP = "Debugger.WatchesPanelPopup"; - @NonNls String REMOVE_WATCH = "Debugger.RemoveWatch"; - @NonNls String NEW_WATCH = "Debugger.NewWatch"; - @NonNls String EDIT_WATCH = "Debugger.EditWatch"; - @NonNls String COPY_VALUE = "Debugger.CopyValue"; - @NonNls String SET_VALUE = "Debugger.SetValue"; - @NonNls String EDIT_FRAME_SOURCE = "Debugger.EditFrameSource"; - @NonNls String EDIT_NODE_SOURCE = "Debugger.EditNodeSource"; - @NonNls String REPRESENTATION_LIST = "Debugger.Representation"; - @NonNls String INSPECT = "Debugger.Inspect"; - @NonNls String DUMP_THREADS = "DumpThreads"; + String POP_FRAME = "Debugger.PopFrame"; + String EVALUATION_DIALOG_POPUP = "Debugger.EvaluationDialogPopup"; + String FRAME_PANEL_POPUP = "Debugger.FramePanelPopup"; + String INSPECT_PANEL_POPUP = "Debugger.InspectPanelPopup"; + String THREADS_PANEL_POPUP = "Debugger.ThreadsPanelPopup"; + String WATCH_PANEL_POPUP = "Debugger.WatchesPanelPopup"; + String REMOVE_WATCH = "Debugger.RemoveWatch"; + String NEW_WATCH = "Debugger.NewWatch"; + String EDIT_WATCH = "Debugger.EditWatch"; + String COPY_VALUE = "Debugger.CopyValue"; + String SET_VALUE = "Debugger.SetValue"; + String EDIT_FRAME_SOURCE = "Debugger.EditFrameSource"; + String EDIT_NODE_SOURCE = "Debugger.EditNodeSource"; + String REPRESENTATION_LIST = "Debugger.Representation"; + String INSPECT = "Debugger.Inspect"; + String DUMP_THREADS = "DumpThreads"; } diff --git a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/EditFrameSourceAction.java b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/EditFrameSourceAction.java index a762f98686..4f67ec4b41 100644 --- a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/EditFrameSourceAction.java +++ b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/EditFrameSourceAction.java @@ -15,6 +15,7 @@ */ package com.intellij.java.debugger.impl.actions; +import consulo.ui.annotation.RequiredUIAccess; import consulo.ui.ex.action.ActionManager; import consulo.ui.ex.action.AnActionEvent; import consulo.ui.ex.action.IdeActions; @@ -22,9 +23,12 @@ /** * @author lex */ -public class EditFrameSourceAction extends GotoFrameSourceAction{ - public void update(AnActionEvent e) { - super.update(e); - e.getPresentation().setText(ActionManager.getInstance().getAction(IdeActions.ACTION_EDIT_SOURCE).getTemplatePresentation().getText()); - } +public class EditFrameSourceAction extends GotoFrameSourceAction { + @Override + @RequiredUIAccess + public void update(AnActionEvent e) { + super.update(e); + e.getPresentation() + .setTextValue(ActionManager.getInstance().getAction(IdeActions.ACTION_EDIT_SOURCE).getTemplatePresentation().getTextValue()); + } } diff --git a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/EditSourceAction.java b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/EditSourceAction.java index 249a069d79..59cc8b1c78 100644 --- a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/EditSourceAction.java +++ b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/EditSourceAction.java @@ -15,122 +15,106 @@ */ package com.intellij.java.debugger.impl.actions; -import com.intellij.java.debugger.impl.DebuggerInvocationUtil; import com.intellij.java.debugger.SourcePosition; -import com.intellij.java.debugger.impl.engine.DebugProcessImpl; -import com.intellij.java.debugger.impl.engine.SourcePositionProvider; import com.intellij.java.debugger.engine.evaluation.expression.Modifier; -import com.intellij.java.debugger.impl.engine.events.DebuggerContextCommandImpl; import com.intellij.java.debugger.impl.DebuggerContextImpl; +import com.intellij.java.debugger.impl.DebuggerInvocationUtil; import com.intellij.java.debugger.impl.DebuggerSession; +import com.intellij.java.debugger.impl.engine.DebugProcessImpl; +import com.intellij.java.debugger.impl.engine.SourcePositionProvider; +import com.intellij.java.debugger.impl.engine.events.DebuggerContextCommandImpl; import com.intellij.java.debugger.impl.ui.impl.watch.DebuggerTreeNodeImpl; import com.intellij.java.debugger.impl.ui.impl.watch.NodeDescriptorImpl; import com.intellij.java.debugger.impl.ui.impl.watch.WatchItemDescriptor; +import consulo.application.AccessRule; +import consulo.project.Project; +import consulo.ui.annotation.RequiredUIAccess; import consulo.ui.ex.action.ActionManager; import consulo.ui.ex.action.AnActionEvent; import consulo.ui.ex.action.IdeActions; import consulo.ui.ex.action.Presentation; -import consulo.application.ReadAction; -import consulo.project.Project; - -public class EditSourceAction extends DebuggerAction -{ - @Override - public void actionPerformed(AnActionEvent e) - { - final Project project = e.getData(Project.KEY); - if(project == null) - { - return; - } +public class EditSourceAction extends DebuggerAction { + @Override + @RequiredUIAccess + public void actionPerformed(AnActionEvent e) { + Project project = e.getData(Project.KEY); - final DebuggerTreeNodeImpl selectedNode = getSelectedNode(e.getDataContext()); - if(selectedNode != null) - { - final DebuggerContextImpl debuggerContext = getDebuggerContext(e.getDataContext()); - DebugProcessImpl process = debuggerContext.getDebugProcess(); - if(process != null) - { - process.getManagerThread().schedule(new DebuggerContextCommandImpl(debuggerContext) - { - @Override - public void threadAction() - { - final SourcePosition sourcePosition = getSourcePosition(selectedNode, debuggerContext); - if(sourcePosition != null) - { - sourcePosition.navigate(true); - } - } - }); - } - } - } + if (project == null) { + return; + } - private static SourcePosition getSourcePosition(DebuggerTreeNodeImpl selectedNode, DebuggerContextImpl debuggerContext) - { - final DebuggerContextImpl context = debuggerContext; + DebuggerTreeNodeImpl selectedNode = getSelectedNode(e.getDataContext()); + if (selectedNode != null) { + DebuggerContextImpl debuggerContext = getDebuggerContext(e.getDataContext()); + DebugProcessImpl process = debuggerContext.getDebugProcess(); + if (process != null) { + process.getManagerThread().schedule(new DebuggerContextCommandImpl(debuggerContext) { + @Override + public void threadAction() { + SourcePosition sourcePosition = getSourcePosition(selectedNode, debuggerContext); + if (sourcePosition != null) { + sourcePosition.navigate(true); + } + } + }); + } + } + } - if(selectedNode == null || context == null) - { - return null; - } + private static SourcePosition getSourcePosition(DebuggerTreeNodeImpl selectedNode, DebuggerContextImpl debuggerContext) { + DebuggerContextImpl context = debuggerContext; - final Project project = selectedNode.getProject(); + if (selectedNode == null || context == null) { + return null; + } - final DebuggerSession debuggerSession = context.getDebuggerSession(); + Project project = selectedNode.getProject(); - if(debuggerSession == null) - { - return null; - } + DebuggerSession debuggerSession = context.getDebuggerSession(); - NodeDescriptorImpl nodeDescriptor = selectedNode.getDescriptor(); - if(nodeDescriptor instanceof WatchItemDescriptor) - { - Modifier modifier = ((WatchItemDescriptor) nodeDescriptor).getModifier(); - if(modifier == null) - { - return null; - } - nodeDescriptor = (NodeDescriptorImpl) modifier.getInspectItem(project); - } + if (debuggerSession == null) { + return null; + } - final NodeDescriptorImpl nodeDescriptor1 = nodeDescriptor; - return ReadAction.compute(() -> SourcePositionProvider.getSourcePosition(nodeDescriptor1, project, context)); - } + NodeDescriptorImpl nodeDescriptor = selectedNode.getDescriptor(); + if (nodeDescriptor instanceof WatchItemDescriptor watchItemDescriptor) { + Modifier modifier = watchItemDescriptor.getModifier(); + if (modifier == null) { + return null; + } + nodeDescriptor = (NodeDescriptorImpl)modifier.getInspectItem(project); + } - @Override - public void update(AnActionEvent e) - { - final Project project = e.getData(Project.KEY); + NodeDescriptorImpl nodeDescriptor1 = nodeDescriptor; + return AccessRule.read(() -> SourcePositionProvider.getSourcePosition(nodeDescriptor1, project, context)); + } - final DebuggerContextImpl debuggerContext = getDebuggerContext(e.getDataContext()); - final DebuggerTreeNodeImpl node = getSelectedNode(e.getDataContext()); + @Override + @RequiredUIAccess + public void update(AnActionEvent e) { + Project project = e.getData(Project.KEY); - final Presentation presentation = e.getPresentation(); - if(debuggerContext.getDebugProcess() != null) - { - presentation.setEnabled(true); - debuggerContext.getDebugProcess().getManagerThread().schedule(new DebuggerContextCommandImpl(debuggerContext) - { - @Override - public void threadAction() - { - final SourcePosition position = getSourcePosition(node, debuggerContext); - if(position == null) - { - DebuggerInvocationUtil.swingInvokeLater(project, () -> presentation.setEnabled(false)); - } - } - }); - } - else - { - presentation.setEnabled(false); - } - e.getPresentation().setText(ActionManager.getInstance().getAction(IdeActions.ACTION_EDIT_SOURCE).getTemplatePresentation().getText()); - } + DebuggerContextImpl debuggerContext = getDebuggerContext(e.getDataContext()); + DebuggerTreeNodeImpl node = getSelectedNode(e.getDataContext()); + Presentation presentation = e.getPresentation(); + if (debuggerContext.getDebugProcess() != null) { + presentation.setEnabled(true); + debuggerContext.getDebugProcess().getManagerThread().schedule(new DebuggerContextCommandImpl(debuggerContext) { + @Override + public void threadAction() { + SourcePosition position = getSourcePosition(node, debuggerContext); + if (position == null) { + DebuggerInvocationUtil.swingInvokeLater(project, () -> presentation.setEnabled(false)); + } + } + }); + } + else { + presentation.setEnabled(false); + } + e.getPresentation() + .setTextValue(ActionManager.getInstance().getAction(IdeActions.ACTION_EDIT_SOURCE).getTemplatePresentation().getTextValue()); + } } diff --git a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/ExportThreadsAction.java b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/ExportThreadsAction.java index 17ffc6bc15..8aefa12021 100644 --- a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/ExportThreadsAction.java +++ b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/ExportThreadsAction.java @@ -13,27 +13,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/** - * class ExportThreadsAction - * - * @author Jeka - */ package com.intellij.java.debugger.impl.actions; import com.intellij.java.debugger.impl.DebuggerContextImpl; import com.intellij.java.debugger.impl.DebuggerManagerEx; import com.intellij.java.debugger.impl.DebuggerSession; import com.intellij.java.debugger.impl.ui.ExportDialog; +import consulo.platform.Platform; import consulo.platform.base.localize.ActionLocalize; import consulo.project.Project; +import consulo.ui.annotation.RequiredUIAccess; import consulo.ui.ex.action.AnAction; import consulo.ui.ex.action.AnActionEvent; import consulo.ui.ex.action.Presentation; import consulo.ui.ex.awt.Messages; import consulo.ui.ex.awt.UIUtil; import consulo.util.lang.StringUtil; -import consulo.util.lang.SystemProperties; import consulo.virtualFileSystem.VirtualFile; import jakarta.annotation.Nonnull; @@ -42,8 +37,12 @@ import java.io.FileWriter; import java.io.IOException; +/** + * @author Jeka + */ public class ExportThreadsAction extends AnAction { @Override + @RequiredUIAccess public void actionPerformed(@Nonnull AnActionEvent e) { Project project = e.getData(Project.KEY); if (project == null) { @@ -53,7 +52,7 @@ public void actionPerformed(@Nonnull AnActionEvent e) { if (context.getDebuggerSession() != null) { String destinationDirectory = ""; - final VirtualFile baseDir = project.getBaseDir(); + VirtualFile baseDir = project.getBaseDir(); if (baseDir != null) { destinationDirectory = baseDir.getPresentableUrl(); } @@ -64,18 +63,27 @@ public void actionPerformed(@Nonnull AnActionEvent e) { try { File file = new File(dialog.getFilePath()); try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) { - String text = StringUtil.convertLineSeparators(dialog.getTextToSave(), SystemProperties.getLineSeparator()); + String text = StringUtil.convertLineSeparators( + dialog.getTextToSave(), + Platform.current().os().lineSeparator().getSeparatorString() + ); writer.write(text); } } catch (IOException ex) { - Messages.showMessageDialog(project, ex.getMessage(), ActionLocalize.actionExportthreadsText().get(), UIUtil.getErrorIcon()); + Messages.showMessageDialog( + project, + ex.getMessage(), + ActionLocalize.actionExportthreadsText().get(), + UIUtil.getErrorIcon() + ); } } } } @Override + @RequiredUIAccess public void update(@Nonnull AnActionEvent event) { Presentation presentation = event.getPresentation(); Project project = event.getData(Project.KEY); diff --git a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/FreezeThreadAction.java b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/FreezeThreadAction.java index d19e6c34c7..9973ff64df 100644 --- a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/FreezeThreadAction.java +++ b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/FreezeThreadAction.java @@ -22,55 +22,59 @@ import com.intellij.java.debugger.impl.ui.impl.watch.DebuggerTreeNodeImpl; import com.intellij.java.debugger.impl.ui.impl.watch.NodeDescriptorImpl; import com.intellij.java.debugger.impl.ui.impl.watch.ThreadDescriptorImpl; +import consulo.ui.annotation.RequiredUIAccess; import consulo.ui.ex.action.AnActionEvent; /** * @author lex */ public class FreezeThreadAction extends DebuggerAction { - public void actionPerformed(final AnActionEvent e) { - DebuggerTreeNodeImpl[] selectedNode = getSelectedNodes(e.getDataContext()); - if (selectedNode == null) { - return; - } - final DebuggerContextImpl debuggerContext = getDebuggerContext(e.getDataContext()); - final DebugProcessImpl debugProcess = debuggerContext.getDebugProcess(); + @Override + @RequiredUIAccess + public void actionPerformed(AnActionEvent e) { + DebuggerTreeNodeImpl[] selectedNode = getSelectedNodes(e.getDataContext()); + if (selectedNode == null) { + return; + } + DebuggerContextImpl debuggerContext = getDebuggerContext(e.getDataContext()); + DebugProcessImpl debugProcess = debuggerContext.getDebugProcess(); - for (final DebuggerTreeNodeImpl debuggerTreeNode : selectedNode) { - ThreadDescriptorImpl threadDescriptor = ((ThreadDescriptorImpl)debuggerTreeNode.getDescriptor()); - final ThreadReferenceProxyImpl thread = threadDescriptor.getThreadReference(); + for (DebuggerTreeNodeImpl debuggerTreeNode : selectedNode) { + ThreadDescriptorImpl threadDescriptor = ((ThreadDescriptorImpl)debuggerTreeNode.getDescriptor()); + ThreadReferenceProxyImpl thread = threadDescriptor.getThreadReference(); - if (!threadDescriptor.isFrozen()) { - debugProcess.getManagerThread().schedule(new SuspendContextCommandImpl(debuggerContext.getSuspendContext()) { - public void contextAction() throws Exception { - debugProcess.createFreezeThreadCommand(thread).run(); - debuggerTreeNode.calcValue(); - } - }); - } + if (!threadDescriptor.isFrozen()) { + debugProcess.getManagerThread().schedule(new SuspendContextCommandImpl(debuggerContext.getSuspendContext()) { + @Override + public void contextAction() throws Exception { + debugProcess.createFreezeThreadCommand(thread).run(); + debuggerTreeNode.calcValue(); + } + }); + } + } } - } - public void update(AnActionEvent e) { - DebuggerTreeNodeImpl[] selectedNode = getSelectedNodes(e.getDataContext()); - if (selectedNode == null) { - return; - } - DebugProcessImpl debugProcess = getDebuggerContext(e.getDataContext()).getDebugProcess(); + @Override + @RequiredUIAccess + public void update(AnActionEvent e) { + DebuggerTreeNodeImpl[] selectedNode = getSelectedNodes(e.getDataContext()); + if (selectedNode == null) { + return; + } + DebugProcessImpl debugProcess = getDebuggerContext(e.getDataContext()).getDebugProcess(); - boolean visible = false; - if (debugProcess != null) { - visible = true; - for (DebuggerTreeNodeImpl aSelectedNode : selectedNode) { - NodeDescriptorImpl threadDescriptor = aSelectedNode.getDescriptor(); - if (!(threadDescriptor instanceof ThreadDescriptorImpl) || ((ThreadDescriptorImpl)threadDescriptor).isFrozen()) { - visible = false; - break; + boolean visible = false; + if (debugProcess != null) { + visible = true; + for (DebuggerTreeNodeImpl aSelectedNode : selectedNode) { + if (!(aSelectedNode.getDescriptor() instanceof ThreadDescriptorImpl tdi && !tdi.isFrozen())) { + visible = false; + break; + } + } } - } + e.getPresentation().setVisible(visible); } - - e.getPresentation().setVisible(visible); - } } diff --git a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/GotoFrameSourceAction.java b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/GotoFrameSourceAction.java index 722e3a3626..397635f1f1 100644 --- a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/GotoFrameSourceAction.java +++ b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/GotoFrameSourceAction.java @@ -18,6 +18,7 @@ import com.intellij.java.debugger.impl.DebuggerContextUtil; import com.intellij.java.debugger.impl.ui.impl.watch.DebuggerTreeNodeImpl; import com.intellij.java.debugger.impl.ui.impl.watch.StackFrameDescriptorImpl; +import consulo.ui.annotation.RequiredUIAccess; import consulo.ui.ex.action.AnActionEvent; import consulo.dataContext.DataContext; import consulo.project.Project; @@ -25,44 +26,39 @@ /** * @author lex */ -public abstract class GotoFrameSourceAction extends DebuggerAction -{ - public void actionPerformed(AnActionEvent e) - { - DataContext dataContext = e.getDataContext(); - doAction(dataContext); - } +public abstract class GotoFrameSourceAction extends DebuggerAction { + @Override + @RequiredUIAccess + public void actionPerformed(AnActionEvent e) { + DataContext dataContext = e.getDataContext(); + doAction(dataContext); + } - protected static void doAction(DataContext dataContext) - { - final Project project = dataContext.getData(Project.KEY); - if (project == null) - { - return; - } - StackFrameDescriptorImpl stackFrameDescriptor = getStackFrameDescriptor(dataContext); - if (stackFrameDescriptor != null) - { - DebuggerContextUtil.setStackFrame(getContextManager(dataContext), stackFrameDescriptor.getFrameProxy()); - } - } + protected static void doAction(DataContext dataContext) { + Project project = dataContext.getData(Project.KEY); + if (project == null) { + return; + } + StackFrameDescriptorImpl stackFrameDescriptor = getStackFrameDescriptor(dataContext); + if (stackFrameDescriptor != null) { + DebuggerContextUtil.setStackFrame(getContextManager(dataContext), stackFrameDescriptor.getFrameProxy()); + } + } - public void update(AnActionEvent e) - { - e.getPresentation().setVisible(getStackFrameDescriptor(e.getDataContext()) != null); - } + @Override + @RequiredUIAccess + public void update(AnActionEvent e) { + e.getPresentation().setVisible(getStackFrameDescriptor(e.getDataContext()) != null); + } - private static StackFrameDescriptorImpl getStackFrameDescriptor(DataContext dataContext) - { - DebuggerTreeNodeImpl selectedNode = getSelectedNode(dataContext); - if (selectedNode == null) - { - return null; - } - if (selectedNode.getDescriptor() == null || !(selectedNode.getDescriptor() instanceof StackFrameDescriptorImpl)) - { - return null; - } - return (StackFrameDescriptorImpl) selectedNode.getDescriptor(); - } + private static StackFrameDescriptorImpl getStackFrameDescriptor(DataContext dataContext) { + DebuggerTreeNodeImpl selectedNode = getSelectedNode(dataContext); + if (selectedNode == null) { + return null; + } + if (selectedNode.getDescriptor() == null || !(selectedNode.getDescriptor() instanceof StackFrameDescriptorImpl)) { + return null; + } + return (StackFrameDescriptorImpl)selectedNode.getDescriptor(); + } } diff --git a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/HotSwapAction.java b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/HotSwapAction.java index fdaca3c91a..6bb8f1f46b 100644 --- a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/HotSwapAction.java +++ b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/HotSwapAction.java @@ -20,6 +20,7 @@ import com.intellij.java.debugger.impl.settings.DebuggerSettings; import com.intellij.java.debugger.impl.ui.HotSwapUI; import consulo.project.Project; +import consulo.ui.annotation.RequiredUIAccess; import consulo.ui.ex.action.AnAction; import consulo.ui.ex.action.AnActionEvent; @@ -28,6 +29,7 @@ */ public class HotSwapAction extends AnAction { @Override + @RequiredUIAccess public void actionPerformed(AnActionEvent e) { Project project = e.getData(Project.KEY); if (project == null) { @@ -43,6 +45,7 @@ public void actionPerformed(AnActionEvent e) { } @Override + @RequiredUIAccess public void update(AnActionEvent e) { Project project = e.getData(Project.KEY); if (project == null) { diff --git a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/InterruptThreadAction.java b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/InterruptThreadAction.java index a8c648f345..e195a35a2a 100644 --- a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/InterruptThreadAction.java +++ b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/InterruptThreadAction.java @@ -15,13 +15,14 @@ */ package com.intellij.java.debugger.impl.actions; -import com.intellij.java.debugger.DebuggerBundle; -import com.intellij.java.debugger.impl.engine.events.DebuggerCommandImpl; import com.intellij.java.debugger.impl.DebuggerContextImpl; +import com.intellij.java.debugger.impl.engine.events.DebuggerCommandImpl; import com.intellij.java.debugger.impl.jdi.ThreadReferenceProxyImpl; import com.intellij.java.debugger.impl.ui.impl.watch.DebuggerTreeNodeImpl; import com.intellij.java.debugger.impl.ui.impl.watch.NodeDescriptorImpl; import com.intellij.java.debugger.impl.ui.impl.watch.ThreadDescriptorImpl; +import com.intellij.java.debugger.localize.JavaDebuggerLocalize; +import consulo.ui.annotation.RequiredUIAccess; import consulo.ui.ex.action.AnActionEvent; import consulo.ui.ex.action.Presentation; @@ -29,70 +30,70 @@ import java.util.List; /** - * User: lex - * Date: Sep 26, 2003 - * Time: 7:35:09 PM + * @author lex + * @since 2003-09-26 */ -public class InterruptThreadAction extends DebuggerAction{ - - public void actionPerformed(final AnActionEvent e) { - final DebuggerTreeNodeImpl[] nodes = getSelectedNodes(e.getDataContext()); - if (nodes == null) { - return; - } +public class InterruptThreadAction extends DebuggerAction { + @Override + @RequiredUIAccess + public void actionPerformed(AnActionEvent e) { + DebuggerTreeNodeImpl[] nodes = getSelectedNodes(e.getDataContext()); + if (nodes == null) { + return; + } - //noinspection ConstantConditions - final List threadsToInterrupt = new ArrayList(); - for (final DebuggerTreeNodeImpl debuggerTreeNode : nodes) { - final NodeDescriptorImpl descriptor = debuggerTreeNode.getDescriptor(); - if (descriptor instanceof ThreadDescriptorImpl) { - threadsToInterrupt.add(((ThreadDescriptorImpl)descriptor).getThreadReference()); - } - } - - if (!threadsToInterrupt.isEmpty()) { - final DebuggerContextImpl debuggerContext = getDebuggerContext(e.getDataContext()); - debuggerContext.getDebugProcess().getManagerThread().schedule(new DebuggerCommandImpl() { - protected void action() throws Exception { - for (ThreadReferenceProxyImpl thread : threadsToInterrupt) { - thread.getThreadReference().interrupt(); - } + //noinspection ConstantConditions + List threadsToInterrupt = new ArrayList<>(); + for (DebuggerTreeNodeImpl debuggerTreeNode : nodes) { + if (debuggerTreeNode.getDescriptor() instanceof ThreadDescriptorImpl threadDescriptor) { + threadsToInterrupt.add(threadDescriptor.getThreadReference()); + } + } + + if (!threadsToInterrupt.isEmpty()) { + DebuggerContextImpl debuggerContext = getDebuggerContext(e.getDataContext()); + debuggerContext.getDebugProcess().getManagerThread().schedule(new DebuggerCommandImpl() { + @Override + protected void action() throws Exception { + for (ThreadReferenceProxyImpl thread : threadsToInterrupt) { + thread.getThreadReference().interrupt(); + } + } + }); } - }); } - } + @Override + @RequiredUIAccess + public void update(AnActionEvent e) { + DebuggerTreeNodeImpl[] selectedNodes = getSelectedNodes(e.getDataContext()); - public void update(AnActionEvent e) { - final DebuggerTreeNodeImpl[] selectedNodes = getSelectedNodes(e.getDataContext()); + boolean visible = false; + boolean enabled = false; - boolean visible = false; - boolean enabled = false; + if (selectedNodes != null && selectedNodes.length > 0) { + visible = true; + enabled = true; + for (DebuggerTreeNodeImpl selectedNode : selectedNodes) { + if (!(selectedNode.getDescriptor() instanceof ThreadDescriptorImpl)) { + visible = false; + break; + } + } - if(selectedNodes != null && selectedNodes.length > 0){ - visible = true; - enabled = true; - for (DebuggerTreeNodeImpl selectedNode : selectedNodes) { - final NodeDescriptorImpl threadDescriptor = selectedNode.getDescriptor(); - if (!(threadDescriptor instanceof ThreadDescriptorImpl)) { - visible = false; - break; - } - } - - if (visible) { - for (DebuggerTreeNodeImpl selectedNode : selectedNodes) { - final ThreadDescriptorImpl threadDescriptor = (ThreadDescriptorImpl)selectedNode.getDescriptor(); - if (threadDescriptor.isFrozen()) { - enabled = false; - break; - } + if (visible) { + for (DebuggerTreeNodeImpl selectedNode : selectedNodes) { + ThreadDescriptorImpl threadDescriptor = (ThreadDescriptorImpl)selectedNode.getDescriptor(); + if (threadDescriptor.isFrozen()) { + enabled = false; + break; + } + } + } } - } + Presentation presentation = e.getPresentation(); + presentation.setTextValue(JavaDebuggerLocalize.actionInterruptThreadText()); + presentation.setVisible(visible); + presentation.setEnabled(enabled); } - final Presentation presentation = e.getPresentation(); - presentation.setText(DebuggerBundle.message("action.interrupt.thread.text")); - presentation.setVisible(visible); - presentation.setEnabled(enabled); - } } diff --git a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/JavaReferringObjectsValue.java b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/JavaReferringObjectsValue.java index d92c86aa8c..ebba12ca68 100644 --- a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/JavaReferringObjectsValue.java +++ b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/JavaReferringObjectsValue.java @@ -15,7 +15,6 @@ */ package com.intellij.java.debugger.impl.actions; -import com.intellij.java.debugger.DebuggerBundle; import com.intellij.java.debugger.DebuggerContext; import com.intellij.java.debugger.engine.evaluation.EvaluateException; import com.intellij.java.debugger.impl.engine.JavaValue; @@ -25,6 +24,7 @@ import com.intellij.java.debugger.impl.ui.impl.watch.FieldDescriptorImpl; import com.intellij.java.debugger.impl.ui.impl.watch.NodeManagerImpl; import com.intellij.java.debugger.impl.ui.impl.watch.ValueDescriptorImpl; +import com.intellij.java.debugger.localize.JavaDebuggerLocalize; import com.intellij.java.language.psi.PsiExpression; import consulo.execution.debug.frame.*; import consulo.execution.debug.frame.presentation.XValueNodePresentationConfigurator; @@ -44,11 +44,13 @@ public class JavaReferringObjectsValue extends JavaValue { private static final long MAX_REFERRING = 100; private final boolean myIsField; - private JavaReferringObjectsValue(@Nullable JavaValue parent, - @Nonnull ValueDescriptorImpl valueDescriptor, - @Nonnull EvaluationContextImpl evaluationContext, - NodeManagerImpl nodeManager, - boolean isField) { + private JavaReferringObjectsValue( + @Nullable JavaValue parent, + @Nonnull ValueDescriptorImpl valueDescriptor, + @Nonnull EvaluationContextImpl evaluationContext, + NodeManagerImpl nodeManager, + boolean isField + ) { super(parent, valueDescriptor, evaluationContext, nodeManager, false); myIsField = isField; } @@ -64,7 +66,7 @@ public boolean canNavigateToSource() { } @Override - public void computeChildren(@Nonnull final XCompositeNode node) { + public void computeChildren(@Nonnull XCompositeNode node) { scheduleCommand(getEvaluationContext(), node, new SuspendContextCommandImpl(getEvaluationContext().getSuspendContext()) { @Override public Priority getPriority() { @@ -73,21 +75,21 @@ public Priority getPriority() { @Override public void contextAction(@Nonnull SuspendContextImpl suspendContext) throws Exception { - final XValueChildrenList children = new XValueChildrenList(); + XValueChildrenList children = new XValueChildrenList(); Value value = getDescriptor().getValue(); List references; try { - references = ((ObjectReference) value).referringObjects(MAX_REFERRING); + references = ((ObjectReference)value).referringObjects(MAX_REFERRING); } catch (ObjectCollectedException e) { - node.setErrorMessage(DebuggerBundle.message("evaluation.error.object.collected")); + node.setErrorMessage(JavaDebuggerLocalize.evaluationErrorObjectCollected().get()); return; } int i = 1; - for (final ObjectReference reference : references) { + for (ObjectReference reference : references) { // try to find field name Field field = findField(reference, value); if (field != null) { @@ -117,7 +119,10 @@ public PsiExpression getDescriptorEvaluation(DebuggerContext context) throws Eva return null; } }; - children.add("Referrer " + i++, new JavaReferringObjectsValue(null, descriptor, getEvaluationContext(), getNodeManager(), false)); + children.add( + "Referrer " + i++, + new JavaReferringObjectsValue(null, descriptor, getEvaluationContext(), getNodeManager(), false) + ); } } @@ -127,61 +132,70 @@ public PsiExpression getDescriptorEvaluation(DebuggerContext context) throws Eva } @Override - public void computePresentation(@Nonnull final XValueNode node, @Nonnull final XValuePlace place) { + public void computePresentation(@Nonnull XValueNode node, @Nonnull XValuePlace place) { if (!myIsField) { super.computePresentation(node, place); } else { - super.computePresentation(new XValueNodePresentationConfigurator.ConfigurableXValueNodeImpl() { - @Override - public void applyPresentation(@Nullable Image icon, @Nonnull final XValuePresentation valuePresenter, boolean hasChildren) { - node.setPresentation(icon, new XValuePresentation() { - @Nonnull - @Override - public String getSeparator() { - return " in "; - } - - @Nullable - @Override - public String getType() { - return valuePresenter.getType(); - } - - @Override - public void renderValue(@Nonnull XValueTextRenderer renderer) { - valuePresenter.renderValue(renderer); - } - }, hasChildren); - } + super.computePresentation( + new XValueNodePresentationConfigurator.ConfigurableXValueNodeImpl() { + @Override + public void applyPresentation( + @Nullable Image icon, + @Nonnull XValuePresentation valuePresenter, + boolean hasChildren + ) { + node.setPresentation(icon, new XValuePresentation() { + @Nonnull + @Override + public String getSeparator() { + return " in "; + } + + @Nullable + @Override + public String getType() { + return valuePresenter.getType(); + } + + @Override + public void renderValue(@Nonnull XValueTextRenderer renderer) { + valuePresenter.renderValue(renderer); + } + }, + hasChildren + ); + } - @Override - public void setFullValueEvaluator(@Nonnull XFullValueEvaluator fullValueEvaluator) { - } + @Override + public void setFullValueEvaluator(@Nonnull XFullValueEvaluator fullValueEvaluator) { + } - @Nullable - @Override - public String getName() { - return null; - } + @Nullable + @Override + public String getName() { + return null; + } - @Nullable - @Override - public XValue getValueContainer() { - return null; - } + @Nullable + @Override + public XValue getValueContainer() { + return null; + } - @Nullable - @Override - public XValueTree getTree() { - return null; - } + @Nullable + @Override + public XValueTree getTree() { + return null; + } - @Override - public boolean isObsolete() { - return false; - } - }, place); + @Override + public boolean isObsolete() { + return false; + } + }, + place + ); } } diff --git a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/JavaSmartStepIntoHandler.java b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/JavaSmartStepIntoHandler.java index 45e2cc04b3..15735b85e9 100644 --- a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/JavaSmartStepIntoHandler.java +++ b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/JavaSmartStepIntoHandler.java @@ -18,6 +18,7 @@ import com.intellij.java.debugger.SourcePosition; import com.intellij.java.language.JavaLanguage; import com.intellij.java.language.psi.*; +import consulo.annotation.access.RequiredReadAction; import consulo.annotation.component.ExtensionImpl; import consulo.document.Document; import consulo.document.FileDocumentManager; @@ -32,146 +33,165 @@ import jakarta.annotation.Nonnull; import jakarta.annotation.Nullable; + import java.util.*; /** - * User: Alexander Podkhalyuzin - * Date: 22.11.11 + * @author Alexander Podkhalyuzin + * @since 2011-11-22 */ @ExtensionImpl public class JavaSmartStepIntoHandler extends JvmSmartStepIntoHandler { - @Override - public boolean isAvailable(final SourcePosition position) { - final PsiFile file = position.getFile(); - return file.getLanguage().isKindOf(JavaLanguage.INSTANCE); - } - - @Override - @Nonnull - public List findSmartStepTargets(final SourcePosition position) { - final int line = position.getLine(); - if (line < 0) { - return Collections.emptyList(); // the document has been changed - } - - final PsiFile file = position.getFile(); - final VirtualFile vFile = file.getVirtualFile(); - if (vFile == null) { - // the file is not physical - return Collections.emptyList(); - } - - final Document doc = FileDocumentManager.getInstance().getDocument(vFile); - if (doc == null) { - return Collections.emptyList(); + @Override + @RequiredReadAction + public boolean isAvailable(SourcePosition position) { + PsiFile file = position.getFile(); + return file.getLanguage().isKindOf(JavaLanguage.INSTANCE); } - if (line >= doc.getLineCount()) { - return Collections.emptyList(); // the document has been changed - } - final int startOffset = doc.getLineStartOffset(line); - final TextRange lineRange = new TextRange(startOffset, doc.getLineEndOffset(line)); - final int offset = CharArrayUtil.shiftForward(doc.getCharsSequence(), startOffset, " \t"); - PsiElement element = file.findElementAt(offset); - if (element != null && !(element instanceof PsiCompiledElement)) { - do { - final PsiElement parent = element.getParent(); - if (parent == null || (parent.getTextOffset() < lineRange.getStartOffset())) { - break; - } - element = parent; - } - while (true); - - final Set targets = new LinkedHashSet(); - - final Range lines = - new Range(doc.getLineNumber(element.getTextOffset()), doc.getLineNumber(element.getTextOffset() + - element.getTextLength())); - final PsiElementVisitor methodCollector = new JavaRecursiveElementVisitor() { - final Stack myContextStack = new Stack(); - final Stack myParamNameStack = new Stack(); - private int myNextLambdaExpressionOrdinal = 0; - - @Nullable - private String getCurrentParamName() { - return myParamNameStack.isEmpty() ? null : myParamNameStack.peek(); + @Nonnull + @Override + @RequiredReadAction + public List findSmartStepTargets(SourcePosition position) { + int line = position.getLine(); + if (line < 0) { + return Collections.emptyList(); // the document has been changed } - @Override - public void visitAnonymousClass(PsiAnonymousClass aClass) { - for (PsiMethod psiMethod : aClass.getMethods()) { - targets.add(new MethodSmartStepTarget(psiMethod, getCurrentParamName(), psiMethod.getBody(), true, lines)); - } + PsiFile file = position.getFile(); + VirtualFile vFile = file.getVirtualFile(); + if (vFile == null) { + // the file is not physical + return Collections.emptyList(); } - public void visitLambdaExpression(PsiLambdaExpression expression) { - targets.add(new LambdaSmartStepTarget(expression, getCurrentParamName(), expression.getBody(), myNextLambdaExpressionOrdinal++, - lines)); + Document doc = FileDocumentManager.getInstance().getDocument(vFile); + if (doc == null) { + return Collections.emptyList(); } - - @Override - public void visitStatement(PsiStatement statement) { - if (lineRange.intersects(statement.getTextRange())) { - super.visitStatement(statement); - } + if (line >= doc.getLineCount()) { + return Collections.emptyList(); // the document has been changed } - - public void visitExpressionList(PsiExpressionList expressionList) { - final PsiMethod psiMethod = myContextStack.isEmpty() ? null : myContextStack.peek(); - if (psiMethod != null) { - final String methodName = psiMethod.getName(); - final PsiExpression[] expressions = expressionList.getExpressions(); - final PsiParameter[] parameters = psiMethod.getParameterList().getParameters(); - for (int idx = 0; idx < expressions.length; idx++) { - final String paramName = (idx < parameters.length && !parameters[idx].isVarArgs()) ? parameters[idx].getName() : "arg" + - (idx + 1); - myParamNameStack.push(methodName + ": " + paramName + "."); - final PsiExpression argExpression = expressions[idx]; - try { - argExpression.accept(this); - } - finally { - myParamNameStack.pop(); - } + int startOffset = doc.getLineStartOffset(line); + TextRange lineRange = new TextRange(startOffset, doc.getLineEndOffset(line)); + int offset = CharArrayUtil.shiftForward(doc.getCharsSequence(), startOffset, " \t"); + PsiElement element = file.findElementAt(offset); + if (element != null && !(element instanceof PsiCompiledElement)) { + do { + PsiElement parent = element.getParent(); + if (parent == null || (parent.getTextOffset() < lineRange.getStartOffset())) { + break; + } + element = parent; } - } - else { - super.visitExpressionList(expressionList); - } - } - - @Override - public void visitCallExpression(final PsiCallExpression expression) { - final PsiMethod psiMethod = expression.resolveMethod(); - if (psiMethod != null) { - myContextStack.push(psiMethod); - targets.add(new MethodSmartStepTarget(psiMethod, null, expression instanceof PsiMethodCallExpression ? ( - (PsiMethodCallExpression)expression).getMethodExpression().getReferenceNameElement() : expression instanceof - PsiNewExpression ? ((PsiNewExpression)expression).getClassOrAnonymousClassReference() : expression, false, lines)); - } - try { - super.visitCallExpression(expression); - } - finally { - if (psiMethod != null) { - myContextStack.pop(); + while (true); + + Set targets = new LinkedHashSet<>(); + + Range lines = new Range<>( + doc.getLineNumber(element.getTextOffset()), + doc.getLineNumber(element.getTextOffset() + element.getTextLength()) + ); + + PsiElementVisitor methodCollector = new JavaRecursiveElementVisitor() { + Stack myContextStack = new Stack<>(); + Stack myParamNameStack = new Stack<>(); + private int myNextLambdaExpressionOrdinal = 0; + + @Nullable + private String getCurrentParamName() { + return myParamNameStack.isEmpty() ? null : myParamNameStack.peek(); + } + + @Override + public void visitAnonymousClass(PsiAnonymousClass aClass) { + for (PsiMethod psiMethod : aClass.getMethods()) { + targets.add(new MethodSmartStepTarget(psiMethod, getCurrentParamName(), psiMethod.getBody(), true, lines)); + } + } + + @Override + public void visitLambdaExpression(@Nonnull PsiLambdaExpression expression) { + targets.add(new LambdaSmartStepTarget( + expression, + getCurrentParamName(), + expression.getBody(), + myNextLambdaExpressionOrdinal++, + lines + )); + } + + @Override + @RequiredReadAction + public void visitStatement(PsiStatement statement) { + if (lineRange.intersects(statement.getTextRange())) { + super.visitStatement(statement); + } + } + + @Override + public void visitExpressionList(@Nonnull PsiExpressionList expressionList) { + PsiMethod psiMethod = myContextStack.isEmpty() ? null : myContextStack.peek(); + if (psiMethod != null) { + String methodName = psiMethod.getName(); + PsiExpression[] expressions = expressionList.getExpressions(); + PsiParameter[] parameters = psiMethod.getParameterList().getParameters(); + for (int idx = 0; idx < expressions.length; idx++) { + String paramName = (idx < parameters.length && !parameters[idx].isVarArgs()) + ? parameters[idx].getName() + : "arg" + (idx + 1); + myParamNameStack.push(methodName + ": " + paramName + "."); + PsiExpression argExpression = expressions[idx]; + try { + argExpression.accept(this); + } + finally { + myParamNameStack.pop(); + } + } + } + else { + super.visitExpressionList(expressionList); + } + } + + @Override + public void visitCallExpression(PsiCallExpression expression) { + PsiMethod psiMethod = expression.resolveMethod(); + if (psiMethod != null) { + myContextStack.push(psiMethod); + targets.add(new MethodSmartStepTarget( + psiMethod, + null, + expression instanceof PsiMethodCallExpression methodCall + ? methodCall.getMethodExpression().getReferenceNameElement() + : expression instanceof PsiNewExpression newExpr + ? newExpr.getClassOrAnonymousClassReference() + : expression, + false, + lines + )); + } + try { + super.visitCallExpression(expression); + } + finally { + if (psiMethod != null) { + myContextStack.pop(); + } + } + } + }; + + element.accept(methodCollector); + for (PsiElement sibling = element.getNextSibling(); sibling != null; sibling = sibling.getNextSibling()) { + if (!lineRange.intersects(sibling.getTextRange())) { + break; + } + sibling.accept(methodCollector); } - } + return new ArrayList<>(targets); } - - }; - - element.accept(methodCollector); - for (PsiElement sibling = element.getNextSibling(); sibling != null; sibling = sibling.getNextSibling()) { - if (!lineRange.intersects(sibling.getTextRange())) { - break; - } - sibling.accept(methodCollector); - } - return new ArrayList<>(targets); + return Collections.emptyList(); } - return Collections.emptyList(); - } - } diff --git a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/JumpToObjectAction.java b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/JumpToObjectAction.java index a641302ca5..88400ed0a8 100644 --- a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/JumpToObjectAction.java +++ b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/JumpToObjectAction.java @@ -16,7 +16,11 @@ package com.intellij.java.debugger.impl.actions; import java.util.List; +import java.util.function.Supplier; +import consulo.application.Application; +import consulo.ui.annotation.RequiredUIAccess; +import jakarta.annotation.Nonnull; import jakarta.annotation.Nullable; import com.intellij.java.debugger.SourcePosition; import com.intellij.java.debugger.impl.engine.DebugProcessImpl; @@ -42,236 +46,191 @@ import consulo.internal.com.sun.jdi.Type; import consulo.internal.com.sun.jdi.Value; -public class JumpToObjectAction extends DebuggerAction -{ - private static final Logger LOG = Logger.getInstance(JumpToObjectAction.class); - - @Override - public void actionPerformed(AnActionEvent e) - { - DebuggerTreeNodeImpl selectedNode = getSelectedNode(e.getDataContext()); - if(selectedNode == null) - { - return; - } - - final NodeDescriptorImpl descriptor = selectedNode.getDescriptor(); - if(!(descriptor instanceof ValueDescriptor)) - { - return; - } - - DebuggerContextImpl debuggerContext = getDebuggerContext(e.getDataContext()); - final DebugProcessImpl debugProcess = debuggerContext.getDebugProcess(); - if(debugProcess == null) - { - return; - } - - debugProcess.getManagerThread().schedule(new NavigateCommand(debuggerContext, (ValueDescriptor) descriptor, debugProcess, e)); - } - - @Override - public void update(final AnActionEvent e) - { - if(!isFirstStart(e)) - { - return; - } - - final DebuggerContextImpl debuggerContext = getDebuggerContext(e.getDataContext()); - final DebugProcessImpl debugProcess = debuggerContext.getDebugProcess(); - if(debugProcess == null) - { - e.getPresentation().setVisible(false); - return; - } - - DebuggerTreeNodeImpl selectedNode = getSelectedNode(e.getDataContext()); - if(selectedNode == null) - { - e.getPresentation().setVisible(false); - return; - } - - final NodeDescriptorImpl descriptor = selectedNode.getDescriptor(); - if(descriptor instanceof ValueDescriptor) - { - debugProcess.getManagerThread().schedule(new EnableCommand(debuggerContext, (ValueDescriptor) descriptor, debugProcess, e)); - } - else - { - e.getPresentation().setVisible(false); - } - } - - private static SourcePosition calcPosition(final ValueDescriptor descriptor, final DebugProcessImpl debugProcess) throws ClassNotLoadedException - { - final Value value = descriptor.getValue(); - if(value == null) - { - return null; - } - - Type type = value.type(); - if(type == null) - { - return null; - } - - try - { - if(type instanceof ArrayType) - { - type = ((ArrayType) type).componentType(); - } - if(type instanceof ClassType) - { - final ClassType clsType = (ClassType) type; - final List locations = clsType.allLineLocations(); - if(locations.size() > 0) - { - final Location location = locations.get(0); - return ApplicationManager.getApplication().runReadAction(new Computable() - { - @Override - public SourcePosition compute() - { - SourcePosition position = debugProcess.getPositionManager().getSourcePosition(location); - // adjust position for non-anonymous classes - if(clsType.name().indexOf('$') < 0) - { - final PsiClass classAt = JVMNameUtil.getClassAt(position); - if(classAt != null) - { - final SourcePosition classPosition = SourcePosition.createFromElement(classAt); - if(classPosition != null) - { - position = classPosition; - } - } - } - return position; - } - }); - } - } - } - catch(ClassNotPreparedException e) - { - LOG.debug(e); - } - catch(AbsentInformationException e) - { - LOG.debug(e); - } - return null; - } - - public static class NavigateCommand extends SourcePositionCommand - { - public NavigateCommand( - final DebuggerContextImpl debuggerContext, - final ValueDescriptor descriptor, - final DebugProcessImpl debugProcess, - final AnActionEvent e) - { - super(debuggerContext, descriptor, debugProcess, e); - } - - @Override - protected NavigateCommand createRetryCommand() - { - return new NavigateCommand(myDebuggerContext, myDescriptor, myDebugProcess, myActionEvent); - } - - @Override - protected void doAction(final SourcePosition sourcePosition) - { - if(sourcePosition != null) - { - sourcePosition.navigate(true); - } - } - } - - private static class EnableCommand extends SourcePositionCommand - { - public EnableCommand( - final DebuggerContextImpl debuggerContext, - final ValueDescriptor descriptor, - final DebugProcessImpl debugProcess, - final AnActionEvent e) - { - super(debuggerContext, descriptor, debugProcess, e); - } - - @Override - protected EnableCommand createRetryCommand() - { - return new EnableCommand(myDebuggerContext, myDescriptor, myDebugProcess, myActionEvent); - } - - @Override - protected void doAction(final SourcePosition sourcePosition) - { - enableAction(myActionEvent, sourcePosition != null); - } - } - - public abstract static class SourcePositionCommand extends SuspendContextCommandImpl - { - protected final DebuggerContextImpl myDebuggerContext; - protected final ValueDescriptor myDescriptor; - protected final DebugProcessImpl myDebugProcess; - protected final AnActionEvent myActionEvent; - - public SourcePositionCommand( - final DebuggerContextImpl debuggerContext, - final ValueDescriptor descriptor, - final DebugProcessImpl debugProcess, - final AnActionEvent actionEvent) - { - super(debuggerContext.getSuspendContext()); - myDebuggerContext = debuggerContext; - myDescriptor = descriptor; - myDebugProcess = debugProcess; - myActionEvent = actionEvent; - } - - @Override - public final void contextAction() throws Exception - { - try - { - doAction(calcPosition(myDescriptor, myDebugProcess)); - } - catch(ClassNotLoadedException ex) - { - final String className = ex.className(); - if(loadClass(className) != null) - { - myDebugProcess.getManagerThread().schedule(createRetryCommand()); - } - } - } - - protected abstract SourcePositionCommand createRetryCommand(); - - protected abstract void doAction(@Nullable SourcePosition sourcePosition); - - private ReferenceType loadClass(final String className) - { - final EvaluationContextImpl eContext = myDebuggerContext.createEvaluationContext(); - try - { - return myDebugProcess.loadClass(eContext, className, eContext.getClassLoader()); - } - catch(Throwable ignored) - { - } - return null; - } - } - +public class JumpToObjectAction extends DebuggerAction { + private static final Logger LOG = Logger.getInstance(JumpToObjectAction.class); + + @Override + @RequiredUIAccess + public void actionPerformed(AnActionEvent e) { + DebuggerTreeNodeImpl selectedNode = getSelectedNode(e.getDataContext()); + if (selectedNode == null) { + return; + } + + NodeDescriptorImpl descriptor = selectedNode.getDescriptor(); + if (!(descriptor instanceof ValueDescriptor valueDescriptor)) { + return; + } + + DebuggerContextImpl debuggerContext = getDebuggerContext(e.getDataContext()); + DebugProcessImpl debugProcess = debuggerContext.getDebugProcess(); + if (debugProcess == null) { + return; + } + + debugProcess.getManagerThread().schedule(new NavigateCommand(debuggerContext, valueDescriptor, debugProcess, e)); + } + + @Override + @RequiredUIAccess + public void update(@Nonnull AnActionEvent e) { + if (!isFirstStart(e)) { + return; + } + + DebuggerContextImpl debuggerContext = getDebuggerContext(e.getDataContext()); + DebugProcessImpl debugProcess = debuggerContext.getDebugProcess(); + if (debugProcess == null) { + e.getPresentation().setVisible(false); + return; + } + + DebuggerTreeNodeImpl selectedNode = getSelectedNode(e.getDataContext()); + if (selectedNode == null) { + e.getPresentation().setVisible(false); + return; + } + + NodeDescriptorImpl descriptor = selectedNode.getDescriptor(); + if (descriptor instanceof ValueDescriptor valueDescriptor) { + debugProcess.getManagerThread().schedule(new EnableCommand(debuggerContext, valueDescriptor, debugProcess, e)); + } + else { + e.getPresentation().setVisible(false); + } + } + + private static SourcePosition calcPosition(ValueDescriptor descriptor, DebugProcessImpl debugProcess) + throws ClassNotLoadedException { + Value value = descriptor.getValue(); + if (value == null) { + return null; + } + + Type type = value.type(); + if (type == null) { + return null; + } + + try { + if (type instanceof ArrayType arrayType) { + type = arrayType.componentType(); + } + if (type instanceof ClassType clsType) { + List locations = clsType.allLineLocations(); + if (locations.size() > 0) { + Location location = locations.get(0); + return Application.get().runReadAction((Supplier)() -> { + SourcePosition position = debugProcess.getPositionManager().getSourcePosition(location); + // adjust position for non-anonymous classes + if (clsType.name().indexOf('$') < 0) { + PsiClass classAt = JVMNameUtil.getClassAt(position); + if (classAt != null) { + SourcePosition classPosition = SourcePosition.createFromElement(classAt); + if (classPosition != null) { + position = classPosition; + } + } + } + return position; + }); + } + } + } + catch (ClassNotPreparedException | AbsentInformationException e) { + LOG.debug(e); + } + return null; + } + + public static class NavigateCommand extends SourcePositionCommand { + public NavigateCommand( + DebuggerContextImpl debuggerContext, + ValueDescriptor descriptor, + DebugProcessImpl debugProcess, + AnActionEvent e + ) { + super(debuggerContext, descriptor, debugProcess, e); + } + + @Override + protected NavigateCommand createRetryCommand() { + return new NavigateCommand(myDebuggerContext, myDescriptor, myDebugProcess, myActionEvent); + } + + @Override + protected void doAction(SourcePosition sourcePosition) { + if (sourcePosition != null) { + sourcePosition.navigate(true); + } + } + } + + private static class EnableCommand extends SourcePositionCommand { + public EnableCommand( + DebuggerContextImpl debuggerContext, + ValueDescriptor descriptor, + DebugProcessImpl debugProcess, + AnActionEvent e + ) { + super(debuggerContext, descriptor, debugProcess, e); + } + + @Override + protected EnableCommand createRetryCommand() { + return new EnableCommand(myDebuggerContext, myDescriptor, myDebugProcess, myActionEvent); + } + + @Override + protected void doAction(SourcePosition sourcePosition) { + enableAction(myActionEvent, sourcePosition != null); + } + } + + public abstract static class SourcePositionCommand extends SuspendContextCommandImpl { + protected final DebuggerContextImpl myDebuggerContext; + protected final ValueDescriptor myDescriptor; + protected final DebugProcessImpl myDebugProcess; + protected final AnActionEvent myActionEvent; + + public SourcePositionCommand( + DebuggerContextImpl debuggerContext, + ValueDescriptor descriptor, + DebugProcessImpl debugProcess, + AnActionEvent actionEvent + ) { + super(debuggerContext.getSuspendContext()); + myDebuggerContext = debuggerContext; + myDescriptor = descriptor; + myDebugProcess = debugProcess; + myActionEvent = actionEvent; + } + + @Override + public final void contextAction() throws Exception { + try { + doAction(calcPosition(myDescriptor, myDebugProcess)); + } + catch (ClassNotLoadedException ex) { + String className = ex.className(); + if (loadClass(className) != null) { + myDebugProcess.getManagerThread().schedule(createRetryCommand()); + } + } + } + + protected abstract SourcePositionCommand createRetryCommand(); + + protected abstract void doAction(@Nullable SourcePosition sourcePosition); + + private ReferenceType loadClass(String className) { + EvaluationContextImpl eContext = myDebuggerContext.createEvaluationContext(); + try { + return myDebugProcess.loadClass(eContext, className, eContext.getClassLoader()); + } + catch (Throwable ignored) { + } + return null; + } + } } diff --git a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/JvmDropFrameActionHandler.java b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/JvmDropFrameActionHandler.java index b21b1e3d4f..524cc8954d 100644 --- a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/JvmDropFrameActionHandler.java +++ b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/JvmDropFrameActionHandler.java @@ -1,16 +1,15 @@ // Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.java.debugger.impl.actions; -import com.intellij.java.debugger.DebuggerBundle; import com.intellij.java.debugger.SourcePosition; import com.intellij.java.debugger.impl.DebuggerContextImpl; import com.intellij.java.debugger.impl.DebuggerSession; import com.intellij.java.debugger.impl.engine.DebugProcessImpl; import com.intellij.java.debugger.impl.engine.JavaStackFrame; import com.intellij.java.debugger.impl.settings.DebuggerSettings; +import com.intellij.java.debugger.localize.JavaDebuggerLocalize; import com.intellij.java.language.psi.*; -import consulo.application.ApplicationManager; -import consulo.application.CommonBundle; +import consulo.annotation.access.RequiredReadAction; import consulo.execution.debug.XDebuggerBundle; import consulo.execution.debug.breakpoint.XExpression; import consulo.execution.debug.evaluation.EvaluationMode; @@ -18,6 +17,7 @@ import consulo.execution.debug.frame.XDropFrameHandler; import consulo.execution.debug.frame.XStackFrame; import consulo.execution.debug.frame.XValue; +import consulo.execution.debug.localize.XDebuggerLocalize; import consulo.internal.com.sun.jdi.InvalidStackFrameException; import consulo.internal.com.sun.jdi.VMDisconnectedException; import consulo.language.psi.PsiElement; @@ -27,9 +27,11 @@ import consulo.platform.base.localize.CommonLocalize; import consulo.project.Project; import consulo.ui.ModalityState; +import consulo.ui.annotation.RequiredUIAccess; import consulo.ui.ex.awt.DialogWrapper; import consulo.ui.ex.awt.MessageDialogBuilder; import consulo.ui.ex.awt.Messages; +import consulo.ui.ex.awt.UIUtil; import consulo.util.collection.ContainerUtil; import jakarta.annotation.Nonnull; import jakarta.annotation.Nullable; @@ -39,7 +41,6 @@ import java.util.List; public class JvmDropFrameActionHandler implements XDropFrameHandler { - private static final Logger LOG = Logger.getInstance(JvmDropFrameActionHandler.class); private final @Nonnull DebuggerSession myDebugSession; @@ -49,6 +50,7 @@ public JvmDropFrameActionHandler(@Nonnull DebuggerSession process) { @Override public boolean canDrop(@Nonnull XStackFrame frame) { + //noinspection SimplifiableIfStatement if (frame instanceof JavaStackFrame javaStackFrame) { return javaStackFrame.getStackFrameProxy().getVirtualMachine().canPopFrames() && javaStackFrame.getDescriptor().canDrop(); } @@ -56,6 +58,7 @@ public boolean canDrop(@Nonnull XStackFrame frame) { } @Override + @RequiredUIAccess public void drop(@Nonnull XStackFrame frame) { if (frame instanceof JavaStackFrame stackFrame) { var project = myDebugSession.getProject(); @@ -63,7 +66,8 @@ public void drop(@Nonnull XStackFrame frame) { var debuggerContext = myDebugSession.getContextManager().getContext(); try { myDebugSession.setSteppingThrough(stackFrame.getStackFrameProxy().threadProxy()); - if (evaluateFinallyBlocks(project, + if (evaluateFinallyBlocks( + project, XDebuggerBundle.message("xdebugger.reset.frame.title"), stackFrame, new XDebuggerEvaluator.XEvaluationCallback() { @@ -73,11 +77,15 @@ public void evaluated(@Nonnull XValue result) { } @Override - public void errorOccurred(@Nonnull final String errorMessage) { - showError(project, DebuggerBundle.message("error.executing.finally", errorMessage), - XDebuggerBundle.message("xdebugger.reset.frame.title")); + public void errorOccurred(@Nonnull String errorMessage) { + showError( + project, + JavaDebuggerLocalize.errorExecutingFinally(errorMessage).get(), + XDebuggerBundle.message("xdebugger.reset.frame.title") + ); } - })) { + } + )) { return; } popFrame(debugProcess, debuggerContext, stackFrame); @@ -87,10 +95,13 @@ public void errorOccurred(@Nonnull final String errorMessage) { } } - public static boolean evaluateFinallyBlocks(Project project, - String title, - JavaStackFrame stackFrame, - XDebuggerEvaluator.XEvaluationCallback callback) { + @RequiredUIAccess + public static boolean evaluateFinallyBlocks( + Project project, + String title, + JavaStackFrame stackFrame, + XDebuggerEvaluator.XEvaluationCallback callback + ) { if (!DebuggerSettings.EVALUATE_FINALLY_NEVER.equals(DebuggerSettings.getInstance().EVALUATE_FINALLY_ON_POP_FRAME)) { List statements = getFinallyStatements(project, stackFrame.getDescriptor().getSourcePosition()); if (!statements.isEmpty()) { @@ -104,25 +115,30 @@ public static boolean evaluateFinallyBlocks(Project project, } else { int res = MessageDialogBuilder - .yesNoCancel(title, - DebuggerBundle.message("warning.finally.block.detected") + sb) - .icon(Messages.getWarningIcon()) - .yesText(DebuggerBundle.message("button.execute.finally")) - .noText(DebuggerBundle.message("button.drop.anyway")) + .yesNoCancel( + title, + JavaDebuggerLocalize.warningFinallyBlockDetected().get() + sb + ) + .icon(UIUtil.getWarningIcon()) + .yesText(JavaDebuggerLocalize.buttonExecuteFinally().get()) + .noText(JavaDebuggerLocalize.buttonDropAnyway().get()) .project(project) - .cancelText(CommonBundle.getCancelButtonText()) + .cancelText(CommonLocalize.buttonCancel().get()) .doNotAsk(new DialogWrapper.DoNotAskOption() { @Override public boolean isToBeShown() { - return !DebuggerSettings.EVALUATE_FINALLY_ALWAYS.equals(DebuggerSettings.getInstance().EVALUATE_FINALLY_ON_POP_FRAME) && - !DebuggerSettings.EVALUATE_FINALLY_NEVER.equals(DebuggerSettings.getInstance().EVALUATE_FINALLY_ON_POP_FRAME); + return !DebuggerSettings.EVALUATE_FINALLY_ALWAYS + .equals(DebuggerSettings.getInstance().EVALUATE_FINALLY_ON_POP_FRAME) + && !DebuggerSettings.EVALUATE_FINALLY_NEVER + .equals(DebuggerSettings.getInstance().EVALUATE_FINALLY_ON_POP_FRAME); } @Override public void setToBeShown(boolean value, int exitCode) { if (!value) { - DebuggerSettings.getInstance().EVALUATE_FINALLY_ON_POP_FRAME = - exitCode == Messages.YES ? DebuggerSettings.EVALUATE_FINALLY_ALWAYS : DebuggerSettings.EVALUATE_FINALLY_NEVER; + DebuggerSettings.getInstance().EVALUATE_FINALLY_ON_POP_FRAME = exitCode == Messages.YES + ? DebuggerSettings.EVALUATE_FINALLY_ALWAYS + : DebuggerSettings.EVALUATE_FINALLY_NEVER; } else { DebuggerSettings.getInstance().EVALUATE_FINALLY_ON_POP_FRAME = DebuggerSettings.EVALUATE_FINALLY_ASK; @@ -169,30 +185,39 @@ private static void popFrame(DebugProcessImpl debugProcess, DebuggerContextImpl .schedule(debugProcess.createPopFrameCommand(debuggerContext, stackFrame.getStackFrameProxy())); } - private static void evaluateAndAct(Project project, - JavaStackFrame stackFrame, - StringBuilder sb, - XDebuggerEvaluator.XEvaluationCallback callback) { + @RequiredUIAccess + private static void evaluateAndAct( + Project project, + JavaStackFrame stackFrame, + StringBuilder sb, + XDebuggerEvaluator.XEvaluationCallback callback + ) { XDebuggerEvaluator evaluator = stackFrame.getEvaluator(); if (evaluator != null) { - evaluator.evaluate(XExpression.fromText(sb.toString(), EvaluationMode.CODE_FRAGMENT), + evaluator.evaluate( + XExpression.fromText(sb.toString(), EvaluationMode.CODE_FRAGMENT), callback, - stackFrame.getSourcePosition()); + stackFrame.getSourcePosition() + ); } else { - Messages.showMessageDialog(project, XDebuggerBundle.message("xdebugger.evaluate.stack.frame.has.not.evaluator"), + Messages.showMessageDialog( + project, + XDebuggerLocalize.xdebuggerEvaluateStackFrameHasNotEvaluator().get(), XDebuggerBundle.message("xdebugger.reset.frame.title"), - Messages.getErrorIcon()); + UIUtil.getErrorIcon() + ); } } - public static void showError(Project project, String message, String title) { - ApplicationManager.getApplication().invokeLater( - () -> Messages.showMessageDialog(project, message, title, Messages.getErrorIcon()), - ModalityState.any()); + project.getApplication().invokeLater( + () -> Messages.showMessageDialog(project, message, title, UIUtil.getErrorIcon()), + ModalityState.any() + ); } + @RequiredReadAction private static List getFinallyStatements(Project project, @Nullable SourcePosition position) { if (position == null) { return Collections.emptyList(); @@ -220,12 +245,13 @@ private static List getFinallyStatements(Project project, @Nullabl return res; } + @RequiredReadAction private static String getResourceName(PsiResourceListElement resource) { - if (resource instanceof PsiResourceVariable) { - return ((PsiResourceVariable) resource).getName(); + if (resource instanceof PsiResourceVariable resourceVar) { + return resourceVar.getName(); } - else if (resource instanceof PsiResourceExpression) { - return ((PsiResourceExpression) resource).getExpression().getText(); + else if (resource instanceof PsiResourceExpression resourceExpr) { + return resourceExpr.getExpression().getText(); } LOG.error("Unknown PsiResourceListElement type: " + resource.getClass()); return null; diff --git a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/JvmSmartStepIntoActionHandler.java b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/JvmSmartStepIntoActionHandler.java index 59d27b9ccb..c12d058433 100644 --- a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/JvmSmartStepIntoActionHandler.java +++ b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/JvmSmartStepIntoActionHandler.java @@ -1,90 +1,82 @@ // Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.java.debugger.impl.actions; -import com.intellij.java.debugger.DebuggerBundle; import com.intellij.java.debugger.SourcePosition; import com.intellij.java.debugger.impl.DebuggerSession; import com.intellij.java.debugger.impl.DebuggerUtilsEx; +import com.intellij.java.debugger.localize.JavaDebuggerLocalize; +import consulo.annotation.access.RequiredReadAction; import consulo.document.util.TextRange; +import consulo.execution.debug.XSourcePosition; import consulo.execution.debug.frame.XSuspendContext; import consulo.execution.debug.step.XSmartStepIntoHandler; import consulo.execution.debug.step.XSmartStepIntoVariant; import consulo.language.psi.PsiElement; -import consulo.util.collection.ContainerUtil; -import consulo.execution.debug.XSourcePosition; +import consulo.ui.annotation.RequiredUIAccess; import consulo.ui.image.Image; - +import consulo.util.collection.ContainerUtil; import jakarta.annotation.Nonnull; import jakarta.annotation.Nullable; import java.util.List; -public class JvmSmartStepIntoActionHandler extends XSmartStepIntoHandler -{ - private final DebuggerSession mySession; +public class JvmSmartStepIntoActionHandler extends XSmartStepIntoHandler { + private final DebuggerSession mySession; - public JvmSmartStepIntoActionHandler(@Nonnull DebuggerSession session) - { - mySession = session; - } + public JvmSmartStepIntoActionHandler(@Nonnull DebuggerSession session) { + mySession = session; + } - @Nonnull - @Override - public List computeSmartStepVariants(@Nonnull XSourcePosition xPosition) - { - SourcePosition pos = DebuggerUtilsEx.toSourcePosition(xPosition, mySession.getProject()); - JvmSmartStepIntoHandler handler = JvmSmartStepIntoHandler.EP_NAME.findFirstSafe(h -> h.isAvailable(pos)); - if(handler != null) - { - List targets = handler.findSmartStepTargets(pos); - return ContainerUtil.map(targets, target -> new JvmSmartStepIntoVariant(target, handler)); - } + @Nonnull + @Override + public List computeSmartStepVariants(@Nonnull XSourcePosition xPosition) { + SourcePosition pos = DebuggerUtilsEx.toSourcePosition(xPosition, mySession.getProject()); + JvmSmartStepIntoHandler handler = JvmSmartStepIntoHandler.EP_NAME.findFirstSafe(h -> h.isAvailable(pos)); + if (handler != null) { + List targets = handler.findSmartStepTargets(pos); + return ContainerUtil.map(targets, target -> new JvmSmartStepIntoVariant(target, handler)); + } - return List.of(); - } + return List.of(); + } - @Override - public String getPopupTitle(@Nonnull XSourcePosition position) - { - return DebuggerBundle.message("title.smart.step.popup"); - } + @Override + public String getPopupTitle(@Nonnull XSourcePosition position) { + return JavaDebuggerLocalize.titleSmartStepPopup().get(); + } - @Override - public void startStepInto(@Nonnull JvmSmartStepIntoVariant variant, @Nullable XSuspendContext context) - { - mySession.stepInto(true, variant.myHandler.createMethodFilter(variant.myTarget)); - } + @Override + @RequiredUIAccess + public void startStepInto(@Nonnull JvmSmartStepIntoVariant variant, @Nullable XSuspendContext context) { + mySession.stepInto(true, variant.myHandler.createMethodFilter(variant.myTarget)); + } - static class JvmSmartStepIntoVariant extends XSmartStepIntoVariant - { - private final SmartStepTarget myTarget; - private final JvmSmartStepIntoHandler myHandler; + static class JvmSmartStepIntoVariant extends XSmartStepIntoVariant { + private final SmartStepTarget myTarget; + private final JvmSmartStepIntoHandler myHandler; - JvmSmartStepIntoVariant(SmartStepTarget target, JvmSmartStepIntoHandler handler) - { - myTarget = target; - myHandler = handler; - } + JvmSmartStepIntoVariant(SmartStepTarget target, JvmSmartStepIntoHandler handler) { + myTarget = target; + myHandler = handler; + } - @Override - public String getText() - { - return myTarget.getPresentation(); - } + @Override + public String getText() { + return myTarget.getPresentation(); + } - @Nullable - @Override - public Image getIcon() - { - return myTarget.getIcon(); - } + @Nullable + @Override + public Image getIcon() { + return myTarget.getIcon(); + } - @Nullable - //@Override - public TextRange getHighlightRange() - { - PsiElement element = myTarget.getHighlightElement(); - return element != null ? element.getTextRange() : null; - } - } + @Nullable + //@Override + @RequiredReadAction + public TextRange getHighlightRange() { + PsiElement element = myTarget.getHighlightElement(); + return element != null ? element.getTextRange() : null; + } + } } diff --git a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/JvmSmartStepIntoHandler.java b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/JvmSmartStepIntoHandler.java index a9c7967ac7..e0803acb09 100644 --- a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/JvmSmartStepIntoHandler.java +++ b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/JvmSmartStepIntoHandler.java @@ -29,104 +29,104 @@ import consulo.fileEditor.TextEditor; import consulo.ide.impl.idea.ui.popup.list.ListPopupImpl; import consulo.language.psi.PsiElement; +import consulo.ui.annotation.RequiredUIAccess; import consulo.ui.ex.awt.JBList; import jakarta.annotation.Nonnull; import jakarta.annotation.Nullable; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; import java.util.Collections; import java.util.List; /** - * User: Alexander Podkhalyuzin - * Date: 22.11.11 + * @author Alexander Podkhalyuzin + * @since 2011-11-22 */ @ExtensionAPI(ComponentScope.APPLICATION) public abstract class JvmSmartStepIntoHandler { - public static final ExtensionPointName EP_NAME = ExtensionPointName.create(JvmSmartStepIntoHandler.class); + public static final ExtensionPointName EP_NAME = ExtensionPointName.create(JvmSmartStepIntoHandler.class); - @Nonnull - public abstract List findSmartStepTargets(SourcePosition position); + @Nonnull + public abstract List findSmartStepTargets(SourcePosition position); - public abstract boolean isAvailable(SourcePosition position); + public abstract boolean isAvailable(SourcePosition position); - /** - * Override this if you haven't PsiMethod, like in Kotlin. - * - * @param position - * @param session - * @param fileEditor - * @return false to continue for another handler or for default action (step into) - */ - public boolean doSmartStep(SourcePosition position, final DebuggerSession session, TextEditor fileEditor) { - final List targets = findSmartStepTargets(position); - if (!targets.isEmpty()) { - final SmartStepTarget firstTarget = targets.get(0); - if (targets.size() == 1) { - session.sessionResumed(); - session.stepInto(true, createMethodFilter(firstTarget)); - } - else { - final Editor editor = fileEditor.getEditor(); - final PsiMethodListPopupStep popupStep = new PsiMethodListPopupStep(editor, targets, new PsiMethodListPopupStep.OnChooseRunnable() { - public void execute(SmartStepTarget chosenTarget) { - session.sessionResumed(); - session.stepInto(true, createMethodFilter(chosenTarget)); - } - }); - ListPopupImpl popup = new ListPopupImpl(popupStep); - DebuggerUIUtil.registerExtraHandleShortcuts(popup, XDebuggerActions.STEP_INTO); - DebuggerUIUtil.registerExtraHandleShortcuts(popup, XDebuggerActions.SMART_STEP_INTO); - popup.addListSelectionListener(new ListSelectionListener() { - public void valueChanged(ListSelectionEvent e) { - popupStep.getScopeHighlighter().dropHighlight(); - if (!e.getValueIsAdjusting()) { - final SmartStepTarget selectedTarget = (SmartStepTarget)((JBList)e.getSource()).getSelectedValue(); - if (selectedTarget != null) { - highlightTarget(popupStep, selectedTarget); - } + /** + * Override this if you haven't PsiMethod, like in Kotlin. + * + * @param position + * @param session + * @param fileEditor + * @return false to continue for another handler or for default action (step into) + */ + @RequiredUIAccess + public boolean doSmartStep(SourcePosition position, DebuggerSession session, TextEditor fileEditor) { + List targets = findSmartStepTargets(position); + if (!targets.isEmpty()) { + SmartStepTarget firstTarget = targets.get(0); + if (targets.size() == 1) { + session.sessionResumed(); + session.stepInto(true, createMethodFilter(firstTarget)); } - } - }); - highlightTarget(popupStep, firstTarget); - DebuggerUIUtil.showPopupForEditorLine(popup, editor, position.getLine()); - } - return true; + else { + Editor editor = fileEditor.getEditor(); + PsiMethodListPopupStep popupStep = + new PsiMethodListPopupStep(editor, targets, new PsiMethodListPopupStep.OnChooseRunnable() { + @Override + @RequiredUIAccess + public void execute(SmartStepTarget chosenTarget) { + session.sessionResumed(); + session.stepInto(true, createMethodFilter(chosenTarget)); + } + }); + ListPopupImpl popup = new ListPopupImpl(popupStep); + DebuggerUIUtil.registerExtraHandleShortcuts(popup, XDebuggerActions.STEP_INTO); + DebuggerUIUtil.registerExtraHandleShortcuts(popup, XDebuggerActions.SMART_STEP_INTO); + popup.addListSelectionListener(e -> { + popupStep.getScopeHighlighter().dropHighlight(); + if (!e.getValueIsAdjusting()) { + SmartStepTarget selectedTarget = (SmartStepTarget)((JBList)e.getSource()).getSelectedValue(); + if (selectedTarget != null) { + highlightTarget(popupStep, selectedTarget); + } + } + }); + highlightTarget(popupStep, firstTarget); + DebuggerUIUtil.showPopupForEditorLine(popup, editor, position.getLine()); + } + return true; + } + return false; } - return false; - } - private static void highlightTarget(PsiMethodListPopupStep popupStep, SmartStepTarget target) { - final PsiElement highlightElement = target.getHighlightElement(); - if (highlightElement != null) { - popupStep.getScopeHighlighter().highlight(highlightElement, Collections.singletonList(highlightElement)); + private static void highlightTarget(PsiMethodListPopupStep popupStep, SmartStepTarget target) { + PsiElement highlightElement = target.getHighlightElement(); + if (highlightElement != null) { + popupStep.getScopeHighlighter().highlight(highlightElement, Collections.singletonList(highlightElement)); + } } - } - /** - * Override in case if your JVMNames slightly different then it can be provided by getJvmSignature method. - * - * @param stepTarget - * @return SmartStepFilter - */ - @Nullable - protected MethodFilter createMethodFilter(SmartStepTarget stepTarget) { - if (stepTarget instanceof MethodSmartStepTarget) { - final PsiMethod method = ((MethodSmartStepTarget)stepTarget).getMethod(); - if (stepTarget.needsBreakpointRequest()) { - return method.getContainingClass() instanceof PsiAnonymousClass ? new ClassInstanceMethodFilter(method, - stepTarget.getCallingExpressionLines()) : new AnonymousClassMethodFilter - (method, stepTarget.getCallingExpressionLines()); - } - else { - return new BasicStepMethodFilter(method, stepTarget.getCallingExpressionLines()); - } - } - if (stepTarget instanceof LambdaSmartStepTarget) { - final LambdaSmartStepTarget lambdaTarget = (LambdaSmartStepTarget)stepTarget; - return new LambdaMethodFilter(lambdaTarget.getLambda(), lambdaTarget.getOrdinal(), stepTarget.getCallingExpressionLines()); + /** + * Override in case if your JVMNames slightly different then it can be provided by getJvmSignature method. + * + * @param stepTarget + * @return SmartStepFilter + */ + @Nullable + protected MethodFilter createMethodFilter(SmartStepTarget stepTarget) { + if (stepTarget instanceof MethodSmartStepTarget methodSmartStepTarget) { + PsiMethod method = methodSmartStepTarget.getMethod(); + if (stepTarget.needsBreakpointRequest()) { + return method.getContainingClass() instanceof PsiAnonymousClass + ? new ClassInstanceMethodFilter(method, stepTarget.getCallingExpressionLines()) + : new AnonymousClassMethodFilter(method, stepTarget.getCallingExpressionLines()); + } + else { + return new BasicStepMethodFilter(method, stepTarget.getCallingExpressionLines()); + } + } + if (stepTarget instanceof LambdaSmartStepTarget lambdaTarget) { + return new LambdaMethodFilter(lambdaTarget.getLambda(), lambdaTarget.getOrdinal(), stepTarget.getCallingExpressionLines()); + } + return null; } - return null; - } } diff --git a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/LambdaSmartStepTarget.java b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/LambdaSmartStepTarget.java index 41dcbc726c..100819f064 100644 --- a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/LambdaSmartStepTarget.java +++ b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/LambdaSmartStepTarget.java @@ -26,73 +26,57 @@ /** * @author Eugene Zhuravlev - * Date: 10/25/13 + * @since 2013-10-25 */ -public class LambdaSmartStepTarget extends SmartStepTarget -{ - private final PsiLambdaExpression myLambda; - private final int myOrdinal; +public class LambdaSmartStepTarget extends SmartStepTarget { + private final PsiLambdaExpression myLambda; + private final int myOrdinal; - public LambdaSmartStepTarget( - @Nonnull PsiLambdaExpression lambda, - @Nullable String label, - @Nullable PsiElement highlightElement, - int ordinal, - Range lines) - { - super(label, highlightElement, true, lines); - myLambda = lambda; - myOrdinal = ordinal; - } + public LambdaSmartStepTarget( + @Nonnull PsiLambdaExpression lambda, + @Nullable String label, + @Nullable PsiElement highlightElement, + int ordinal, + Range lines + ) { + super(label, highlightElement, true, lines); + myLambda = lambda; + myOrdinal = ordinal; + } - public PsiLambdaExpression getLambda() - { - return myLambda; - } + public PsiLambdaExpression getLambda() { + return myLambda; + } - public int getOrdinal() - { - return myOrdinal; - } + public int getOrdinal() { + return myOrdinal; + } - @Nullable - @Override - public Image getIcon() - { - return PlatformIconGroup.nodesLambda(); - } + @Nullable + @Override + public Image getIcon() { + return PlatformIconGroup.nodesLambda(); + } - @Override - public boolean equals(Object o) - { - if(this == o) - { - return true; - } - if(o == null || getClass() != o.getClass()) - { - return false; - } + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } - final LambdaSmartStepTarget that = (LambdaSmartStepTarget) o; + LambdaSmartStepTarget that = (LambdaSmartStepTarget)o; - if(myOrdinal != that.myOrdinal) - { - return false; - } - if(!myLambda.equals(that.myLambda)) - { - return false; - } + return myOrdinal == that.myOrdinal + && myLambda.equals(that.myLambda); + } - return true; - } - - @Override - public int hashCode() - { - int result = myLambda.hashCode(); - result = 31 * result + myOrdinal; - return result; - } + @Override + public int hashCode() { + int result = myLambda.hashCode(); + result = 31 * result + myOrdinal; + return result; + } } diff --git a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/MethodSmartStepTarget.java b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/MethodSmartStepTarget.java index a90df16cda..e9495368eb 100644 --- a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/MethodSmartStepTarget.java +++ b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/MethodSmartStepTarget.java @@ -19,6 +19,7 @@ import com.intellij.java.language.psi.PsiSubstitutor; import com.intellij.java.language.psi.util.PsiFormatUtil; import com.intellij.java.language.psi.util.PsiFormatUtilBase; +import consulo.annotation.access.RequiredReadAction; import consulo.language.icon.IconDescriptorUpdaters; import consulo.language.psi.PsiElement; import consulo.ui.image.Image; @@ -29,74 +30,64 @@ /** * @author Eugene Zhuravlev - * Date: 10/25/13 + * @since 2013-10-25 */ -public class MethodSmartStepTarget extends SmartStepTarget -{ - private final PsiMethod myMethod; +public class MethodSmartStepTarget extends SmartStepTarget { + private final PsiMethod myMethod; - public MethodSmartStepTarget( - @Nonnull PsiMethod method, - @Nullable String label, - @Nullable PsiElement highlightElement, - boolean needBreakpointRequest, - Range lines) - { - super(label, highlightElement, needBreakpointRequest, lines); - myMethod = method; - } + public MethodSmartStepTarget( + @Nonnull PsiMethod method, + @Nullable String label, + @Nullable PsiElement highlightElement, + boolean needBreakpointRequest, + Range lines + ) { + super(label, highlightElement, needBreakpointRequest, lines); + myMethod = method; + } - @Nullable - @Override - public Image getIcon() - { - return IconDescriptorUpdaters.getIcon(myMethod, 0); - } + @Nullable + @Override + @RequiredReadAction + public Image getIcon() { + return IconDescriptorUpdaters.getIcon(myMethod, 0); + } - @Nonnull - @Override - public String getPresentation() - { - String label = getLabel(); - String formatted = PsiFormatUtil.formatMethod( - myMethod, - PsiSubstitutor.EMPTY, - PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS, - PsiFormatUtilBase.SHOW_TYPE, - 999 - ); - return label != null ? label + formatted : formatted; - } + @Nonnull + @Override + public String getPresentation() { + String label = getLabel(); + String formatted = PsiFormatUtil.formatMethod( + myMethod, + PsiSubstitutor.EMPTY, + PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS, + PsiFormatUtilBase.SHOW_TYPE, + 999 + ); + return label != null ? label + formatted : formatted; + } - @Nonnull - public PsiMethod getMethod() - { - return myMethod; - } + @Nonnull + public PsiMethod getMethod() { + return myMethod; + } - public boolean equals(Object o) - { - if(this == o) - { - return true; - } - if(o == null || getClass() != o.getClass()) - { - return false; - } + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } - final MethodSmartStepTarget that = (MethodSmartStepTarget) o; + MethodSmartStepTarget that = (MethodSmartStepTarget)o; - if(!myMethod.equals(that.myMethod)) - { - return false; - } + return myMethod.equals(that.myMethod); + } - return true; - } - - public int hashCode() - { - return myMethod.hashCode(); - } + @Override + public int hashCode() { + return myMethod.hashCode(); + } } diff --git a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/PlaceInDocument.java b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/PlaceInDocument.java index f3e27a6e38..57772f8d54 100644 --- a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/PlaceInDocument.java +++ b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/PlaceInDocument.java @@ -17,24 +17,20 @@ import consulo.document.Document; -class PlaceInDocument -{ - private final Document myDocument; - private final int myOffset; +class PlaceInDocument { + private final Document myDocument; + private final int myOffset; - PlaceInDocument(Document document, int offset) - { - myDocument = document; - myOffset = offset; - } + PlaceInDocument(Document document, int offset) { + myDocument = document; + myOffset = offset; + } - public Document getDocument() - { - return myDocument; - } + public Document getDocument() { + return myDocument; + } - public int getOffset() - { - return myOffset; - } + public int getOffset() { + return myOffset; + } } diff --git a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/PsiMethodListPopupStep.java b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/PsiMethodListPopupStep.java index 4cb5573281..4f7dbae09f 100644 --- a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/PsiMethodListPopupStep.java +++ b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/PsiMethodListPopupStep.java @@ -15,176 +15,153 @@ */ package com.intellij.java.debugger.impl.actions; -import consulo.language.editor.refactoring.unwrap.ScopeHighlighter; -import com.intellij.java.debugger.DebuggerBundle; -import consulo.application.AllIcons; -import consulo.codeEditor.Editor; +import com.intellij.java.debugger.localize.JavaDebuggerLocalize; import com.intellij.java.language.psi.PsiLambdaExpression; import com.intellij.java.language.psi.PsiMethod; import com.intellij.java.language.psi.PsiSubstitutor; import com.intellij.java.language.psi.util.PsiFormatUtil; +import consulo.codeEditor.Editor; +import consulo.language.editor.refactoring.unwrap.ScopeHighlighter; import consulo.language.icon.IconDescriptorUpdaters; +import consulo.platform.base.icon.PlatformIconGroup; import consulo.ui.annotation.RequiredUIAccess; import consulo.ui.ex.popup.*; import consulo.ui.image.Image; - import jakarta.annotation.Nonnull; + import java.util.List; /** * @author Eugene Zhuravlev - * Date: Nov 21, 2006 + * @since 2006-11-21 */ -class PsiMethodListPopupStep implements ListPopupStep -{ - private final List myTargets; - private final OnChooseRunnable myStepRunnable; - private final ScopeHighlighter myScopeHighlighter; - - public interface OnChooseRunnable - { - void execute(SmartStepTarget stepTarget); - } - - public PsiMethodListPopupStep(Editor editor, final List targets, final OnChooseRunnable stepRunnable) - { - myTargets = targets; - myScopeHighlighter = new ScopeHighlighter(editor); - myStepRunnable = stepRunnable; - } - - @Nonnull - public ScopeHighlighter getScopeHighlighter() - { - return myScopeHighlighter; - } - - @Override - @Nonnull - public List getValues() - { - return myTargets; - } - - @Override - public boolean isSelectable(SmartStepTarget value) - { - return true; - } - - @Override - @RequiredUIAccess - public Image getIconFor(SmartStepTarget aValue) - { - if(aValue instanceof MethodSmartStepTarget) - { - return IconDescriptorUpdaters.getIcon(((MethodSmartStepTarget) aValue).getMethod(), 0); - } - if(aValue instanceof LambdaSmartStepTarget) - { - return AllIcons.Nodes.Function; - } - return null; - } - - @Override - @Nonnull - public String getTextFor(SmartStepTarget value) - { - final String label = value.getLabel(); - final String formatted; - if(value instanceof MethodSmartStepTarget) - { - final PsiMethod method = ((MethodSmartStepTarget) value).getMethod(); - formatted = PsiFormatUtil.formatMethod(method, PsiSubstitutor.EMPTY, PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_PARAMETERS, - PsiFormatUtil.SHOW_TYPE, 999); - } - else if(value instanceof LambdaSmartStepTarget) - { - final PsiLambdaExpression lambda = ((LambdaSmartStepTarget) value).getLambda(); - formatted = PsiFormatUtil.formatType(lambda.getType(), 0, PsiSubstitutor.EMPTY); - } - else - { - formatted = ""; - } - return label != null ? label + formatted : formatted; - } - - @Override - public ListSeparator getSeparatorAbove(SmartStepTarget value) - { - return null; - } - - @Override - public int getDefaultOptionIndex() - { - return 0; - } - - @Override - public String getTitle() - { - return DebuggerBundle.message("title.smart.step.popup"); - } - - @Override - public PopupStep onChosen(SmartStepTarget selectedValue, final boolean finalChoice) - { - if(finalChoice) - { - myScopeHighlighter.dropHighlight(); - myStepRunnable.execute(selectedValue); - } - return FINAL_CHOICE; - } - - @Override - public Runnable getFinalRunnable() - { - return null; - } - - @Override - public boolean hasSubstep(SmartStepTarget selectedValue) - { - return false; - } - - @Override - public void canceled() - { - myScopeHighlighter.dropHighlight(); - } - - @Override - public boolean isMnemonicsNavigationEnabled() - { - return false; - } - - @Override - public MnemonicNavigationFilter getMnemonicNavigationFilter() - { - return null; - } - - @Override - public boolean isSpeedSearchEnabled() - { - return false; - } - - @Override - public SpeedSearchFilter getSpeedSearchFilter() - { - return null; - } - - @Override - public boolean isAutoSelectionEnabled() - { - return false; - } +class PsiMethodListPopupStep implements ListPopupStep { + private final List myTargets; + private final OnChooseRunnable myStepRunnable; + private final ScopeHighlighter myScopeHighlighter; + + public interface OnChooseRunnable { + void execute(SmartStepTarget stepTarget); + } + + public PsiMethodListPopupStep(Editor editor, List targets, OnChooseRunnable stepRunnable) { + myTargets = targets; + myScopeHighlighter = new ScopeHighlighter(editor); + myStepRunnable = stepRunnable; + } + + @Nonnull + public ScopeHighlighter getScopeHighlighter() { + return myScopeHighlighter; + } + + @Override + @Nonnull + public List getValues() { + return myTargets; + } + + @Override + public boolean isSelectable(SmartStepTarget value) { + return true; + } + + @Override + @RequiredUIAccess + public Image getIconFor(SmartStepTarget aValue) { + if (aValue instanceof MethodSmartStepTarget methodSmartStepTarget) { + return IconDescriptorUpdaters.getIcon(methodSmartStepTarget.getMethod(), 0); + } + if (aValue instanceof LambdaSmartStepTarget) { + return PlatformIconGroup.nodesFunction(); + } + return null; + } + + @Nonnull + @Override + public String getTextFor(SmartStepTarget value) { + String label = value.getLabel(); + String formatted; + if (value instanceof MethodSmartStepTarget methodSmartStepTarget) { + formatted = PsiFormatUtil.formatMethod( + methodSmartStepTarget.getMethod(), + PsiSubstitutor.EMPTY, + PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_PARAMETERS, + PsiFormatUtil.SHOW_TYPE, + 999 + ); + } + else if (value instanceof LambdaSmartStepTarget lambdaSmartStepTarget) { + formatted = PsiFormatUtil.formatType(lambdaSmartStepTarget.getLambda().getType(), 0, PsiSubstitutor.EMPTY); + } + else { + formatted = ""; + } + return label != null ? label + formatted : formatted; + } + + @Override + public ListSeparator getSeparatorAbove(SmartStepTarget value) { + return null; + } + + @Override + public int getDefaultOptionIndex() { + return 0; + } + + @Override + public String getTitle() { + return JavaDebuggerLocalize.titleSmartStepPopup().get(); + } + + @Override + public PopupStep onChosen(SmartStepTarget selectedValue, boolean finalChoice) { + if (finalChoice) { + myScopeHighlighter.dropHighlight(); + myStepRunnable.execute(selectedValue); + } + return FINAL_CHOICE; + } + + @Override + public Runnable getFinalRunnable() { + return null; + } + + @Override + public boolean hasSubstep(SmartStepTarget selectedValue) { + return false; + } + + @Override + public void canceled() { + myScopeHighlighter.dropHighlight(); + } + + @Override + public boolean isMnemonicsNavigationEnabled() { + return false; + } + + @Override + public MnemonicNavigationFilter getMnemonicNavigationFilter() { + return null; + } + + @Override + public boolean isSpeedSearchEnabled() { + return false; + } + + @Override + public SpeedSearchFilter getSpeedSearchFilter() { + return null; + } + + @Override + public boolean isAutoSelectionEnabled() { + return false; + } } diff --git a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/ResumeThreadAction.java b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/ResumeThreadAction.java index 781cae7bea..a7d8645fc0 100644 --- a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/ResumeThreadAction.java +++ b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/ResumeThreadAction.java @@ -15,80 +15,84 @@ */ package com.intellij.java.debugger.impl.actions; -import com.intellij.java.debugger.DebuggerBundle; +import com.intellij.java.debugger.impl.DebuggerContextImpl; import com.intellij.java.debugger.impl.engine.DebugProcessImpl; import com.intellij.java.debugger.impl.engine.events.SuspendContextCommandImpl; -import com.intellij.java.debugger.impl.DebuggerContextImpl; import com.intellij.java.debugger.impl.jdi.ThreadReferenceProxyImpl; import com.intellij.java.debugger.impl.ui.impl.watch.DebuggerTreeNodeImpl; import com.intellij.java.debugger.impl.ui.impl.watch.NodeDescriptorImpl; import com.intellij.java.debugger.impl.ui.impl.watch.ThreadDescriptorImpl; +import com.intellij.java.debugger.localize.JavaDebuggerLocalize; +import consulo.internal.com.sun.jdi.request.EventRequest; +import consulo.localize.LocalizeValue; +import consulo.ui.annotation.RequiredUIAccess; import consulo.ui.ex.action.AnActionEvent; import consulo.ui.ex.action.Presentation; -import consulo.internal.com.sun.jdi.request.EventRequest; /** - * User: lex - * Date: Sep 26, 2003 - * Time: 7:35:09 PM + * @author lex + * @since 2003-09-26 */ -public class ResumeThreadAction extends DebuggerAction{ - public void actionPerformed(final AnActionEvent e) { - DebuggerTreeNodeImpl[] selectedNode = getSelectedNodes(e.getDataContext()); - final DebuggerContextImpl debuggerContext = getDebuggerContext(e.getDataContext()); - final DebugProcessImpl debugProcess = debuggerContext.getDebugProcess(); +public class ResumeThreadAction extends DebuggerAction { + @Override + @RequiredUIAccess + public void actionPerformed(AnActionEvent e) { + DebuggerTreeNodeImpl[] selectedNode = getSelectedNodes(e.getDataContext()); + DebuggerContextImpl debuggerContext = getDebuggerContext(e.getDataContext()); + DebugProcessImpl debugProcess = debuggerContext.getDebugProcess(); - //noinspection ConstantConditions - for (final DebuggerTreeNodeImpl debuggerTreeNode : selectedNode) { - final ThreadDescriptorImpl threadDescriptor = ((ThreadDescriptorImpl)debuggerTreeNode.getDescriptor()); + //noinspection ConstantConditions + for (DebuggerTreeNodeImpl debuggerTreeNode : selectedNode) { + ThreadDescriptorImpl threadDescriptor = ((ThreadDescriptorImpl)debuggerTreeNode.getDescriptor()); - if (threadDescriptor.isSuspended()) { - final ThreadReferenceProxyImpl thread = threadDescriptor.getThreadReference(); - debugProcess.getManagerThread().schedule(new SuspendContextCommandImpl(debuggerContext.getSuspendContext()) { - public void contextAction() throws Exception { - debugProcess.createResumeThreadCommand(getSuspendContext(), thread).run(); - debuggerTreeNode.calcValue(); - } - }); - } + if (threadDescriptor.isSuspended()) { + ThreadReferenceProxyImpl thread = threadDescriptor.getThreadReference(); + debugProcess.getManagerThread().schedule(new SuspendContextCommandImpl(debuggerContext.getSuspendContext()) { + @Override + public void contextAction() throws Exception { + debugProcess.createResumeThreadCommand(getSuspendContext(), thread).run(); + debuggerTreeNode.calcValue(); + } + }); + } + } } - } - public void update(AnActionEvent e) { - DebuggerTreeNodeImpl[] selectedNodes = getSelectedNodes(e.getDataContext()); + @Override + @RequiredUIAccess + public void update(AnActionEvent e) { + DebuggerTreeNodeImpl[] selectedNodes = getSelectedNodes(e.getDataContext()); - boolean visible = false; - boolean enabled = false; - String text = DebuggerBundle.message("action.resume.thread.text.resume"); + boolean visible = false; + boolean enabled = false; + LocalizeValue text = JavaDebuggerLocalize.actionResumeThreadTextResume(); - if(selectedNodes != null && selectedNodes.length > 0){ - visible = true; - enabled = true; - for (DebuggerTreeNodeImpl selectedNode : selectedNodes) { - final NodeDescriptorImpl threadDescriptor = selectedNode.getDescriptor(); - if (!(threadDescriptor instanceof ThreadDescriptorImpl) || !((ThreadDescriptorImpl)threadDescriptor).isSuspended()) { - visible = false; - break; - } - } - if (visible) { - for (DebuggerTreeNodeImpl selectedNode : selectedNodes) { - final ThreadDescriptorImpl threadDescriptor = (ThreadDescriptorImpl)selectedNode.getDescriptor(); - if (threadDescriptor.getSuspendContext().getSuspendPolicy() == EventRequest.SUSPEND_ALL && !threadDescriptor.isFrozen()) { - enabled = false; - break; - } - else { - if (threadDescriptor.isFrozen()) { - text = DebuggerBundle.message("action.resume.thread.text.unfreeze"); + if (selectedNodes != null && selectedNodes.length > 0) { + visible = true; + enabled = true; + for (DebuggerTreeNodeImpl selectedNode : selectedNodes) { + if (!(selectedNode.getDescriptor() instanceof ThreadDescriptorImpl threadDescr && threadDescr.isSuspended())) { + visible = false; + break; + } + } + if (visible) { + for (DebuggerTreeNodeImpl selectedNode : selectedNodes) { + ThreadDescriptorImpl threadDescriptor = (ThreadDescriptorImpl)selectedNode.getDescriptor(); + if (threadDescriptor.getSuspendContext().getSuspendPolicy() == EventRequest.SUSPEND_ALL + && !threadDescriptor.isFrozen()) { + enabled = false; + break; + } + else if (threadDescriptor.isFrozen()) { + text = JavaDebuggerLocalize.actionResumeThreadTextUnfreeze(); + } + } } - } } - } + Presentation presentation = e.getPresentation(); + presentation.setTextValue(text); + presentation.setVisible(visible); + presentation.setEnabled(enabled); } - final Presentation presentation = e.getPresentation(); - presentation.setText(text); - presentation.setVisible(visible); - presentation.setEnabled(enabled); - } } diff --git a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/SmartStepTarget.java b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/SmartStepTarget.java index 96714258a5..339b5799dd 100644 --- a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/SmartStepTarget.java +++ b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/SmartStepTarget.java @@ -25,58 +25,51 @@ /** * @author Eugene Zhuravlev - * Date: 10/25/13 + * @since 2013-10-25 */ -public abstract class SmartStepTarget -{ - private final PsiElement myHighlightElement; - private final String myLabel; - private final boolean myNeedBreakpointRequest; - private final Range myExpressionLines; +public abstract class SmartStepTarget { + private final PsiElement myHighlightElement; + private final String myLabel; + private final boolean myNeedBreakpointRequest; + private final Range myExpressionLines; - protected SmartStepTarget( - @Nullable String label, - @Nullable PsiElement highlightElement, - boolean needBreakpointRequest, - Range expressionLines) - { - myHighlightElement = highlightElement; - myLabel = label; - myNeedBreakpointRequest = needBreakpointRequest; - myExpressionLines = expressionLines; - } + protected SmartStepTarget( + @Nullable String label, + @Nullable PsiElement highlightElement, + boolean needBreakpointRequest, + Range expressionLines + ) { + myHighlightElement = highlightElement; + myLabel = label; + myNeedBreakpointRequest = needBreakpointRequest; + myExpressionLines = expressionLines; + } - @Nullable - public PsiElement getHighlightElement() - { - return myHighlightElement; - } + @Nullable + public PsiElement getHighlightElement() { + return myHighlightElement; + } - @Nullable - public String getLabel() - { - return myLabel; - } + @Nullable + public String getLabel() { + return myLabel; + } - public boolean needsBreakpointRequest() - { - return myNeedBreakpointRequest; - } + public boolean needsBreakpointRequest() { + return myNeedBreakpointRequest; + } - public Range getCallingExpressionLines() - { - return myExpressionLines; - } + public Range getCallingExpressionLines() { + return myExpressionLines; + } - @Nullable - public Image getIcon() - { - return null; - } + @Nullable + public Image getIcon() { + return null; + } - @Nonnull - public String getPresentation() - { - return StringUtil.notNullize(getLabel()); - } + @Nonnull + public String getPresentation() { + return StringUtil.notNullize(getLabel()); + } } diff --git a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/ThreadDumpAction.java b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/ThreadDumpAction.java index 74f632a98d..aaa513c476 100644 --- a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/ThreadDumpAction.java +++ b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/ThreadDumpAction.java @@ -13,16 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/** - * class ExportThreadsAction - * - * @author Eugene Zhuravlev - * @author Sascha Weinreuter - */ package com.intellij.java.debugger.impl.actions; -import com.intellij.java.debugger.DebuggerBundle; import com.intellij.java.debugger.impl.DebuggerContextImpl; import com.intellij.java.debugger.impl.DebuggerManagerEx; import com.intellij.java.debugger.impl.DebuggerSession; @@ -30,49 +22,61 @@ import com.intellij.java.debugger.impl.engine.DebugProcessImpl; import com.intellij.java.debugger.impl.engine.events.DebuggerCommandImpl; import com.intellij.java.debugger.impl.jdi.VirtualMachineProxyImpl; +import com.intellij.java.debugger.localize.JavaDebuggerLocalize; import com.intellij.java.execution.unscramble.ThreadDumpParser; import consulo.application.Application; import consulo.execution.debug.XDebugSession; import consulo.execution.unscramble.ThreadState; import consulo.internal.com.sun.jdi.*; +import consulo.localize.LocalizeValue; import consulo.project.Project; +import consulo.ui.annotation.RequiredUIAccess; import consulo.ui.ex.action.AnAction; import consulo.ui.ex.action.AnActionEvent; import consulo.ui.ex.action.Presentation; import consulo.util.collection.SmartList; import consulo.util.collection.primitive.ints.IntMaps; import consulo.util.collection.primitive.ints.IntObjectMap; +import jakarta.annotation.Nonnull; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +/** + * @author Eugene Zhuravlev + * @author Sascha Weinreuter + */ public class ThreadDumpAction extends AnAction { @Override + @RequiredUIAccess public void actionPerformed(AnActionEvent e) { - final Project project = e.getData(Project.KEY); + Project project = e.getData(Project.KEY); if (project == null) { return; } DebuggerContextImpl context = (DebuggerManagerEx.getInstanceEx(project)).getContext(); - final DebuggerSession session = context.getDebuggerSession(); + DebuggerSession session = context.getDebuggerSession(); if (session != null && session.isAttached()) { - final DebugProcessImpl process = context.getDebugProcess(); + DebugProcessImpl process = context.getDebugProcess(); process.getManagerThread().invoke(new DebuggerCommandImpl() { @Override protected void action() throws Exception { - final VirtualMachineProxyImpl vm = process.getVirtualMachineProxy(); + VirtualMachineProxyImpl vm = process.getVirtualMachineProxy(); vm.suspend(); try { - final List threads = buildThreadStates(vm); - project.getApplication().invokeLater(() -> { - XDebugSession xSession = session.getXDebugSession(); - if (xSession != null) { - DebuggerUtilsEx.addThreadDump(project, threads, xSession.getUI(), session); - } - }, Application.get().getNoneModalityState()); + List threads = buildThreadStates(vm); + project.getApplication().invokeLater( + () -> { + XDebugSession xSession = session.getXDebugSession(); + if (xSession != null) { + DebuggerUtilsEx.addThreadDump(project, threads, xSession.getUI(), session); + } + }, + Application.get().getNoneModalityState() + ); } finally { vm.resume(); @@ -83,19 +87,19 @@ protected void action() throws Exception { } static List buildThreadStates(VirtualMachineProxyImpl vmProxy) { - final List threads = vmProxy.getVirtualMachine().allThreads(); - final List result = new ArrayList<>(); - final Map nameToThreadMap = new HashMap<>(); - final Map waitingMap = new HashMap<>(); // key 'waits_for' value + List threads = vmProxy.getVirtualMachine().allThreads(); + List result = new ArrayList<>(); + Map nameToThreadMap = new HashMap<>(); + Map waitingMap = new HashMap<>(); // key 'waits_for' value for (ThreadReference threadReference : threads) { - final StringBuilder buffer = new StringBuilder(); + StringBuilder buffer = new StringBuilder(); boolean hasEmptyStack = true; - final int threadStatus = threadReference.status(); + int threadStatus = threadReference.status(); if (threadStatus == ThreadReference.THREAD_STATUS_ZOMBIE) { continue; } - final String threadName = threadName(threadReference); - final ThreadState threadState = new ThreadState(threadName, threadStatusToState(threadStatus)); + String threadName = threadName(threadReference); + ThreadState threadState = new ThreadState(threadName, threadStatusToState(threadStatus)); nameToThreadMap.put(threadName, threadState); result.add(threadState); threadState.setJavaThreadState(threadStatusToJavaThreadState(threadStatus)); @@ -108,7 +112,7 @@ static List buildThreadStates(VirtualMachineProxyImpl vmProxy) { if (daemon != null) { Value value = threadReference.getValue(daemon); if (value instanceof BooleanValue booleanValue && booleanValue.booleanValue()) { - buffer.append(" ").append(DebuggerBundle.message("threads.export.attribute.label.daemon")); + buffer.append(" ").append(JavaDebuggerLocalize.threadsExportAttributeLabelDaemon()); threadState.setDaemon(true); } } @@ -118,7 +122,8 @@ static List buildThreadStates(VirtualMachineProxyImpl vmProxy) { if (priority != null) { Value value = threadReference.getValue(priority); if (value instanceof IntegerValue integerValue) { - buffer.append(" ").append(DebuggerBundle.message("threads.export.attribute.label.priority", integerValue.intValue())); + buffer.append(" ") + .append(JavaDebuggerLocalize.threadsExportAttributeLabelPriority(integerValue.intValue())); } } @@ -126,16 +131,17 @@ static List buildThreadStates(VirtualMachineProxyImpl vmProxy) { if (tid != null) { Value value = threadReference.getValue(tid); if (value instanceof LongValue longValue) { - buffer.append(" ").append(DebuggerBundle.message("threads.export.attribute.label.tid", Long.toHexString(longValue.longValue()))); + buffer.append(" ") + .append(JavaDebuggerLocalize.threadsExportAttributeLabelTid(Long.toHexString(longValue.longValue()))); buffer.append(" nid=NA"); } } } //ThreadGroupReference groupReference = threadReference.threadGroup(); //if (groupReference != null) { - // buffer.append(", ").append(DebuggerBundle.message("threads.export.attribute.label.group", groupReference.name())); + // buffer.append(", ").append(DebuggerBundle.message("threads.export.attribute.label.group", groupReference.name())); //} - final String state = threadState.getState(); + String state = threadState.getState(); if (state != null) { buffer.append(" ").append(state); } @@ -149,11 +155,12 @@ static List buildThreadStates(VirtualMachineProxyImpl vmProxy) { if (!vmProxy.canGetMonitorFrameInfo()) { // java 5 and earlier buffer.append("\n\t ").append(renderLockedObject(reference)); } - final List waiting = reference.waitingThreads(); + List waiting = reference.waitingThreads(); for (ThreadReference thread : waiting) { - final String waitingThreadName = threadName(thread); + String waitingThreadName = threadName(thread); waitingMap.put(waitingThreadName, threadName); - buffer.append("\n\t ").append(DebuggerBundle.message("threads.export.attribute.label.blocks.thread", waitingThreadName)); + buffer.append("\n\t ") + .append(JavaDebuggerLocalize.threadsExportAttributeLabelBlocksThread(waitingThreadName)); } } } @@ -163,21 +170,23 @@ static List buildThreadStates(VirtualMachineProxyImpl vmProxy) { if (vmProxy.canGetMonitorInfo()) { ThreadReference waitedMonitorOwner = waitedMonitor.owningThread(); if (waitedMonitorOwner != null) { - final String monitorOwningThreadName = threadName(waitedMonitorOwner); + String monitorOwningThreadName = threadName(waitedMonitorOwner); waitingMap.put(threadName, monitorOwningThreadName); - buffer.append("\n\t ").append(DebuggerBundle.message("threads.export.attribute.label.waiting.for.thread", - monitorOwningThreadName, renderObject(waitedMonitor))); + buffer.append("\n\t ").append(JavaDebuggerLocalize.threadsExportAttributeLabelWaitingForThread( + monitorOwningThreadName, + renderObject(waitedMonitor) + )); } } } - final List frames = threadReference.frames(); + List frames = threadReference.frames(); hasEmptyStack = frames.size() == 0; - final IntObjectMap> lockedAt = IntMaps.newIntObjectHashMap(); + IntObjectMap> lockedAt = IntMaps.newIntObjectHashMap(); if (vmProxy.canGetMonitorFrameInfo()) { for (MonitorInfo info : threadReference.ownedMonitorsAndFrames()) { - final int stackDepth = info.stackDepth(); + int stackDepth = info.stackDepth(); List monitors; if ((monitors = lockedAt.get(stackDepth)) == null) { lockedAt.put(stackDepth, monitors = new SmartList<>()); @@ -187,12 +196,12 @@ static List buildThreadStates(VirtualMachineProxyImpl vmProxy) { } for (int i = 0, framesSize = frames.size(); i < framesSize; i++) { - final StackFrame stackFrame = frames.get(i); + StackFrame stackFrame = frames.get(i); try { - final Location location = stackFrame.location(); + Location location = stackFrame.location(); buffer.append("\n\t ").append(renderLocation(location)); - final List monitors = lockedAt.get(i); + List monitors = lockedAt.get(i); if (monitors != null) { for (ObjectReference monitor : monitors) { buffer.append("\n\t - ").append(renderLockedObject(monitor)); @@ -205,15 +214,15 @@ static List buildThreadStates(VirtualMachineProxyImpl vmProxy) { } } catch (IncompatibleThreadStateException e) { - buffer.append("\n\t ").append(DebuggerBundle.message("threads.export.attribute.error.incompatible.state")); + buffer.append("\n\t ").append(JavaDebuggerLocalize.threadsExportAttributeErrorIncompatibleState()); } threadState.setStackTrace(buffer.toString(), hasEmptyStack); ThreadDumpParser.inferThreadStateDetail(threadState); } for (String waiting : waitingMap.keySet()) { - final ThreadState waitingThread = nameToThreadMap.get(waiting); - final ThreadState awaitedThread = nameToThreadMap.get(waitingMap.get(waiting)); + ThreadState waitingThread = nameToThreadMap.get(waiting); + ThreadState awaitedThread = nameToThreadMap.get(waitingMap.get(waiting)); awaitedThread.addWaitingThread(waitingThread); } @@ -231,8 +240,9 @@ static List buildThreadStates(VirtualMachineProxyImpl vmProxy) { return result; } - private static String renderLockedObject(ObjectReference monitor) { - return DebuggerBundle.message("threads.export.attribute.label.locked", renderObject(monitor)); + @Nonnull + private static LocalizeValue renderLockedObject(ObjectReference monitor) { + return JavaDebuggerLocalize.threadsExportAttributeLabelLocked(renderObject(monitor)); } public static String renderObject(ObjectReference monitor) { @@ -243,7 +253,7 @@ public static String renderObject(ObjectReference monitor) { catch (Throwable e) { monitorTypeName = "Error getting object type: '" + e.getMessage() + "'"; } - return DebuggerBundle.message("threads.export.attribute.label.object-id", Long.toHexString(monitor.uniqueID()), monitorTypeName); + return JavaDebuggerLocalize.threadsExportAttributeLabelObjectId(Long.toHexString(monitor.uniqueID()), monitorTypeName).get(); } private static String threadStatusToJavaThreadState(int status) { @@ -288,7 +298,7 @@ private static String threadStatusToState(int status) { } } - public static String renderLocation(final Location location) { + public static String renderLocation(Location location) { String sourceName; try { sourceName = location.sourceName(); @@ -297,7 +307,7 @@ public static String renderLocation(final Location location) { sourceName = "Unknown Source"; } - final StringBuilder methodName = new StringBuilder(); + StringBuilder methodName = new StringBuilder(); try { methodName.append(location.declaringType().name()); } @@ -319,7 +329,7 @@ public static String renderLocation(final Location location) { catch (Throwable e) { lineNumber = -1; } - return DebuggerBundle.message("export.threads.stackframe.format", methodName.toString(), sourceName, lineNumber); + return JavaDebuggerLocalize.exportThreadsStackframeFormat(methodName.toString(), sourceName, lineNumber).get(); } private static String threadName(ThreadReference threadReference) { @@ -327,6 +337,7 @@ private static String threadName(ThreadReference threadReference) { } @Override + @RequiredUIAccess public void update(AnActionEvent event) { Presentation presentation = event.getPresentation(); Project project = event.getData(Project.KEY); diff --git a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/ToggleFieldBreakpointAction.java b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/ToggleFieldBreakpointAction.java index 4a73997fb8..6d9b7733d9 100644 --- a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/ToggleFieldBreakpointAction.java +++ b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/ToggleFieldBreakpointAction.java @@ -15,7 +15,6 @@ */ package com.intellij.java.debugger.impl.actions; -import com.intellij.java.debugger.DebuggerBundle; import com.intellij.java.debugger.SourcePosition; import com.intellij.java.debugger.engine.DebuggerUtils; import com.intellij.java.debugger.impl.DebuggerContextImpl; @@ -31,6 +30,7 @@ import com.intellij.java.debugger.impl.ui.impl.watch.DebuggerTree; import com.intellij.java.debugger.impl.ui.impl.watch.DebuggerTreeNodeImpl; import com.intellij.java.debugger.impl.ui.impl.watch.FieldDescriptorImpl; +import com.intellij.java.debugger.localize.JavaDebuggerLocalize; import com.intellij.java.language.impl.JavaClassFileType; import com.intellij.java.language.impl.JavaFileType; import com.intellij.java.language.psi.PsiClass; @@ -46,38 +46,40 @@ import consulo.language.psi.PsiFile; import consulo.language.psi.scope.GlobalSearchScope; import consulo.project.Project; +import consulo.ui.annotation.RequiredUIAccess; import consulo.ui.ex.action.ActionPlaces; import consulo.ui.ex.action.AnAction; import consulo.ui.ex.action.AnActionEvent; import consulo.ui.ex.action.Presentation; -import consulo.util.lang.ref.Ref; +import consulo.util.lang.ref.SimpleReference; import consulo.virtualFileSystem.VirtualFile; import consulo.virtualFileSystem.fileType.FileType; +import jakarta.annotation.Nonnull; import jakarta.annotation.Nullable; public class ToggleFieldBreakpointAction extends AnAction { - @Override + @RequiredUIAccess public void actionPerformed(AnActionEvent e) { Project project = e.getData(Project.KEY); if (project == null) { return; } - final SourcePosition place = getPlace(e); + SourcePosition place = getPlace(e); if (place != null) { Document document = PsiDocumentManager.getInstance(project).getDocument(place.getFile()); if (document != null) { DebuggerManagerEx debuggerManager = DebuggerManagerEx.getInstanceEx(project); BreakpointManager manager = debuggerManager.getBreakpointManager(); - final int offset = place.getOffset(); - final Breakpoint breakpoint = offset >= 0 ? manager.findBreakpoint(document, offset, FieldBreakpoint.CATEGORY) : null; + int offset = place.getOffset(); + Breakpoint breakpoint = offset >= 0 ? manager.findBreakpoint(document, offset, FieldBreakpoint.CATEGORY) : null; if (breakpoint == null) { FieldBreakpoint fieldBreakpoint = manager.addFieldBreakpoint(document, offset); if (fieldBreakpoint != null) { if (DebuggerAction.isContextView(e)) { - final DebuggerTreeNodeImpl selectedNode = DebuggerAction.getSelectedNode(e.getDataContext()); + DebuggerTreeNodeImpl selectedNode = DebuggerAction.getSelectedNode(e.getDataContext()); if (selectedNode != null && selectedNode.getDescriptor() instanceof FieldDescriptorImpl fieldDescriptor) { ObjectReference object = fieldDescriptor.getObject(); if (object != null) { @@ -89,7 +91,7 @@ public void actionPerformed(AnActionEvent e) { } } - final Editor editor = e.getData(Editor.KEY); + Editor editor = e.getData(Editor.KEY); if (editor != null) { manager.editBreakpoint(fieldBreakpoint, editor); } @@ -103,7 +105,8 @@ public void actionPerformed(AnActionEvent e) { } @Override - public void update(AnActionEvent event) { + @RequiredUIAccess + public void update(@Nonnull AnActionEvent event) { SourcePosition place = getPlace(event); boolean toEnable = place != null; @@ -114,14 +117,14 @@ public void update(AnActionEvent event) { presentation.setVisible(toEnable); } else if (DebuggerAction.isContextView(event)) { - presentation.setText(DebuggerBundle.message("action.add.field.watchpoint.text")); + presentation.setTextValue(JavaDebuggerLocalize.actionAddFieldWatchpointText()); Project project = event.getData(Project.KEY); if (project != null && place != null) { Document document = PsiDocumentManager.getInstance(project).getDocument(place.getFile()); if (document != null) { - final int offset = place.getOffset(); - final BreakpointManager breakpointManager = (DebuggerManagerEx.getInstanceEx(project)).getBreakpointManager(); - final Breakpoint fieldBreakpoint = + int offset = place.getOffset(); + BreakpointManager breakpointManager = (DebuggerManagerEx.getInstanceEx(project)).getBreakpointManager(); + Breakpoint fieldBreakpoint = offset >= 0 ? breakpointManager.findBreakpoint(document, offset, FieldBreakpoint.CATEGORY) : null; if (fieldBreakpoint != null) { presentation.setEnabled(false); @@ -135,27 +138,23 @@ else if (DebuggerAction.isContextView(event)) { @Nullable public static SourcePosition getPlace(AnActionEvent event) { - final DataContext dataContext = event.getDataContext(); - final Project project = event.getData(Project.KEY); + DataContext dataContext = event.getDataContext(); + Project project = event.getData(Project.KEY); if (project == null) { return null; } if (ActionPlaces.PROJECT_VIEW_POPUP.equals(event.getPlace()) || ActionPlaces.STRUCTURE_VIEW_POPUP.equals(event.getPlace()) || ActionPlaces.FAVORITES_VIEW_POPUP.equals(event.getPlace())) { - final PsiElement psiElement = event.getData(PsiElement.KEY); - if (psiElement instanceof PsiField) { - return SourcePosition.createFromElement(psiElement); - } - return null; + return event.getData(PsiElement.KEY) instanceof PsiField field ? SourcePosition.createFromElement(field) : null; } - final DebuggerTreeNodeImpl selectedNode = DebuggerAction.getSelectedNode(dataContext); + DebuggerTreeNodeImpl selectedNode = DebuggerAction.getSelectedNode(dataContext); if (selectedNode != null && selectedNode.getDescriptor() instanceof FieldDescriptorImpl) { - final DebuggerContextImpl debuggerContext = DebuggerAction.getDebuggerContext(dataContext); - final DebugProcessImpl debugProcess = debuggerContext.getDebugProcess(); + DebuggerContextImpl debuggerContext = DebuggerAction.getDebuggerContext(dataContext); + DebugProcessImpl debugProcess = debuggerContext.getDebugProcess(); if (debugProcess != null) { // if there is an active debug session - final Ref positionRef = new Ref<>(null); + SimpleReference positionRef = new SimpleReference<>(null); debugProcess.getManagerThread().invokeAndWait(new DebuggerContextCommandImpl(debuggerContext) { @Override public Priority getPriority() { @@ -164,12 +163,12 @@ public Priority getPriority() { @Override public void threadAction() { - project.getApplication().runReadAction( - () -> positionRef.set(SourcePositionProvider.getSourcePosition(selectedNode.getDescriptor(), project, debuggerContext)) - ); + project.getApplication().runReadAction(() -> positionRef.set( + SourcePositionProvider.getSourcePosition(selectedNode.getDescriptor(), project, debuggerContext) + )); } }); - final SourcePosition sourcePosition = positionRef.get(); + SourcePosition sourcePosition = positionRef.get(); if (sourcePosition != null) { return sourcePosition; } @@ -179,15 +178,15 @@ public void threadAction() { if (DebuggerAction.isContextView(event)) { DebuggerTree tree = event.getData(DebuggerTree.DATA_KEY); if (tree != null && tree.getSelectionPath() != null) { - DebuggerTreeNodeImpl node = ((DebuggerTreeNodeImpl) tree.getSelectionPath().getLastPathComponent()); + DebuggerTreeNodeImpl node = ((DebuggerTreeNodeImpl)tree.getSelectionPath().getLastPathComponent()); if (node != null && node.getDescriptor() instanceof FieldDescriptorImpl fieldDescriptor) { Field field = fieldDescriptor.getField(); DebuggerSession session = tree.getDebuggerContext().getDebuggerSession(); PsiClass psiClass = DebuggerUtils.findClass(field.declaringType().name(), project, (session != null) ? session.getSearchScope() : GlobalSearchScope.allScope(project)); if (psiClass != null) { - psiClass = (PsiClass) psiClass.getNavigationElement(); - final PsiField psiField = psiClass.findFieldByName(field.name(), true); + psiClass = (PsiClass)psiClass.getNavigationElement(); + PsiField psiField = psiClass.findFieldByName(field.name(), true); if (psiField != null) { return SourcePosition.createFromElement(psiField); } @@ -202,13 +201,13 @@ public void threadAction() { editor = FileEditorManager.getInstance(project).getSelectedTextEditor(); } if (editor != null) { - final Document document = editor.getDocument(); + Document document = editor.getDocument(); PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document); if (file != null) { - final VirtualFile virtualFile = file.getVirtualFile(); + VirtualFile virtualFile = file.getVirtualFile(); FileType fileType = virtualFile != null ? virtualFile.getFileType() : null; if (fileType == JavaFileType.INSTANCE || fileType == JavaClassFileType.INSTANCE) { - final PsiField field = FieldBreakpoint.findField(project, document, editor.getCaretModel().getOffset()); + PsiField field = FieldBreakpoint.findField(project, document, editor.getCaretModel().getOffset()); if (field != null) { return SourcePosition.createFromElement(field); } diff --git a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/ToggleMethodBreakpointAction.java b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/ToggleMethodBreakpointAction.java index 693c5486c7..8c06a06c4f 100644 --- a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/ToggleMethodBreakpointAction.java +++ b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/ToggleMethodBreakpointAction.java @@ -32,17 +32,20 @@ import consulo.language.psi.PsiElement; import consulo.language.psi.PsiFile; import consulo.project.Project; +import consulo.ui.annotation.RequiredUIAccess; import consulo.ui.ex.action.ActionPlaces; import consulo.ui.ex.action.AnAction; import consulo.ui.ex.action.AnActionEvent; import consulo.util.lang.CharArrayUtil; import consulo.virtualFileSystem.VirtualFile; import consulo.virtualFileSystem.fileType.FileType; +import jakarta.annotation.Nonnull; import jakarta.annotation.Nullable; public class ToggleMethodBreakpointAction extends AnAction { @Override - public void update(AnActionEvent event) { + @RequiredUIAccess + public void update(@Nonnull AnActionEvent event) { boolean toEnable = getPlace(event) != null; if (ActionPlaces.isPopupPlace(event.getPlace())) { @@ -53,8 +56,8 @@ public void update(AnActionEvent event) { } } - @Override + @RequiredUIAccess public void actionPerformed(AnActionEvent e) { Project project = e.getData(Project.KEY); if (project == null) { @@ -62,8 +65,8 @@ public void actionPerformed(AnActionEvent e) { } DebuggerManagerEx debugManager = DebuggerManagerEx.getInstanceEx(project); - final BreakpointManager manager = debugManager.getBreakpointManager(); - final PlaceInDocument place = getPlace(e); + BreakpointManager manager = debugManager.getBreakpointManager(); + PlaceInDocument place = getPlace(e); if (place != null && DocumentUtil.isValidOffset(place.getOffset(), place.getDocument())) { Breakpoint breakpoint = manager.findBreakpoint(place.getDocument(), place.getOffset(), MethodBreakpoint.CATEGORY); if (breakpoint == null) { @@ -77,7 +80,7 @@ public void actionPerformed(AnActionEvent e) { @Nullable private static PlaceInDocument getPlace(AnActionEvent event) { - final Project project = event.getData(Project.KEY); + Project project = event.getData(Project.KEY); if (project == null) { return null; } @@ -85,13 +88,15 @@ private static PlaceInDocument getPlace(AnActionEvent event) { PsiElement method = null; Document document = null; - if (ActionPlaces.PROJECT_VIEW_POPUP.equals(event.getPlace()) || ActionPlaces.STRUCTURE_VIEW_POPUP.equals(event.getPlace()) - || ActionPlaces.FAVORITES_VIEW_POPUP.equals(event.getPlace()) || ActionPlaces.NAVIGATION_BAR_POPUP.equals(event.getPlace())) { - final PsiElement psiElement = event.getData(PsiElement.KEY); - if (psiElement instanceof PsiMethod) { - final PsiFile containingFile = psiElement.getContainingFile(); + String place = event.getPlace(); + if (ActionPlaces.PROJECT_VIEW_POPUP.equals(place) + || ActionPlaces.STRUCTURE_VIEW_POPUP.equals(place) + || ActionPlaces.FAVORITES_VIEW_POPUP.equals(place) + || ActionPlaces.NAVIGATION_BAR_POPUP.equals(place)) { + if (event.getData(PsiElement.KEY) instanceof PsiMethod m) { + PsiFile containingFile = m.getContainingFile(); if (containingFile != null) { - method = psiElement; + method = m; document = PsiDocumentManager.getInstance(project).getDocument(containingFile); } } @@ -105,7 +110,7 @@ private static PlaceInDocument getPlace(AnActionEvent event) { document = editor.getDocument(); PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document); if (file != null) { - final VirtualFile virtualFile = file.getVirtualFile(); + VirtualFile virtualFile = file.getVirtualFile(); FileType fileType = virtualFile != null ? virtualFile.getFileType() : null; if (JavaFileType.INSTANCE == fileType || JavaClassFileType.INSTANCE == fileType) { method = findMethod(project, editor); @@ -126,7 +131,7 @@ private static PsiMethod findMethod(Project project, Editor editor) { if (psiFile == null) { return null; } - final int offset = CharArrayUtil.shiftForward(editor.getDocument().getCharsSequence(), editor.getCaretModel().getOffset(), " \t"); + int offset = CharArrayUtil.shiftForward(editor.getDocument().getCharsSequence(), editor.getCaretModel().getOffset(), " \t"); return DebuggerUtilsEx.findPsiMethod(psiFile, offset); } } \ No newline at end of file diff --git a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/ViewAsGroup.java b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/ViewAsGroup.java index b5bdb26ab2..d7b02ae25d 100644 --- a/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/ViewAsGroup.java +++ b/java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/actions/ViewAsGroup.java @@ -28,6 +28,7 @@ import consulo.execution.debug.frame.XValueNode; import consulo.execution.debug.ui.XValueTree; import consulo.logging.Logger; +import consulo.ui.annotation.RequiredUIAccess; import consulo.ui.ex.action.*; import jakarta.annotation.Nonnull; import jakarta.annotation.Nullable; @@ -52,7 +53,8 @@ public RendererAction(NodeRenderer nodeRenderer) { myNodeRenderer = nodeRenderer; } - public boolean isSelected(AnActionEvent e) { + @Override + public boolean isSelected(@Nonnull AnActionEvent e) { List values = getSelectedValues(e); if (values.isEmpty()) { return false; @@ -66,15 +68,15 @@ public boolean isSelected(AnActionEvent e) { } @Override - public void setSelected(AnActionEvent e, final boolean state) { + public void setSelected(@Nonnull AnActionEvent e, boolean state) { if (!state) { return; } - final DebuggerContextImpl debuggerContext = DebuggerAction.getDebuggerContext(e.getDataContext()); - final List values = getSelectedValues(e); + DebuggerContextImpl debuggerContext = DebuggerAction.getDebuggerContext(e.getDataContext()); + List values = getSelectedValues(e); XValueTree tree = e.getData(XValueTree.KEY); - final List selectedNodes = tree == null ? List.of() : tree.getSelectedNodes(); + List selectedNodes = tree == null ? List.of() : tree.getSelectedNodes(); LOG.assertTrue(!values.isEmpty()); @@ -85,11 +87,11 @@ public void setSelected(AnActionEvent e, final boolean state) { process.getManagerThread().schedule(new DebuggerContextCommandImpl(debuggerContext) { @Override - public void threadAction(SuspendContextImpl context) { + public void threadAction(@Nonnull SuspendContextImpl context) { for (XValueNode node : selectedNodes) { - final XValue container = node.getValueContainer(); - if (container instanceof JavaValue) { - ((JavaValue) container).setRenderer(myNodeRenderer, node); + XValue container = node.getValueContainer(); + if (container instanceof JavaValue javaValue) { + javaValue.setRenderer(myNodeRenderer, node); } } } @@ -98,7 +100,8 @@ public void threadAction(SuspendContextImpl context) { } @Nonnull - public AnAction[] getChildren(@Nullable final AnActionEvent e) { + @Override + public AnAction[] getChildren(@Nullable AnActionEvent e) { return myChildren; } @@ -134,7 +137,8 @@ private static AnAction[] calcChildren(List values) { } List children = new ArrayList<>(); - AnAction[] viewAsActions = ((DefaultActionGroup) ActionManager.getInstance().getAction(DebuggerActions.REPRESENTATION_LIST)).getChildren(null); + AnAction[] viewAsActions = + ((DefaultActionGroup)ActionManager.getInstance().getAction(DebuggerActions.REPRESENTATION_LIST)).getChildren(null); for (AnAction viewAsAction : viewAsActions) { if (viewAsAction instanceof AutoRendererAction) { if (renderers.size() > 1) { @@ -155,26 +159,29 @@ private static AnAction[] calcChildren(List values) { return children.toArray(new AnAction[children.size()]); } - public void update(final AnActionEvent event) { + @Override + @RequiredUIAccess + public void update(@Nonnull AnActionEvent event) { if (!DebuggerAction.isFirstStart(event)) { return; } myChildren = AnAction.EMPTY_ARRAY; - final DebuggerContextImpl debuggerContext = DebuggerAction.getDebuggerContext(event.getDataContext()); - final List values = getSelectedValues(event); + DebuggerContextImpl debuggerContext = DebuggerAction.getDebuggerContext(event.getDataContext()); + List values = getSelectedValues(event); if (values.isEmpty()) { event.getPresentation().setEnabledAndVisible(false); return; } - final DebugProcessImpl process = debuggerContext.getDebugProcess(); + DebugProcessImpl process = debuggerContext.getDebugProcess(); if (process == null) { event.getPresentation().setEnabled(false); return; } process.getManagerThread().schedule(new DebuggerContextCommandImpl(debuggerContext) { + @Override public void threadAction() { myChildren = calcChildren(values); DebuggerAction.enableAction(event, myChildren.length > 0); @@ -189,9 +196,8 @@ public static List getSelectedValues(AnActionEvent event) { List values = new ArrayList<>(); for (XValueNode node : selectedNodes) { - XValue valueContainer = node.getValueContainer(); - if (valueContainer instanceof JavaValue) { - values.add((JavaValue) valueContainer); + if (node.getValueContainer() instanceof JavaValue javaValue) { + values.add(javaValue); } } return values;