First submit for debug plugin
[phpeclipse.git] / net.sourceforge.phpeclipse.debug.core / src / net / sourceforge / phpdt / internal / debug / core / model / PHPVariable.java
diff --git a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPVariable.java b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPVariable.java
new file mode 100644 (file)
index 0000000..7534052
--- /dev/null
@@ -0,0 +1,228 @@
+/**********************************************************************
+Copyright (c) 2000, 2002 IBM Corp. and others.
+All rights reserved. This program and the accompanying materials
+are made available under the terms of the Common Public License v1.0
+which accompanies this distribution, and is available at
+http://www.eclipse.org/legal/cpl-v10.html
+
+Contributors:
+    IBM Corporation - Initial implementation
+    Vicente Fernando - www.alfersoft.com.ar
+**********************************************************************/
+package net.sourceforge.phpdt.internal.debug.core.model;
+
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.model.IDebugTarget;
+import org.eclipse.debug.core.model.IValue;
+import org.eclipse.debug.core.model.IVariable;
+
+public class PHPVariable implements IVariable {
+
+       private boolean isBoolean;
+       private boolean isString;
+       private boolean isResource;
+    private boolean isObject;
+    private boolean isLocal;
+    private PHPStackFrame stackFrame;
+    private String name;
+    private String objectId;
+       private String className;
+    private PHPValue value;
+    private PHPVariable parent;
+
+    public PHPVariable(PHPStackFrame stackFrame, String name, String scope) {
+        this.initialize(stackFrame, name, scope, null, new PHPValue(this), "", "string");
+    }
+
+    public PHPVariable(PHPStackFrame stackFrame, String name, String scope, String value, String type, boolean hasChildren, String objectId, String className) {
+        this.initialize(stackFrame, name, scope, objectId, new PHPValue(this, value, type, hasChildren), className, type);
+    }
+
+       public PHPVariable(PHPStackFrame stackFrame, String name, String scope, boolean isRef, PHPValue varPHP) {
+               if(isRef)
+                       this.initialize(stackFrame, name, scope, "-1", varPHP, "", "string");
+               else
+                       this.initialize(stackFrame, name, scope, "-1", new PHPValue(this), "", "string");
+       }
+
+    protected final void initialize(PHPStackFrame stackFrame, String name, String scope, String objectId, PHPValue value, String className, String typeName) {
+        this.stackFrame = stackFrame;
+        this.value = value;
+        this.name = name;
+        this.objectId = objectId;
+        // scope
+               this.isLocal = scope.equals("local");
+               // type
+               this.isObject = typeName.equals("object");
+               this.isResource = typeName.equals("resource");
+               this.isBoolean = typeName.equals("boolean");
+               this.isString = typeName.equals("string");
+               
+        this.className = className;
+    }
+
+    /**
+     * @see org.eclipse.debug.core.model.IVariable#getValue()
+     */
+    public IValue getValue() {
+        return value;
+    }
+
+    /**
+     * @see org.eclipse.debug.core.model.IVariable#getName()
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * @see org.eclipse.debug.core.model.IVariable#getReferenceTypeName()
+     */
+    public String getReferenceTypeName() {
+        return "RefTypeName";
+    }
+
+    /**
+     * @see org.eclipse.debug.core.model.IVariable#hasValueChanged()
+     */
+    public boolean hasValueChanged() throws DebugException {
+        return false;
+    }
+
+    /**
+     * @see org.eclipse.debug.core.model.IDebugElement#getModelIdentifier()
+     */
+    public String getModelIdentifier() {
+        return this.getDebugTarget().getModelIdentifier();
+    }
+
+    /**
+     * @see org.eclipse.debug.core.model.IDebugElement#getDebugTarget()
+     */
+    public IDebugTarget getDebugTarget() {
+        return stackFrame.getDebugTarget();
+    }
+
+    /**
+     * @see org.eclipse.debug.core.model.IDebugElement#getLaunch()
+     */
+    public ILaunch getLaunch() {
+        return this.getDebugTarget().getLaunch();
+    }
+
+    /**
+     * @see org.eclipse.debug.core.model.IValueModification#setValue(String)
+     */
+    public void setValue(String expression) throws DebugException {
+    }
+
+    /**
+     * @see org.eclipse.debug.core.model.IValueModification#setValue(IValue)
+     */
+    public void setValue(IValue value) throws DebugException {
+    }
+
+    /**
+     * @see org.eclipse.debug.core.model.IValueModification#supportsValueModification()
+     */
+    public boolean supportsValueModification() {
+        return false;
+    }
+
+    /**
+     * @see org.eclipse.debug.core.model.IValueModification#verifyValue(String)
+     */
+    public boolean verifyValue(String expression) throws DebugException {
+        return false;
+    }
+
+    /**
+     * @see org.eclipse.debug.core.model.IValueModification#verifyValue(IValue)
+     */
+    public boolean verifyValue(IValue value) throws DebugException {
+        return false;
+    }
+
+    /**
+     * @see org.eclipse.core.runtime.IAdaptable#getAdapter(Class)
+     */
+    public Object getAdapter(Class adapter) {
+        return Platform.getAdapterManager().getAdapter(this, adapter);
+    }
+
+    public String toString() {
+       
+               if(this.isObject()) {
+                       return this.getName() + " [class: " + this.getClassName() + "]";
+               } else if(this.isResource()) {
+                       return this.getName() + " [resource: " + this.getClassName() + "] = " + ((PHPValue) this.getValue());
+               } else if (this.isHashValue()) {
+               int elements= Integer.parseInt(((PHPValue) this.getValue()).getValueString());
+               switch (elements) {
+                       case 0:
+                                       return this.getName() + " [no elements]";
+                               case 1:
+                                       return this.getName() + " [1 element]";
+                               default:
+                                       return this.getName() + " [" + elements + " elements]";
+               }
+        } else {
+                       return this.getName() + " = " + ((PHPValue) this.getValue());
+        }
+
+    }
+
+    public PHPStackFrame getStackFrame() {
+        return stackFrame;
+    }
+
+    public PHPVariable getParent() {
+        return parent;
+    }
+
+    public void setParent(PHPVariable parent) {
+        this.parent = parent;
+    }
+
+    public String getQualifiedName() {
+        return this.getName();
+    }
+
+       public boolean isBoolean() {
+               return isBoolean;
+       }
+
+       public boolean isResource() {
+               return isResource;
+       }
+       
+       public boolean isString() {
+               return isString;
+       }
+
+    public boolean isLocal() {
+        return isLocal;
+    }
+
+    public boolean isObject() {
+        return isObject;
+    }
+
+    public String getObjectId() {
+        return objectId;
+    }
+
+    public boolean isHashValue() {
+        try {
+                       return ((PHPValue) this.getValue()).hasVariables();
+        } catch (DebugException e) {
+                       return false; 
+        }
+    }
+
+       public String getClassName() {
+               return className;
+       }
+}