/********************************************************************** 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 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; 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 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#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#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 getDebugTarget().getModelIdentifier(); } /** * @see org.eclipse.debug.core.model.IDebugElement#getDebugTarget() */ public IDebugTarget getDebugTarget() { return fStackFrame.getDebugTarget(); } /** * @see org.eclipse.debug.core.model.IDebugElement#getLaunch() */ public ILaunch getLaunch() { return getDebugTarget().getLaunch(); } /** * @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#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#supportsValueModification() */ public boolean supportsValueModification() { return true; } /** * @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) */ public Object getAdapter(Class adapter) { return Platform.getAdapterManager().getAdapter(this, adapter); } public String toString() { int type=-1; String str=""; switch (getReferenceType()) { case PHPValue.PEVT_ARRAY : int elements=fValue.getVariables().length; switch (elements) { case 0: str= this.getName() + " [no elements]"; break; case 1: str= this.getName() + " [1 element]"; break; default: 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; } }