Initial implementation of the new Debug Plugin
[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
10 import net.sourceforge.phpeclipse.xdebug.core.PHPDebugUtils;
11
12 import org.eclipse.debug.core.DebugEvent;
13 import org.eclipse.debug.core.DebugException;
14 import org.eclipse.debug.core.model.IValue;
15 import org.eclipse.debug.core.model.IVariable;
16 import org.w3c.dom.Node;
17
18 /**
19  * @author Axel
20  *
21  * TODO To change the template for this generated type comment go to
22  * Window - Preferences - Java - Code Style - Code Templates
23  */
24 public class XDebugVariable  extends XDebugElement implements IVariable {
25         
26         public static final int VARTYPE_UNKNOWN = -1;
27         public static final int VARTYPE_UNINITIALIZED = 0;
28         public static final int VARTYPE_STRING = 1;
29         public static final int VARTYPE_INT = 2;
30         public static final int VARTYPE_FLOAT = 3;
31         public static final int VARTYPE_ARRAY = 8;
32         public static final int VARTYPE_HASH = 9;
33         public static final int VARTYPE_OBJECT = 10;
34
35         
36         // name & stack frmae
37         private String fName;
38         private XDebugStackFrame fFrame;
39         private String fFullName;
40 //      private String fTypeName;
41 //      private int fType;
42         private XDebugAbstractValue fValue;
43         private String fEncoding;
44         private int fNumChildren;
45 //      private Node fVariableNode;
46         
47         /**
48          * Constructs a variable contained in the given stack frame
49          * with the given name.
50          * 
51          * @param frame owning stack frame
52          * @param name variable name
53          */
54         public XDebugVariable(XDebugStackFrame frame, Node property) {
55                 super((XDebugTarget) frame.getDebugTarget());
56                 fFrame = frame;
57                 init(property);
58
59         }
60         
61         private void  init(Node property) {
62                 fFullName=PHPDebugUtils.getAttributeValue(property,"fullname");
63                 fName=PHPDebugUtils.getAttributeValue(property,"name");
64                 fEncoding=PHPDebugUtils.getAttributeValue(property,"encoding");
65                 if (PHPDebugUtils.getAttributeValue(property,"numchildren").equals(""))
66                         fNumChildren = 0;
67                 else
68                         fNumChildren=Integer.parseInt(PHPDebugUtils.getAttributeValue(property,"numchildren"));
69
70                 String typeName=PHPDebugUtils.getAttributeValue(property,"type");
71
72 //              if (typeName.equals("uninitialized") )
73 //                      fValue= new XDebugValue(this,property,typeName);
74                 if (typeName.equals("int") ) 
75                         fValue= new XDebugIntValue(this,property,typeName);
76                 else if (typeName.equals("float") ) 
77                         fValue= new XDebugFloatValue(this,property,typeName);
78                 else if (typeName.equals("bool") ) 
79                         fValue= new XDebugBooleanValue(this,property,typeName);
80                 else if (typeName.equals("string") )
81                         fValue= new XDebugStringValue(this,property,typeName);
82                 else if (typeName.equals("array") )
83                         fValue= new XDebugArrayValue(this,property,typeName);
84                 else if (typeName.equals("hash") )
85                         fValue= new XDebugArrayValue(this,property,typeName);
86                 else if (typeName.equals("object") )
87                         fValue= new XDebugArrayValue(this,property,typeName);
88                 else
89                         fValue= new XDebugValue(this,property,typeName);
90
91 //              else if (typeName.equals("float") )
92 //                      fTypeName= VARTYPE_FLOAT;
93 //              else if (typeName.equals("string") )
94 //                      fTypeName= VARTYPE_STRING;
95 //              else if (typeName.equals("hash") )
96 //                      fTypeName= VARTYPE_HASH;
97 //              else if (typeName.equals("array") )
98 //                      fTypeName= VARTYPE_ARRAY;
99 //              else if (typeName.equals("object") )
100 //                      fTypeName= VARTYPE_OBJECT;
101
102                 
103                                 
104 //              fTypeName=type;
105 //              
106 //              fValue= new XDebugValue(this,property);
107         }
108         /* (non-Javadoc)
109          * @see org.eclipse.debug.core.model.IVariable#getValue()
110          */
111         public IValue getValue() throws DebugException {
112                 return fValue;
113 //              return ((XDebugTarget)getDebugTarget()).getVariableValue(this);
114         }
115         /* (non-Javadoc)
116          * @see org.eclipse.debug.core.model.IVariable#getName()
117          */
118         public String getName() throws DebugException {
119                 if (fFullName.endsWith("]"))
120                         return fFullName.substring(fFullName.lastIndexOf('['));
121                 else
122                         return fName;
123         }
124         /* (non-Javadoc)
125          * @see org.eclipse.debug.core.model.IVariable#getReferenceTypeName()
126          */
127         public String getReferenceTypeName() throws DebugException {
128                 return fValue.getReferenceTypeName();
129         }
130         /* (non-Javadoc)
131          * @see org.eclipse.debug.core.model.IVariable#hasValueChanged()
132          */
133         public boolean hasValueChanged() throws DebugException {
134                 // TODO Auto-generated method stub
135                 return false;
136         }
137         /* (non-Javadoc)
138          * @see org.eclipse.debug.core.model.IValueModification#setValue(java.lang.String)
139          */
140         public void setValue(String expression) throws DebugException {
141                 if(fValue.setValue(expression))
142                         fireEvent(new DebugEvent(this, DebugEvent.CHANGE, DebugEvent.CONTENT));
143         }
144         /* (non-Javadoc)
145          * @see org.eclipse.debug.core.model.IValueModification#setValue(org.eclipse.debug.core.model.IValue)
146          */
147         public void setValue(IValue value) throws DebugException {
148         }
149         /* (non-Javadoc)
150          * @see org.eclipse.debug.core.model.IValueModification#supportsValueModification()
151          */
152         public boolean supportsValueModification() {
153                 return fValue.supportsValueModification();
154         }
155         /* (non-Javadoc)
156          * @see org.eclipse.debug.core.model.IValueModification#verifyValue(java.lang.String)
157          */
158         public boolean verifyValue(String expression) throws DebugException {
159                 return fValue.verifyValue(expression);
160         }
161         /* (non-Javadoc)
162          * @see org.eclipse.debug.core.model.IValueModification#verifyValue(org.eclipse.debug.core.model.IValue)
163          */
164         public boolean verifyValue(IValue value) throws DebugException {
165                 return false;
166         }
167         
168         /**
169          * Returns the stack frame owning this variable.
170          * 
171          * @return the stack frame owning this variable
172          */
173         protected XDebugStackFrame getStackFrame() {
174                 return fFrame;
175         }
176
177 //      public int getType() {
178 //              return fType;
179 //      }
180
181         public String getValueString() throws DebugException {
182                 return fValue.getValueString();
183         }
184         
185         public boolean hasChildren() {
186                 return (fNumChildren>0);
187         }
188
189         public boolean isArray() {
190                 return (fValue.isArray());
191         }
192
193         public String getEncoding() {
194                 return fEncoding;
195         }
196
197         public void setEncoding(String encoding) {
198                 fEncoding = encoding;
199         }
200         
201         public String toString() {
202                 return fValue.toString();
203         }
204
205         public String getFullName() {
206                 return fFullName;
207         }
208
209 }