**********************************************************************/
package net.sourceforge.phpdt.internal.debug.core.model;
+import java.util.Vector;
+
import net.sourceforge.phpdt.internal.debug.core.PHPDBGProxy;
import org.eclipse.debug.core.DebugEvent;
import org.eclipse.debug.core.model.IThread;
import org.eclipse.debug.core.model.IVariable;
-public class PHPStackFrame extends PHPDebugElement implements IStackFrame {
+/**
+ *
+ * TODO Remove the variables array and use only the varList vector
+ * Have also to change hasVariables
+ */
+public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Comparable{
private PHPThread thread; // The thread to which this stackframe belongs
private String file; // The file name???
private int lineNumber; //
private int index; //
private int modno; //
- private PHPVariable[] variables; // The array of variables
+ private PHPVariable[] variables; // The array of variables TODO: better introduce a vector?
+ private Vector varList = new Vector ();
private String description; //
/**
* @return The array of PHPVariables for this stackframe.
*/
public IVariable[] getVariables() throws DebugException {
- PHPVariable[] variablesNew; // The intermediate storage of the variable array we get from DBG proxy
+ //PHPVariable[] variablesNew; // The intermediate storage of the variable array we get from DBG proxy
+
+ //variablesNew = this.getPHPDBGProxy ().readVariables (this); // Get the variable array from DBG proxy
+ //variables = variablesNew; // Store the array the stackframes member variable
+ varList = this.getPHPDBGProxy ().readVariables (this);
- variablesNew = this.getPHPDBGProxy ().readVariables (this); // Get the variable array from DBG proxy
- variables = variablesNew; // Store the array the stackframes member variable
+ variables = (PHPVariable[]) varList.toArray (new PHPVariable[varList.size ()]);
return variables; // Give the array back to user interface
}
/**
- * TODO Is this really used (who calls this)
- * I think this method could be removed
*
- * @param s The variables name we are looking for.
- * @return
*/
- public IVariable findVariable (String s) throws DebugException {
- String name;
- int i;
-
- if (this.hasVariables ()) { // Does this stackframe have variables?
- name = "$" + s; // Prefix the variable name with $
-
- for (i = 0; i < variables.length; i++) { // For all variables
- if ((variables[i].getName ()).equals (name)) {
- return variables[i];
+ private PHPVariable findVariable (Vector varList, String varname) {
+ PHPVariable variable;
+ PHPValue value;
+ int i;
+
+ for (i = 0; i < varList.size (); i++) { // For all variables
+ variable = (PHPVariable) varList.get (i); // Get the variable
+ value = (PHPValue) variable.getValue (); // Get the value of the variable
+
+ try {
+ if (value.hasVariables ()) { // Does the variable/value have children
+ variable = findVariable (value.getChildVariables (), varname);
+
+ if (variable != null) {
+ return variable;
+ }
+ }
+ else if ((variable.getName ()).equals (varname)) { //
+ return variable; //
}
}
+ catch (DebugException e) { // That's, because of the hasVariables method
+ }
}
return null;
}
/**
+ * This method is called from the UI (e.g. from PHPDebugHover
+ * to find the variable the mouse is pointing to)
+ *
+ * @param s The variable name we are looking for.
+ * @return
+ */
+ public IVariable findVariable (String s) throws DebugException {
+ return (findVariable (varList, s)); // Prefix the variable name with $
+ }
+
+ /**
*
*/
public boolean hasVariables () throws DebugException {
return index;
}
+ public void setIndex (int index) {
+ this.index = index;
+ }
+
public PHPDBGProxy getPHPDBGProxy() {
PHPDebugTarget DebugTarget;
public int getModNo() {
return modno;
}
+
+ /**
+ * This function is needed when sorting the stackframes by their index numbers.
+ *
+ * @param obj The stackframe which this one is compared to.
+ * @return
+ * <ul>
+ * <li> -1 if the index of this stackframe is less.
+ * <li> 0 if the index of both stackfream is equal (should no happen).
+ * <li> 1 if the index of this stackfram is greater.
+ * </ul>
+ */
+ public int compareTo (Object obj)
+ {
+ if (index < ((PHPStackFrame) obj).getIndex ()) {
+ return -1;
+ }
+ else if (index > ((PHPStackFrame) obj).getIndex ()) {
+ return 1;
+ }
+
+ return 0;
+ }
}