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;
10 import org.eclipse.debug.core.DebugException;
11 import org.eclipse.debug.core.DebugEvent;
12 import org.eclipse.debug.core.model.IValue;
13 import org.eclipse.debug.core.model.IVariable;
14 import org.w3c.dom.Node;
19 * TODO To change the template for this generated type comment go to
20 * Window - Preferences - Java - Code Style - Code Templates
22 public class XDebugVariable extends XDebugElement implements IVariable {
23 public static final int VARTYPE_UNKNOWN = -1;
24 public static final int VARTYPE_UNINITIALIZED = 0;
25 public static final int VARTYPE_STRING = 1;
26 public static final int VARTYPE_INT = 2;
27 public static final int VARTYPE_FLOAT = 3;
28 public static final int VARTYPE_ARRAY = 8;
29 public static final int VARTYPE_HASH = 9;
30 public static final int VARTYPE_OBJECT = 10;
31 public static final int VARTYPE_RESOURCE = 11;
35 private XDebugStackFrame fFrame;
36 private String fFullName;
37 private XDebugAbstractValue fValue;
38 private String fEncoding;
39 private int fNumChildren;
42 * Constructs a variable contained in the given stack frame
43 * with the given name.
45 * @param frame owning stack frame
46 * @param name variable name
48 public XDebugVariable( String typeName, String fullname ) {
51 if (typeName.equals("int") )
52 fValue= new XDebugIntValue(this,typeName);
53 else if (typeName.equals("float") )
54 fValue= new XDebugFloatValue(this,typeName);
55 else if (typeName.equals("bool") )
56 fValue= new XDebugBooleanValue(this,typeName);
57 else if (typeName.equals("string") )
58 fValue= new XDebugStringValue(this,typeName);
59 else if (typeName.equals("array") )
60 fValue= new XDebugArrayValue(this,typeName);
61 else if (typeName.equals("hash") )
62 fValue= new XDebugArrayValue(this,typeName);
63 else if (typeName.equals("object") )
64 fValue= new XDebugArrayValue(this,typeName);
65 else if (typeName.equals("resource") )
66 fValue= new XDebugResourceValue(this,typeName);
68 fValue= new XDebugValue(this,typeName);
71 public XDebugVariable(XDebugStackFrame frame, Node property) {
72 super((XDebugTarget) frame.getDebugTarget());
77 public XDebugVariable(XDebugStackFrame frame, String fullname, String name, String typeName) {
78 super((XDebugTarget) frame.getDebugTarget());
82 if (typeName.equals("int") )
83 fValue= new XDebugIntValue(this,typeName);
84 else if (typeName.equals("float") )
85 fValue= new XDebugFloatValue(this,typeName);
86 else if (typeName.equals("bool") )
87 fValue= new XDebugBooleanValue(this,typeName);
88 else if (typeName.equals("string") )
89 fValue= new XDebugStringValue(this,typeName);
90 else if (typeName.equals("array") )
91 fValue= new XDebugArrayValue(this,typeName);
92 else if (typeName.equals("hash") )
93 fValue= new XDebugArrayValue(this,typeName);
94 else if (typeName.equals("object") )
95 fValue= new XDebugArrayValue(this,typeName);
96 else if (typeName.equals("resource") )
97 fValue= new XDebugResourceValue(this,typeName);
99 fValue= new XDebugValue(this,typeName);
102 private void init(Node property) {
103 fFullName=PHPDebugUtils.getAttributeValue(property,"fullname");
104 fName=PHPDebugUtils.getAttributeValue(property,"name");
105 fEncoding=PHPDebugUtils.getAttributeValue(property,"encoding");
106 if (PHPDebugUtils.getAttributeValue(property,"numchildren").equals(""))
109 fNumChildren=Integer.parseInt(PHPDebugUtils.getAttributeValue(property,"numchildren"));
111 String typeName=PHPDebugUtils.getAttributeValue(property,"type");
113 // if (typeName.equals("uninitialized") )
114 // fValue= new XDebugValue(this,property,typeName);
115 if (typeName.equals("int") )
116 fValue= new XDebugIntValue(this,property,typeName);
117 else if (typeName.equals("float") )
118 fValue= new XDebugFloatValue(this,property,typeName);
119 else if (typeName.equals("bool") )
120 fValue= new XDebugBooleanValue(this,property,typeName);
121 else if (typeName.equals("string") )
122 fValue= new XDebugStringValue(this,property,typeName);
123 else if (typeName.equals("array") )
124 fValue= new XDebugArrayValue(this,property,typeName);
125 else if (typeName.equals("hash") )
126 fValue= new XDebugArrayValue(this,property,typeName);
127 else if (typeName.equals("object") )
128 fValue= new XDebugArrayValue(this,property,typeName);
130 fValue= new XDebugValue(this,property,typeName);
134 * @see org.eclipse.debug.core.model.IVariable#getValue()
136 public IValue getValue() throws DebugException {
138 // return ((XDebugTarget)getDebugTarget()).getVariableValue(this);
142 * @see org.eclipse.debug.core.model.IVariable#getName()
144 public String getName() throws DebugException {
145 if (fFullName.endsWith("]"))
146 return fFullName.substring(fFullName.lastIndexOf('['));
152 * @see org.eclipse.debug.core.model.IVariable#getReferenceTypeName()
154 public String getReferenceTypeName() throws DebugException {
155 return fValue.getReferenceTypeName();
159 * @see org.eclipse.debug.core.model.IVariable#hasValueChanged()
161 public boolean hasValueChanged() throws DebugException {
162 return fValue.hasChanged();
166 * @see org.eclipse.debug.core.model.IValueModification#setValue(java.lang.String)
168 public void setValue(String expression) throws DebugException {
169 if(fValue.setValue(expression))
170 fireEvent(new DebugEvent(this, DebugEvent.CHANGE, DebugEvent.CONTENT));
171 //fValue.setValueA(expression);
175 * @see org.eclipse.debug.core.model.IValueModification#setValue(org.eclipse.debug.core.model.IValue)
177 public void setValue(IValue value) throws DebugException {
178 fValue.setValueB(value);
182 * @see org.eclipse.debug.core.model.IValueModification#supportsValueModification()
184 public boolean supportsValueModification() {
185 return fValue.supportsValueModification();
189 * @see org.eclipse.debug.core.model.IValueModification#verifyValue(java.lang.String)
191 public boolean verifyValue(String expression) throws DebugException {
192 return fValue.verifyValue(expression);
196 * @see org.eclipse.debug.core.model.IValueModification#verifyValue(org.eclipse.debug.core.model.IValue)
198 public boolean verifyValue(IValue value) throws DebugException {
203 * Returns the stack frame owning this variable.
205 * @return the stack frame owning this variable
207 protected XDebugStackFrame getStackFrame() {
211 public void setStackFrame(XDebugStackFrame frame) {
213 super.setDebugTarget((XDebugTarget)frame.getDebugTarget());
216 // public int getType() {
220 public String getValueString() throws DebugException {
221 return fValue.getValueString();
224 /*public setValueString(String newValueStrig) throws DebugException {
225 fValue.setValueString getValueString();
228 public boolean hasChildren() {
229 return (fNumChildren > 0);
232 public boolean isArray() {
233 return (fValue.isArray());
236 public String getEncoding() {
240 public void setEncoding(String encoding) {
241 fEncoding = encoding;
244 public String toString() {
245 return fValue.toString();
248 public String getFullName() {
252 public int getNumChildren() {
256 public void setNumChildren(int numChildren) {
257 fNumChildren = numChildren;
260 public void setChange(IVariable oldVariable) throws DebugException {
261 XDebugAbstractValue oldValue = null;
262 IVariable[] newVariable = null;
263 IVariable[] oldVariable1 = null;
266 oldValue = (XDebugAbstractValue) oldVariable.getValue();
267 } catch (DebugException e) {
271 oldVariable1 = ((XDebugVariable)oldVariable).getValue().getVariables();
272 newVariable = fValue.getVariables();
273 } catch (DebugException e) {
277 if(((XDebugVariable) oldVariable).getNumChildren() > 0) {
278 if ( this.getNumChildren() == 0) {
280 if (!fValue.getValueString().equals(((XDebugAbstractValue)oldValue).getValueString())) {
281 fValue.sethasChanged(true);
283 fValue.sethasChanged(false);
285 } catch (DebugException e) {
288 for(int i = 0; i < newVariable.length; i++) {
289 ((XDebugVariable)newVariable[i]).setChange(((XDebugVariable)oldVariable1[i]));
293 if ( this.getNumChildren() == 0) {
294 // controllare anche il tipo (unknow)
295 //if (!fValue.getValueString().equals("uninitialized")) {
296 if (!fValue.getValueString().equals(oldValue.getValueString())) {
297 fValue.sethasChanged(true);
299 fValue.sethasChanged(false);
302 IVariable dummy = new XDebugVariable("UNKNOWN", "");
303 dummy.setValue("uninitialized");
304 for(int i = 0; i < newVariable.length; i++) {
305 ((XDebugVariable)newVariable[i]).setChange(dummy);
307 fValue.sethasChanged(true);