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;
11 //import org.eclipse.core.runtime.CoreException;
12 import org.eclipse.debug.core.DebugException;
13 import org.eclipse.debug.core.DebugEvent;
14 import org.eclipse.debug.core.model.IValue;
15 import org.eclipse.debug.core.model.IVariable;
16 import org.w3c.dom.Node;
17 import org.eclipse.debug.core.model.IWatchExpressionDelegate;
21 * TODO To change the template for this generated type comment go to
22 * Window - Preferences - Java - Code Style - Code Templates
24 public class XDebugVariable extends XDebugElement implements IVariable/*, IWatchExpressionFactoryAdapter*/ {
25 public static final int VARTYPE_UNKNOWN = -1;
26 public static final int VARTYPE_UNINITIALIZED = 0;
27 public static final int VARTYPE_STRING = 1;
28 public static final int VARTYPE_INT = 2;
29 public static final int VARTYPE_FLOAT = 3;
30 public static final int VARTYPE_ARRAY = 8;
31 public static final int VARTYPE_HASH = 9;
32 public static final int VARTYPE_OBJECT = 10;
33 public static final int VARTYPE_RESOURCE = 11;
35 private int fNumChildren;
37 private String fFullName;
38 private String fEncoding;
39 private XDebugStackFrame fFrame;
40 private XDebugAbstractValue fValue;
41 private String fFacet;
44 * Constructs a variable contained in the given stack frame
45 * with the given name.
47 * @param frame owning stack frame
48 * @param name variable name
50 public XDebugVariable(XDebugStackFrame frame, Node property) {
52 //super((XDebugTarget) frame.getDebugTarget());
56 String address = PHPDebugUtils.getAttributeValue(property,"address");
58 fName = PHPDebugUtils.getAttributeValue(property,"name");
59 if ("".equals(fName)) {
65 fFullName = PHPDebugUtils.getAttributeValue(property,"fullname");
66 fEncoding = PHPDebugUtils.getAttributeValue(property,"encoding");
67 if (PHPDebugUtils.getAttributeValue(property,"numchildren").equals("")) {
70 fNumChildren = Integer.parseInt(PHPDebugUtils.getAttributeValue(property, "numchildren"));
73 String typeName = PHPDebugUtils.getAttributeValue(property, "type");
75 fFacet = PHPDebugUtils.getAttributeValue(property, "facet");
77 if (typeName.equals("int") )
78 fValue= new XDebugIntValue(this,property,typeName);
79 else if (typeName.equals("float") )
80 fValue= new XDebugFloatValue(this,property,typeName);
81 else if (typeName.equals("bool") )
82 fValue= new XDebugBooleanValue(this,property,typeName);
83 else if (typeName.equals("string") )
84 fValue= new XDebugStringValue(this,property,typeName);
85 else if (typeName.equals("array") )
86 fValue= new XDebugArrayValue(this,property,typeName);
87 else if (typeName.equals("hash") )
88 fValue= new XDebugArrayValue(this,property,typeName);
89 else if (typeName.equals("object") )
90 fValue= new XDebugArrayValue(this,property,typeName);
92 fValue= new XDebugValue(this,property,typeName);
96 * @see org.eclipse.debug.core.model.IVariable#getValue()
98 public IValue getValue() throws DebugException {
100 // return ((XDebugTarget)getDebugTarget()).getVariableValue(this);
104 * @see org.eclipse.debug.core.model.IVariable#getName()
106 public String getName() throws DebugException {
107 if (fFullName.endsWith("]"))
108 return fFullName.substring(fFullName.lastIndexOf('['));
114 * @see org.eclipse.debug.core.model.IVariable#getReferenceTypeName()
116 public String getReferenceTypeName() throws DebugException {
117 return fValue.getReferenceTypeName();
121 * @see org.eclipse.debug.core.model.IVariable#hasValueChanged()
123 public boolean hasValueChanged() throws DebugException {
124 return fValue.hasChanged();
128 * @see org.eclipse.debug.core.model.IValueModification#setValue(java.lang.String)
130 public void setValue(String expression) throws DebugException {
131 if(fValue.setValue(expression))
132 fireEvent(new DebugEvent(this, DebugEvent.CHANGE, DebugEvent.CONTENT));
133 //fValue.setValueA(expression);
137 * @see org.eclipse.debug.core.model.IValueModification#setValue(org.eclipse.debug.core.model.IValue)
139 public void setValue(IValue value) throws DebugException {
140 fValue.setValueB(value);
144 * @see org.eclipse.debug.core.model.IValueModification#supportsValueModification()
146 public boolean supportsValueModification() {
147 return fValue.supportsValueModification();
151 * @see org.eclipse.debug.core.model.IValueModification#verifyValue(java.lang.String)
153 public boolean verifyValue(String expression) throws DebugException {
154 return fValue.verifyValue(expression);
158 * @see org.eclipse.debug.core.model.IValueModification#verifyValue(org.eclipse.debug.core.model.IValue)
160 public boolean verifyValue(IValue value) throws DebugException {
165 * Returns the stack frame owning this variable.
167 * @return the stack frame owning this variable
169 protected XDebugStackFrame getStackFrame() {
173 public void setStackFrame(XDebugStackFrame frame) {
175 super.setDebugTarget((XDebugTarget) frame.getDebugTarget());
178 // public int getType() {
182 public String getValueString() throws DebugException {
183 return fValue.getValueString();
186 /*public setValueString(String newValueStrig) throws DebugException {
187 fValue.setValueString getValueString();
190 public boolean hasChildren() {
191 return (fNumChildren > 0);
194 public boolean isArray() {
195 return (fValue.isArray());
198 public String getEncoding() {
202 public String getVisibility() {
206 public void setEncoding(String encoding) {
207 fEncoding = encoding;
210 public String toString() {
211 return fValue.toString();
214 public String getFullName() {
218 public int getNumChildren() {
222 public void setNumChildren(int numChildren) {
223 fNumChildren = numChildren;
226 public void setChange(IVariable oldVariable) throws DebugException {
227 XDebugAbstractValue oldValue = null;
228 IVariable[] newVariable = null;
229 IVariable[] oldVariable1 = null;
232 oldValue = (XDebugAbstractValue) oldVariable.getValue();
233 } catch (DebugException e) {
237 oldVariable1 = ((XDebugVariable)oldVariable).getValue().getVariables();
238 newVariable = fValue.getVariables();
239 } catch (DebugException e) {
243 if(((XDebugVariable) oldVariable).getNumChildren() > 0) {
244 if ( this.getNumChildren() == 0) {
246 if (!fValue.getValueString().equals(((XDebugAbstractValue)oldValue).getValueString())) {
247 fValue.sethasChanged(true);
249 fValue.sethasChanged(false);
251 } catch (DebugException e) {
254 for(int i = 0; i < newVariable.length; i++) {
255 ((XDebugVariable)newVariable[i]).setChange(((XDebugVariable)oldVariable1[i]));
259 if ( this.getNumChildren() == 0) {
260 // controllare anche il tipo (unknow)
261 //if (!fValue.getValueString().equals("uninitialized")) {
262 if (!fValue.getValueString().equals(oldValue.getValueString())) {
263 fValue.sethasChanged(true);
265 fValue.sethasChanged(false);
268 //IVariable dummy = new XDebugVariable("UNKNOWN", "");
269 /*dummy.setValue("uninitialized");
270 for(int i = 0; i < newVariable.length; i++) {
271 ((XDebugVariable)newVariable[i]).setChange(dummy);
273 fValue.sethasChanged(true);*/
278 * Creates and returns an expression for the specified variable
279 * which is used to created an {@link org.eclipse.debug.core.model.IWatchExpression}.
281 * @param variable variable a watch expression is required for
282 * @return text used to create a watch expression
283 * @exception org.eclipse.core.runtime.CoreException if unable to create a watch
286 /*public String createWatchExpression(IVariable variable) throws CoreException {