From: toshihiro Date: Thu, 9 Aug 2007 01:09:49 +0000 (+0000) Subject: Modified: 1764120 - Variables View doesn't show global vars in class context X-Git-Url: http://secure.phpeclipse.com Modified: 1764120 - Variables View doesn't show global vars in class context --- diff --git a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/PHPDBGInterface.java b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/PHPDBGInterface.java index 79a9ae5..5769aab 100644 --- a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/PHPDBGInterface.java +++ b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/PHPDBGInterface.java @@ -14,7 +14,6 @@ package net.sourceforge.phpdt.internal.debug.core; import java.io.BufferedReader; import java.io.IOException; import java.io.OutputStream; -import java.util.Arrays; import java.util.Collections; import java.util.Vector; @@ -47,7 +46,6 @@ public class PHPDBGInterface { private OutputStream os; // The stream which goes to DBG private boolean shouldStop = false; private String evalRet = new String(""); - //private String serGlobals = new String(""); private int rawCounter = 1000; // An rawData frame ID counter private PHPDBGProxy proxy = null; private int lastCmd = -1; @@ -427,64 +425,43 @@ public class PHPDBGInterface { PHPDBGFrame DBGFrame1; PHPDBGEvalString evalStr; + // get global variables (and assign them to 'main()' stackframe) Vector globalList = new Vector(); - // IStackFrame[] stacks = stack.getThread().getStackFrames(); - // ( PHPStackFrame.getThread().getStackFrames() returns DBGStackList ) - if (DBGStackList.length > 1) { - // get global variables (and assign them to 'main()' stackframe) - globalList = getVariables(DBGStackList[DBGStackList.length - 1], PHPDBGBase.GLOBAL_SCOPE_ID); - if (!globalList.isEmpty()) { - // remove unexpected '$this=?' variable - PHPVariable var = (PHPVariable) globalList.get(0); - PHPValue val = (PHPValue) var.getValue(); - Vector workList = val.getChildVariables(); - for (int i = 0; i < workList.size(); i++) { - if (((PHPVariable) workList.get(i)).getName().equals("$this")) { - workList.remove(i); - break; - } + globalList = getVariables(DBGStackList[DBGStackList.length - 1], PHPDBGBase.GLOBAL_SCOPE_ID); + if (!globalList.isEmpty()) { + // remove unexpected '$this=?' variable + PHPVariable var = (PHPVariable) globalList.get(0); + PHPValue val = (PHPValue) var.getValue(); + Vector workList = val.getChildVariables(); + for (int i = 0; i < workList.size(); i++) { + if (((PHPVariable) workList.get(i)).getName().equals("$this")) { + workList.remove(i); + break; } - var.setName(GlobalVariablesTitle); - var.setModifiable(false); } + var.setName(GlobalVariablesTitle); + var.setModifiable(false); } -// DBGPacket = new PHPDBGPacket (PHPDBGBase.DBGA_REQUEST); // -// DBGFrame1 = new PHPDBGFrame (PHPDBGBase.FRAME_EVAL); // -// -// DBGFrame1.addInt (0); // istr = raw data ID -// DBGFrame1.addInt (1); // scope_id = -1 means current location, 0 never used, +1 first depth -// -// DBGPacket.addFrame (DBGFrame1); // Add command data -// -// if (proxy.getSocket ().isClosed ()) { // Do we have a socket for DBG communication? -// return new Vector (); // No, then leave here with an empty vector -// } -// -// serGlobals = ""; -// DBGPacket.sendPacket (os); // Send the request to DBG -// -// waitResponse (1000); // Wait for the DBG response (1 second) -// flushAllPackets (); // Read and process the response from DBG -// -// evalStr = new PHPDBGEvalString (stack, serGlobals); // Process serialized variables -// DBGVarList = evalStr.getVariables (); - - int scopeID = stack.getScopeID(); - if (scopeID == PHPDBGBase.CURLOC_SCOPE_ID) { - // current stackframe - DBGVarList = getVariables(stack, PHPDBGBase.CURLOC_SCOPE_ID); - } else if ((scopeID == PHPDBGBase.CURLOC_SCOPE_ID + 1) && !globalList.isEmpty()) { + int scopeID = stack.getScopeID(); + if (!globalList.isEmpty() + && ((DBGStackList.length == 1) + || (scopeID == PHPDBGBase.CURLOC_SCOPE_ID + 1))) { // 'main()' stackframe PHPVariable var = (PHPVariable) globalList.get(0); PHPValue val = (PHPValue) var.getValue(); DBGVarList = val.getChildVariables(); return DBGVarList; + + } else if (scopeID == PHPDBGBase.CURLOC_SCOPE_ID) { + // current stackframe + DBGVarList = getVariables(stack, PHPDBGBase.CURLOC_SCOPE_ID); + } else { // back-trace stackframe - // Never: DBGVarList = getVariables(stack, scopeID); + DBGVarList = getVariables(stack, scopeID); // DBG 2.15.5 causes Application Error (on win32) in some cases - DBGVarList.clear(); + //DBGVarList.clear(); } if (DBGVarList.size() > 0) { // Did we get back variables? @@ -581,7 +558,11 @@ public class PHPDBGInterface { rawCounter++; DBGFrame1.addInt(rawCounter); // istr = raw data ID //DBGFrame1.addInt(1); // scope_id = -1 means current location, 0 never used, +1 first depth - DBGFrame1.addInt(stack.getScopeID()); + int scope_id = stack.getScopeID(); + if (DBGStackList.length == 1 || scope_id == PHPDBGBase.CURLOC_SCOPE_ID + 1) { + scope_id = PHPDBGBase.GLOBAL_SCOPE_ID; + } //- + DBGFrame1.addInt(scope_id); DBGFrame2.addInt(rawCounter); // FRAME_RAWDATA ID DBGFrame2.addInt(evalString.length() + 1); // length of rawdata (+ null char) @@ -1035,7 +1016,6 @@ public class PHPDBGInterface { evalRet = getRawFrameData (entirePack, dbg_eval_tmp[1]); // evalString = getRawFrameData (entirePack, dbg_eval_tmp[0]); // - //serGlobals = evalRet; // break; case PHPDBGBase.FRAME_BPS: // diff --git a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPStackFrame.java b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPStackFrame.java index c9cde49..19a0843 100644 --- a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPStackFrame.java +++ b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPStackFrame.java @@ -11,10 +11,9 @@ Contributors: **********************************************************************/ package net.sourceforge.phpdt.internal.debug.core.model; -import java.util.Arrays; +import java.util.Collections; import java.util.Vector; -import net.sourceforge.phpdt.internal.debug.core.PHPDBGBase; import net.sourceforge.phpdt.internal.debug.core.PHPDBGProxy; import org.eclipse.core.runtime.IAdaptable; @@ -40,7 +39,7 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa private int index; private int modno; private int scope_id; // scope id - private PHPVariable[] variables; // The array of variables TODO: better introduce a vector? + //private PHPVariable[] variables; // The array of variables TODO: better introduce a vector? private Vector varList = new Vector(); private String description; // The source file name with the full path on target/remote system private boolean fUpToDate; // Indicates whether the variable list within this stackframe is @@ -79,14 +78,14 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa * @param line * @param index */ - public PHPStackFrame (PHPThread thread, String file, int line, int index) { - super (null); + public PHPStackFrame(PHPThread thread, String file, int line, int index) { + super(null); this.lineNumber = line; - this.index = index; - this.file = file; - this.thread = thread; - this.fUpToDate = false; + this.index = index; + this.file = file; + this.thread = thread; + this.fUpToDate = false; } /** @@ -108,46 +107,45 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa /** * */ - public IThread getThread () { + public IThread getThread() { return thread; } /** * @param thread */ - public void setThread (PHPThread thread) { + public void setThread(PHPThread thread) { this.thread = thread; } /** * */ - private void setUpToDate (boolean upToDate) { + private void setUpToDate(boolean upToDate) { fUpToDate = upToDate; } /** * */ - private boolean isUpToDate () { + private boolean isUpToDate() { return fUpToDate; } /** * */ - public void setAvailable (boolean available) { + public void setAvailable(boolean available) { fAvailable = available; } /** * */ - public boolean isAvailable () { + public boolean isAvailable() { return fAvailable; } - /** * @see IAdaptable#getAdapter(Class) */ @@ -161,28 +159,26 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa /** * - * */ - private void resetHasChangedInfo (Vector varList) { + private void resetHasChangedInfo(Vector varList) { int n; PHPVariable var; - PHPValue val; + PHPValue val; - for (n = 0; n < varList.size (); n++) { // For every variable in 'DBG list' - var = (PHPVariable) varList.get (n); // Get the variable - val = (PHPValue) var.getValue (); // Get the variable's value + for (n = 0; n < varList.size(); n++) { // For every variable in 'DBG list' + var = (PHPVariable) varList.get(n); // Get the variable + val = (PHPValue) var.getValue(); // Get the variable's value try { - if (val.hasVariables ()) { // Do we have other variables within the value - if (!hasRecursion (var)) { // Is this variable (value) branch recursive? - resetHasChangedInfo (val.getChildVariables ()); // No, go into branch + if (val.hasVariables()) { // Do we have other variables within the value + if (!hasRecursion(var)) { // Is this variable (value) branch recursive? + resetHasChangedInfo(val.getChildVariables()); // No, go into branch } } - } - catch (DebugException e) { // That's, because of the hasVariables method + } catch (DebugException e) { // That's, because of the hasVariables method } - var.setValueChanged (false); // Reset the 'has changed' flag + var.setValueChanged(false); // Reset the 'has changed' flag } } @@ -200,26 +196,26 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa *
  • true if the PHPValue is * */ - private boolean hasRecursion (PHPVariable var) { + private boolean hasRecursion(PHPVariable var) { PHPVariable parentVar; - PHPValue val; + PHPValue val; - val = (PHPValue) var.getValue (); // Get the PHPValue from the current PHPVariable + val = (PHPValue) var.getValue(); // Get the PHPValue from the current PHPVariable - while (var != null) { // As long as we have PHPVariable - parentVar = var.getParent (); // Get the parent PHPVariable + while (var != null) { // As long as we have PHPVariable + parentVar = var.getParent(); // Get the parent PHPVariable - if (parentVar != null) { // Is there a parent? - if (parentVar.getValue ().equals (val)) { // Get the PHPValue for the parent PHPVariable and check + if (parentVar != null) { // Is there a parent? + if (parentVar.getValue().equals(val)) { // Get the PHPValue for the parent PHPVariable and check // whether it is the same - return true; // Return, if we have recursion + return true; // Return, if we have recursion } } var = parentVar; } - return false; // No recursion found + return false; // No recursion found } /** @@ -241,76 +237,73 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa * @param varListOld The 'static' list of variables which are to be updated. * @param varListNew The new list of (current) variables from DBG. */ - private void updateVariableList (Vector varListOld, Vector varListNew) - { - PHPVariable varOld; // The variable from the 'static' list - PHPVariable varNew; // The variable from the DBG list - PHPValue valOld; // The value of the current variable from 'static' list - PHPValue valNew; // The value of the current variable from DBG list - int n; // Index for the DBG list - int o; // Index for the static list + private void updateVariableList(Vector varListOld, Vector varListNew) { + PHPVariable varOld; // The variable from the 'static' list + PHPVariable varNew; // The variable from the DBG list + PHPValue valOld; // The value of the current variable from 'static' list + PHPValue valNew; // The value of the current variable from DBG list + int n; // Index for the DBG list + int o; // Index for the static list // Add the variables (and childs) to the static list if they are new // and update the values of variables which are already existend within // the 'static' list. - for (n = 0; n < varListNew.size (); n++) { // For every variable in 'DBG list' - varNew = (PHPVariable) varListNew.get (n); // Get the DBG variable + for (n = 0; n < varListNew.size(); n++) { // For every variable in 'DBG list' + varNew = (PHPVariable) varListNew.get(n); // Get the DBG variable - for (o = 0; o < varListOld.size (); o++) { // For every variable in static list - varOld = (PHPVariable) varListOld.get (o); // Get the static variable + for (o = 0; o < varListOld.size(); o++) { // For every variable in static list + varOld = (PHPVariable) varListOld.get(o); // Get the static variable - if (varNew.getName ().equals (varOld.getName ())) { // Did we found the variable within the 'static' list? - valOld = (PHPValue) varOld.getValue (); // Get the value from 'static' - valNew = (PHPValue) varNew.getValue (); // Get the value from DBG + if (varNew.getName().equals(varOld.getName())) { // Did we found the variable within the 'static' list? + valOld = (PHPValue) varOld.getValue(); // Get the value from 'static' + valNew = (PHPValue) varNew.getValue(); // Get the value from DBG try { - if (valOld.hasVariables () || // If the 'static' value has child variables - valNew.hasVariables ()) { // or if the DBG value has child variables - if (!hasRecursion (varOld) && - !hasRecursion (varNew)) { // Both branches should not have a recursion - updateVariableList (valOld.getChildVariables (), // Update the variable list for the child variables - valNew.getChildVariables ()); + if (valOld.hasVariables() || // If the 'static' value has child variables + valNew.hasVariables()) { // or if the DBG value has child variables + if (!hasRecursion(varOld) && !hasRecursion(varNew)) { // Both branches should not have a recursion + updateVariableList(valOld.getChildVariables(), // Update the variable list for the child variables + valNew.getChildVariables()); } - } - else if (!valOld.getValueString ().equals (valNew.getValueString ())) { // Has the value changed? - valOld.setValueString (valNew.getValueString ()); // Yes, set the 'static' value (variable) to the new value - varOld.setValueChanged (true); // and set the 'has changed' flag, so that the variable view - // could show the user the changed status with a different - // color + } else if (!valOld.getValueString().equals( + valNew.getValueString())) { // Has the value changed? + valOld.setValueString(valNew.getValueString()); // Yes, set the 'static' value (variable) to the new value + varOld.setValueChanged(true); // and set the 'has changed' flag, so that the variable view + // could show the user the changed status with a different + // color } //else { // varOld.setValueChanged (false); // Reset the 'has changed' flag //} - } - catch (DebugException e) { // That's, because of the hasVariables method + } catch (DebugException e) { // That's, because of the hasVariables method } - break; // Found the variable, + break; // Found the variable, } } - if (o == varListOld.size ()) { // Did we found the variable within the static list? - varListOld.add (varNew); // No, then add the DBG variable to the static list + if (o == varListOld.size()) { // Did we found the variable within the static list? + varListOld.add(varNew); // No, then add the DBG variable to the static list } } // Look for the variables we can remove from the 'static' list - for (o = 0; o < varListOld.size (); o++) { // For every variable in 'static' list - varOld = (PHPVariable) varListOld.get (o); // Get the static variable + for (o = 0; o < varListOld.size(); o++) { // For every variable in 'static' list + varOld = (PHPVariable) varListOld.get(o); // Get the static variable - for (n = 0; n < varListNew.size (); n++) { // For all variables in 'DBG' list - varNew = (PHPVariable) varListNew.get (n); // Get the variable from the 'DBG' list + for (n = 0; n < varListNew.size(); n++) { // For all variables in 'DBG' list + varNew = (PHPVariable) varListNew.get(n); // Get the variable from the 'DBG' list - if (varNew.getName ().equals (varOld.getName ())) { // Did we found the 'static' list variable within the 'DBG' list? - break; // Yes we found the variable, then leave the loop + if (varNew.getName().equals(varOld.getName())) { // Did we found the 'static' list variable within the 'DBG' list? + break; // Yes we found the variable, then leave the loop } } - if (n == varListNew.size ()) { // Did not find the 'static' list variable within the 'DBG' list? - varListOld.remove (o); // then remove the 'static' list variable from list - o -= 1; // Adjust the 'static' list index + if (n == varListNew.size()) { // Did not find the 'static' list variable within the 'DBG' list? + varListOld.remove(o); // then remove the 'static' list variable from list + o -= 1; // Adjust the 'static' list index } } } @@ -332,42 +325,42 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa resetHasChangedInfo(varList); updateVariableList(varList, this.getPHPDBGProxy().readVariables(this)); setUpToDate(true); - - variables = (PHPVariable[]) varList.toArray(new PHPVariable[varList.size()]); - Arrays.sort(variables, new PHPVariableComparator()); + Collections.sort(varList, new PHPVariableComparator()); + //variables = (PHPVariable[]) varList.toArray(new PHPVariable[varList.size()]); + //Arrays.sort(variables, new PHPVariableComparator()); } - return variables; // Give the array back to user interface + //return variables; // Give the array back to user interface + return (PHPVariable[]) varList.toArray(new PHPVariable[varList.size()]); } /** * */ - private PHPVariable findVariable (Vector varList, String varname) { - PHPVariable variable; - PHPValue value; - int i; + private PHPVariable findVariable(Vector varList, String varname) { + PHPVariable variable; + PHPValue value; + int i; - for (i = 0; i < varList.size (); i++) { // For all variables - variable = (PHPVariable) varList.get (i); // Get the variable - value = (PHPValue) variable.getValue (); // Get the value of the variable + for (i = 0; i < varList.size(); i++) { // For all variables + variable = (PHPVariable) varList.get(i); // Get the variable + value = (PHPValue) variable.getValue(); // Get the value of the variable try { - if (value.hasVariables ()) { // Does the variable/value have children - if (!hasRecursion (variable)) { // Don't follow recursive variable/values - variable = findVariable (value.getChildVariables (), varname); + if (value.hasVariables()) { // Does the variable/value have children + if (!hasRecursion(variable)) { // Don't follow recursive variable/values + variable = findVariable(value.getChildVariables(), + varname); if (variable != null) { return variable; } } + } else if ((variable.getName()).equals(varname)) { // + return variable; // } - else if ((variable.getName ()).equals (varname)) { // - return variable; // - } + } catch (DebugException e) { // That's, because of the hasVariables method } - catch (DebugException e) { // That's, because of the hasVariables method - } } return null; @@ -380,22 +373,22 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa * @param s The variable name we are looking for. * @return */ - public IVariable findVariable (String s) throws DebugException { - if (!isUpToDate ()) { - resetHasChangedInfo (varList); - updateVariableList (varList, this.getPHPDBGProxy ().readVariables (this)); - setUpToDate (true); - - variables = (PHPVariable[]) varList.toArray (new PHPVariable[varList.size ()]); + public IVariable findVariable(String s) throws DebugException { + if (!isUpToDate()) { + //resetHasChangedInfo(varList); + //updateVariableList(varList, this.getPHPDBGProxy().readVariables(this)); + //setUpToDate(true); + //variables = (PHPVariable[]) varList.toArray(new PHPVariable[varList.size()]); + getVariables(); } - return (findVariable (varList, s)); // Prefix the variable name with $ + return (findVariable(varList, s)); // Prefix the variable name with $ } /** * */ - public boolean hasVariables () throws DebugException { + public boolean hasVariables() throws DebugException { return true; // return (varList.size () > 0); } @@ -421,16 +414,15 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa public String getName() { StringBuffer name = new StringBuffer(); - if (!this.getDescription().equals ("")) { - name.append (this.getDescription ()); - } - else { - name.append (this.getFileName ()); + if (!this.getDescription().equals("")) { + name.append(this.getDescription()); + } else { + name.append(this.getFileName()); } - name.append (" [line "); - name.append (this.getLineNumber ()); - name.append ("]"); + name.append(" [line "); + name.append(this.getLineNumber()); + name.append("]"); return name.toString(); } @@ -440,7 +432,7 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa } public void setDescription(String desc) { - this.description= desc; + this.description = desc; } public String getDescription() { @@ -486,13 +478,13 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa /** * */ - public void stepInto () throws DebugException { - DebugEvent ev; + public void stepInto() throws DebugException { + DebugEvent ev; - setUpToDate (false); + setUpToDate(false); - thread.prepareForResume (DebugEvent.STEP_INTO); // Don't know why, but this is necessary - this.getPHPDBGProxy ().readStepIntoEnd (PHPStackFrame.this); + thread.prepareForResume(DebugEvent.STEP_INTO); // Don't know why, but this is necessary + this.getPHPDBGProxy().readStepIntoEnd(PHPStackFrame.this); // Commented out sending the RESUME event because it was already sent by prepareForResume. // The second RESUME event leads only to a little flickering within the variables view. @@ -508,13 +500,13 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa /** * */ - public void stepOver () throws DebugException { - DebugEvent ev; + public void stepOver() throws DebugException { + DebugEvent ev; - setUpToDate (false); + setUpToDate(false); - thread.prepareForResume (DebugEvent.STEP_OVER); - this.getPHPDBGProxy ().readStepOverEnd (PHPStackFrame.this) ; + thread.prepareForResume(DebugEvent.STEP_OVER); + this.getPHPDBGProxy().readStepOverEnd(PHPStackFrame.this); // See comment within the previous stepInto method. // @@ -525,19 +517,18 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa /** * */ - public void stepReturn () throws DebugException { - DebugEvent ev; + public void stepReturn() throws DebugException { + DebugEvent ev; - setUpToDate (false); + setUpToDate(false); - thread.prepareForResume (DebugEvent.STEP_RETURN); - this.getPHPDBGProxy ().readStepReturnEnd (PHPStackFrame.this) ; + thread.prepareForResume(DebugEvent.STEP_RETURN); + this.getPHPDBGProxy().readStepReturnEnd(PHPStackFrame.this); //ev = new DebugEvent (this.getThread (), DebugEvent.RESUME, DebugEvent.STEP_RETURN); //DebugPlugin.getDefault ().fireDebugEventSet (new DebugEvent[] { ev }); } - public boolean canResume() { return this.getThread().canResume(); } @@ -551,7 +542,7 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa } public void resume() throws DebugException { - setUpToDate (false); + setUpToDate(false); this.getThread().resume(); } @@ -574,16 +565,16 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa return index; } - public void setIndex (int index) { + public void setIndex(int index) { this.index = index; } public PHPDBGProxy getPHPDBGProxy() { PHPDebugTarget DebugTarget; - DebugTarget = (PHPDebugTarget) thread.getDebugTarget (); + DebugTarget = (PHPDebugTarget) thread.getDebugTarget(); - return DebugTarget.getPHPDBGProxy (); + return DebugTarget.getPHPDBGProxy(); } public void setFile(String file) { @@ -605,15 +596,14 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa *
  • 1 if the index of this stackfram is greater. * */ - public int compareTo (Object obj) - { - if (index < ((PHPStackFrame) obj).getIndex ()) { - return -1; - } - else if (index > ((PHPStackFrame) obj).getIndex ()) { - return 1; - } - - return 0; + public int compareTo(Object obj) { + //if (index < ((PHPStackFrame) obj).getIndex()) { + // return -1; + //} else if (index > ((PHPStackFrame) obj).getIndex()) { + // return 1; + //} + + //return 0; + return Integer.signum(index - ((PHPStackFrame) obj).getIndex()); } } diff --git a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPValue.java b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPValue.java index b736b8e..ef5d52d 100644 --- a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPValue.java +++ b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPValue.java @@ -1,18 +1,18 @@ /********************************************************************** -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 -**********************************************************************/ + 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.Collections; import java.util.Iterator; import java.util.Vector; @@ -22,7 +22,6 @@ import org.eclipse.debug.core.model.IDebugTarget; import org.eclipse.debug.core.model.IValue; import org.eclipse.debug.core.model.IVariable; - /** * PHPValue object belongs to a PHPVariable (is a member of PHPVariable). * A PHPValue itself can have PHPVariables as children. @@ -30,43 +29,46 @@ import org.eclipse.debug.core.model.IVariable; */ public class PHPValue implements IValue { - final static String[] PEV_NAMES = {"undefined", // 0 - "long", // 1 - "double", // 2 - "string", // 3 - "array", // 4 - "object", // 5 - "boolean", // 6 - "resource", // 7 - "reference", // 8 - "soft reference"}; // 9 + final static String[] PEV_NAMES = { + "undefined", // 0 + "long", // 1 + "double", // 2 + "string", // 3 + "array", // 4 + "object", // 5 + "boolean", // 6 + "resource", // 7 + "reference", // 8 + "soft reference" }; // 9 + final static int PEVT_UNKNOWN = 0; final static int PEVT_LONG = 1; - final static int PEVT_DOUBLE = 2; - final static int PEVT_STRING = 3; - final static int PEVT_ARRAY = 4; - final static int PEVT_OBJECT = 5; - final static int PEVT_BOOLEAN = 6; - final static int PEVT_RESOURCE = 7; - final static int PEVT_REF = 8; - final static int PEVT_SOFTREF = 9; - - private int fValueType; // The type of this value (see the PEVT_... values) - private boolean hasChildren; // This value (variable) has children (more variables) - private String fValueString; // The value of this variable as text - private Vector fVariables; // The children of this variable (other variables) if any - private PHPStackFrame fStackFrame; // The stackframe this value (variable) belongs to - private boolean fHasChanged; // The value has changed between two suspends + final static int PEVT_DOUBLE = 2; + final static int PEVT_STRING = 3; + final static int PEVT_ARRAY = 4; + final static int PEVT_OBJECT = 5; + final static int PEVT_BOOLEAN = 6; + final static int PEVT_RESOURCE = 7; + final static int PEVT_REF = 8; + final static int PEVT_SOFTREF = 9; + + private int fValueType; // The type of this value (see the PEVT_... values) + //private boolean hasChildren; // This value (variable) has children (more variables) + private String fValueString; // The value of this variable as text + private Vector fVariables; // The children of this variable (other variables) if any + private PHPStackFrame fStackFrame; // The stackframe this value (variable) belongs to + private boolean fHasChanged; // The value has changed between two suspends // This variable was moved from PHPVariable due to the fact, // that two PHPVariables can reference the same PHPValue, // so only the first PHPVariable would win, when we check the variable tree // for changed values. + private boolean fSorted; /** * */ - PHPValue () { - this (null, "", PEVT_UNKNOWN, null); // Creates an empty value + PHPValue() { + this(null, "", PEVT_UNKNOWN, null); // Creates an empty value } /** @@ -76,18 +78,17 @@ public class PHPValue implements IValue { * @param fValueType The type of this value (see the PEVT_... values). * @param subitems This value has subitems. */ - PHPValue (PHPStackFrame frame, String value, int fValueType, Vector subitems) - { - this.fValueType = fValueType; + public PHPValue(PHPStackFrame frame, String value, int fValueType, Vector subitems) { + this.fValueType = fValueType; this.fValueString = value; - this.fStackFrame = frame; - this.fHasChanged = false; - - if (subitems != null) { // If there are children for this value (variable) - this.fVariables = new Vector (subitems); // Then add the children to this value (variable) - } - else { - this.fVariables = new Vector (); // Create an empty vector + this.fStackFrame = frame; + this.fHasChanged = false; + this.fSorted = false; + + if (subitems != null) { // If there are children for this value (variable) + this.fVariables = new Vector(subitems); // Then add the children to this value (variable) + } else { + this.fVariables = new Vector(); // Create an empty vector } } @@ -95,10 +96,10 @@ public class PHPValue implements IValue { * * @param item */ - Vector addVariable (Vector item) - { - if (item != null) { // If there is something we want to add - this.fVariables.addAll (item); // + public Vector addVariable(Vector item) { + if (item != null) { // If there is something we want to add + this.fVariables.addAll(item); + this.fSorted = false; } return this.fVariables; @@ -108,12 +109,12 @@ public class PHPValue implements IValue { * * @param parent */ - public void setParent (PHPVariable parent) { - if (!fVariables.isEmpty ()) { // If we have child variables - Iterator iter = fVariables.iterator (); // Create an iterator for the children + public void setParent(PHPVariable parent) { + if (!fVariables.isEmpty()) { // If we have child variables + Iterator iter = fVariables.iterator(); // Create an iterator for the children - while (iter.hasNext ()) { // As long as we have children - ((PHPVariable) iter.next ()).setParent (parent); // Set all child's parent + while (iter.hasNext()) { // As long as we have children + ((PHPVariable) iter.next()).setParent(parent); // Set all child's parent } } } @@ -121,21 +122,21 @@ public class PHPValue implements IValue { /** * @see org.eclipse.debug.core.model.IValue#getReferenceTypeName() */ - public String getReferenceTypeName(){ + public String getReferenceTypeName() { return PEV_NAMES[fValueType]; } /** * */ - public int getReferenceType(){ + public int getReferenceType() { return fValueType; } /** * @param type Set the reference type (see the PEVT_... values). */ - public int setReferenceType (int type) { + public int setReferenceType(int type) { return fValueType = type; } @@ -144,7 +145,7 @@ public class PHPValue implements IValue { * * @param value The changed value for this variable. */ - public void setValueString (String value) { + public void setValueString(String value) { fValueString = value; } @@ -168,15 +169,20 @@ public class PHPValue implements IValue { * @return The array of child variable for this value (variable). */ public IVariable[] getVariables() { - return (PHPVariable[]) fVariables.toArray (new PHPVariable[fVariables.size ()]); -// return (IVariable[])fVariables.toArray(); + return (PHPVariable[]) getChildVariables().toArray( + new PHPVariable[fVariables.size()]); } /** * */ - public Vector getChildVariables () { - return (fVariables); + public Vector getChildVariables() { + if (!fSorted) { + Collections.sort(fVariables, new PHPVariableComparator()); + fSorted = true; + } + + return fVariables; } /** @@ -189,8 +195,8 @@ public class PHPValue implements IValue { * */ public boolean hasVariables() throws DebugException { - // return (!fVariables.isEmpty ()); - return (fVariables.size () != 0); + // return (!fVariables.isEmpty()); + return (fVariables.size() != 0); } /** @@ -222,13 +228,12 @@ public class PHPValue implements IValue { return null; } - public boolean hasValueChanged () throws DebugException { + public boolean hasValueChanged() throws DebugException { return fHasChanged; } - public void setValueChanged (boolean changed) { + public void setValueChanged(boolean changed) { fHasChanged = changed; } - }