1) Added missing strings for italic, underline and strike through.
[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                         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
55                                 }
56                                 else {
57                                         fName = "$" + name;                                   // if not, prepend the variable 'short' name with the php variable prefix '$'
58                                 }
59                         }
60                 }
61                 else {
62                     if (fParent.isArray ()) {
63                         fName = "['" + name + "']";
64                     }
65                     else if (fParent.isObject ()) {
66                         fName = name;
67                     }
68                     else {
69                         fName = name;                                             // If this is the root variable don't prepend prefix '$'
70                     }
71                 }
72
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
76
77                 if ("".equals(fName)) {
78                         fName = PHPDebugUtils.getAttributeValue (property, "address");
79                 }
80
81                 fFacet    = PHPDebugUtils.getAttributeValue (property, "facet");
82                 fTypeName = PHPDebugUtils.getAttributeValue (property, "type");
83
84                 if (fTypeName.equals ("int")) {
85                         fValue = new XDebugIntValue (frame, property);
86                 }
87                 else if (fTypeName.equals ("float")) {
88                         fValue = new XDebugFloatValue (frame, property);
89                 }
90                 else if (fTypeName.equals ("bool")) {
91                         fValue = new XDebugBooleanValue (frame, property);
92                 }
93                 else if (fTypeName.equals ("string")) {
94                         fValue = new XDebugStringValue (frame, property);
95                 }
96                 else if (fTypeName.equals ("array")) {
97                         fValue = new XDebugArrayValue (frame, property, this);
98                 }
99                 else if (fTypeName.equals ("object")) {
100                         fValue = new XDebugObjectValue (frame, property, this);
101                 }
102                 else if (fTypeName.equals ("resource")) {
103                         fValue = new XDebugResourceValue (frame, property);
104                 }
105                 else {
106                         fValue = new XDebugValue (frame, property);
107                 }
108         }
109
110         public boolean isArray () {
111             return fTypeName.equals ("array");
112         }
113
114     public boolean isObject () {
115         return fTypeName.equals ("object");
116     }
117
118     /**
119      * @see org.eclipse.core.runtime.IAdaptable#getAdapter(Class)
120      */
121     public Object getAdapter(Class adapter) {
122         if (adapter.getName ().equals ("org.eclipse.debug.ui.actions.IWatchExpressionFactoryAdapter")) {
123             return new XDebugWatchExpressionFactoryAdapter ();
124         }
125         
126         return Platform.getAdapterManager().getAdapter (this, adapter);     
127     }
128
129         /* (non-Javadoc)
130          * @see org.eclipse.debug.core.model.IVariable#getValue()
131          */
132         public IValue getValue() {
133                 return fValue;
134         }
135
136         /* (non-Javadoc)
137          * @see org.eclipse.debug.core.model.IVariable#getName()
138          */
139         public String getName () {
140                 return fName;
141         }
142
143         /*
144          * @return The fully qualified name of the variable
145          */
146     public String getNameFull () {
147         return fNameFull;
148     }
149
150         /* (non-Javadoc)
151          * @see org.eclipse.debug.core.model.IVariable#getReferenceTypeName()
152          */
153         public String getReferenceTypeName() throws DebugException {
154                 return fValue.getReferenceTypeName();
155         }
156
157         /* (non-Javadoc)
158          * @see org.eclipse.debug.core.model.IVariable#hasValueChanged()
159          */
160         public boolean hasValueChanged() throws DebugException {
161                 return fValue.hasChanged();
162         }
163
164         /* (non-Javadoc)
165          * @see org.eclipse.debug.core.model.IValueModification#setValue(java.lang.String)
166          */
167         public void setValue(String expression) throws DebugException {
168                 if (fFrame.setVariableValue(this, expression)) {
169                         fValue.setValue(expression);
170                 }
171         }
172
173         /* (non-Javadoc)
174          * @see org.eclipse.debug.core.model.IValueModification#setValue(org.eclipse.debug.core.model.IValue)
175          */
176         public void setValue(IValue value) throws DebugException {
177                 fValue = (XDebugAbstractValue) value;
178         }
179
180         /**
181          *
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
185          *                a different color.
186          */
187         public void setValueChanged(boolean changed) {
188                 fValue.setChanged(changed);
189         }
190
191         /* (non-Javadoc)
192          * @see org.eclipse.debug.core.model.IValueModification#supportsValueModification()
193          */
194         public boolean supportsValueModification() {
195                 return fValue.supportsValueModification();
196         }
197
198         /* (non-Javadoc)
199          * @see org.eclipse.debug.core.model.IValueModification#verifyValue(java.lang.String)
200          */
201         public boolean verifyValue(String expression) throws DebugException {
202                 /*return true; */return fValue.verifyValue(expression);
203         }
204
205         /* (non-Javadoc)
206          * @see org.eclipse.debug.core.model.IValueModification#verifyValue(org.eclipse.debug.core.model.IValue)
207          */
208         public boolean verifyValue(IValue value) throws DebugException {
209                 return false;
210         }
211
212         public String getValueString() throws DebugException {
213                 return fValue.getValueString();
214         }
215
216         public String getVisibility() {
217                 return fFacet;
218         }
219
220         /**
221          *
222          */
223         public XDebugVariable getParent() {
224                 return fParent;
225         }
226
227         /**
228          *
229          */
230         public void setParent(XDebugVariable parent) {
231                 this.fParent = parent;
232         }
233 }