1) Setting a new value did not work because the short name was send to XDebug instead...
[phpeclipse.git] / net.sourceforge.phpeclipse.xdebug.core / src / net / sourceforge / phpeclipse / xdebug / php / model / XDebugVariable.java
1 /*
2  * Created on 23.11.2004
3  *
4  * TODO To change the template for this generated file go to
5  * Window - Preferences - Java - Code Style - Code Templates
6  */
7 package net.sourceforge.phpeclipse.xdebug.php.model;
8
9 import net.sourceforge.phpeclipse.xdebug.core.PHPDebugUtils;
10
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;
16
17 /**
18  * @author Axel
19  *
20  * TODO To change the template for this generated type comment go to
21  * Window - Preferences - Java - Code Style - Code Templates
22  */
23 public class XDebugVariable extends XDebugElement implements IVariable {
24         private String                          fName;
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;
31
32
33         /**
34          * Constructs a variable contained in the given stack frame
35          * with the given name.
36          *
37          * @param frame owning stack frame
38          * @param name variable name
39          */
40         public XDebugVariable(XDebugStackFrame frame, Node property, XDebugVariable parent) throws DebugException {
41                 super((XDebugTarget) frame.getDebugTarget());
42
43                 this.fParent = parent;
44
45                 if (frame != null ) {
46                         fFrame = frame;
47                 }
48
49                 String name = PHPDebugUtils.getAttributeValue (property, "name"); // Get the name of the variable (XDebug submits the name without the '$' prefix)
50
51                 if (fParent == null) {
52                     fName = "$" + name;                                           // Prepend the variable 'short' name with the php variable prefix '$'
53                 }
54                 else {
55                     if (fParent.isArray ()) {
56                         fName = "['" + name + "']";
57                     }
58                     else if (fParent.isObject ()) {
59                         fName = name;
60                     }
61                     else {
62                         fName = name;                                             // If this is the root variable don't prepend prefix '$'
63                     }
64                 }
65
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
69
70                 if ("".equals(fName)) {
71                         fName = PHPDebugUtils.getAttributeValue (property, "address");
72                 }
73
74                 fFacet    = PHPDebugUtils.getAttributeValue (property, "facet");
75                 fTypeName = PHPDebugUtils.getAttributeValue (property, "type");
76
77                 if (fTypeName.equals ("int")) {
78                         fValue = new XDebugIntValue (frame, property);
79                 }
80                 else if (fTypeName.equals ("float")) {
81                         fValue = new XDebugFloatValue (frame, property);
82                 }
83                 else if (fTypeName.equals ("bool")) {
84                         fValue = new XDebugBooleanValue (frame, property);
85                 }
86                 else if (fTypeName.equals ("string")) {
87                         fValue = new XDebugStringValue (frame, property);
88                 }
89                 else if (fTypeName.equals ("array")) {
90                         fValue = new XDebugArrayValue (frame, property, this);
91                 }
92                 else if (fTypeName.equals ("object")) {
93                         fValue = new XDebugObjectValue (frame, property, this);
94                 }
95                 else if (fTypeName.equals ("resource")) {
96                         fValue = new XDebugResourceValue (frame, property);
97                 }
98                 else {
99                         fValue = new XDebugValue (frame, property);
100                 }
101         }
102
103         public boolean isArray () {
104             return fTypeName.equals ("array");
105         }
106
107     public boolean isObject () {
108         return fTypeName.equals ("object");
109     }
110
111     /**
112      * @see org.eclipse.core.runtime.IAdaptable#getAdapter(Class)
113      */
114     public Object getAdapter(Class adapter) {
115         if (adapter.getName ().equals ("org.eclipse.debug.ui.actions.IWatchExpressionFactoryAdapter")) {
116             return new XDebugWatchExpressionFactoryAdapter ();
117         }
118         
119         return Platform.getAdapterManager().getAdapter (this, adapter);     
120     }
121
122         /* (non-Javadoc)
123          * @see org.eclipse.debug.core.model.IVariable#getValue()
124          */
125         public IValue getValue() {
126                 return fValue;
127         }
128
129         /* (non-Javadoc)
130          * @see org.eclipse.debug.core.model.IVariable#getName()
131          */
132         public String getName () {
133                 return fName;
134         }
135
136         /*
137          * @return The fully qualified name of the variable
138          */
139     public String getNameFull () {
140         return fNameFull;
141     }
142
143         /* (non-Javadoc)
144          * @see org.eclipse.debug.core.model.IVariable#getReferenceTypeName()
145          */
146         public String getReferenceTypeName() throws DebugException {
147                 return fValue.getReferenceTypeName();
148         }
149
150         /* (non-Javadoc)
151          * @see org.eclipse.debug.core.model.IVariable#hasValueChanged()
152          */
153         public boolean hasValueChanged() throws DebugException {
154                 return fValue.hasChanged();
155         }
156
157         /* (non-Javadoc)
158          * @see org.eclipse.debug.core.model.IValueModification#setValue(java.lang.String)
159          */
160         public void setValue(String expression) throws DebugException {
161                 if (fFrame.setVariableValue(this, expression)) {
162                         fValue.setValue(expression);
163                 }
164         }
165
166         /* (non-Javadoc)
167          * @see org.eclipse.debug.core.model.IValueModification#setValue(org.eclipse.debug.core.model.IValue)
168          */
169         public void setValue(IValue value) throws DebugException {
170                 fValue = (XDebugAbstractValue) value;
171         }
172
173         /**
174          *
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
178          *                a different color.
179          */
180         public void setValueChanged(boolean changed) {
181                 fValue.setChanged(changed);
182         }
183
184         /* (non-Javadoc)
185          * @see org.eclipse.debug.core.model.IValueModification#supportsValueModification()
186          */
187         public boolean supportsValueModification() {
188                 return fValue.supportsValueModification();
189         }
190
191         /* (non-Javadoc)
192          * @see org.eclipse.debug.core.model.IValueModification#verifyValue(java.lang.String)
193          */
194         public boolean verifyValue(String expression) throws DebugException {
195                 /*return true; */return fValue.verifyValue(expression);
196         }
197
198         /* (non-Javadoc)
199          * @see org.eclipse.debug.core.model.IValueModification#verifyValue(org.eclipse.debug.core.model.IValue)
200          */
201         public boolean verifyValue(IValue value) throws DebugException {
202                 return false;
203         }
204
205         public String getValueString() throws DebugException {
206                 return fValue.getValueString();
207         }
208
209         public String getVisibility() {
210                 return fFacet;
211         }
212
213         /**
214          *
215          */
216         public XDebugVariable getParent() {
217                 return fParent;
218         }
219
220         /**
221          *
222          */
223         public void setParent(XDebugVariable parent) {
224                 this.fParent = parent;
225         }
226 }