Whole refactor.
[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 fFullName;
25         private XDebugStackFrame fFrame;
26         private XDebugAbstractValue fValue;
27         private String fFacet;
28         
29         /**
30          * Constructs a variable contained in the given stack frame
31          * with the given name.
32          * 
33          * @param frame owning stack frame
34          * @param name variable name
35          */
36         public XDebugVariable(XDebugStackFrame frame, Node property) {
37                 if (frame != null ) {
38                         //super((XDebugTarget) frame.getDebugTarget());
39                         fFrame = frame;
40                 }
41
42                 String address = PHPDebugUtils.getAttributeValue(property,"address");
43
44                 fName = PHPDebugUtils.getAttributeValue(property,"name");
45                 if ("".equals(fName)) {
46                         fName = address;
47                 }
48                 
49                 fFullName = PHPDebugUtils.getAttributeValue(property,"fullname");
50
51                 String typeName = PHPDebugUtils.getAttributeValue(property, "type");
52
53                 fFacet = PHPDebugUtils.getAttributeValue(property, "facet");
54
55                 if (typeName.equals("int") ) 
56                         fValue = new XDebugIntValue(frame, property);
57                 else if (typeName.equals("float") ) 
58                         fValue = new XDebugFloatValue(frame, property);
59                 else if (typeName.equals("bool") ) 
60                         fValue = new XDebugBooleanValue(frame, property);
61                 else if (typeName.equals("string") )
62                         fValue = new XDebugStringValue(frame, property);
63                 else if (typeName.equals("array") )
64                         fValue = new XDebugArrayValue(frame, property);
65                 else if (typeName.equals("hash") )
66                         fValue = new XDebugArrayValue(frame, property);
67                 else if (typeName.equals("object") )
68                         fValue = new XDebugArrayValue(frame, property);
69                 else if (typeName.equals("resource") )
70                         fValue = new XDebugResourceValue(frame, property);
71                 else
72                         fValue = new XDebugValue(frame, property);
73         }
74                 
75         /* (non-Javadoc)
76          * @see org.eclipse.debug.core.model.IVariable#getValue()
77          */
78         public IValue getValue() throws DebugException {
79                 return fValue;
80         }
81         
82         /* (non-Javadoc)
83          * @see org.eclipse.debug.core.model.IVariable#getName()
84          */
85         public String getName() throws DebugException {
86                 if (fFullName.endsWith("]"))
87                         return fFullName.substring(fFullName.lastIndexOf('['));
88                 else
89                         return fName;
90         }
91         
92         /* (non-Javadoc)
93          * @see org.eclipse.debug.core.model.IVariable#getReferenceTypeName()
94          */
95         public String getReferenceTypeName() throws DebugException {
96                 return fValue.getReferenceTypeName();
97         }
98         
99         /* (non-Javadoc)
100          * @see org.eclipse.debug.core.model.IVariable#hasValueChanged()
101          */
102         public boolean hasValueChanged() throws DebugException {
103                 return fValue.hasChanged();
104         }
105         
106         /* (non-Javadoc)
107          * @see org.eclipse.debug.core.model.IValueModification#setValue(java.lang.String)
108          */
109         public void setValue(String expression) throws DebugException {
110                 if(fValue.setValue(expression)) {
111                         
112                 }
113                         //fireEvent(new DebugEvent(this, DebugEvent.CHANGE, DebugEvent.CONTENT));
114                 //fValue.setValueA(expression);
115         }
116         
117         /* (non-Javadoc)
118          * @see org.eclipse.debug.core.model.IValueModification#setValue(org.eclipse.debug.core.model.IValue)
119          */
120         public void setValue(IValue value) throws DebugException {
121                 //fValue.setValueB(value);
122         }
123
124         /* (non-Javadoc)
125          * @see org.eclipse.debug.core.model.IValueModification#supportsValueModification()
126          */
127         public boolean supportsValueModification() {
128                 return fValue.supportsValueModification();
129         }
130
131         /* (non-Javadoc)
132          * @see org.eclipse.debug.core.model.IValueModification#verifyValue(java.lang.String)
133          */
134         public boolean verifyValue(String expression) throws DebugException {
135                 return fValue.verifyValue(expression);
136         }
137
138         /* (non-Javadoc)
139          * @see org.eclipse.debug.core.model.IValueModification#verifyValue(org.eclipse.debug.core.model.IValue)
140          */
141         public boolean verifyValue(IValue value) throws DebugException {
142                 return false;
143         }
144         
145         /**
146          * Returns the stack frame owning this variable.
147          * 
148          * @return the stack frame owning this variable
149          */
150         protected XDebugStackFrame getStackFrame() {
151                 return fFrame;
152         }
153         
154         public String getValueString() throws DebugException {
155                 return fValue.getValueString();
156         }
157         
158         public String getVisibility() {
159                 return fFacet;
160         }
161
162         public String toString() {
163                 return null;
164         }
165
166         public String getFullName() {
167                 return fFullName;
168         }
169 }