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; // ???
40 this (null, "", null, "", PHPValue.PEVT_UNKNOWN, null); // create an empty variable (a simple dummy node?)
45 * @param frame The stackframe this variable belongs to
46 * @param name The name for this variable
47 * @param parent The parent variable if this is not the root
48 * @param value The value of this variable which is a simple value or again a variable
49 * @param valueType The type of the value (e.g. int, double, string etc.) @see PHPValue
52 PHPVariable (PHPStackFrame frame, String name, PHPVariable parent, String value, int valueType, Vector subitems)
54 this.fStackFrame = frame;
55 this.fValue = new PHPValue (frame, value, valueType, subitems);
56 this.fParent = parent;
65 public void setName (String name) {
66 if ((fParent == null) || // If we have no parent for this variable
67 (fParent.getName () == "")) { // or we have a parent which is just a simple node ???
68 fLongName = name; // Set the long name
69 fName = name; // and set the name
74 switch (fParent.getReferenceType ()) { // Get the type of the parent variable
75 case PHPValue.PEVT_ARRAY : // It's an array
76 fName = "['" + name + "']"; // So set the variable name as [name]
77 fLongName = fParent.getLongName () + fName; // Set the longname to parentVariableLongname[name]
80 case PHPValue.PEVT_OBJECT : // It's an object
81 fName = name; // Set the name to name
82 fLongName = fParent.getLongName () + "." + fName; // Set the longname to parentVariableLongname.name
86 fName = name; // Set the name to name
87 fLongName = name; // Set the Longname to name
93 * @see org.eclipse.debug.core.model.IVariable#getValue()
95 public IValue getValue() {
100 * @see org.eclipse.debug.core.model.IVariable#getfName()
102 public String getName() {
109 public PHPVariable getParent()
117 public void setParent(PHPVariable parent)
120 fLongName=parent.getLongName()+fName;
126 public String getLongName() {
131 * @see org.eclipse.debug.core.model.IVariable#getReferenceTypefName()
133 public String getReferenceTypeName() {
134 return fValue.getReferenceTypeName();
140 public int getReferenceType() {
141 return fValue.getReferenceType();
147 public int setReferenceType(int type) {
148 return ((PHPValue) getValue()).setReferenceType(type);
152 * @see org.eclipse.debug.core.model.IVariable#hasValueChanged()
154 public boolean hasValueChanged() throws DebugException {
155 return fValue.hasValueChanged ();
160 * @param changed This method is called after a suspend when the list of
161 * variables is updated, to mark that this variable has a changed
162 * value. The variable view will show this variable in
165 public void setValueChanged (boolean changed) {
166 fValue.setValueChanged (changed);
170 * @see org.eclipse.debug.core.model.IDebugElement#getModelIdentifier()
172 public String getModelIdentifier() {
173 return getDebugTarget().getModelIdentifier();
177 * @see org.eclipse.debug.core.model.IDebugElement#getDebugTarget()
179 public IDebugTarget getDebugTarget() {
180 return fStackFrame.getDebugTarget();
184 * @see org.eclipse.debug.core.model.IDebugElement#getLaunch()
186 public ILaunch getLaunch() {
187 return getDebugTarget().getLaunch();
191 * @see org.eclipse.debug.core.model.IValueModification#setValue(java.lang.String)
193 public void setValue(String expression) throws DebugException {
195 if(fValue.getReferenceType()==PHPValue.PEVT_STRING)
196 evalString=fLongName+"=\""+expression+"\"";
198 evalString=fLongName+"="+expression;
199 PHPVariable[] vars=fStackFrame.getPHPDBGProxy().eval(fStackFrame,evalString);
200 setValue(vars[0].fValue);
204 * @see org.eclipse.debug.core.model.IValueModification#setValue(org.eclipse.debug.core.model.IValue)
206 public void setValue(IValue value) throws DebugException {
207 // TODO Auto-generated method stub
208 this.fValue=(PHPValue)value;
212 * @see org.eclipse.debug.core.model.IValueModification#supportsValueModification()
214 public boolean supportsValueModification() {
219 * @see org.eclipse.debug.core.model.IValueModification#verifyValue(java.lang.String)
221 public boolean verifyValue(String expression) throws DebugException {
222 // TODO Auto-generated method stub
227 * @see org.eclipse.debug.core.model.IValueModification#verifyValue(org.eclipse.debug.core.model.IValue)
229 public boolean verifyValue(IValue value) throws DebugException {
230 // TODO Auto-generated method stub
235 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(Class)
237 public Object getAdapter(Class adapter) {
238 return Platform.getAdapterManager().getAdapter(this, adapter);
242 * This method is called from variable view and denominates the variables with
243 * a type specific explanation.
246 public String toString () {
250 switch (getReferenceType ()) {
251 case PHPValue.PEVT_ARRAY : // Variable is an array
252 int elements = fValue.getVariables ().length; // Get the number of child elements
254 switch (elements) { // Switch for the number of child elements
255 case 0: // We have no child element
256 str = this.getName () + " [no elements]"; // string => 'varname [no elements]'
259 case 1: // We have exactly one child element
260 str = this.getName () + " [1 element]"; // string => 'varname [1 element]'
263 default: // We have more than one element
264 str = this.getName () + " [" + elements + " elements]"; // string => 'varname [x elements]'
269 case PHPValue.PEVT_OBJECT : // Variable is an object
270 str = this.getName () + " [class: " + fValue.getValueString() + "]"; // string => 'varname [class: varvalue]'
273 case PHPValue.PEVT_STRING : // Variable is a string
274 str = this.getName () + " = \"" + fValue.getValueString() +"\"" ; // string => 'varname = "varvalue"'
277 case PHPValue.PEVT_SOFTREF : // Variable is a soft reference
278 default : // or anything else
279 str = this.getName () + " = " + fValue.getValueString(); // string => 'varname = varvalue'