From 90fd607e2a3767dc747466d2fe872ac36e7ae428 Mon Sep 17 00:00:00 2001 From: robekras Date: Mon, 28 Mar 2011 18:40:12 +0000 Subject: [PATCH] 1) Indeces of arrays will be surrounded by [''], so it's easier to distinguish between members of arrays and members of objects. 2) Introduced XDebugWatchExpressionFactoryAdapter, so child variables can be added to watch expressions by their fully qualified name. --- .../META-INF/MANIFEST.MF | 1 + .../xdebug/php/model/XDebugStackFrame.java | 2 +- .../xdebug/php/model/XDebugVariable.java | 124 +++++++++++++------- .../model/XDebugWatchExpressionFactoryAdapter.java | 13 ++ 4 files changed, 96 insertions(+), 44 deletions(-) create mode 100644 net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugWatchExpressionFactoryAdapter.java diff --git a/net.sourceforge.phpeclipse.xdebug.core/META-INF/MANIFEST.MF b/net.sourceforge.phpeclipse.xdebug.core/META-INF/MANIFEST.MF index 7541cd5..d0060f8 100644 --- a/net.sourceforge.phpeclipse.xdebug.core/META-INF/MANIFEST.MF +++ b/net.sourceforge.phpeclipse.xdebug.core/META-INF/MANIFEST.MF @@ -16,3 +16,4 @@ Bundle-RequiredExecutionEnvironment: J2SE-1.4 Bundle-ActivationPolicy: lazy Bundle-ManifestVersion: 2 Bundle-Vendor: PHPEclipse project team +Import-Package: org.eclipse.debug.ui.actions diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugStackFrame.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugStackFrame.java index 0ff0e23..4f56af6 100644 --- a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugStackFrame.java +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugStackFrame.java @@ -582,7 +582,7 @@ public class XDebugStackFrame extends XDebugElement implements IStackFrame, Com } public boolean setVariableValue(XDebugVariable variable, String expression) throws DebugException { - return ((XDebugTarget) getDebugTarget()).setVarValue("$" + variable.getName(), expression); + return ((XDebugTarget) getDebugTarget()).setVarValue(variable.getName(), expression); } public Node eval(String expression) throws DebugException { diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugVariable.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugVariable.java index 31b9b0d..8a1b7f8 100644 --- a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugVariable.java +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugVariable.java @@ -8,6 +8,7 @@ package net.sourceforge.phpeclipse.xdebug.php.model; import net.sourceforge.phpeclipse.xdebug.core.PHPDebugUtils; +import org.eclipse.core.runtime.Platform; import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.model.IValue; import org.eclipse.debug.core.model.IVariable; @@ -26,75 +27,112 @@ public class XDebugVariable extends XDebugElement implements IVariable { private XDebugAbstractValue fValue; private String fFacet; private XDebugVariable fParent; // The parent variable (a back link) + private String fTypeName; + - /** * Constructs a variable contained in the given stack frame * with the given name. - * + * * @param frame owning stack frame * @param name variable name */ public XDebugVariable(XDebugStackFrame frame, Node property, XDebugVariable parent) throws DebugException { super((XDebugTarget) frame.getDebugTarget()); - + this.fParent = parent; - + if (frame != null ) { fFrame = frame; } - if (parent == null) { - fName = "$" + PHPDebugUtils.getAttributeValue(property,"name"); // Prepend the variable 'short' name with the php variable prefix '$' + String name = PHPDebugUtils.getAttributeValue (property, "name"); // Get the name of the variable (XDebug submits the name without the '$' prefix) + + if (fParent == null) { + fName = "$" + name; // Prepend the variable 'short' name with the php variable prefix '$' } else { - fName = PHPDebugUtils.getAttributeValue(property,"name"); // If this is the root variable don't prepend prefix '$' + if (fParent.isArray ()) { + fName = "['" + name + "']"; + } + else if (fParent.isObject ()) { + fName = name; + } + else { + fName = name; // If this is the root variable don't prepend prefix '$' + } } - + fNameFull = PHPDebugUtils.getAttributeValue(property,"fullname"); // The fullname has the '$' prepended, but it is the fully qualified name // e.g. $myvar->child->a_variable. The fullname would be suitable to take for // the setting a watch expression - + if ("".equals(fName)) { - fName = PHPDebugUtils.getAttributeValue(property,"address"); + fName = PHPDebugUtils.getAttributeValue (property, "address"); + } + + fFacet = PHPDebugUtils.getAttributeValue (property, "facet"); + fTypeName = PHPDebugUtils.getAttributeValue (property, "type"); + + if (fTypeName.equals ("int")) { + fValue = new XDebugIntValue (frame, property); + } + else if (fTypeName.equals ("float")) { + fValue = new XDebugFloatValue (frame, property); + } + else if (fTypeName.equals ("bool")) { + fValue = new XDebugBooleanValue (frame, property); + } + else if (fTypeName.equals ("string")) { + fValue = new XDebugStringValue (frame, property); + } + else if (fTypeName.equals ("array")) { + fValue = new XDebugArrayValue (frame, property, this); + } + else if (fTypeName.equals ("object")) { + fValue = new XDebugObjectValue (frame, property, this); + } + else if (fTypeName.equals ("resource")) { + fValue = new XDebugResourceValue (frame, property); + } + else { + fValue = new XDebugValue (frame, property); } - - fFacet = PHPDebugUtils.getAttributeValue(property, "facet"); - - String typeName = PHPDebugUtils.getAttributeValue(property, "type"); - - if (typeName.equals("int") ) - fValue = new XDebugIntValue(frame, property); - else if (typeName.equals("float") ) - fValue = new XDebugFloatValue(frame, property); - else if (typeName.equals("bool") ) - fValue = new XDebugBooleanValue(frame, property); - else if (typeName.equals("string") ) - fValue = new XDebugStringValue(frame, property); - else if (typeName.equals("array") ) - fValue = new XDebugArrayValue(frame, property, this); - else if (typeName.equals("object") ) - fValue = new XDebugObjectValue(frame, property, this); - else if (typeName.equals("resource") ) - fValue = new XDebugResourceValue(frame, property); - else - fValue = new XDebugValue(frame, property); - } - + } + + public boolean isArray () { + return fTypeName.equals ("array"); + } + + public boolean isObject () { + return fTypeName.equals ("object"); + } + + /** + * @see org.eclipse.core.runtime.IAdaptable#getAdapter(Class) + */ + public Object getAdapter(Class adapter) { + if (adapter.getName ().equals ("org.eclipse.debug.ui.actions.IWatchExpressionFactoryAdapter")) { + return new XDebugWatchExpressionFactoryAdapter (); + } + + return Platform.getAdapterManager().getAdapter (this, adapter); + } + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IVariable#getValue() */ public IValue getValue() { return fValue; } - + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IVariable#getName() */ - public String getName() { + public String getName () { return fName; } - + /* * @return The fully qualified name of the variable */ @@ -108,14 +146,14 @@ public class XDebugVariable extends XDebugElement implements IVariable { public String getReferenceTypeName() throws DebugException { return fValue.getReferenceTypeName(); } - + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IVariable#hasValueChanged() */ public boolean hasValueChanged() throws DebugException { return fValue.hasChanged(); } - + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IValueModification#setValue(java.lang.String) */ @@ -124,7 +162,7 @@ public class XDebugVariable extends XDebugElement implements IVariable { fValue.setValue(expression); } } - + /* (non-Javadoc) * @see org.eclipse.debug.core.model.IValueModification#setValue(org.eclipse.debug.core.model.IValue) */ @@ -162,15 +200,15 @@ public class XDebugVariable extends XDebugElement implements IVariable { public boolean verifyValue(IValue value) throws DebugException { return false; } - + public String getValueString() throws DebugException { return fValue.getValueString(); } - + public String getVisibility() { return fFacet; } - + /** * */ @@ -184,4 +222,4 @@ public class XDebugVariable extends XDebugElement implements IVariable { public void setParent(XDebugVariable parent) { this.fParent = parent; } -} \ No newline at end of file +} diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugWatchExpressionFactoryAdapter.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugWatchExpressionFactoryAdapter.java new file mode 100644 index 0000000..0658295 --- /dev/null +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugWatchExpressionFactoryAdapter.java @@ -0,0 +1,13 @@ +package net.sourceforge.phpeclipse.xdebug.php.model; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.model.IVariable; +import org.eclipse.debug.ui.actions.IWatchExpressionFactoryAdapter; + + +public class XDebugWatchExpressionFactoryAdapter implements IWatchExpressionFactoryAdapter { + public String createWatchExpression (IVariable variable) throws CoreException + { + return ((XDebugVariable) variable).getNameFull (); + } +} -- 1.7.1