|
1 package org.symbian.tools.tmw.debug.internal; |
|
2 |
|
3 import org.chromium.debug.core.model.ChromiumLineBreakpoint; |
|
4 import org.eclipse.core.resources.IResource; |
|
5 import org.eclipse.core.runtime.CoreException; |
|
6 import org.eclipse.core.runtime.IStatus; |
|
7 import org.eclipse.core.runtime.Status; |
|
8 import org.eclipse.debug.core.DebugPlugin; |
|
9 import org.eclipse.jface.text.BadLocationException; |
|
10 import org.eclipse.jface.text.IDocument; |
|
11 import org.eclipse.jface.text.ITypedRegion; |
|
12 import org.eclipse.ui.IEditorInput; |
|
13 import org.eclipse.wst.html.core.text.IHTMLPartitions; |
|
14 import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; |
|
15 import org.eclipse.wst.sse.ui.internal.provisional.extensions.ISourceEditingTextTools; |
|
16 import org.eclipse.wst.sse.ui.internal.provisional.extensions.breakpoint.IBreakpointProvider; |
|
17 import org.symbian.tools.tmw.debug.internal.launch.WRTProjectWorkspaceBridge; |
|
18 |
|
19 @SuppressWarnings("restriction") |
|
20 public class HtmlBreakpointProvider implements IBreakpointProvider { |
|
21 |
|
22 public IStatus addBreakpoint(IDocument document, IEditorInput input, |
|
23 int lineNumber, int offset) throws CoreException { |
|
24 boolean hasScript = hasJavaScript(document, lineNumber); |
|
25 |
|
26 if (hasScript) { |
|
27 ChromiumLineBreakpoint breakpoint = new ChromiumLineBreakpoint(getResource(input), lineNumber, |
|
28 WRTProjectWorkspaceBridge.DEBUG_MODEL_ID); |
|
29 DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(breakpoint); |
|
30 } |
|
31 return Status.OK_STATUS; |
|
32 } |
|
33 |
|
34 private boolean hasJavaScript(IDocument document, int lineNumber) { |
|
35 try { |
|
36 if (document instanceof IStructuredDocument) { |
|
37 IStructuredDocument doc = (IStructuredDocument) document; |
|
38 int lineOffset = doc.getLineOffset(lineNumber - 1); |
|
39 int lineLength = doc.getLineLength(lineNumber - 1); |
|
40 ITypedRegion[] computePartitioning = doc.computePartitioning( |
|
41 lineOffset, lineLength); |
|
42 for (ITypedRegion region : computePartitioning) { |
|
43 if (IHTMLPartitions.SCRIPT.equals(region.getType()) |
|
44 || IHTMLPartitions.SCRIPT_EVENTHANDLER |
|
45 .equals(region.getType())) { |
|
46 return true; |
|
47 } |
|
48 } |
|
49 } |
|
50 } catch (BadLocationException e) { |
|
51 Activator.log(e); |
|
52 } |
|
53 return false; |
|
54 } |
|
55 |
|
56 public IResource getResource(IEditorInput input) { |
|
57 return (IResource) input.getAdapter(IResource.class); |
|
58 } |
|
59 |
|
60 public void setSourceEditingTextTools(ISourceEditingTextTools tools) { |
|
61 // Do nothing |
|
62 } |
|
63 |
|
64 } |