summaryrefslogtreecommitdiff
path: root/plugins/xslt-debugger/src/org/intellij/plugins/xsltDebugger/impl/XsltExecutionStack.java
blob: 3f57574e175cddc24b6946e941a1c2ffbb757075 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package org.intellij.plugins.xsltDebugger.impl;

import com.intellij.xdebugger.frame.XExecutionStack;
import com.intellij.xdebugger.frame.XStackFrame;
import org.intellij.plugins.xsltDebugger.VMPausedException;
import org.intellij.plugins.xsltDebugger.XsltDebuggerSession;
import org.intellij.plugins.xsltDebugger.rt.engine.Debugger;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class XsltExecutionStack extends XExecutionStack {
  private final XsltStackFrame myTopFrame;
  private final XsltDebuggerSession myDebuggerSession;

  public XsltExecutionStack(String name, Debugger.Frame topFrame, XsltDebuggerSession debuggerSession) {
    super(name);
    myDebuggerSession = debuggerSession;
    myTopFrame = new XsltStackFrame(topFrame, myDebuggerSession);
  }

  @Override
  public XStackFrame getTopFrame() {
    return myTopFrame;
  }

  @Override
  public void computeStackFrames(int firstFrameIndex, XStackFrameContainer container) {
    try {
      if (myDebuggerSession.getCurrentState() == Debugger.State.SUSPENDED) {
        Debugger.Frame frame = myTopFrame.getFrame();
        final List<XStackFrame> frames = new ArrayList<XStackFrame>();
        while (frame != null) {
          frame = frame.getPrevious();
          if (frame != null) {
            frames.add(new XsltStackFrame(frame, myDebuggerSession));
          }
        }
        if (firstFrameIndex <= frames.size()) {
          container.addStackFrames(frames.subList(firstFrameIndex - 1, frames.size()), true);
        } else {
          container.addStackFrames(Collections.<XStackFrame>emptyList(), true);
        }
      }
    } catch (VMPausedException e) {
      container.errorOccurred(VMPausedException.MESSAGE);
    }
  }
}