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 **********************************************************************/
12 package net.sourceforge.phpdt.internal.debug.core.model;
14 import org.eclipse.core.runtime.Platform;
15 import org.eclipse.debug.core.DebugException;
16 import org.eclipse.debug.core.ILaunch;
17 import org.eclipse.debug.core.model.IDebugTarget;
18 import org.eclipse.debug.core.model.IValue;
19 import org.eclipse.debug.core.model.IVariable;
21 public class PHPVariable implements IVariable {
23 private boolean isBoolean;
24 private boolean isString;
25 private boolean isResource;
26 private boolean isObject;
27 private boolean isLocal;
28 private PHPStackFrame stackFrame;
30 private String objectId;
31 private String className;
32 private PHPValue value;
33 private PHPVariable parent;
35 public PHPVariable(PHPStackFrame stackFrame, String name, String scope) {
36 this.initialize(stackFrame, name, scope, null, new PHPValue(this), "", "string");
39 public PHPVariable(PHPStackFrame stackFrame, String name, String scope, String value, String type, boolean hasChildren, String objectId, String className) {
40 this.initialize(stackFrame, name, scope, objectId, new PHPValue(this, value, type, hasChildren), className, type);
43 public PHPVariable(PHPStackFrame stackFrame, String name, String scope, boolean isRef, PHPValue varPHP) {
45 this.initialize(stackFrame, name, scope, "-1", varPHP, "", "string");
47 this.initialize(stackFrame, name, scope, "-1", new PHPValue(this), "", "string");
50 protected final void initialize(PHPStackFrame stackFrame, String name, String scope, String objectId, PHPValue value, String className, String typeName) {
51 this.stackFrame = stackFrame;
54 this.objectId = objectId;
56 this.isLocal = scope.equals("local");
58 this.isObject = typeName.equals("object");
59 this.isResource = typeName.equals("resource");
60 this.isBoolean = typeName.equals("boolean");
61 this.isString = typeName.equals("string");
63 this.className = className;
67 * @see org.eclipse.debug.core.model.IVariable#getValue()
69 public IValue getValue() {
74 * @see org.eclipse.debug.core.model.IVariable#getName()
76 public String getName() {
81 * @see org.eclipse.debug.core.model.IVariable#getReferenceTypeName()
83 public String getReferenceTypeName() {
88 * @see org.eclipse.debug.core.model.IVariable#hasValueChanged()
90 public boolean hasValueChanged() throws DebugException {
95 * @see org.eclipse.debug.core.model.IDebugElement#getModelIdentifier()
97 public String getModelIdentifier() {
98 return this.getDebugTarget().getModelIdentifier();
102 * @see org.eclipse.debug.core.model.IDebugElement#getDebugTarget()
104 public IDebugTarget getDebugTarget() {
105 return stackFrame.getDebugTarget();
109 * @see org.eclipse.debug.core.model.IDebugElement#getLaunch()
111 public ILaunch getLaunch() {
112 return this.getDebugTarget().getLaunch();
116 * @see org.eclipse.debug.core.model.IValueModification#setValue(String)
118 public void setValue(String expression) throws DebugException {
122 * @see org.eclipse.debug.core.model.IValueModification#setValue(IValue)
124 public void setValue(IValue value) throws DebugException {
128 * @see org.eclipse.debug.core.model.IValueModification#supportsValueModification()
130 public boolean supportsValueModification() {
135 * @see org.eclipse.debug.core.model.IValueModification#verifyValue(String)
137 public boolean verifyValue(String expression) throws DebugException {
142 * @see org.eclipse.debug.core.model.IValueModification#verifyValue(IValue)
144 public boolean verifyValue(IValue value) throws DebugException {
149 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(Class)
151 public Object getAdapter(Class adapter) {
152 return Platform.getAdapterManager().getAdapter(this, adapter);
155 public String toString() {
157 if(this.isObject()) {
158 return this.getName() + " [class: " + this.getClassName() + "]";
159 } else if(this.isResource()) {
160 return this.getName() + " [resource: " + this.getClassName() + "] = " + ((PHPValue) this.getValue());
161 } else if (this.isHashValue()) {
162 int elements= Integer.parseInt(((PHPValue) this.getValue()).getValueString());
165 return this.getName() + " [no elements]";
167 return this.getName() + " [1 element]";
169 return this.getName() + " [" + elements + " elements]";
172 return this.getName() + " = " + ((PHPValue) this.getValue());
177 public PHPStackFrame getStackFrame() {
181 public PHPVariable getParent() {
185 public void setParent(PHPVariable parent) {
186 this.parent = parent;
189 public String getQualifiedName() {
190 return this.getName();
193 public boolean isBoolean() {
197 public boolean isResource() {
201 public boolean isString() {
205 public boolean isLocal() {
209 public boolean isObject() {
213 public String getObjectId() {
217 public boolean isHashValue() {
219 return ((PHPValue) this.getValue()).hasVariables();
220 } catch (DebugException e) {
225 public String getClassName() {