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.Collections;
16 import java.util.Iterator;
17 import java.util.Vector;
19 import org.eclipse.debug.core.DebugException;
20 import org.eclipse.debug.core.ILaunch;
21 import org.eclipse.debug.core.model.IDebugTarget;
22 import org.eclipse.debug.core.model.IValue;
23 import org.eclipse.debug.core.model.IVariable;
26 * PHPValue object belongs to a PHPVariable (is a member of PHPVariable).
27 * A PHPValue itself can have PHPVariables as children.
30 public class PHPValue implements IValue {
32 final static String[] PEV_NAMES = {
42 "soft reference" }; // 9
44 public final static int PEVT_UNKNOWN = 0;
45 public final static int PEVT_LONG = 1;
46 public final static int PEVT_DOUBLE = 2;
47 public final static int PEVT_STRING = 3;
48 public final static int PEVT_ARRAY = 4;
49 public final static int PEVT_OBJECT = 5;
50 public final static int PEVT_BOOLEAN = 6;
51 public final static int PEVT_RESOURCE = 7;
52 public final static int PEVT_REF = 8;
53 public final static int PEVT_SOFTREF = 9;
55 private int fValueType; // The type of this value (see the PEVT_... values)
56 //private boolean hasChildren; // This value (variable) has children (more variables)
57 private String fValueString; // The value of this variable as text
58 private Vector fVariables; // The children of this variable (other variables) if any
59 private PHPStackFrame fStackFrame; // The stackframe this value (variable) belongs to
60 private boolean fHasChanged; // The value has changed between two suspends
61 // This variable was moved from PHPVariable due to the fact,
62 // that two PHPVariables can reference the same PHPValue,
63 // so only the first PHPVariable would win, when we check the variable tree
64 // for changed values.
65 private boolean fSorted;
71 this(null, "", PEVT_UNKNOWN, null); // Creates an empty value
76 * @param frame The stackframe this value (and variable) belongs to.
77 * @param value The value of this value.
78 * @param fValueType The type of this value (see the PEVT_... values).
79 * @param subitems This value has subitems.
81 public PHPValue(PHPStackFrame frame, String value, int fValueType, Vector subitems) {
82 this.fValueType = fValueType;
83 this.fValueString = value;
84 this.fStackFrame = frame;
85 this.fHasChanged = false;
88 if (subitems != null) { // If there are children for this value (variable)
89 this.fVariables = new Vector(subitems); // Then add the children to this value (variable)
91 this.fVariables = new Vector(); // Create an empty vector
99 public Vector addVariable(Vector item) {
100 if (item != null) { // If there is something we want to add
101 this.fVariables.addAll(item);
102 this.fSorted = false;
105 return this.fVariables;
112 public void setParent(PHPVariable parent) {
113 if (!fVariables.isEmpty()) { // If we have child variables
114 Iterator iter = fVariables.iterator(); // Create an iterator for the children
116 while (iter.hasNext()) { // As long as we have children
117 ((PHPVariable) iter.next()).setParent(parent); // Set all child's parent
123 * @see org.eclipse.debug.core.model.IValue#getReferenceTypeName()
125 public String getReferenceTypeName() {
126 return PEV_NAMES[fValueType];
132 public int getReferenceType() {
137 * @param type Set the reference type (see the PEVT_... values).
139 public int setReferenceType(int type) {
140 return fValueType = type;
144 * This method is called whenever this value (variable) is changed.
146 * @param value The changed value for this variable.
148 public void setValueString(String value) {
149 fValueString = value;
153 * @see org.eclipse.debug.core.model.IValue#getfValueString()
155 public String getValueString() {
160 * @see org.eclipse.debug.core.model.IValue#isAllocated()
162 public boolean isAllocated() throws DebugException {
167 * @see org.eclipse.debug.core.model.IValue#getVariables()
169 * @return The array of child variable for this value (variable).
171 public IVariable[] getVariables() {
172 return (PHPVariable[]) getChildVariables().toArray(
173 new PHPVariable[fVariables.size()]);
179 public Vector getChildVariables() {
181 Collections.sort(fVariables, new PHPVariableComparator());
189 * @see org.eclipse.debug.core.model.IValue#hasVariables()
193 * <li> <code>true</code> if this value (variable) has child variables
194 * <li> <code>false</code> if no child variable available
197 public boolean hasVariables() throws DebugException {
198 // return (!fVariables.isEmpty());
199 return (fVariables.size() != 0);
203 * @see org.eclipse.debug.core.model.IDebugElement#getModelIdentifier()
205 public String getModelIdentifier() {
206 // TODO Auto-generated method stub
211 * @see org.eclipse.debug.core.model.IDebugElement#getDebugTarget()
213 public IDebugTarget getDebugTarget() {
214 return fStackFrame.getDebugTarget();
218 * @see org.eclipse.debug.core.model.IDebugElement#getLaunch()
220 public ILaunch getLaunch() {
221 return getDebugTarget().getLaunch();
225 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
227 public Object getAdapter(Class adapter) {
231 public boolean hasValueChanged() throws DebugException {
235 public void setValueChanged(boolean changed) {
236 fHasChanged = changed;
240 * ONLY FOR net.sourceforge.phpdt.internal.debug.core.model.PHPDBGEvalString#copyItems(PHPVariable, PHPValue)
242 protected void setVariables(Vector variables) {
243 fVariables = variables;
247 * ONLY FOR net.sourceforge.phpdt.internal.debug.core.model.PHPDBGEvalString#copyItems(PHPVariable, PHPValue)
249 protected Object clone() throws CloneNotSupportedException {
250 PHPValue val = new PHPValue();
251 val.fValueType = fValueType;
252 val.fValueString = fValueString;
253 val.fVariables = fVariables;
254 val.fStackFrame = fStackFrame;
255 val.fHasChanged = fHasChanged;
256 val.fSorted = fSorted;