Lines 1-5
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2009 IBM Corporation and others. |
2 |
* Copyright (c) 2009, 2011 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
Lines 11-17
Link Here
|
11 |
package org.eclipse.wst.jsdt.debug.internal.ui; |
11 |
package org.eclipse.wst.jsdt.debug.internal.ui; |
12 |
|
12 |
|
13 |
import java.io.File; |
13 |
import java.io.File; |
|
|
14 |
import java.io.UnsupportedEncodingException; |
14 |
import java.net.URISyntaxException; |
15 |
import java.net.URISyntaxException; |
|
|
16 |
import java.net.URLDecoder; |
15 |
import java.util.HashMap; |
17 |
import java.util.HashMap; |
16 |
|
18 |
|
17 |
import org.eclipse.core.filesystem.EFS; |
19 |
import org.eclipse.core.filesystem.EFS; |
Lines 19-32
Link Here
|
19 |
import org.eclipse.core.resources.IResource; |
21 |
import org.eclipse.core.resources.IResource; |
20 |
import org.eclipse.core.resources.ResourcesPlugin; |
22 |
import org.eclipse.core.resources.ResourcesPlugin; |
21 |
import org.eclipse.core.runtime.CoreException; |
23 |
import org.eclipse.core.runtime.CoreException; |
|
|
24 |
import org.eclipse.core.runtime.IPath; |
22 |
import org.eclipse.core.runtime.Path; |
25 |
import org.eclipse.core.runtime.Path; |
23 |
import org.eclipse.core.runtime.URIUtil; |
26 |
import org.eclipse.core.runtime.URIUtil; |
24 |
import org.eclipse.debug.core.DebugException; |
27 |
import org.eclipse.debug.core.DebugException; |
|
|
28 |
import org.eclipse.debug.core.model.IBreakpoint; |
29 |
import org.eclipse.debug.core.model.IDebugElement; |
25 |
import org.eclipse.debug.core.model.IDebugTarget; |
30 |
import org.eclipse.debug.core.model.IDebugTarget; |
|
|
31 |
import org.eclipse.debug.core.model.IDisconnect; |
26 |
import org.eclipse.debug.core.model.IStackFrame; |
32 |
import org.eclipse.debug.core.model.IStackFrame; |
|
|
33 |
import org.eclipse.debug.core.model.ITerminate; |
27 |
import org.eclipse.debug.core.model.IThread; |
34 |
import org.eclipse.debug.core.model.IThread; |
28 |
import org.eclipse.debug.core.model.IValue; |
35 |
import org.eclipse.debug.core.model.IValue; |
29 |
import org.eclipse.debug.core.model.IVariable; |
36 |
import org.eclipse.debug.core.model.IVariable; |
|
|
37 |
import org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage; |
30 |
import org.eclipse.debug.ui.IDebugModelPresentationExtension; |
38 |
import org.eclipse.debug.ui.IDebugModelPresentationExtension; |
31 |
import org.eclipse.debug.ui.IValueDetailListener; |
39 |
import org.eclipse.debug.ui.IValueDetailListener; |
32 |
import org.eclipse.jface.viewers.LabelProvider; |
40 |
import org.eclipse.jface.viewers.LabelProvider; |
Lines 43-53
Link Here
|
43 |
import org.eclipse.wst.jsdt.debug.core.breakpoints.IJavaScriptFunctionBreakpoint; |
51 |
import org.eclipse.wst.jsdt.debug.core.breakpoints.IJavaScriptFunctionBreakpoint; |
44 |
import org.eclipse.wst.jsdt.debug.core.breakpoints.IJavaScriptLineBreakpoint; |
52 |
import org.eclipse.wst.jsdt.debug.core.breakpoints.IJavaScriptLineBreakpoint; |
45 |
import org.eclipse.wst.jsdt.debug.core.breakpoints.IJavaScriptLoadBreakpoint; |
53 |
import org.eclipse.wst.jsdt.debug.core.breakpoints.IJavaScriptLoadBreakpoint; |
|
|
54 |
import org.eclipse.wst.jsdt.debug.core.model.IJavaScriptStackFrame; |
55 |
import org.eclipse.wst.jsdt.debug.core.model.IJavaScriptThread; |
46 |
import org.eclipse.wst.jsdt.debug.core.model.IJavaScriptValue; |
56 |
import org.eclipse.wst.jsdt.debug.core.model.IJavaScriptValue; |
47 |
import org.eclipse.wst.jsdt.debug.core.model.IScript; |
57 |
import org.eclipse.wst.jsdt.debug.core.model.IScript; |
48 |
import org.eclipse.wst.jsdt.debug.core.model.IScriptGroup; |
58 |
import org.eclipse.wst.jsdt.debug.core.model.IScriptGroup; |
|
|
59 |
import org.eclipse.wst.jsdt.debug.internal.core.Constants; |
60 |
import org.eclipse.wst.jsdt.debug.internal.core.JavaScriptDebugPlugin; |
49 |
import org.eclipse.wst.jsdt.debug.internal.core.TextUtils; |
61 |
import org.eclipse.wst.jsdt.debug.internal.core.TextUtils; |
|
|
62 |
import org.eclipse.wst.jsdt.debug.internal.core.breakpoints.JavaScriptExceptionBreakpoint; |
50 |
import org.eclipse.wst.jsdt.debug.internal.core.model.JavaScriptValue; |
63 |
import org.eclipse.wst.jsdt.debug.internal.core.model.JavaScriptValue; |
|
|
64 |
import org.eclipse.wst.jsdt.debug.internal.ui.eval.JavaScriptInspectExpression; |
51 |
|
65 |
|
52 |
/** |
66 |
/** |
53 |
* Default model presentation for JSDI model elements |
67 |
* Default model presentation for JSDI model elements |
Lines 126-177
Link Here
|
126 |
* @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object) |
140 |
* @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object) |
127 |
*/ |
141 |
*/ |
128 |
public String getText(Object element) { |
142 |
public String getText(Object element) { |
|
|
143 |
StringBuffer buffer = new StringBuffer(); |
129 |
try { |
144 |
try { |
130 |
if(element instanceof IDebugTarget) { |
145 |
if(element instanceof IDebugElement) { |
131 |
return ((IDebugTarget)element).getName(); |
146 |
if(element instanceof IDebugTarget) { |
|
|
147 |
buffer.append(((IDebugTarget)element).getName()); |
148 |
} |
149 |
else if(element instanceof IStackFrame) { |
150 |
buffer.append(getStackframeText((IJavaScriptStackFrame) element)); |
151 |
} |
152 |
else if(element instanceof IThread) { |
153 |
buffer.append(getThreadText((IJavaScriptThread) element)); |
154 |
} |
155 |
else if(element instanceof IVariable) { |
156 |
buffer.append(((IVariable)element).getName()); |
157 |
} |
158 |
else if(element instanceof IValue) { |
159 |
buffer.append(((IValue)element).getValueString()); |
160 |
} |
161 |
else if(element instanceof IScriptGroup) { |
162 |
buffer.append(Messages.scripts); |
163 |
} |
164 |
else if(element instanceof IScript) { |
165 |
buffer.append(getScriptText((IScript) element)); |
166 |
} |
132 |
} |
167 |
} |
133 |
if(element instanceof IStackFrame) { |
168 |
if(element instanceof JavaScriptInspectExpression) { |
134 |
return ((IStackFrame)element).getName(); |
169 |
JavaScriptInspectExpression exp = (JavaScriptInspectExpression) element; |
|
|
170 |
return exp.getValue().getReferenceTypeName(); |
171 |
} |
172 |
if(element instanceof ITerminate) { |
173 |
if(((ITerminate)element).isTerminated()) { |
174 |
buffer.insert(0, Messages.terminated); |
175 |
} |
176 |
else if(element instanceof IDisconnect) { |
177 |
if(((IDisconnect)element).isDisconnected()) { |
178 |
buffer.insert(0, Messages.disconnected); |
179 |
} |
180 |
} |
135 |
} |
181 |
} |
136 |
if(element instanceof IThread) { |
182 |
else if(element instanceof IDisconnect) { |
137 |
return ((IThread)element).getName(); |
183 |
if(((IDisconnect)element).isDisconnected()) { |
|
|
184 |
buffer.insert(0, Messages.disconnected); |
185 |
} |
138 |
} |
186 |
} |
139 |
if(element instanceof IVariable) { |
187 |
else if(element instanceof IJavaScriptFunctionBreakpoint) { |
140 |
return ((IVariable)element).getName(); |
188 |
buffer.append(getFunctionBreakpointText((IJavaScriptFunctionBreakpoint) element)); |
141 |
} |
189 |
} |
142 |
if(element instanceof IValue) { |
190 |
else if(element instanceof IJavaScriptLoadBreakpoint) { |
143 |
return ((IValue)element).getValueString(); |
191 |
buffer.append(getScriptLoadBreakpointText((IJavaScriptLoadBreakpoint) element)); |
144 |
} |
192 |
} |
145 |
if(element instanceof IJavaScriptFunctionBreakpoint) { |
193 |
else if(element instanceof IJavaScriptLineBreakpoint) { |
146 |
return getFunctionBreakpointText((IJavaScriptFunctionBreakpoint) element); |
194 |
buffer.append(getLineBreakpointText((IJavaScriptLineBreakpoint) element)); |
147 |
} |
195 |
} |
148 |
if(element instanceof IJavaScriptLoadBreakpoint) { |
196 |
} |
149 |
return getScriptLoadBreakpointText((IJavaScriptLoadBreakpoint) element); |
197 |
catch(CoreException ce) { |
|
|
198 |
JavaScriptDebugUIPlugin.log(ce); |
199 |
buffer.append(Messages.unknown); |
200 |
} |
201 |
if(buffer.length() < 1) { |
202 |
return Messages.unknown; |
203 |
} |
204 |
return buffer.toString(); |
205 |
} |
206 |
|
207 |
/** |
208 |
* Computes the thread name + adornment |
209 |
* |
210 |
* @param thread |
211 |
* @return |
212 |
* @throws DebugException |
213 |
*/ |
214 |
String getThreadText(IJavaScriptThread thread) throws DebugException { |
215 |
String adornment = Messages.unknown_state; |
216 |
if(thread.isSuspended()) { |
217 |
IBreakpoint[] bps = thread.getBreakpoints(); |
218 |
if(bps.length > 0) { |
219 |
try { |
220 |
IJavaScriptBreakpoint breakpoint = (IJavaScriptBreakpoint) bps[0]; |
221 |
if (breakpoint instanceof IJavaScriptLoadBreakpoint) { |
222 |
String name = breakpoint.getScriptPath(); |
223 |
if (Constants.EMPTY_STRING.equals(name)) { |
224 |
name = getSourceName(thread); |
225 |
} |
226 |
else { |
227 |
//decode it |
228 |
try { |
229 |
name = URLDecoder.decode(name, Constants.UTF_8); |
230 |
} |
231 |
catch(UnsupportedEncodingException uee) { |
232 |
//ignore |
233 |
} |
234 |
} |
235 |
adornment = NLS.bind(Messages.suspend_loading_script, name); |
236 |
} |
237 |
else if(breakpoint instanceof JavaScriptExceptionBreakpoint) { |
238 |
adornment = NLS.bind(Messages.suspended_on_exception, breakpoint.getMarker().getAttribute(JavaScriptExceptionBreakpoint.MESSAGE)); |
239 |
} |
240 |
else if (breakpoint instanceof IJavaScriptLineBreakpoint) { |
241 |
IJavaScriptLineBreakpoint bp = (IJavaScriptLineBreakpoint) breakpoint; |
242 |
adornment = NLS.bind(Messages.suspended_on_line_breakpoint, new String[] { Integer.toString(bp.getLineNumber()), getSourceName(thread) }); |
243 |
} |
244 |
else if(breakpoint instanceof IJavaScriptFunctionBreakpoint) { |
245 |
IJavaScriptFunctionBreakpoint bp = (IJavaScriptFunctionBreakpoint) breakpoint; |
246 |
adornment = NLS.bind(Messages.suspended_on_func_breakpoint, new String[] {bp.getFunctionName(), getSourceName(thread)}); |
247 |
} |
248 |
// TODO also need to report stopped at debugger; statement |
249 |
} catch (CoreException ce) { |
250 |
JavaScriptDebugPlugin.log(ce); |
251 |
} |
150 |
} |
252 |
} |
151 |
if(element instanceof IJavaScriptLineBreakpoint) { |
253 |
else { |
152 |
return getLineBreakpointText((IJavaScriptLineBreakpoint) element); |
254 |
adornment = Messages.suspended_state; |
153 |
} |
255 |
} |
154 |
if(element instanceof IScriptGroup) { |
256 |
} |
155 |
return Messages.scripts; |
257 |
else if(thread.isStepping()) { |
|
|
258 |
adornment = Messages.stepping_state; |
259 |
} |
260 |
else if(thread.isTerminated()) { |
261 |
adornment = Messages.terminated_state; |
262 |
} |
263 |
else { |
264 |
adornment = Messages.running_state; |
265 |
} |
266 |
return NLS.bind(Messages.thread_name, new String[] {thread.getName(), adornment}); |
267 |
} |
268 |
|
269 |
/** |
270 |
* Returns the name of the source from the top stackframe or a default name |
271 |
* <code><evaluated_source></code> |
272 |
* |
273 |
* @return the name for the source |
274 |
* @throws DebugException |
275 |
*/ |
276 |
String getSourceName(IJavaScriptThread thread) throws DebugException { |
277 |
IJavaScriptStackFrame frame = (IJavaScriptStackFrame) thread.getTopStackFrame(); |
278 |
if (frame != null) { |
279 |
try { |
280 |
String uri = URLDecoder.decode(frame.getSourceName(), Constants.UTF_8); |
281 |
return TextUtils.shortenText(uri, 100); |
156 |
} |
282 |
} |
157 |
if(element instanceof IScript) { |
283 |
catch (UnsupportedEncodingException uee) { |
158 |
return getScriptText((IScript) element); |
284 |
//ignore |
159 |
} |
285 |
} |
160 |
} |
286 |
} |
161 |
catch(CoreException ce) { |
287 |
// all else failed say "evaluated_script" |
162 |
JavaScriptDebugUIPlugin.log(ce); |
288 |
return Messages.evald_script; |
|
|
289 |
} |
290 |
|
291 |
/** |
292 |
* Returns the display name of the given {@link IJavaScriptStackFrame} |
293 |
* |
294 |
* @param frame |
295 |
* @return the display text or {@link Messages#unknown} |
296 |
* @throws DebugException |
297 |
*/ |
298 |
String getStackframeText(IJavaScriptStackFrame frame) throws DebugException { |
299 |
try { |
300 |
return TextUtils.shortenText(NLS.bind(Messages.stackframe_name, new String[] { |
301 |
URLDecoder.decode(frame.getName(), Constants.UTF_8), |
302 |
Integer.toString(frame.getLineNumber())}), 100); |
303 |
} |
304 |
catch (UnsupportedEncodingException uee) { |
305 |
//ignore |
163 |
} |
306 |
} |
164 |
return element.toString(); |
307 |
return Messages.unknown; |
165 |
} |
308 |
} |
166 |
|
309 |
|
167 |
/** |
310 |
/** |
168 |
* Returns the display text for the given script element |
311 |
* Returns the display text for the given script element |
|
|
312 |
* |
169 |
* @param script |
313 |
* @param script |
170 |
* @return the display text for the given script |
314 |
* @return the display text for the given script or {@link Messages#unknown} |
171 |
*/ |
315 |
*/ |
172 |
String getScriptText(IScript script) { |
316 |
String getScriptText(IScript script) { |
173 |
String uri = script.sourceURI().toString(); |
317 |
String uri; |
174 |
return TextUtils.shortenText(uri, 100); |
318 |
try { |
|
|
319 |
uri = URLDecoder.decode(script.sourceURI().toString(), Constants.UTF_8); |
320 |
return TextUtils.shortenText(uri, 100); |
321 |
} catch (UnsupportedEncodingException e) { |
322 |
//do nothing |
323 |
} |
324 |
return Messages.unknown; |
175 |
} |
325 |
} |
176 |
|
326 |
|
177 |
/** |
327 |
/** |
Lines 182-189
Link Here
|
182 |
*/ |
332 |
*/ |
183 |
String getLineBreakpointText(IJavaScriptLineBreakpoint breakpoint) throws CoreException { |
333 |
String getLineBreakpointText(IJavaScriptLineBreakpoint breakpoint) throws CoreException { |
184 |
String path = getElementPath(breakpoint.getScriptPath()); |
334 |
String path = getElementPath(breakpoint.getScriptPath()); |
185 |
StringBuffer buffer = new StringBuffer(); |
335 |
StringBuffer buffer = new StringBuffer(path); |
186 |
buffer.append(path).append(NLS.bind(Messages.bp_line_number, new String[] {Integer.toString(breakpoint.getLineNumber())})); |
336 |
buffer.append(NLS.bind(Messages.bp_line_number, new String[] {Integer.toString(breakpoint.getLineNumber())})); |
187 |
int hitcount = breakpoint.getHitCount(); |
337 |
int hitcount = breakpoint.getHitCount(); |
188 |
if(hitcount > 0) { |
338 |
if(hitcount > 0) { |
189 |
buffer.append(NLS.bind(Messages.bp_hit_count, new String[] {Integer.toString(hitcount)})); |
339 |
buffer.append(NLS.bind(Messages.bp_hit_count, new String[] {Integer.toString(hitcount)})); |
Lines 205-212
Link Here
|
205 |
*/ |
355 |
*/ |
206 |
String getFunctionBreakpointText(IJavaScriptFunctionBreakpoint breakpoint) throws CoreException { |
356 |
String getFunctionBreakpointText(IJavaScriptFunctionBreakpoint breakpoint) throws CoreException { |
207 |
String path = getElementPath(breakpoint.getScriptPath()); |
357 |
String path = getElementPath(breakpoint.getScriptPath()); |
208 |
StringBuffer buffer = new StringBuffer(); |
358 |
StringBuffer buffer = new StringBuffer(path); |
209 |
buffer.append(path); |
|
|
210 |
if(breakpoint.isEntry()) { |
359 |
if(breakpoint.isEntry()) { |
211 |
if(breakpoint.isExit()) { |
360 |
if(breakpoint.isExit()) { |
212 |
buffer.append(Messages.bp_entry_and_exit); |
361 |
buffer.append(Messages.bp_entry_and_exit); |
Lines 241-248
Link Here
|
241 |
*/ |
390 |
*/ |
242 |
String getScriptLoadBreakpointText(IJavaScriptLoadBreakpoint breakpoint) throws CoreException { |
391 |
String getScriptLoadBreakpointText(IJavaScriptLoadBreakpoint breakpoint) throws CoreException { |
243 |
String path = getElementPath(breakpoint.getScriptPath()); |
392 |
String path = getElementPath(breakpoint.getScriptPath()); |
244 |
StringBuffer buffer = new StringBuffer(); |
393 |
StringBuffer buffer = new StringBuffer(path); |
245 |
buffer.append(path); |
|
|
246 |
int hitcount = breakpoint.getHitCount(); |
394 |
int hitcount = breakpoint.getHitCount(); |
247 |
if(hitcount > 0) { |
395 |
if(hitcount > 0) { |
248 |
buffer.append(NLS.bind(Messages.bp_hit_count, new String[] {Integer.toString(hitcount)})); |
396 |
buffer.append(NLS.bind(Messages.bp_hit_count, new String[] {Integer.toString(hitcount)})); |
Lines 259-265
Link Here
|
259 |
* @return |
407 |
* @return |
260 |
*/ |
408 |
*/ |
261 |
String getElementPath(String path) { |
409 |
String getElementPath(String path) { |
262 |
if(! showQualifiedNames()) { |
410 |
if(!showQualifiedNames()) { |
263 |
try { |
411 |
try { |
264 |
return URIUtil.lastSegment(URIUtil.fromString(path)); |
412 |
return URIUtil.lastSegment(URIUtil.fromString(path)); |
265 |
} |
413 |
} |
Lines 370-375
Link Here
|
370 |
* @see org.eclipse.debug.ui.ISourcePresentation#getEditorInput(java.lang.Object) |
518 |
* @see org.eclipse.debug.ui.ISourcePresentation#getEditorInput(java.lang.Object) |
371 |
*/ |
519 |
*/ |
372 |
public IEditorInput getEditorInput(Object element) { |
520 |
public IEditorInput getEditorInput(Object element) { |
|
|
521 |
if(element instanceof LocalFileStorage) { |
522 |
return getEditorInput(((LocalFileStorage)element).getFile()); |
523 |
} |
373 |
if(element instanceof File) { |
524 |
if(element instanceof File) { |
374 |
return new FileStoreEditorInput(EFS.getLocalFileSystem().fromLocalFile((File) element)); |
525 |
return new FileStoreEditorInput(EFS.getLocalFileSystem().fromLocalFile((File) element)); |
375 |
} |
526 |
} |
Lines 379-386
Link Here
|
379 |
if(element instanceof IJavaScriptLoadBreakpoint) { |
530 |
if(element instanceof IJavaScriptLoadBreakpoint) { |
380 |
try { |
531 |
try { |
381 |
IJavaScriptLoadBreakpoint bp = (IJavaScriptLoadBreakpoint) element; |
532 |
IJavaScriptLoadBreakpoint bp = (IJavaScriptLoadBreakpoint) element; |
382 |
IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(bp.getScriptPath())); |
533 |
IPath path = new Path(bp.getScriptPath()); |
383 |
if(resource.getType() == IResource.FILE) { |
534 |
IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(path); |
|
|
535 |
if(resource != null && resource.getType() == IResource.FILE) { |
384 |
return new FileEditorInput((IFile) resource); |
536 |
return new FileEditorInput((IFile) resource); |
385 |
} |
537 |
} |
386 |
} |
538 |
} |