X-Git-Url: http://secure.phpeclipse.com diff --git a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPVariable.java b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPVariable.java index 072e0b3..8bd7406 100644 --- a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPVariable.java +++ b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPVariable.java @@ -32,10 +32,11 @@ import org.eclipse.debug.core.model.IVariable; public class PHPVariable implements IVariable { private PHPValue fValue; // The value of this variable - private String fName; // The name of the variable + private String fName; // The name of the variable private PHPStackFrame fStackFrame; // The stackframe this variable belongs to private PHPVariable fParent; // The parent variable (a back link) - private String fLongName; // The qualified name + private String fLongName; // The qualified name + private boolean fModifiable = true; /** * @@ -53,13 +54,13 @@ public class PHPVariable implements IVariable { * @param valueType The type of the value (e.g. int, double, string etc.) @see PHPValue * @param subitems */ - public PHPVariable(PHPStackFrame frame, String name, PHPVariable parent, - String value, int valueType, Vector subitems) { + public PHPVariable (PHPStackFrame frame, String name, PHPVariable parent, + String value, int valueType, Vector subitems) { this.fStackFrame = frame; - this.fValue = new PHPValue(frame, value, valueType, subitems); - this.fParent = parent; + this.fValue = new PHPValue(frame, value, valueType, subitems); + this.fParent = parent; - setName(name); + setName (name); } /** @@ -68,7 +69,7 @@ public class PHPVariable implements IVariable { */ public void setName(String name) { if ((fParent == null) || // If we have no parent for this variable - (fParent.getName() == "")) { // or we have a parent which is just a simple node ??? + (fParent.getName() == "")) { // or we have a parent which is just a simple node ??? fLongName = name; // Set the long name fName = name; // and set the name @@ -76,20 +77,20 @@ public class PHPVariable implements IVariable { } switch (fParent.getReferenceType()) { // Get the type of the parent variable - case PHPValue.PEVT_ARRAY: // It's an array - fName = "['" + name + "']"; // So set the variable name as [name] - fLongName = fParent.getLongName() + fName; // Set the longname to parentVariableLongname[name] - break; + case PHPValue.PEVT_ARRAY: // It's an array + fName = "['" + name + "']"; // So set the variable name as [name] + fLongName = fParent.getLongName() + fName; // Set the longname to parentVariableLongname[name] + break; - case PHPValue.PEVT_OBJECT: // It's an object - fName = name; // Set the name to name - fLongName = fParent.getLongName() + "->" + fName; // Set the longname to parentVariableLongname.name - break; + case PHPValue.PEVT_OBJECT: // It's an object + fName = name; // Set the name to name + fLongName = fParent.getLongName() + "->" + fName;// Set the longname to parentVariableLongname.name + break; - default: - fName = name; // Set the name to name - fLongName = name; // Set the Longname to name - break; + default: + fName = name; // Set the name to name + fLongName = name; // Set the Longname to name + break; } } @@ -119,7 +120,20 @@ public class PHPVariable implements IVariable { */ public void setParent(PHPVariable parent) { this.fParent = parent; - fLongName = parent.getLongName() + fName; + + switch (fParent.getReferenceType ()) { + case PHPValue.PEVT_ARRAY: + fLongName = fParent.getLongName() + fName; + break; + + case PHPValue.PEVT_OBJECT: + fLongName = fParent.getLongName() + "->" + fName; + break; + + default: + fLongName = fName; + break; + } } /** @@ -192,32 +206,50 @@ public class PHPVariable implements IVariable { /** * @see org.eclipse.debug.core.model.IValueModification#setValue(java.lang.String) */ - public void setValue(String expression) throws DebugException { + public void setValue (String expression) throws DebugException { String evalString; - if (fValue.getReferenceType() == PHPValue.PEVT_STRING) + + if (fValue.getReferenceType () == PHPValue.PEVT_STRING) { evalString = fLongName + "=\"" + expression + "\""; - else + } + else { evalString = fLongName + "=" + expression; - PHPVariable[] vars = fStackFrame.getPHPDBGProxy().eval(fStackFrame, - evalString); + } + PHPVariable[] vars = fStackFrame.getPHPDBGProxy ().eval (fStackFrame, evalString); +///* if (vars == null || vars.length == 0) { - vars = fStackFrame.getPHPDBGProxy().eval(fStackFrame, fLongName); + vars = fStackFrame.getPHPDBGProxy ().eval (fStackFrame, fLongName); + if (vars == null || vars.length == 0) { - int code = 0; - String msg = "Could not set " + expression + " to " + fLongName; - Status status = new Status(Status.ERROR, - PHPDebugCorePlugin.PLUGIN_ID, code, msg, null); - PHPDebugCorePlugin.log(status); - throw new DebugException(status); + int code = 0; + String msg = "Could not set " + expression + " to " + fLongName; + Status status = new Status (Status.ERROR, PHPDebugCorePlugin.PLUGIN_ID, code, msg, null); + PHPDebugCorePlugin.log (status); + + throw new DebugException (status); } } +//*/ + fValue = vars[0].fValue; +///* + if (fValue.hasVariables ()) { // set parent if new value has children + Vector variables = fValue.getChildVariables (); + + for (int i = 0; i < variables.size (); i++) { + PHPVariable var = (PHPVariable) variables.get (i); + + var.setParent (this); - setValue(vars[0].fValue); + if (fValue.getReferenceType() == PHPValue.PEVT_ARRAY) { // adjust name if value type is array + var.setName (var.getName ()); // (still bare name. make "['name']") + } + } + } - DebugPlugin.getDefault().fireDebugEventSet( - new DebugEvent[] { new DebugEvent(this, DebugEvent.CHANGE, - DebugEvent.CONTENT) }); + DebugPlugin.getDefault().fireDebugEventSet (new DebugEvent[] { + new DebugEvent (this, DebugEvent.CHANGE, DebugEvent.CONTENT) }); +//*/ } /** @@ -231,7 +263,16 @@ public class PHPVariable implements IVariable { * @see org.eclipse.debug.core.model.IValueModification#supportsValueModification() */ public boolean supportsValueModification() { - return true; + return fModifiable; + } + + /** + * Set whether this variable can be modified (default is true) + * + * for Global Variables root element only + */ + public void setModifiable(boolean modifiable) { + fModifiable = modifiable; } /** @@ -262,7 +303,6 @@ public class PHPVariable implements IVariable { * with a type specific explanation. */ public String toString() { - int type = -1; String str = ""; switch (getReferenceType()) { @@ -300,4 +340,21 @@ public class PHPVariable implements IVariable { return str; } + + /* + * ONLY FOR net.sourceforge.phpdt.internal.debug.core.model.PHPDBGEvalString#copyItems(PHPVariable, PHPValue) + */ + protected Object clone() throws CloneNotSupportedException { + PHPVariable var = new PHPVariable(); + + var.fValue = fValue; + var.fName = fName; + var.fStackFrame = fStackFrame; + var.fParent = fParent; + var.fLongName = fLongName; + var.fModifiable = fModifiable; + + return var; + } + }