IDEA-128022 Missing "adjust range" for arrays/collections

This commit is contained in:
Egor.Ushakov
2014-09-04 15:01:07 +04:00
parent 8e88104130
commit 46fafc29fc
10 changed files with 108 additions and 51 deletions
@@ -16,6 +16,7 @@
package com.intellij.debugger.actions;
import com.intellij.debugger.engine.DebugProcessImpl;
import com.intellij.debugger.engine.JavaValue;
import com.intellij.debugger.engine.events.SuspendContextCommandImpl;
import com.intellij.debugger.impl.DebuggerContextImpl;
import com.intellij.debugger.settings.ArrayRendererConfigurable;
@@ -27,6 +28,9 @@ import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.options.ShowSettingsUtil;
import com.intellij.openapi.project.Project;
import com.intellij.xdebugger.frame.XValue;
import com.intellij.xdebugger.impl.ui.tree.actions.XDebuggerTreeActionBase;
import com.intellij.xdebugger.impl.ui.tree.nodes.XValueNodeImpl;
import org.jetbrains.annotations.Nullable;
public class AdjustArrayRangeAction extends DebuggerAction {
@@ -44,42 +48,48 @@ public class AdjustArrayRangeAction extends DebuggerAction {
final Project project = debuggerContext.getProject();
final DebuggerTreeNodeImpl selectedNode = getSelectedNode(e.getDataContext());
if (selectedNode == null) {
return;
}
NodeDescriptorImpl descriptor = selectedNode.getDescriptor();
if(!(descriptor instanceof ValueDescriptorImpl /*&& ((ValueDescriptorImpl)descriptor).isArray()*/)) {
final XValueNodeImpl node = XDebuggerTreeActionBase.getSelectedNode(e.getDataContext());
if (node == null) {
return;
}
final ArrayRenderer renderer = getArrayRenderer((ValueDescriptorImpl)descriptor)/*(ArrayRenderer)((ValueDescriptorImpl)selectedNode.getDescriptor()).getLastRenderer()*/;
XValue container = node.getValueContainer();
if (!(container instanceof JavaValue)) {
return;
}
final ValueDescriptorImpl descriptor = ((JavaValue)container).getDescriptor();
ArrayRenderer renderer = getArrayRenderer(descriptor);
if (renderer == null) {
return;
}
String title = createNodeTitle("", selectedNode);
String label = selectedNode.toString();
int index = label.indexOf('=');
if (index > 0) {
title = title + " " + label.substring(index);
}
//String title = createNodeTitle("", selectedNode);
//String label = selectedNode.toString();
//int index = label.indexOf('=');
//if (index > 0) {
// title = title + " " + label.substring(index);
//}
String title = node.getName();
final ArrayRenderer clonedRenderer = renderer.clone();
clonedRenderer.setForced(true);
if (ShowSettingsUtil.getInstance().editConfigurable(project, new NamedArrayConfigurable(title, clonedRenderer))) {
debugProcess.getManagerThread().schedule(new SuspendContextCommandImpl(debuggerContext.getSuspendContext()) {
@Override
public void contextAction() throws Exception {
final ValueDescriptorImpl nodeDescriptor = (ValueDescriptorImpl)selectedNode.getDescriptor();
final Renderer lastRenderer = nodeDescriptor.getLastRenderer();
final Renderer lastRenderer = descriptor.getLastRenderer();
if (lastRenderer instanceof ArrayRenderer) {
selectedNode.setRenderer(clonedRenderer);
descriptor.setRenderer(clonedRenderer);
refreshViews(node);
//selectedNode.setRenderer(clonedRenderer);
}
else if (lastRenderer instanceof CompoundNodeRenderer) {
final CompoundNodeRenderer compoundRenderer = (CompoundNodeRenderer)lastRenderer;
final ChildrenRenderer childrenRenderer = compoundRenderer.getChildrenRenderer();
if (childrenRenderer instanceof ExpressionChildrenRenderer) {
ExpressionChildrenRenderer.setPreferableChildrenRenderer(nodeDescriptor, clonedRenderer);
selectedNode.calcRepresentation();
ExpressionChildrenRenderer.setPreferableChildrenRenderer(descriptor, clonedRenderer);
refreshViews(node);
//selectedNode.calcRepresentation();
}
}
}
@@ -90,10 +100,14 @@ public class AdjustArrayRangeAction extends DebuggerAction {
@Override
public void update(AnActionEvent e) {
boolean enable = false;
DebuggerTreeNodeImpl selectedNode = getSelectedNode(e.getDataContext());
if(selectedNode != null) {
NodeDescriptorImpl descriptor = selectedNode.getDescriptor();
enable = descriptor instanceof ValueDescriptorImpl && getArrayRenderer((ValueDescriptorImpl)descriptor) != null;
XValueNodeImpl node = XDebuggerTreeActionBase.getSelectedNode(e.getDataContext());
if (node == null) {
return;
}
XValue container = node.getValueContainer();
if (container instanceof JavaValue) {
ValueDescriptorImpl descriptor = ((JavaValue)container).getDescriptor();
enable = getArrayRenderer(descriptor) != null;
}
e.getPresentation().setVisible(enable);
}
@@ -22,6 +22,7 @@ package com.intellij.debugger.actions;
import com.intellij.debugger.DebuggerManagerEx;
import com.intellij.debugger.engine.JavaDebugProcess;
import com.intellij.debugger.impl.DebuggerContextImpl;
import com.intellij.debugger.impl.DebuggerStateManager;
import com.intellij.debugger.ui.impl.DebuggerTreePanel;
@@ -32,6 +33,10 @@ import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.project.Project;
import com.intellij.ui.DoubleClickListener;
import com.intellij.xdebugger.XDebugProcess;
import com.intellij.xdebugger.XDebugSession;
import com.intellij.xdebugger.impl.frame.XDebugView;
import com.intellij.xdebugger.impl.ui.tree.nodes.XValueNodeImpl;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
@@ -153,4 +158,15 @@ public abstract class DebuggerAction extends AnAction {
}
});
}
public static void refreshViews(XValueNodeImpl node) {
final XDebugSession session = XDebugView.getSession(node.getTree());
if (session != null) {
XDebugProcess process = session.getDebugProcess();
if (process instanceof JavaDebugProcess) {
((JavaDebugProcess)process).saveNodeHistory();
}
session.rebuildViews();
}
}
}
@@ -22,13 +22,11 @@ import com.intellij.debugger.impl.DebuggerContextImpl;
import com.intellij.debugger.settings.NodeRendererSettings;
import com.intellij.debugger.ui.impl.watch.NodeDescriptorImpl;
import com.intellij.debugger.ui.impl.watch.ValueDescriptorImpl;
import com.intellij.debugger.ui.tree.render.DescriptorLabelListener;
import com.intellij.debugger.ui.tree.render.NodeRenderer;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.DumbAware;
import com.intellij.xdebugger.frame.XValue;
import com.intellij.xdebugger.frame.XValuePlace;
import com.intellij.xdebugger.impl.ui.tree.actions.XDebuggerTreeActionBase;
import com.intellij.xdebugger.impl.ui.tree.nodes.XValueNodeImpl;
import org.jetbrains.annotations.NotNull;
@@ -66,7 +64,7 @@ public class ViewAsGroup extends ActionGroup implements DumbAware {
}
XValue container = node.getValueContainer();
if (container instanceof JavaValue) {
if (((ValueDescriptorImpl)((JavaValue)container).getDescriptor()).getLastRenderer() != myNodeRenderer) {
if (((JavaValue)container).getDescriptor().getLastRenderer() != myNodeRenderer) {
return false;
}
}
@@ -83,11 +81,12 @@ public class ViewAsGroup extends ActionGroup implements DumbAware {
public void threadAction() {
XValue container = node.getValueContainer();
if (container instanceof JavaValue) {
final ValueDescriptorImpl valueDescriptor = (ValueDescriptorImpl)((JavaValue)container).getDescriptor();
final ValueDescriptorImpl valueDescriptor = ((JavaValue)container).getDescriptor();
if (state) {
valueDescriptor.setRenderer(myNodeRenderer);
valueDescriptor.updateRepresentation(debuggerContext.createEvaluationContext(), DescriptorLabelListener.DUMMY_LISTENER);
container.computePresentation(node, XValuePlace.TREE);
DebuggerAction.refreshViews(node);
//valueDescriptor.updateRepresentation(debuggerContext.createEvaluationContext(), DescriptorLabelListener.DUMMY_LISTENER);
//container.computePresentation(node, XValuePlace.TREE);
}
}
}
@@ -18,20 +18,18 @@ package com.intellij.debugger.engine;
import com.intellij.debugger.DebuggerBundle;
import com.intellij.debugger.actions.DebuggerActions;
import com.intellij.debugger.engine.evaluation.EvaluationContext;
import com.intellij.debugger.engine.evaluation.EvaluationContextImpl;
import com.intellij.debugger.engine.events.DebuggerCommandImpl;
import com.intellij.debugger.engine.events.DebuggerContextCommandImpl;
import com.intellij.debugger.impl.*;
import com.intellij.debugger.jdi.StackFrameProxyImpl;
import com.intellij.debugger.settings.DebuggerSettings;
import com.intellij.debugger.ui.DebuggerContentInfo;
import com.intellij.debugger.ui.breakpoints.Breakpoint;
import com.intellij.debugger.ui.impl.ThreadsPanel;
import com.intellij.debugger.ui.impl.watch.DebuggerTreeNodeImpl;
import com.intellij.debugger.ui.impl.watch.MessageDescriptor;
import com.intellij.debugger.ui.impl.watch.NodeDescriptorImpl;
import com.intellij.debugger.ui.impl.watch.NodeManagerImpl;
import com.intellij.debugger.ui.tree.NodeDescriptor;
import com.intellij.debugger.ui.tree.render.DescriptorLabelListener;
import com.intellij.execution.process.ProcessHandler;
import com.intellij.execution.ui.ExecutionConsole;
import com.intellij.execution.ui.ExecutionConsoleEx;
@@ -150,29 +148,40 @@ public class JavaDebugProcess extends XDebugProcess {
};
session.addSessionListener(new XDebugSessionAdapter() {
@Override
public void beforeSessionResume() {
myJavaSession.getProcess().getManagerThread().schedule(new DebuggerCommandImpl() {
@Override
protected void action() throws Exception {
myNodeManager.setHistoryByContext(getDebuggerStateManager().getContext());
}
@Override
public Priority getPriority() {
return Priority.NORMAL;
}
});
public void sessionPaused() {
saveNodeHistory();
}
@Override
public void stackFrameChanged() {
XStackFrame frame = session.getCurrentStackFrame();
if (frame instanceof JavaStackFrame) {
DebuggerContextUtil.setStackFrame(javaSession.getContextManager(), ((JavaStackFrame)frame).getStackFrameProxy());
StackFrameProxyImpl frameProxy = ((JavaStackFrame)frame).getStackFrameProxy();
DebuggerContextUtil.setStackFrame(javaSession.getContextManager(), frameProxy);
saveNodeHistory(frameProxy);
}
}
});
}
public void saveNodeHistory() {
saveNodeHistory(getDebuggerStateManager().getContext().getFrameProxy());
}
private void saveNodeHistory(final StackFrameProxyImpl frameProxy) {
myJavaSession.getProcess().getManagerThread().invoke(new DebuggerCommandImpl() {
@Override
protected void action() throws Exception {
myNodeManager.setHistoryByContext(frameProxy);
}
@Override
public Priority getPriority() {
return Priority.NORMAL;
}
});
}
private DebuggerStateManager getDebuggerStateManager() {
return myJavaSession.getContextManager();
}
@@ -103,6 +103,7 @@ public class JavaValue extends XNamedValue implements NodeDescriptorProvider, XV
}
@Override
@NotNull
public ValueDescriptorImpl getDescriptor() {
return myValueDescriptor;
}
@@ -199,6 +199,7 @@ public class DebuggerSession implements AbstractDebuggerSession {
ValueLookupManager.getInstance(getProject()).startListening();
}
@NotNull
public DebuggerStateManager getContextManager() {
return myContextManager;
}
@@ -93,6 +93,10 @@ public class NodeDescriptorFactoryImpl implements NodeDescriptorFactory {
}
public void deriveHistoryTree(DescriptorTree tree, final StackFrameContext context) {
deriveHistoryTree(tree, context.getFrameProxy());
}
public void deriveHistoryTree(DescriptorTree tree, final StackFrameProxy frameProxy) {
final MarkedDescriptorTree descriptorTree = new MarkedDescriptorTree();
final MarkedDescriptorTree displayDescriptorTree = new MarkedDescriptorTree();
@@ -109,13 +113,12 @@ public class NodeDescriptorFactoryImpl implements NodeDescriptorFactory {
myDescriptorSearcher = new DescriptorTreeSearcher(descriptorTree);
myDisplayDescriptorSearcher = new DisplayDescriptorTreeSearcher(displayDescriptorTree);
myCurrentHistoryTree = createDescriptorTree(context, tree);
myCurrentHistoryTree = createDescriptorTree(frameProxy, tree);
}
private static DescriptorTree createDescriptorTree(final StackFrameContext context, final DescriptorTree fromTree) {
private static DescriptorTree createDescriptorTree(final StackFrameProxy frameProxy, final DescriptorTree fromTree) {
int frameCount = -1;
int frameIndex = -1;
final StackFrameProxy frameProxy = context.getFrameProxy();
if (frameProxy != null) {
try {
final ThreadReferenceProxy threadReferenceProxy = frameProxy.threadProxy();
@@ -75,11 +75,15 @@ public class NodeManagerImpl extends NodeDescriptorFactoryImpl implements NodeMa
}
public void setHistoryByContext(final DebuggerContextImpl context) {
setHistoryByContext(context.getFrameProxy());
}
public void setHistoryByContext(StackFrameProxyImpl frameProxy) {
if (myHistoryKey != null) {
myHistories.put(myHistoryKey, getCurrentHistoryTree());
}
final String historyKey = getContextKey(context.getFrameProxy());
final String historyKey = getContextKey(frameProxy);
final DescriptorTree descriptorTree;
if (historyKey != null) {
final DescriptorTree historyTree = myHistories.get(historyKey);
@@ -89,7 +93,7 @@ public class NodeManagerImpl extends NodeDescriptorFactoryImpl implements NodeMa
descriptorTree = new DescriptorTree(true);
}
deriveHistoryTree(descriptorTree, context);
deriveHistoryTree(descriptorTree, frameProxy);
myHistoryKey = historyKey;
}
@@ -65,6 +65,8 @@ public class ArrayRenderer extends NodeRendererImpl{
public int ENTRIES_LIMIT = 101;
private final static String MORE_ELEMENTS = "...";
private boolean myForced = false;
public ArrayRenderer() {
myProperties.setEnabled(true);
}
@@ -97,13 +99,19 @@ public class ArrayRenderer extends NodeRendererImpl{
return ClassRenderer.calcLabel(descriptor);
}
public void setForced(boolean forced) {
myForced = forced;
}
public void buildChildren(Value value, ChildrenBuilder builder, EvaluationContext evaluationContext) {
DebuggerManagerThreadImpl.assertIsManagerThread();
List<DebuggerTreeNode> children = new ArrayList<DebuggerTreeNode>();
NodeManagerImpl nodeManager = (NodeManagerImpl)builder.getNodeManager();
NodeDescriptorFactory descriptorFactory = builder.getDescriptorManager();
builder.initChildrenArrayRenderer(this);
if (!myForced) {
builder.initChildrenArrayRenderer(this);
}
ArrayReference array = (ArrayReference)value;
if (array.length() > 0) {
@@ -182,7 +190,7 @@ public class ArrayRenderer extends NodeRendererImpl{
// children.add(0, nodeManager.createMessageNode(new MessageDescriptor(MORE_ELEMENTS, MessageDescriptor.SPECIAL)));
//}
if(END_INDEX < array.length() - 1) {
if(!myForced && END_INDEX < array.length() - 1) {
//children.add(nodeManager.createMessageNode(new MessageDescriptor(MORE_ELEMENTS, MessageDescriptor.SPECIAL)));
builder.setRemaining(array.length()-END_INDEX);
}
+3 -1
View File
@@ -153,7 +153,6 @@
</action>
<group id="JavaDebuggerActions">
<action id="Debugger.AdjustArrayRange" class="com.intellij.debugger.actions.AdjustArrayRangeAction"/>
<action id="Debugger.Inspect" class="com.intellij.debugger.actions.InspectAction"/>
<action id="Debugger.CustomizeContextView" class="com.intellij.debugger.actions.CustomizeContextViewAction">
<add-to-group group-id="XDebugger.Variables.Tree.Popup" anchor="last"/>
@@ -178,6 +177,9 @@
<action id="Debugger.ViewAsGroup" class="com.intellij.debugger.actions.ViewAsGroup">
<add-to-group group-id="XDebugger.ValueGroup" anchor="last"/>
</action>
<action id="Debugger.AdjustArrayRange" class="com.intellij.debugger.actions.AdjustArrayRangeAction">
<add-to-group group-id="XDebugger.ValueGroup" anchor="last"/>
</action>
<!--<action id="Debugger.SetValue" class="com.intellij.debugger.actions.SetValueAction"/>-->
<!--<action id="Debugger.ShowAsHex" class="com.intellij.debugger.actions.ShowAsHexAction" text="Show as Hex"/>-->
<action id="Debugger.ShowFrame" class="com.intellij.debugger.actions.ShowFrameAction"/>