1) Added parameter 'parent' to XDebugVariable, so we can determine whether a variable...
[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.debug.core.DebugException;
12 import org.eclipse.debug.core.model.IValue;
13 import org.eclipse.debug.core.model.IVariable;
14 import org.w3c.dom.Node;
15
16 /**
17  * @author Axel
18  *
19  * TODO To change the template for this generated type comment go to
20  * Window - Preferences - Java - Code Style - Code Templates
21  */
22 public class XDebugVariable extends XDebugElement implements IVariable {
23         private String                          fName;
24         private String              fNameFull;
25         private XDebugStackFrame        fFrame;
26         private XDebugAbstractValue fValue;
27         private String                          fFacet;
28         private XDebugVariable          fParent;                // The parent variable (a back link)
29
30         
31         /**
32          * Constructs a variable contained in the given stack frame
33          * with the given name.
34          * 
35          * @param frame owning stack frame
36          * @param name variable name
37          */
38         public XDebugVariable(XDebugStackFrame frame, Node property, XDebugVariable parent) throws DebugException {
39                 super((XDebugTarget) frame.getDebugTarget());
40                 
41                 this.fParent = parent;
42                 
43                 if (frame != null ) {
44                         fFrame = frame;
45                 }
46
47                 if (parent == null) {
48                     fName = "$" + PHPDebugUtils.getAttributeValue(property,"name"); // Prepend the variable 'short' name with the php variable prefix '$'
49                 }
50                 else {
51                     fName = PHPDebugUtils.getAttributeValue(property,"name");       // If this is the root variable don't prepend prefix '$'
52                 }
53                   
54                 fNameFull = PHPDebugUtils.getAttributeValue(property,"fullname");   // The fullname has the '$' prepended, but it is the fully qualified name
55                                                                                     // e.g. $myvar->child->a_variable. The fullname would be suitable to take for
56                                                                                     // the setting a watch expression
57                 
58                 if ("".equals(fName)) {
59                         fName = PHPDebugUtils.getAttributeValue(property,"address");
60                 }
61                 
62                 fFacet = PHPDebugUtils.getAttributeValue(property, "facet");
63
64                 String typeName = PHPDebugUtils.getAttributeValue(property, "type");
65
66                 if (typeName.equals("int") ) 
67                         fValue = new XDebugIntValue(frame, property);
68                 else if (typeName.equals("float") ) 
69                         fValue = new XDebugFloatValue(frame, property);
70                 else if (typeName.equals("bool") ) 
71                         fValue = new XDebugBooleanValue(frame, property);
72                 else if (typeName.equals("string") )
73                         fValue = new XDebugStringValue(frame, property);
74                 else if (typeName.equals("array") )
75                         fValue = new XDebugArrayValue(frame, property, this);
76                 else if (typeName.equals("object") )
77                         fValue = new XDebugObjectValue(frame, property, this);
78                 else if (typeName.equals("resource") )
79                         fValue = new XDebugResourceValue(frame, property);
80                 else
81                         fValue = new XDebugValue(frame, property);
82         }
83                 
84         /* (non-Javadoc)
85          * @see org.eclipse.debug.core.model.IVariable#getValue()
86          */
87         public IValue getValue() {
88                 return fValue;
89         }
90         
91         /* (non-Javadoc)
92          * @see org.eclipse.debug.core.model.IVariable#getName()
93          */
94         public String getName() {
95                 return fName;
96         }
97         
98         /*
99          * @return The fully qualified name of the variable
100          */
101     public String getNameFull () {
102         return fNameFull;
103     }
104
105         /* (non-Javadoc)
106          * @see org.eclipse.debug.core.model.IVariable#getReferenceTypeName()
107          */
108         public String getReferenceTypeName() throws DebugException {
109                 return fValue.getReferenceTypeName();
110         }
111         
112         /* (non-Javadoc)
113          * @see org.eclipse.debug.core.model.IVariable#hasValueChanged()
114          */
115         public boolean hasValueChanged() throws DebugException {
116                 return fValue.hasChanged();
117         }
118         
119         /* (non-Javadoc)
120          * @see org.eclipse.debug.core.model.IValueModification#setValue(java.lang.String)
121          */
122         public void setValue(String expression) throws DebugException {
123                 if (fFrame.setVariableValue(this, expression)) {
124                         fValue.setValue(expression);
125                 }
126         }
127         
128         /* (non-Javadoc)
129          * @see org.eclipse.debug.core.model.IValueModification#setValue(org.eclipse.debug.core.model.IValue)
130          */
131         public void setValue(IValue value) throws DebugException {
132         }
133
134         /**
135          *
136          * @param changed This method is called after a suspend when the list of
137          *                variables is updated, to mark that this variable has a changed
138          *                value. The variable view will show this variable in
139          *                a different color.
140          */
141         public void setValueChanged(boolean changed) {
142                 fValue.setChanged(changed);
143         }
144
145         /* (non-Javadoc)
146          * @see org.eclipse.debug.core.model.IValueModification#supportsValueModification()
147          */
148         public boolean supportsValueModification() {
149                 return fValue.supportsValueModification();
150         }
151
152         /* (non-Javadoc)
153          * @see org.eclipse.debug.core.model.IValueModification#verifyValue(java.lang.String)
154          */
155         public boolean verifyValue(String expression) throws DebugException {
156                 /*return true; */return fValue.verifyValue(expression);
157         }
158
159         /* (non-Javadoc)
160          * @see org.eclipse.debug.core.model.IValueModification#verifyValue(org.eclipse.debug.core.model.IValue)
161          */
162         public boolean verifyValue(IValue value) throws DebugException {
163                 return false;
164         }
165         
166         public String getValueString() throws DebugException {
167                 return fValue.getValueString();
168         }
169         
170         public String getVisibility() {
171                 return fFacet;
172         }
173         
174         /**
175          *
176          */
177         public XDebugVariable getParent() {
178                 return fParent;
179         }
180
181         /**
182          *
183          */
184         public void setParent(XDebugVariable parent) {
185                 this.fParent = parent;
186         }
187 }