blob: 637f831544e9d6f87cec538db96421726ae1d425 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.e4.languages.javascript.debug.model;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IRegisterGroup;
import org.eclipse.debug.core.model.IStackFrame;
import org.eclipse.debug.core.model.IThread;
import org.eclipse.debug.core.model.IVariable;
import org.eclipse.e4.languages.javascript.jsdi.StackFrame;
import org.eclipse.osgi.util.NLS;
/**
* A JSDI stack frame
*
* @since 1.0
*/
public class JSDIStackFrame extends JSDIDebugElement implements IStackFrame {
/**
* Owning thread.
*/
private JSDIThread thread;
/**
* The underlying {@link StackFrame}
*/
private StackFrame stackframe = null;
/**
* Name cache
*/
private String name = null;
/**
* Constructs a Rhino stack frame in the given thread.
*
* @param thread
*/
public JSDIStackFrame(JSDIThread thread, StackFrame stackFrame) {
super(thread.getJSDITarget());
this.thread = thread;
this.stackframe = stackFrame;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.core.model.IStackFrame#getCharEnd()
*/
public int getCharEnd() throws DebugException {
return -1;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.core.model.IStackFrame#getCharStart()
*/
public int getCharStart() throws DebugException {
return -1;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.core.model.IStackFrame#getLineNumber()
*/
public int getLineNumber() throws DebugException {
return (stackframe.location() != null ? stackframe.location().lineNumber() : -1);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.core.model.IStackFrame#getName()
*/
public String getName() throws DebugException {
if (name == null) {
name = stackframe.location().functionName();
if (name == null) {
NLS.bind(ModelMessages.JSDIStackFrame_stackframe_name, new String[] { stackframe.location().scriptReference().source(), Integer.toString(stackframe.location().lineNumber()) });
}
}
return name;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.core.model.IStackFrame#getRegisterGroups()
*/
public IRegisterGroup[] getRegisterGroups() throws DebugException {
return null;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.core.model.IStackFrame#getThread()
*/
public IThread getThread() {
return thread;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.core.model.IStackFrame#getVariables()
*/
public IVariable[] getVariables() throws DebugException {
return (IVariable[]) stackframe.variables().toArray(new IVariable[stackframe.variables().size()]);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.core.model.IStackFrame#hasRegisterGroups()
*/
public boolean hasRegisterGroups() throws DebugException {
return false;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.core.model.IStackFrame#hasVariables()
*/
public boolean hasVariables() throws DebugException {
return stackframe.variables().size() > 0;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.core.model.IStep#canStepInto()
*/
public boolean canStepInto() {
return thread.canStepInto();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.core.model.IStep#canStepOver()
*/
public boolean canStepOver() {
return thread.canStepOver();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.core.model.IStep#canStepReturn()
*/
public boolean canStepReturn() {
return thread.canStepReturn();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.core.model.IStep#isStepping()
*/
public boolean isStepping() {
return thread.isStepping();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.core.model.IStep#stepInto()
*/
public void stepInto() throws DebugException {
thread.stepInto();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.core.model.IStep#stepOver()
*/
public void stepOver() throws DebugException {
thread.stepOver();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.core.model.IStep#stepReturn()
*/
public void stepReturn() throws DebugException {
thread.stepReturn();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.core.model.ISuspendResume#canResume()
*/
public boolean canResume() {
return thread.canResume();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.core.model.ISuspendResume#canSuspend()
*/
public boolean canSuspend() {
return thread.canSuspend();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.core.model.ISuspendResume#isSuspended()
*/
public boolean isSuspended() {
return thread.isSuspended();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.core.model.ISuspendResume#resume()
*/
public void resume() throws DebugException {
thread.resume();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.core.model.ISuspendResume#suspend()
*/
public void suspend() throws DebugException {
thread.suspend();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.core.model.ITerminate#canTerminate()
*/
public boolean canTerminate() {
return thread.canTerminate();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.core.model.ITerminate#isTerminated()
*/
public boolean isTerminated() {
return thread.isTerminated();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.core.model.ITerminate#terminate()
*/
public void terminate() throws DebugException {
if (thread.canTerminate()) {
thread.terminate();
} else {
getJSDITarget().terminate();
}
}
}