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 if (!name.isEmpty ()) { // If we have a name
53 if (name.charAt(0) == '$') { // If variable name has already a '$' in front (newer version of XDebug)
54 fName = name; // take the name as is
57 fName = "$" + name; // if not, prepend the variable 'short' name with the php variable prefix '$'
62 if (fParent.isArray ()) {
63 fName = "['" + name + "']";
65 else if (fParent.isObject ()) {
69 fName = name; // If this is the root variable don't prepend prefix '$'
73 fNameFull = PHPDebugUtils.getAttributeValue(property,"fullname"); // The fullname has the '$' prepended, but it is the fully qualified name
74 // e.g. $myvar->child->a_variable. The fullname would be suitable to take for
75 // the setting a watch expression
77 if ("".equals(fName)) {
78 fName = PHPDebugUtils.getAttributeValue (property, "address");
81 fFacet = PHPDebugUtils.getAttributeValue (property, "facet");
82 fTypeName = PHPDebugUtils.getAttributeValue (property, "type");
84 if (fTypeName.equals ("int")) {
85 fValue = new XDebugIntValue (frame, property);
87 else if (fTypeName.equals ("float")) {
88 fValue = new XDebugFloatValue (frame, property);
90 else if (fTypeName.equals ("bool")) {
91 fValue = new XDebugBooleanValue (frame, property);
93 else if (fTypeName.equals ("string")) {
94 fValue = new XDebugStringValue (frame, property);
96 else if (fTypeName.equals ("array")) {
97 fValue = new XDebugArrayValue (frame, property, this);
99 else if (fTypeName.equals ("object")) {
100 fValue = new XDebugObjectValue (frame, property, this);
102 else if (fTypeName.equals ("resource")) {
103 fValue = new XDebugResourceValue (frame, property);
106 fValue = new XDebugValue (frame, property);
110 public boolean isArray () {
111 return fTypeName.equals ("array");
114 public boolean isObject () {
115 return fTypeName.equals ("object");
119 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(Class)
121 public Object getAdapter(Class adapter) {
122 if (adapter.getName ().equals ("org.eclipse.debug.ui.actions.IWatchExpressionFactoryAdapter")) {
123 return new XDebugWatchExpressionFactoryAdapter ();
126 return Platform.getAdapterManager().getAdapter (this, adapter);
130 * @see org.eclipse.debug.core.model.IVariable#getValue()
132 public IValue getValue() {
137 * @see org.eclipse.debug.core.model.IVariable#getName()
139 public String getName () {
144 * @return The fully qualified name of the variable
146 public String getNameFull () {
151 * @see org.eclipse.debug.core.model.IVariable#getReferenceTypeName()
153 public String getReferenceTypeName() throws DebugException {
154 return fValue.getReferenceTypeName();
158 * @see org.eclipse.debug.core.model.IVariable#hasValueChanged()
160 public boolean hasValueChanged() throws DebugException {
161 return fValue.hasChanged();
165 * @see org.eclipse.debug.core.model.IValueModification#setValue(java.lang.String)
167 public void setValue(String expression) throws DebugException {
168 if (fFrame.setVariableValue(this, expression)) {
169 fValue.setValue(expression);
174 * @see org.eclipse.debug.core.model.IValueModification#setValue(org.eclipse.debug.core.model.IValue)
176 public void setValue(IValue value) throws DebugException {
177 fValue = (XDebugAbstractValue) value;
182 * @param changed This method is called after a suspend when the list of
183 * variables is updated, to mark that this variable has a changed
184 * value. The variable view will show this variable in
187 public void setValueChanged(boolean changed) {
188 fValue.setChanged(changed);
192 * @see org.eclipse.debug.core.model.IValueModification#supportsValueModification()
194 public boolean supportsValueModification() {
195 return fValue.supportsValueModification();
199 * @see org.eclipse.debug.core.model.IValueModification#verifyValue(java.lang.String)
201 public boolean verifyValue(String expression) throws DebugException {
202 /*return true; */return fValue.verifyValue(expression);
206 * @see org.eclipse.debug.core.model.IValueModification#verifyValue(org.eclipse.debug.core.model.IValue)
208 public boolean verifyValue(IValue value) throws DebugException {
212 public String getValueString() throws DebugException {
213 return fValue.getValueString();
216 public String getVisibility() {
223 public XDebugVariable getParent() {
230 public void setParent(XDebugVariable parent) {
231 this.fParent = parent;