2 * Created on 23.11.2004
4 * TODO To change the template for this generated file go to
5 * Window - Preferences - Java - Code Style - Code Templates
7 package net.sourceforge.phpeclipse.xdebug.php.model;
9 import net.sourceforge.phpeclipse.xdebug.core.PHPDebugUtils;
11 import org.eclipse.core.runtime.Platform;
12 import org.eclipse.debug.core.DebugException;
13 import org.eclipse.debug.core.model.IValue;
14 import org.eclipse.debug.core.model.IVariable;
15 import org.w3c.dom.Node;
20 * TODO To change the template for this generated type comment go to
21 * Window - Preferences - Java - Code Style - Code Templates
23 public class XDebugVariable extends XDebugElement implements IVariable {
25 private String fNameFull;
26 private XDebugStackFrame fFrame;
27 private XDebugAbstractValue fValue;
28 private String fFacet;
29 private XDebugVariable fParent; // The parent variable (a back link)
30 private String fTypeName;
34 * Constructs a variable contained in the given stack frame
35 * with the given name.
37 * @param frame owning stack frame
38 * @param name variable name
40 public XDebugVariable(XDebugStackFrame frame, Node property, XDebugVariable parent) throws DebugException {
41 super((XDebugTarget) frame.getDebugTarget());
43 this.fParent = parent;
49 String name = PHPDebugUtils.getAttributeValue (property, "name"); // Get the name of the variable (XDebug submits the name without the '$' prefix)
51 if (fParent == null) {
52 fName = "$" + name; // Prepend the variable 'short' name with the php variable prefix '$'
55 if (fParent.isArray ()) {
56 fName = "['" + name + "']";
58 else if (fParent.isObject ()) {
62 fName = name; // If this is the root variable don't prepend prefix '$'
66 fNameFull = PHPDebugUtils.getAttributeValue(property,"fullname"); // The fullname has the '$' prepended, but it is the fully qualified name
67 // e.g. $myvar->child->a_variable. The fullname would be suitable to take for
68 // the setting a watch expression
70 if ("".equals(fName)) {
71 fName = PHPDebugUtils.getAttributeValue (property, "address");
74 fFacet = PHPDebugUtils.getAttributeValue (property, "facet");
75 fTypeName = PHPDebugUtils.getAttributeValue (property, "type");
77 if (fTypeName.equals ("int")) {
78 fValue = new XDebugIntValue (frame, property);
80 else if (fTypeName.equals ("float")) {
81 fValue = new XDebugFloatValue (frame, property);
83 else if (fTypeName.equals ("bool")) {
84 fValue = new XDebugBooleanValue (frame, property);
86 else if (fTypeName.equals ("string")) {
87 fValue = new XDebugStringValue (frame, property);
89 else if (fTypeName.equals ("array")) {
90 fValue = new XDebugArrayValue (frame, property, this);
92 else if (fTypeName.equals ("object")) {
93 fValue = new XDebugObjectValue (frame, property, this);
95 else if (fTypeName.equals ("resource")) {
96 fValue = new XDebugResourceValue (frame, property);
99 fValue = new XDebugValue (frame, property);
103 public boolean isArray () {
104 return fTypeName.equals ("array");
107 public boolean isObject () {
108 return fTypeName.equals ("object");
112 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(Class)
114 public Object getAdapter(Class adapter) {
115 if (adapter.getName ().equals ("org.eclipse.debug.ui.actions.IWatchExpressionFactoryAdapter")) {
116 return new XDebugWatchExpressionFactoryAdapter ();
119 return Platform.getAdapterManager().getAdapter (this, adapter);
123 * @see org.eclipse.debug.core.model.IVariable#getValue()
125 public IValue getValue() {
130 * @see org.eclipse.debug.core.model.IVariable#getName()
132 public String getName () {
137 * @return The fully qualified name of the variable
139 public String getNameFull () {
144 * @see org.eclipse.debug.core.model.IVariable#getReferenceTypeName()
146 public String getReferenceTypeName() throws DebugException {
147 return fValue.getReferenceTypeName();
151 * @see org.eclipse.debug.core.model.IVariable#hasValueChanged()
153 public boolean hasValueChanged() throws DebugException {
154 return fValue.hasChanged();
158 * @see org.eclipse.debug.core.model.IValueModification#setValue(java.lang.String)
160 public void setValue(String expression) throws DebugException {
161 if (fFrame.setVariableValue(this, expression)) {
162 fValue.setValue(expression);
167 * @see org.eclipse.debug.core.model.IValueModification#setValue(org.eclipse.debug.core.model.IValue)
169 public void setValue(IValue value) throws DebugException {
170 fValue = (XDebugAbstractValue) value;
175 * @param changed This method is called after a suspend when the list of
176 * variables is updated, to mark that this variable has a changed
177 * value. The variable view will show this variable in
180 public void setValueChanged(boolean changed) {
181 fValue.setChanged(changed);
185 * @see org.eclipse.debug.core.model.IValueModification#supportsValueModification()
187 public boolean supportsValueModification() {
188 return fValue.supportsValueModification();
192 * @see org.eclipse.debug.core.model.IValueModification#verifyValue(java.lang.String)
194 public boolean verifyValue(String expression) throws DebugException {
195 /*return true; */return fValue.verifyValue(expression);
199 * @see org.eclipse.debug.core.model.IValueModification#verifyValue(org.eclipse.debug.core.model.IValue)
201 public boolean verifyValue(IValue value) throws DebugException {
205 public String getValueString() throws DebugException {
206 return fValue.getValueString();
209 public String getVisibility() {
216 public XDebugVariable getParent() {
223 public void setParent(XDebugVariable parent) {
224 this.fParent = parent;