import net.sourceforge.phpeclipse.xdebug.core.PHPDebugUtils;
-import org.eclipse.debug.core.DebugEvent;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IValue;
import org.eclipse.debug.core.model.IVariable;
/**
* @author Axel
- *
- * TODO To change the template for this generated type comment go to Window -
- * Preferences - Java - Code Style - Code Templates
+ *
+ * TODO To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Style - Code Templates
*/
public class XDebugVariable extends XDebugElement implements IVariable {
-
- public static final int VARTYPE_UNKNOWN = -1;
-
- public static final int VARTYPE_UNINITIALIZED = 0;
-
- public static final int VARTYPE_STRING = 1;
-
- public static final int VARTYPE_INT = 2;
-
- public static final int VARTYPE_FLOAT = 3;
-
- public static final int VARTYPE_ARRAY = 8;
-
- public static final int VARTYPE_HASH = 9;
-
- public static final int VARTYPE_OBJECT = 10;
-
- // name & stack frmae
- private String fName;
-
- private XDebugStackFrame fFrame;
-
- private String fFullName;
-
- // private String fTypeName;
- // private int fType;
+ private String fName;
+ private String fNameFull;
+ private XDebugStackFrame fFrame;
private XDebugAbstractValue fValue;
+ private String fFacet;
+ private XDebugVariable fParent; // The parent variable (a back link)
+ private String fTypeName;
- private String fEncoding;
-
- private int fNumChildren;
-
- // private Node fVariableNode;
/**
- * Constructs a variable contained in the given stack frame with the given
- * name.
- *
- * @param frame
- * owning stack frame
- * @param name
- * variable name
+ * Constructs a variable contained in the given stack frame
+ * with the given name.
+ *
+ * @param frame owning stack frame
+ * @param name variable name
*/
- public XDebugVariable(XDebugStackFrame frame, Node property) {
+ public XDebugVariable(XDebugStackFrame frame, Node property, XDebugVariable parent) throws DebugException {
super((XDebugTarget) frame.getDebugTarget());
- fFrame = frame;
- init(property);
-
- }
-
- private void init(Node property) {
- fFullName = PHPDebugUtils.getAttributeValue(property, "fullname");
- fName = PHPDebugUtils.getAttributeValue(property, "name");
- fEncoding = PHPDebugUtils.getAttributeValue(property, "encoding");
- if (PHPDebugUtils.getAttributeValue(property, "numchildren").equals(""))
- fNumChildren = 0;
- else
- fNumChildren = Integer.parseInt(PHPDebugUtils.getAttributeValue(
- property, "numchildren"));
-
- String typeName = PHPDebugUtils.getAttributeValue(property, "type");
-
- // if (typeName.equals("uninitialized") )
- // fValue= new XDebugValue(this,property,typeName);
- if (typeName.equals("int"))
- fValue = new XDebugIntValue(this, property, typeName);
- else if (typeName.equals("float"))
- fValue = new XDebugFloatValue(this, property, typeName);
- else if (typeName.equals("bool"))
- fValue = new XDebugBooleanValue(this, property, typeName);
- else if (typeName.equals("string"))
- fValue = new XDebugStringValue(this, property, typeName);
- else if (typeName.equals("array"))
- fValue = new XDebugArrayValue(this, property, typeName);
- else if (typeName.equals("hash"))
- fValue = new XDebugArrayValue(this, property, typeName);
- else if (typeName.equals("object"))
- fValue = new XDebugArrayValue(this, property, typeName);
- else
- fValue = new XDebugValue(this, property, typeName);
-
- // else if (typeName.equals("float") )
- // fTypeName= VARTYPE_FLOAT;
- // else if (typeName.equals("string") )
- // fTypeName= VARTYPE_STRING;
- // else if (typeName.equals("hash") )
- // fTypeName= VARTYPE_HASH;
- // else if (typeName.equals("array") )
- // fTypeName= VARTYPE_ARRAY;
- // else if (typeName.equals("object") )
- // fTypeName= VARTYPE_OBJECT;
-
- // fTypeName=type;
- //
- // fValue= new XDebugValue(this,property);
- }
- /*
- * (non-Javadoc)
- *
+ this.fParent = parent;
+
+ if (frame != null ) {
+ fFrame = frame;
+ }
+
+ String name = PHPDebugUtils.getAttributeValue (property, "name"); // Get the name of the variable (XDebug submits the name without the '$' prefix)
+
+ if (fParent == null) {
+ if (!name.isEmpty ()) { // If we have a name
+ if (name.charAt(0) == '$') { // If variable name has already a '$' in front (newer version of XDebug)
+ fName = name; // take the name as is
+ }
+ else {
+ fName = "$" + name; // if not, prepend the variable 'short' name with the php variable prefix '$'
+ }
+ }
+ }
+ else {
+ if (fParent.isArray ()) {
+ fName = "['" + name + "']";
+ }
+ else if (fParent.isObject ()) {
+ fName = name;
+ }
+ else {
+ fName = name; // If this is the root variable don't prepend prefix '$'
+ }
+ }
+
+ fNameFull = PHPDebugUtils.getAttributeValue(property,"fullname"); // The fullname has the '$' prepended, but it is the fully qualified name
+ // e.g. $myvar->child->a_variable. The fullname would be suitable to take for
+ // the setting a watch expression
+
+ if ("".equals(fName)) {
+ fName = PHPDebugUtils.getAttributeValue (property, "address");
+ }
+
+ fFacet = PHPDebugUtils.getAttributeValue (property, "facet");
+ fTypeName = PHPDebugUtils.getAttributeValue (property, "type");
+
+ if (fTypeName.equals ("int")) {
+ fValue = new XDebugIntValue (frame, property);
+ }
+ else if (fTypeName.equals ("float")) {
+ fValue = new XDebugFloatValue (frame, property);
+ }
+ else if (fTypeName.equals ("bool")) {
+ fValue = new XDebugBooleanValue (frame, property);
+ }
+ else if (fTypeName.equals ("string")) {
+ fValue = new XDebugStringValue (frame, property);
+ }
+ else if (fTypeName.equals ("array")) {
+ fValue = new XDebugArrayValue (frame, property, this);
+ }
+ else if (fTypeName.equals ("object")) {
+ fValue = new XDebugObjectValue (frame, property, this);
+ }
+ else if (fTypeName.equals ("resource")) {
+ fValue = new XDebugResourceValue (frame, property);
+ }
+ else {
+ fValue = new XDebugValue (frame, property);
+ }
+ }
+
+ public boolean isArray () {
+ return fTypeName.equals ("array");
+ }
+
+ public boolean isObject () {
+ return fTypeName.equals ("object");
+ }
+
+ /**
+ * @see org.eclipse.core.runtime.IAdaptable#getAdapter(Class)
+ */
+ public Object getAdapter(Class adapter) {
+ if (adapter.getName ().equals ("org.eclipse.debug.ui.actions.IWatchExpressionFactoryAdapter")) {
+ return new XDebugWatchExpressionFactoryAdapter ();
+ }
+
+ return Platform.getAdapterManager().getAdapter (this, adapter);
+ }
+
+ /* (non-Javadoc)
* @see org.eclipse.debug.core.model.IVariable#getValue()
*/
- public IValue getValue() throws DebugException {
+ public IValue getValue() {
return fValue;
- // return ((XDebugTarget)getDebugTarget()).getVariableValue(this);
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.eclipse.debug.core.model.IVariable#getName()
*/
- public String getName() throws DebugException {
- if (fFullName.endsWith("]"))
- return fFullName.substring(fFullName.lastIndexOf('['));
- else
- return fName;
+ public String getName () {
+ return fName;
}
/*
- * (non-Javadoc)
- *
+ * @return The fully qualified name of the variable
+ */
+ public String getNameFull () {
+ return fNameFull;
+ }
+
+ /* (non-Javadoc)
* @see org.eclipse.debug.core.model.IVariable#getReferenceTypeName()
*/
public String getReferenceTypeName() throws DebugException {
return fValue.getReferenceTypeName();
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.eclipse.debug.core.model.IVariable#hasValueChanged()
*/
public boolean hasValueChanged() throws DebugException {
- // TODO Auto-generated method stub
- return false;
+ return fValue.hasChanged();
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.eclipse.debug.core.model.IValueModification#setValue(java.lang.String)
*/
public void setValue(String expression) throws DebugException {
- if (fValue.setValue(expression))
- fireEvent(new DebugEvent(this, DebugEvent.CHANGE,
- DebugEvent.CONTENT));
+ if (fFrame.setVariableValue(this, expression)) {
+ fValue.setValue(expression);
+ }
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.eclipse.debug.core.model.IValueModification#setValue(org.eclipse.debug.core.model.IValue)
*/
public void setValue(IValue value) throws DebugException {
+ fValue = (XDebugAbstractValue) value;
}
- /*
- * (non-Javadoc)
- *
+ /**
+ *
+ * @param changed This method is called after a suspend when the list of
+ * variables is updated, to mark that this variable has a changed
+ * value. The variable view will show this variable in
+ * a different color.
+ */
+ public void setValueChanged(boolean changed) {
+ fValue.setChanged(changed);
+ }
+
+ /* (non-Javadoc)
* @see org.eclipse.debug.core.model.IValueModification#supportsValueModification()
*/
public boolean supportsValueModification() {
return fValue.supportsValueModification();
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.eclipse.debug.core.model.IValueModification#verifyValue(java.lang.String)
*/
public boolean verifyValue(String expression) throws DebugException {
- return fValue.verifyValue(expression);
+ /*return true; */return fValue.verifyValue(expression);
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.eclipse.debug.core.model.IValueModification#verifyValue(org.eclipse.debug.core.model.IValue)
*/
public boolean verifyValue(IValue value) throws DebugException {
return false;
}
- /**
- * Returns the stack frame owning this variable.
- *
- * @return the stack frame owning this variable
- */
- protected XDebugStackFrame getStackFrame() {
- return fFrame;
- }
-
- // public int getType() {
- // return fType;
- // }
-
public String getValueString() throws DebugException {
return fValue.getValueString();
}
- public boolean hasChildren() {
- return (fNumChildren > 0);
- }
-
- public boolean isArray() {
- return (fValue.isArray());
- }
-
- public String getEncoding() {
- return fEncoding;
- }
-
- public void setEncoding(String encoding) {
- fEncoding = encoding;
+ public String getVisibility() {
+ return fFacet;
}
- public String toString() {
- return fValue.toString();
+ /**
+ *
+ */
+ public XDebugVariable getParent() {
+ return fParent;
}
- public String getFullName() {
- return fFullName;
+ /**
+ *
+ */
+ public void setParent(XDebugVariable parent) {
+ this.fParent = parent;
}
-
}