2
|
1 |
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
|
|
2 |
// Use of this source code is governed by a BSD-style license that can be
|
|
3 |
// found in the LICENSE file.
|
|
4 |
|
|
5 |
package org.chromium.debug.core.model;
|
|
6 |
|
|
7 |
import org.chromium.debug.core.ChromiumDebugPlugin;
|
|
8 |
import org.chromium.sdk.Breakpoint;
|
|
9 |
import org.eclipse.core.resources.IMarker;
|
|
10 |
import org.eclipse.core.resources.IResource;
|
|
11 |
import org.eclipse.core.resources.IWorkspaceRunnable;
|
|
12 |
import org.eclipse.core.runtime.CoreException;
|
|
13 |
import org.eclipse.core.runtime.IProgressMonitor;
|
|
14 |
import org.eclipse.debug.core.model.IBreakpoint;
|
|
15 |
import org.eclipse.debug.core.model.LineBreakpoint;
|
|
16 |
import org.eclipse.osgi.util.NLS;
|
|
17 |
|
|
18 |
/**
|
|
19 |
* JavaScript line breakpoint.
|
|
20 |
*/
|
|
21 |
public class ChromiumLineBreakpoint extends LineBreakpoint {
|
|
22 |
|
|
23 |
/** Ignore count */
|
|
24 |
private static final String IGNORE_COUNT_ATTR = ChromiumDebugPlugin.PLUGIN_ID + ".ignoreCount"; //$NON-NLS-1$
|
|
25 |
|
|
26 |
/** Condition */
|
|
27 |
private static final String CONDITION_ATTR = ChromiumDebugPlugin.PLUGIN_ID + ".condition"; //$NON-NLS-1$
|
|
28 |
|
|
29 |
private Breakpoint browserBreakpoint;
|
|
30 |
|
|
31 |
/**
|
|
32 |
* Default constructor is required for the breakpoint manager to re-create
|
|
33 |
* persisted breakpoints. After instantiating a breakpoint, the setMarker
|
|
34 |
* method is called to restore this breakpoint's attributes.
|
|
35 |
*/
|
|
36 |
// FIXME(apavlov): now this does not restore the browserBreakpoint value
|
|
37 |
public ChromiumLineBreakpoint() {
|
|
38 |
}
|
|
39 |
|
|
40 |
public void setBreakpoint(Breakpoint breakpoint) {
|
|
41 |
this.browserBreakpoint = breakpoint;
|
|
42 |
}
|
|
43 |
|
|
44 |
public Breakpoint getBrowserBreakpoint() {
|
|
45 |
return browserBreakpoint;
|
|
46 |
}
|
|
47 |
|
|
48 |
/**
|
|
49 |
* Constructs a line breakpoint on the given resource at the given line number
|
|
50 |
* (line number is 1-based).
|
|
51 |
*
|
|
52 |
* @param resource file on which to set the breakpoint
|
|
53 |
* @param lineNumber 1-based line number of the breakpoint
|
|
54 |
* @throws CoreException if unable to create the breakpoint
|
|
55 |
*/
|
|
56 |
public ChromiumLineBreakpoint(final IResource resource, final int lineNumber)
|
|
57 |
throws CoreException {
|
|
58 |
IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
|
|
59 |
public void run(IProgressMonitor monitor) throws CoreException {
|
|
60 |
IMarker marker = resource.createMarker(ChromiumDebugPlugin.BP_MARKER);
|
|
61 |
setMarker(marker);
|
|
62 |
marker.setAttribute(IBreakpoint.ENABLED, Boolean.TRUE);
|
|
63 |
marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
|
|
64 |
marker.setAttribute(IBreakpoint.ID, getModelIdentifier());
|
|
65 |
marker.setAttribute(IMarker.MESSAGE, NLS.bind(
|
|
66 |
Messages.JsLineBreakpoint_MessageMarkerFormat, resource.getName(), lineNumber));
|
|
67 |
}
|
|
68 |
};
|
|
69 |
run(getMarkerRule(resource), runnable);
|
|
70 |
}
|
|
71 |
|
|
72 |
@Override
|
|
73 |
public boolean isEnabled() {
|
|
74 |
try {
|
|
75 |
return super.isEnabled();
|
|
76 |
} catch (CoreException e) {
|
|
77 |
ChromiumDebugPlugin.log(e);
|
|
78 |
return false;
|
|
79 |
}
|
|
80 |
}
|
|
81 |
|
|
82 |
public void setIgnoreCount(int ignoreCount) {
|
|
83 |
setMarkerAttribute(IGNORE_COUNT_ATTR, ignoreCount);
|
|
84 |
}
|
|
85 |
|
|
86 |
private void setMarkerAttribute(String attributeName, Object value) {
|
|
87 |
try {
|
|
88 |
setAttribute(attributeName, value);
|
|
89 |
} catch (CoreException e) {
|
|
90 |
ChromiumDebugPlugin.log(e);
|
|
91 |
}
|
|
92 |
}
|
|
93 |
|
|
94 |
public int getIgnoreCount() {
|
|
95 |
return getMarker().getAttribute(IGNORE_COUNT_ATTR, Breakpoint.EMPTY_VALUE);
|
|
96 |
}
|
|
97 |
|
|
98 |
public void setCondition(String condition) throws CoreException {
|
|
99 |
setMarkerAttribute(CONDITION_ATTR, condition);
|
|
100 |
}
|
|
101 |
|
|
102 |
public String getCondition() {
|
|
103 |
return getMarker().getAttribute(CONDITION_ATTR, null);
|
|
104 |
}
|
|
105 |
|
|
106 |
public String getModelIdentifier() {
|
|
107 |
return ChromiumDebugPlugin.DEBUG_MODEL_ID;
|
|
108 |
}
|
|
109 |
|
|
110 |
public void changed() {
|
|
111 |
if (browserBreakpoint != null) {
|
|
112 |
browserBreakpoint.setCondition(getCondition());
|
|
113 |
browserBreakpoint.setEnabled(isEnabled());
|
|
114 |
browserBreakpoint.setIgnoreCount(getIgnoreCount());
|
|
115 |
browserBreakpoint.flush(null);
|
|
116 |
}
|
|
117 |
}
|
|
118 |
|
|
119 |
public void clear() {
|
|
120 |
if (browserBreakpoint != null) {
|
|
121 |
browserBreakpoint.clear(null);
|
|
122 |
}
|
|
123 |
}
|
|
124 |
}
|