Skip to content
Browse files

Bug 306831 - Provide toString() implementations for ScriptReferenceI…

…mpl and locationImpl
  • Loading branch information...
1 parent 8dbdae7 commit 63857cdf0418073cbb4339b6acd199af7f1a31ce mrennie committed Mar 23, 2010
View
43 ...wst.jsdt.debug.rhino/src/org/eclipse/wst/jsdt/debug/internal/rhino/jsdi/LocationImpl.java
@@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.wst.jsdt.debug.internal.rhino.jsdi;
+import java.util.Comparator;
+
import org.eclipse.wst.jsdt.debug.core.jsdi.Location;
import org.eclipse.wst.jsdt.debug.core.jsdi.ScriptReference;
@@ -19,6 +21,31 @@
* @since 1.0
*/
public class LocationImpl extends MirrorImpl implements Location {
+
+ /**
+ * Comparator that orders {@link Location}s by line number - useful for debugging
+ */
+ static class LocationComparator implements Comparator {
+ /* (non-Javadoc)
+ * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
+ */
+ public int compare(Object o1, Object o2) {
+ int value = -1;
+ if(o1 instanceof Location && o2 instanceof Location) {
+ int first = ((Location)o1).lineNumber();
+ int second = ((Location)o2).lineNumber();
+ if(first == second) {
+ value = 0;
+ }
+ else if(first > second) {
+ value = 1;
+ }
+ }
+ return value;
+ }
+
+ }
+ private static LocationComparator comparator = new LocationComparator();
private String functionName;
private int lineNumber;
private ScriptReferenceImpl scriptReference;
@@ -38,6 +65,10 @@ public LocationImpl(VirtualMachineImpl vm, String functionName, int lineNumber,
this.scriptReference = scriptReference;
}
+ static LocationComparator getLocationComparator() {
+ return comparator;
+ }
+
/* (non-Javadoc)
* @see org.eclipse.wst.jsdt.debug.core.jsdi.Location#functionName()
*/
@@ -58,4 +89,16 @@ public int lineNumber() {
public ScriptReference scriptReference() {
return scriptReference;
}
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("LocationImpl: "); //$NON-NLS-1$
+ buffer.append("[script - ").append(scriptReference.sourceURI()).append("] "); //$NON-NLS-1$ //$NON-NLS-2$
+ buffer.append("[function - ").append(functionName).append("] "); //$NON-NLS-1$ //$NON-NLS-2$
+ buffer.append("[line - ").append(lineNumber).append("]"); //$NON-NLS-1$ //$NON-NLS-2$
+ return buffer.toString();
+ }
}
View
25 ...t.debug.rhino/src/org/eclipse/wst/jsdt/debug/internal/rhino/jsdi/ScriptReferenceImpl.java
@@ -168,4 +168,29 @@ else if(this.sourcePath != null) {
}
return this.sourceuri;
}
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("ScriptReferenceImpl: "); //$NON-NLS-1$
+ buffer.append("[sourceuri - ").append(sourceURI()).append("]\n"); //$NON-NLS-1$ //$NON-NLS-2$
+ buffer.append("Line locations: \n"); //$NON-NLS-1$
+ List list = new ArrayList(allLineLocations());
+ Collections.sort(list, LocationImpl.getLocationComparator());
+ for (Iterator iter = list.iterator(); iter.hasNext();) {
+ Location loc = (Location) iter.next();
+ buffer.append("\t").append(loc.toString()).append("\n"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ buffer.append("Function locations: \n"); //$NON-NLS-1$
+ list = new ArrayList(allFunctionLocations());
+ Collections.sort(list, LocationImpl.getLocationComparator());
+ for (Iterator iter = list.iterator(); iter.hasNext();) {
+ Location loc = (Location) iter.next();
+ buffer.append("\t").append(loc.toString()).append("\n"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ buffer.append("\n"); //$NON-NLS-1$
+ return buffer.toString();
+ }
}

0 comments on commit 63857cd

Please sign in to comment.
Something went wrong with that request. Please try again.