X-Git-Url: http://git.phpeclipse.com 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 index 7534052..fdb3b81 100644 --- 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 @@ -8,9 +8,12 @@ http://www.eclipse.org/legal/cpl-v10.html Contributors: IBM Corporation - Initial implementation Vicente Fernando - www.alfersoft.com.ar + Christian Perkonig - cperkonig@gmx.at **********************************************************************/ package net.sourceforge.phpdt.internal.debug.core.model; +import java.util.Vector; + import org.eclipse.core.runtime.Platform; import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.ILaunch; @@ -20,130 +23,163 @@ 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; - } + + private PHPValue fValue; + private String fName; + private PHPStackFrame fStackFrame; + private PHPVariable fParent; + private String fLongName; + + PHPVariable(){ + this(null,"",null,"",PHPValue.PEVT_UNKNOWN,null); + } + + PHPVariable(PHPStackFrame frame,String name, PHPVariable parent,String value,int valueType,Vector subitems) + { + this.fStackFrame=frame; + this.fValue=new PHPValue(frame,value,valueType,subitems); + this.fParent=parent; + setName(name); + } + + private void setName(String name) { + if ((fParent==null) || (fParent.getName()=="")) { + fLongName=name; + fName=name; + return; + } + switch (fParent.getReferenceType()) { + case PHPValue.PEVT_ARRAY : + fName="['"+name+"']"; + fLongName=fParent.getLongName()+fName; + break; + case PHPValue.PEVT_OBJECT : + fName=name; + fLongName=fParent.getLongName()+"."+fName; + break; + default : + fName=name; + fLongName=name; + break; + } + } + /** + * @see org.eclipse.debug.core.model.IVariable#getValue() + */ + public IValue getValue() { + return fValue; + } - /** - * @see org.eclipse.debug.core.model.IVariable#getReferenceTypeName() - */ - public String getReferenceTypeName() { - return "RefTypeName"; - } + /** + * @see org.eclipse.debug.core.model.IVariable#getfName() + */ + public String getName() { + return fName; + } + + public PHPVariable getParent() + { + return fParent; + } + + public void setParent(PHPVariable parent) + { + this.fParent=parent; + fLongName=parent.getLongName()+fName; + } + + public String getLongName() { + return fLongName; + } - /** - * @see org.eclipse.debug.core.model.IVariable#hasValueChanged() - */ - public boolean hasValueChanged() throws DebugException { - return false; - } + /** + * @see org.eclipse.debug.core.model.IVariable#getReferenceTypefName() + */ + public String getReferenceTypeName() { + return fValue.getReferenceTypeName(); + } + + public int getReferenceType() { + return fValue.getReferenceType(); + } + + public int setReferenceType(int type) { + return ((PHPValue) getValue()).setReferenceType(type); + } - /** + /** + * @see org.eclipse.debug.core.model.IVariable#hasValueChanged() + */ + public boolean hasValueChanged() throws DebugException { + // TODO Auto-generated method stub + return false; + } + + /** * @see org.eclipse.debug.core.model.IDebugElement#getModelIdentifier() */ public String getModelIdentifier() { - return this.getDebugTarget().getModelIdentifier(); + return getDebugTarget().getModelIdentifier(); } /** * @see org.eclipse.debug.core.model.IDebugElement#getDebugTarget() */ public IDebugTarget getDebugTarget() { - return stackFrame.getDebugTarget(); + return fStackFrame.getDebugTarget(); } /** * @see org.eclipse.debug.core.model.IDebugElement#getLaunch() */ public ILaunch getLaunch() { - return this.getDebugTarget().getLaunch(); + return 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#setValue(java.lang.String) + */ + public void setValue(String expression) throws DebugException { + String evalString; + if(fValue.getReferenceType()==PHPValue.PEVT_STRING) + evalString=fLongName+"=\""+expression+"\""; + else + evalString=fLongName+"="+expression; + PHPVariable[] vars=fStackFrame.getPHPDBGProxy().eval(fStackFrame,evalString); + setValue(vars[0].fValue); + } - /** - * @see org.eclipse.debug.core.model.IValueModification#supportsValueModification() - */ - public boolean supportsValueModification() { - return false; - } + /** + * @see org.eclipse.debug.core.model.IValueModification#setValue(org.eclipse.debug.core.model.IValue) + */ + public void setValue(IValue value) throws DebugException { + // TODO Auto-generated method stub + this.fValue=(PHPValue)value; + } - /** - * @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#supportsValueModification() + */ + public boolean supportsValueModification() { + return true; + } - /** - * @see org.eclipse.debug.core.model.IValueModification#verifyValue(IValue) - */ - public boolean verifyValue(IValue value) throws DebugException { - return false; - } + /** + * @see org.eclipse.debug.core.model.IValueModification#verifyValue(java.lang.String) + */ + public boolean verifyValue(String expression) throws DebugException { + // TODO Auto-generated method stub + return true; + } + + /** + * @see org.eclipse.debug.core.model.IValueModification#verifyValue(org.eclipse.debug.core.model.IValue) + */ + public boolean verifyValue(IValue value) throws DebugException { + // TODO Auto-generated method stub + return false; + } /** * @see org.eclipse.core.runtime.IAdaptable#getAdapter(Class) @@ -151,78 +187,40 @@ public class PHPVariable implements IVariable { public Object getAdapter(Class adapter) { return Platform.getAdapterManager().getAdapter(this, adapter); } - + public String toString() { + int type=-1; + String str=""; - 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) { + switch (getReferenceType()) + { + case PHPValue.PEVT_ARRAY : + int elements=fValue.getVariables().length; + switch (elements) { case 0: - return this.getName() + " [no elements]"; + str= this.getName() + " [no elements]"; + break; case 1: - return this.getName() + " [1 element]"; + str= this.getName() + " [1 element]"; + break; 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; - } + str= this.getName() + " [" + elements + " elements]"; + break; + } + break; + case PHPValue.PEVT_OBJECT : + str =this.getName() + " [class: " + fValue.getValueString() + "]"; + break; + case PHPValue.PEVT_STRING : + str =this.getName() + " = \"" + fValue.getValueString() +"\"" ; + break; + case PHPValue.PEVT_SOFTREF : + default : + str =this.getName() + " = " + fValue.getValueString(); + break; + } + + return str; + } - - public String getClassName() { - return className; - } }