View | Details | Raw Unified | Return to bug 306831
Collapse All | Expand All

(-)src/org/eclipse/wst/jsdt/debug/internal/rhino/jsdi/LocationImpl.java (+43 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.wst.jsdt.debug.internal.rhino.jsdi;
11
package org.eclipse.wst.jsdt.debug.internal.rhino.jsdi;
12
12
13
import java.util.Comparator;
14
13
import org.eclipse.wst.jsdt.debug.core.jsdi.Location;
15
import org.eclipse.wst.jsdt.debug.core.jsdi.Location;
14
import org.eclipse.wst.jsdt.debug.core.jsdi.ScriptReference;
16
import org.eclipse.wst.jsdt.debug.core.jsdi.ScriptReference;
15
17
Lines 19-24 Link Here
19
 * @since 1.0
21
 * @since 1.0
20
 */
22
 */
21
public class LocationImpl extends MirrorImpl implements Location {
23
public class LocationImpl extends MirrorImpl implements Location {
24
	
25
	/**
26
	 * Comparator that orders {@link Location}s by line number - useful for debugging
27
	 */
28
	static class LocationComparator implements Comparator {
29
		/* (non-Javadoc)
30
		 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
31
		 */
32
		public int compare(Object o1, Object o2) {
33
			int value = -1;
34
			if(o1 instanceof Location && o2 instanceof Location) {
35
				int first = ((Location)o1).lineNumber();
36
				int second = ((Location)o2).lineNumber(); 
37
				if(first == second) {
38
					value = 0;
39
				}
40
				else if(first > second) {
41
					value = 1;
42
				}
43
			}
44
			return value;
45
		}
46
		
47
	}
48
	private static LocationComparator comparator = new LocationComparator();
22
	private String functionName;
49
	private String functionName;
23
	private int lineNumber;
50
	private int lineNumber;
24
	private ScriptReferenceImpl scriptReference;
51
	private ScriptReferenceImpl scriptReference;
Lines 38-43 Link Here
38
		this.scriptReference = scriptReference;
65
		this.scriptReference = scriptReference;
39
	}
66
	}
40
67
68
	static LocationComparator getLocationComparator() {
69
		return comparator;
70
	}
71
	
41
	/* (non-Javadoc)
72
	/* (non-Javadoc)
42
	 * @see org.eclipse.wst.jsdt.debug.core.jsdi.Location#functionName()
73
	 * @see org.eclipse.wst.jsdt.debug.core.jsdi.Location#functionName()
43
	 */
74
	 */
Lines 58-61 Link Here
58
	public ScriptReference scriptReference() {
89
	public ScriptReference scriptReference() {
59
		return scriptReference;
90
		return scriptReference;
60
	}
91
	}
92
	
93
	/* (non-Javadoc)
94
	 * @see java.lang.Object#toString()
95
	 */
96
	public String toString() {
97
		StringBuffer buffer = new StringBuffer();
98
		buffer.append("LocationImpl: "); //$NON-NLS-1$
99
		buffer.append("[script - ").append(scriptReference.sourceURI()).append("] "); //$NON-NLS-1$ //$NON-NLS-2$
100
		buffer.append("[function - ").append(functionName).append("] "); //$NON-NLS-1$ //$NON-NLS-2$
101
		buffer.append("[line - ").append(lineNumber).append("]"); //$NON-NLS-1$ //$NON-NLS-2$
102
		return buffer.toString();
103
	}
61
}
104
}
(-)src/org/eclipse/wst/jsdt/debug/internal/rhino/jsdi/ScriptReferenceImpl.java (+25 lines)
Lines 168-171 Link Here
168
		}
168
		}
169
		return this.sourceuri;
169
		return this.sourceuri;
170
	}
170
	}
171
	
172
	/* (non-Javadoc)
173
	 * @see java.lang.Object#toString()
174
	 */
175
	public String toString() {
176
		StringBuffer buffer = new StringBuffer();
177
		buffer.append("ScriptReferenceImpl: "); //$NON-NLS-1$
178
		buffer.append("[sourceuri - ").append(sourceURI()).append("]\n"); //$NON-NLS-1$ //$NON-NLS-2$
179
		buffer.append("Line locations: \n"); //$NON-NLS-1$
180
		List list = new ArrayList(allLineLocations());
181
		Collections.sort(list, LocationImpl.getLocationComparator());
182
		for (Iterator iter = list.iterator(); iter.hasNext();) {
183
			Location loc = (Location) iter.next();
184
			buffer.append("\t").append(loc.toString()).append("\n"); //$NON-NLS-1$ //$NON-NLS-2$
185
		}
186
		buffer.append("Function locations: \n"); //$NON-NLS-1$
187
		list = new ArrayList(allFunctionLocations());
188
		Collections.sort(list, LocationImpl.getLocationComparator());
189
		for (Iterator iter = list.iterator(); iter.hasNext();) {
190
			Location loc = (Location) iter.next();
191
			buffer.append("\t").append(loc.toString()).append("\n"); //$NON-NLS-1$ //$NON-NLS-2$
192
		}
193
		buffer.append("\n"); //$NON-NLS-1$
194
		return buffer.toString();
195
	}
171
}
196
}

Return to bug 306831