From 61d11c82e30766c4d103596bd9be3008a04f7f51 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Wed, 5 Mar 2014 18:30:33 +0100 Subject: [PATCH] nashorn: x variables view --- .../engine/CompoundPositionManager.java | 6 +- .../debugger/engine}/PositionManagerEx.java | 7 +- .../debugger/ui/impl/FrameVariablesTree.java | 29 +++++++- .../debugger/ui/impl/VariablesPanel.java | 67 +++++++++++++++++-- .../debugger/ui/impl/watch/DebuggerTree.java | 2 +- .../impl/watch/StackFrameDescriptorImpl.java | 12 ++-- .../debugger/engine/DebugProcess.java | 3 +- 7 files changed, 106 insertions(+), 20 deletions(-) rename java/debugger/{openapi/src/com/intellij/debugger => impl/src/com/intellij/debugger/engine}/PositionManagerEx.java (76%) diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/CompoundPositionManager.java b/java/debugger/impl/src/com/intellij/debugger/engine/CompoundPositionManager.java index 399c55fd00e5..c0c0910afa84 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/CompoundPositionManager.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/CompoundPositionManager.java @@ -17,9 +17,9 @@ package com.intellij.debugger.engine; import com.intellij.debugger.NoDataException; import com.intellij.debugger.PositionManager; -import com.intellij.debugger.PositionManagerEx; import com.intellij.debugger.SourcePosition; import com.intellij.debugger.requests.ClassPrepareRequestor; +import com.intellij.debugger.ui.impl.watch.StackFrameDescriptorImpl; import com.intellij.xdebugger.frame.XStackFrame; import com.sun.jdi.Location; import com.sun.jdi.ReferenceType; @@ -100,10 +100,10 @@ public class CompoundPositionManager extends PositionManagerEx { @Nullable @Override - public XStackFrame createStackFrame(@NotNull Location location) { + public XStackFrame createStackFrame(@NotNull StackFrameDescriptorImpl frameDescriptor) { for (PositionManager positionManager : myPositionManagers) { if (positionManager instanceof PositionManagerEx) { - XStackFrame xStackFrame = ((PositionManagerEx)positionManager).createStackFrame(location); + XStackFrame xStackFrame = ((PositionManagerEx)positionManager).createStackFrame(frameDescriptor); if (xStackFrame != null) { return xStackFrame; } diff --git a/java/debugger/openapi/src/com/intellij/debugger/PositionManagerEx.java b/java/debugger/impl/src/com/intellij/debugger/engine/PositionManagerEx.java similarity index 76% rename from java/debugger/openapi/src/com/intellij/debugger/PositionManagerEx.java rename to java/debugger/impl/src/com/intellij/debugger/engine/PositionManagerEx.java index c1faee1f763f..82358d77d14b 100644 --- a/java/debugger/openapi/src/com/intellij/debugger/PositionManagerEx.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/PositionManagerEx.java @@ -13,14 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.intellij.debugger; +package com.intellij.debugger.engine; +import com.intellij.debugger.PositionManager; +import com.intellij.debugger.ui.impl.watch.StackFrameDescriptorImpl; import com.intellij.xdebugger.frame.XStackFrame; -import com.sun.jdi.Location; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public abstract class PositionManagerEx implements PositionManager { @Nullable - public abstract XStackFrame createStackFrame(@NotNull Location location); + public abstract XStackFrame createStackFrame(@NotNull StackFrameDescriptorImpl frameDescriptor); } diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/impl/FrameVariablesTree.java b/java/debugger/impl/src/com/intellij/debugger/ui/impl/FrameVariablesTree.java index 3bffee582805..8722246939bb 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/impl/FrameVariablesTree.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/impl/FrameVariablesTree.java @@ -52,9 +52,12 @@ import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.text.CharArrayUtil; import com.intellij.util.ui.tree.TreeModelAdapter; import com.intellij.xdebugger.XDebuggerBundle; +import com.intellij.xdebugger.frame.XStackFrame; import com.sun.jdi.*; import gnu.trove.TIntObjectHashMap; import gnu.trove.TObjectProcedure; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.swing.event.TreeModelEvent; import javax.swing.tree.TreeModel; @@ -67,9 +70,17 @@ public class FrameVariablesTree extends DebuggerTree { private boolean myAnyNewLocals; private boolean myAutoWatchMode = false; - public FrameVariablesTree(Project project) { + private final VariablesPanel myVariablesPanel; + + public FrameVariablesTree(@NotNull Project project) { + this(project, null); + } + + public FrameVariablesTree(@NotNull Project project, @Nullable VariablesPanel variablesPanel) { super(project); + getEmptyText().setText(XDebuggerBundle.message("debugger.variables.not.available")); + myVariablesPanel = variablesPanel; } public boolean isAutoWatchMode() { @@ -122,7 +133,21 @@ public class FrameVariablesTree extends DebuggerTree { public BuildFrameTreeVariablesCommand(DebuggerTreeNodeImpl stackNode) { super(stackNode); } - + + @Override + public void threadAction() { + if (myVariablesPanel != null) { + StackFrameDescriptorImpl stackDescriptor = (StackFrameDescriptorImpl)getNode().getDescriptor(); + XStackFrame xStackFrame = stackDescriptor.getXStackFrame(); + myVariablesPanel.stackChanged(xStackFrame); + if (xStackFrame != null) { + return; + } + } + + super.threadAction(); + } + @Override protected void buildVariables(final StackFrameDescriptorImpl stackDescriptor, final EvaluationContextImpl evaluationContext) throws EvaluateException { final DebuggerContextImpl debuggerContext = getDebuggerContext(); diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/impl/VariablesPanel.java b/java/debugger/impl/src/com/intellij/debugger/ui/impl/VariablesPanel.java index 3417e369ad2d..71e5ff878d70 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/impl/VariablesPanel.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/impl/VariablesPanel.java @@ -23,9 +23,19 @@ import com.intellij.debugger.impl.DebuggerStateManager; import com.intellij.debugger.ui.impl.watch.DebuggerTree; import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.*; +import com.intellij.openapi.editor.Document; +import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.project.Project; import com.intellij.ui.ScrollPaneFactory; +import com.intellij.util.SystemProperties; +import com.intellij.xdebugger.XSourcePosition; +import com.intellij.xdebugger.evaluation.EvaluationMode; +import com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider; +import com.intellij.xdebugger.frame.XStackFrame; +import com.intellij.xdebugger.impl.frame.XVariablesViewBase; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; @@ -34,14 +44,25 @@ import java.awt.event.KeyEvent; public class VariablesPanel extends DebuggerTreePanel implements DataProvider { @NonNls private static final String HELP_ID = "debugging.debugFrame"; + private static final String TREE = "tree"; + private static final String X_TREE = "xTree"; + private final JPanel myCards; + private final MyXVariablesView myXTree; + public VariablesPanel(Project project, DebuggerStateManager stateManager, Disposable parent) { super(project, stateManager); - setBorder(null); + setBorder(null); final FrameVariablesTree frameTree = getFrameTree(); - add(ScrollPaneFactory.createScrollPane(frameTree), BorderLayout.CENTER); + myCards = new JPanel(new CardLayout()); + myCards.add(frameTree, TREE); + + myXTree = new MyXVariablesView(project); + myCards.add(myXTree.getTree(), X_TREE); + + add(ScrollPaneFactory.createScrollPane(myCards), BorderLayout.CENTER); registerDisposable(DebuggerAction.installEditAction(frameTree, DebuggerActions.EDIT_NODE_SOURCE)); overrideShortcut(frameTree, DebuggerActions.COPY_VALUE, CommonShortcuts.getCopy()); @@ -52,7 +73,7 @@ public class VariablesPanel extends DebuggerTreePanel implements DataProvider { @Override protected DebuggerTree createTreeView() { - return new FrameVariablesTree(getProject()); + return new FrameVariablesTree(getProject(), SystemProperties.getBooleanProperty("java.debugger.xTree", false) ? this : null); } @Override @@ -76,8 +97,46 @@ public class VariablesPanel extends DebuggerTreePanel implements DataProvider { return super.getData(dataId); } - public FrameVariablesTree getFrameTree() { return (FrameVariablesTree)getTree(); } + + public void stackChanged(@Nullable XStackFrame xStackFrame) { + myXTree.stackChanged(xStackFrame); + ((CardLayout)(myCards.getLayout())).show(myCards, xStackFrame == null ? TREE : X_TREE); + } + + private static final class MyXVariablesView extends XVariablesViewBase { + private XStackFrame myCurrentXStackFrame; + + public MyXVariablesView(Project project) { + super(project, new XDebuggerEditorsProvider() { + @NotNull + @Override + public FileType getFileType() { + throw new UnsupportedOperationException(); + } + + @NotNull + @Override + public Document createDocument(@NotNull Project project, @NotNull String text, @Nullable XSourcePosition sourcePosition, @NotNull EvaluationMode mode) { + throw new UnsupportedOperationException(); + } + }, null); + } + + public void stackChanged(@Nullable XStackFrame stackFrame) { + if (myCurrentXStackFrame != null) { + saveCurrentTreeState(stackFrame); + } + + myCurrentXStackFrame = stackFrame; + if (stackFrame == null) { + getTree().setSourcePosition(null); + } + else { + buildTreeAndRestoreState(stackFrame); + } + } + } } diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/DebuggerTree.java b/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/DebuggerTree.java index 788c11233c80..1b1033a4b263 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/DebuggerTree.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/DebuggerTree.java @@ -440,7 +440,7 @@ public abstract class DebuggerTree extends DebuggerTreeBase implements DataProvi } @Override - public final void threadAction() { + public void threadAction() { try { final StackFrameDescriptorImpl stackDescriptor = (StackFrameDescriptorImpl)getNode().getDescriptor(); final StackFrameProxyImpl frame = stackDescriptor.getFrameProxy(); diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/StackFrameDescriptorImpl.java b/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/StackFrameDescriptorImpl.java index 8e11e545dcd0..a883e647a525 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/StackFrameDescriptorImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/StackFrameDescriptorImpl.java @@ -16,10 +16,7 @@ package com.intellij.debugger.ui.impl.watch; import com.intellij.debugger.SourcePosition; -import com.intellij.debugger.engine.ContextUtil; -import com.intellij.debugger.engine.DebugProcess; -import com.intellij.debugger.engine.DebuggerManagerThreadImpl; -import com.intellij.debugger.engine.DebuggerUtils; +import com.intellij.debugger.engine.*; import com.intellij.debugger.engine.evaluation.EvaluateException; import com.intellij.debugger.engine.evaluation.EvaluationContextImpl; import com.intellij.debugger.jdi.StackFrameProxyImpl; @@ -102,7 +99,12 @@ public class StackFrameDescriptorImpl extends NodeDescriptorImpl implements Stac myIsInLibraryContent = false; } - myXStackFrame = myLocation == null ? null : getDebugProcess().getPositionManager().createStackFrame(myLocation); + myXStackFrame = myLocation == null ? null : ((DebugProcessImpl)getDebugProcess()).getPositionManager().createStackFrame(this); + } + + @Nullable + public XStackFrame getXStackFrame() { + return myXStackFrame; } public int getUiIndex() { diff --git a/java/debugger/openapi/src/com/intellij/debugger/engine/DebugProcess.java b/java/debugger/openapi/src/com/intellij/debugger/engine/DebugProcess.java index 43c7fd47f02f..66fea2d7f38c 100644 --- a/java/debugger/openapi/src/com/intellij/debugger/engine/DebugProcess.java +++ b/java/debugger/openapi/src/com/intellij/debugger/engine/DebugProcess.java @@ -16,7 +16,6 @@ package com.intellij.debugger.engine; import com.intellij.debugger.PositionManager; -import com.intellij.debugger.PositionManagerEx; import com.intellij.debugger.engine.evaluation.EvaluateException; import com.intellij.debugger.engine.evaluation.EvaluationContext; import com.intellij.debugger.engine.jdi.VirtualMachineProxy; @@ -45,7 +44,7 @@ public interface DebugProcess { RequestManager getRequestsManager(); - PositionManagerEx getPositionManager(); + PositionManager getPositionManager(); VirtualMachineProxy getVirtualMachineProxy();