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 net.sourceforge.phpdt.internal.debug.core.PHPDebugCorePlugin;
19 import org.eclipse.core.runtime.Platform;
20 import org.eclipse.core.runtime.Status;
21 import org.eclipse.debug.core.DebugException;
22 import org.eclipse.debug.core.ILaunch;
23 import org.eclipse.debug.core.model.IDebugTarget;
24 import org.eclipse.debug.core.model.IValue;
25 import org.eclipse.debug.core.model.IVariable;
31 public class PHPVariable implements IVariable {
33 private PHPValue fValue; // The value of this variable
34 private String fName; // The name of the variable
35 private PHPStackFrame fStackFrame; // The stackframe this variable belongs to
36 private PHPVariable fParent; // The parent variable (a back link)
37 private String fLongName; // ???
43 this (null, "", null, "", PHPValue.PEVT_UNKNOWN, null); // create an empty variable (a simple dummy node?)
48 * @param frame The stackframe this variable belongs to
49 * @param name The name for this variable
50 * @param parent The parent variable if this is not the root
51 * @param value The value of this variable which is a simple value or again a variable
52 * @param valueType The type of the value (e.g. int, double, string etc.) @see PHPValue
55 PHPVariable (PHPStackFrame frame, String name, PHPVariable parent, String value, int valueType, Vector subitems)
57 this.fStackFrame = frame;
58 this.fValue = new PHPValue (frame, value, valueType, subitems);
59 this.fParent = parent;
68 public void setName (String name) {
69 if ((fParent == null) || // If we have no parent for this variable
70 (fParent.getName () == "")) { // or we have a parent which is just a simple node ???
71 fLongName = name; // Set the long name
72 fName = name; // and set the name
77 switch (fParent.getReferenceType ()) { // Get the type of the parent variable
78 case PHPValue.PEVT_ARRAY : // It's an array
79 fName = "['" + name + "']"; // So set the variable name as [name]
80 fLongName = fParent.getLongName () + fName; // Set the longname to parentVariableLongname[name]
83 case PHPValue.PEVT_OBJECT : // It's an object
84 fName = name; // Set the name to name
85 fLongName = fParent.getLongName () + "." + fName; // Set the longname to parentVariableLongname.name
89 fName = name; // Set the name to name
90 fLongName = name; // Set the Longname to name
96 * @see org.eclipse.debug.core.model.IVariable#getValue()
98 public IValue getValue() {
103 * @see org.eclipse.debug.core.model.IVariable#getfName()
105 public String getName() {
112 public PHPVariable getParent()
120 public void setParent(PHPVariable parent)
123 fLongName=parent.getLongName()+fName;
129 public String getLongName() {
134 * @see org.eclipse.debug.core.model.IVariable#getReferenceTypefName()
136 public String getReferenceTypeName() {
137 return fValue.getReferenceTypeName();
143 public int getReferenceType() {
144 return fValue.getReferenceType();
150 public int setReferenceType(int type) {
151 return ((PHPValue) getValue()).setReferenceType(type);
155 * @see org.eclipse.debug.core.model.IVariable#hasValueChanged()
157 public boolean hasValueChanged() throws DebugException {
158 return fValue.hasValueChanged ();
163 * @param changed This method is called after a suspend when the list of
164 * variables is updated, to mark that this variable has a changed
165 * value. The variable view will show this variable in
168 public void setValueChanged (boolean changed) {
169 fValue.setValueChanged (changed);
173 * @see org.eclipse.debug.core.model.IDebugElement#getModelIdentifier()
175 public String getModelIdentifier() {
176 return getDebugTarget().getModelIdentifier();
180 * @see org.eclipse.debug.core.model.IDebugElement#getDebugTarget()
182 public IDebugTarget getDebugTarget() {
183 return fStackFrame.getDebugTarget();
187 * @see org.eclipse.debug.core.model.IDebugElement#getLaunch()
189 public ILaunch getLaunch() {
190 return getDebugTarget().getLaunch();
194 * @see org.eclipse.debug.core.model.IValueModification#setValue(java.lang.String)
196 public void setValue(String expression) throws DebugException {
198 if(fValue.getReferenceType()==PHPValue.PEVT_STRING)
199 evalString=fLongName+"=\""+expression+"\"";
201 evalString=fLongName+"="+expression;
202 PHPVariable[] vars=fStackFrame.getPHPDBGProxy().eval(fStackFrame,evalString);
204 if (vars == null || vars.length == 0) {
205 vars = fStackFrame.getPHPDBGProxy().eval(fStackFrame, fLongName);
206 if (vars == null || vars.length == 0) {
207 // TODO code and message
209 String msg = "Could not assign and get variable";
210 Status status = new Status(Status.ERROR,
211 PHPDebugCorePlugin.PLUGIN_ID, code, msg, null);
212 PHPDebugCorePlugin.log(status);
213 throw new DebugException(status);
217 setValue(vars[0].fValue);
221 * @see org.eclipse.debug.core.model.IValueModification#setValue(org.eclipse.debug.core.model.IValue)
223 public void setValue(IValue value) throws DebugException {
224 // TODO Auto-generated method stub
225 this.fValue=(PHPValue)value;
229 * @see org.eclipse.debug.core.model.IValueModification#supportsValueModification()
231 public boolean supportsValueModification() {
236 * @see org.eclipse.debug.core.model.IValueModification#verifyValue(java.lang.String)
238 public boolean verifyValue(String expression) throws DebugException {
239 // TODO Auto-generated method stub
244 * @see org.eclipse.debug.core.model.IValueModification#verifyValue(org.eclipse.debug.core.model.IValue)
246 public boolean verifyValue(IValue value) throws DebugException {
247 // TODO Auto-generated method stub
252 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(Class)
254 public Object getAdapter(Class adapter) {
255 return Platform.getAdapterManager().getAdapter(this, adapter);
259 * This method is called from variable view and denominates the variables with
260 * a type specific explanation.
263 public String toString () {
267 switch (getReferenceType ()) {
268 case PHPValue.PEVT_ARRAY : // Variable is an array
269 int elements = fValue.getVariables ().length; // Get the number of child elements
271 switch (elements) { // Switch for the number of child elements
272 case 0: // We have no child element
273 str = this.getName () + " [no elements]"; // string => 'varname [no elements]'
276 case 1: // We have exactly one child element
277 str = this.getName () + " [1 element]"; // string => 'varname [1 element]'
280 default: // We have more than one element
281 str = this.getName () + " [" + elements + " elements]"; // string => 'varname [x elements]'
286 case PHPValue.PEVT_OBJECT : // Variable is an object
287 str = this.getName () + " [class: " + fValue.getValueString() + "]"; // string => 'varname [class: varvalue]'
290 case PHPValue.PEVT_STRING : // Variable is a string
291 str = this.getName () + " = \"" + fValue.getValueString() +"\"" ; // string => 'varname = "varvalue"'
294 case PHPValue.PEVT_SOFTREF : // Variable is a soft reference
295 default : // or anything else
296 str = this.getName () + " = " + fValue.getValueString(); // string => 'varname = varvalue'