1 /**********************************************************************
2 Copyright (c) 2000, 2002 IBM Corp. and others.
3 All rights reserved. This program and the accompanying materials
4 are made available under the terms of the Common Public License v1.0
5 which accompanies this distribution, and is available at
6 http://www.eclipse.org/legal/cpl-v10.html
9 IBM Corporation - Initial implementation
10 Vicente Fernando - www.alfersoft.com.ar
11 Christian Perkonig - cperkonig@gmx.at
12 **********************************************************************/
13 package net.sourceforge.phpdt.internal.debug.core.model;
15 import java.util.Vector;
17 import org.eclipse.core.runtime.Platform;
18 import org.eclipse.debug.core.DebugException;
19 import org.eclipse.debug.core.ILaunch;
20 import org.eclipse.debug.core.model.IDebugTarget;
21 import org.eclipse.debug.core.model.IValue;
22 import org.eclipse.debug.core.model.IVariable;
28 public class PHPVariable implements IVariable {
30 private PHPValue fValue; // The value of this variable
31 private String fName; // The name of the variable
32 private PHPStackFrame fStackFrame; // The stackframe this variable belongs to
33 private PHPVariable fParent; // The parent variable (a back link)
34 private String fLongName; // ???
35 private boolean fHasChanged; //
41 this (null, "", null, "", PHPValue.PEVT_UNKNOWN, null); // create an empty variable (a simple dummy node?)
46 * @param frame The stackframe this variable belongs to
47 * @param name The name for this variable
48 * @param parent The parent variable if this is not the root
49 * @param value The value of this variable which is a simple value or again a variable
50 * @param valueType The type of the value (e.g. int, double, string etc.) @see PHPValue
53 PHPVariable (PHPStackFrame frame, String name, PHPVariable parent, String value, int valueType, Vector subitems)
55 this.fStackFrame = frame;
56 this.fValue = new PHPValue (frame, value, valueType, subitems);
57 this.fParent = parent;
58 this.fHasChanged = false;
67 private void setName (String name) {
68 if ((fParent == null) || // If we have no parent for this variable
69 (fParent.getName () == "")) { // or we have a parent which is just a simple node ???
70 fLongName = name; // Set the long name
71 fName = name; // and set the name
76 switch (fParent.getReferenceType ()) { // Get the type of the parent variable
77 case PHPValue.PEVT_ARRAY : // It's an array
78 fName = "['" + name + "']"; // So set the variable name as [name]
79 fLongName = fParent.getLongName () + fName; // Set the longname to parentVariableLongname[name]
82 case PHPValue.PEVT_OBJECT : // It's an object
83 fName = name; // Set the name to name
84 fLongName = fParent.getLongName () + "." + fName; // Set the longname to parentVariableLongname.name
88 fName = name; // Set the name to name
89 fLongName = name; // Set the Longname to name
95 * @see org.eclipse.debug.core.model.IVariable#getValue()
97 public IValue getValue() {
102 * @see org.eclipse.debug.core.model.IVariable#getfName()
104 public String getName() {
111 public PHPVariable getParent()
119 public void setParent(PHPVariable parent)
122 fLongName=parent.getLongName()+fName;
128 public String getLongName() {
133 * @see org.eclipse.debug.core.model.IVariable#getReferenceTypefName()
135 public String getReferenceTypeName() {
136 return fValue.getReferenceTypeName();
142 public int getReferenceType() {
143 return fValue.getReferenceType();
149 public int setReferenceType(int type) {
150 return ((PHPValue) getValue()).setReferenceType(type);
154 * @see org.eclipse.debug.core.model.IVariable#hasValueChanged()
156 public boolean hasValueChanged() throws DebugException {
157 // TODO Auto-generated method stub
164 * @param changed This method is called after a suspend when the list of
165 * variables is updated, to mark that this variable has a changed
166 * value. The variable view will show this variable in
169 public void setValueChanged (boolean changed) {
170 fHasChanged = changed;
174 * @see org.eclipse.debug.core.model.IDebugElement#getModelIdentifier()
176 public String getModelIdentifier() {
177 return getDebugTarget().getModelIdentifier();
181 * @see org.eclipse.debug.core.model.IDebugElement#getDebugTarget()
183 public IDebugTarget getDebugTarget() {
184 return fStackFrame.getDebugTarget();
188 * @see org.eclipse.debug.core.model.IDebugElement#getLaunch()
190 public ILaunch getLaunch() {
191 return getDebugTarget().getLaunch();
195 * @see org.eclipse.debug.core.model.IValueModification#setValue(java.lang.String)
197 public void setValue(String expression) throws DebugException {
199 if(fValue.getReferenceType()==PHPValue.PEVT_STRING)
200 evalString=fLongName+"=\""+expression+"\"";
202 evalString=fLongName+"="+expression;
203 PHPVariable[] vars=fStackFrame.getPHPDBGProxy().eval(fStackFrame,evalString);
204 setValue(vars[0].fValue);
208 * @see org.eclipse.debug.core.model.IValueModification#setValue(org.eclipse.debug.core.model.IValue)
210 public void setValue(IValue value) throws DebugException {
211 // TODO Auto-generated method stub
212 this.fValue=(PHPValue)value;
216 * @see org.eclipse.debug.core.model.IValueModification#supportsValueModification()
218 public boolean supportsValueModification() {
223 * @see org.eclipse.debug.core.model.IValueModification#verifyValue(java.lang.String)
225 public boolean verifyValue(String expression) throws DebugException {
226 // TODO Auto-generated method stub
231 * @see org.eclipse.debug.core.model.IValueModification#verifyValue(org.eclipse.debug.core.model.IValue)
233 public boolean verifyValue(IValue value) throws DebugException {
234 // TODO Auto-generated method stub
239 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(Class)
241 public Object getAdapter(Class adapter) {
242 return Platform.getAdapterManager().getAdapter(this, adapter);
246 * This method is called from variable view and denominates the variables with
247 * a type specific explanation.
250 public String toString () {
254 switch (getReferenceType ()) {
255 case PHPValue.PEVT_ARRAY : // Variable is an array
256 int elements = fValue.getVariables ().length; // Get the number of child elements
258 switch (elements) { // Switch for the number of child elements
259 case 0: // We have no child element
260 str = this.getName () + " [no elements]"; // string => 'varname [no elements]'
263 case 1: // We have exactly one child element
264 str = this.getName () + " [1 element]"; // string => 'varname [1 element]'
267 default: // We have more than one element
268 str = this.getName () + " [" + elements + " elements]"; // string => 'varname [x elements]'
273 case PHPValue.PEVT_OBJECT : // Variable is an object
274 str = this.getName () + " [class: " + fValue.getValueString() + "]"; // string => 'varname [class: varvalue]'
277 case PHPValue.PEVT_STRING : // Variable is a string
278 str = this.getName () + " = \"" + fValue.getValueString() +"\"" ; // string => 'varname = "varvalue"'
281 case PHPValue.PEVT_SOFTREF : // Variable is a soft reference
282 default : // or anything else
283 str = this.getName () + " = " + fValue.getValueString(); // string => 'varname = varvalue'