use of org.eclipse.che.api.debug.shared.model.Breakpoint in project che by eclipse.
the class JavaDebugger method addBreakpoint.
@Override
public void addBreakpoint(Breakpoint breakpoint) throws DebuggerException {
final String className = findFQN(breakpoint);
final int lineNumber = breakpoint.getLocation().getLineNumber();
List<ReferenceType> classes = vm.classesByName(className);
// it may mean that class doesn't loaded by a target JVM yet
if (classes.isEmpty()) {
deferBreakpoint(breakpoint);
throw new DebuggerException("Class not loaded");
}
ReferenceType clazz = classes.get(0);
List<com.sun.jdi.Location> locations;
try {
locations = clazz.locationsOfLine(lineNumber);
} catch (AbsentInformationException | ClassNotPreparedException e) {
throw new DebuggerException(e.getMessage(), e);
}
if (locations.isEmpty()) {
throw new DebuggerException("Line " + lineNumber + " not found in class " + className);
}
com.sun.jdi.Location location = locations.get(0);
if (location.method() == null) {
// Line is out of method.
throw new DebuggerException("Invalid line " + lineNumber + " in class " + className);
}
// Ignore new breakpoint if already have breakpoint at the same location.
EventRequestManager requestManager = getEventManager();
for (BreakpointRequest breakpointRequest : requestManager.breakpointRequests()) {
if (location.equals(breakpointRequest.location())) {
LOG.debug("Breakpoint at {} already set", location);
return;
}
}
try {
EventRequest breakPointRequest = requestManager.createBreakpointRequest(location);
breakPointRequest.setSuspendPolicy(EventRequest.SUSPEND_ALL);
String expression = breakpoint.getCondition();
if (!(expression == null || expression.isEmpty())) {
ExpressionParser parser = ExpressionParser.newInstance(expression);
breakPointRequest.putProperty("org.eclipse.che.ide.java.debug.condition.expression.parser", parser);
}
breakPointRequest.setEnabled(true);
} catch (NativeMethodException | IllegalThreadStateException | InvalidRequestStateException e) {
throw new DebuggerException(e.getMessage(), e);
}
debuggerCallback.onEvent(new BreakpointActivatedEventImpl(new BreakpointImpl(breakpoint.getLocation(), true, breakpoint.getCondition())));
LOG.debug("Add breakpoint: {}", location);
}
use of org.eclipse.che.api.debug.shared.model.Breakpoint in project che by eclipse.
the class JavaDebugger method findFQN.
private String findFQN(Breakpoint breakpoint) throws DebuggerException {
Location location = breakpoint.getLocation();
final String parentFqn = location.getTarget();
final String projectPath = location.getResourceProjectPath();
int lineNumber = location.getLineNumber();
return debuggerUtil.findFqnByPosition(projectPath, parentFqn, lineNumber);
}
use of org.eclipse.che.api.debug.shared.model.Breakpoint in project che by eclipse.
the class JavaDebugger method deleteBreakpoint.
@Override
public void deleteBreakpoint(Location location) throws DebuggerException {
final String className = location.getTarget();
final int lineNumber = location.getLineNumber();
EventRequestManager requestManager = getEventManager();
List<BreakpointRequest> snapshot = new ArrayList<>(requestManager.breakpointRequests());
for (BreakpointRequest breakpointRequest : snapshot) {
com.sun.jdi.Location jdiLocation = breakpointRequest.location();
if (jdiLocation.declaringType().name().equals(className) && jdiLocation.lineNumber() == lineNumber) {
requestManager.deleteEventRequest(breakpointRequest);
LOG.debug("Delete breakpoint: {}", location);
}
}
}
use of org.eclipse.che.api.debug.shared.model.Breakpoint in project che by eclipse.
the class BreakPointComparator method compare.
@Override
public int compare(Breakpoint o1, Breakpoint o2) {
String className1 = o1.getLocation().getTarget();
String className2 = o2.getLocation().getTarget();
if (className1 == null && className2 == null) {
return 0;
}
if (className1 == null) {
return 1;
}
if (className2 == null) {
return -1;
}
int result = className1.compareTo(className2);
if (result == 0) {
result = o1.getLocation().getLineNumber() - o2.getLocation().getLineNumber();
}
return result;
}
use of org.eclipse.che.api.debug.shared.model.Breakpoint in project che by eclipse.
the class JavaDebuggerTest method testAddBreakpoint.
@Test(priority = 3)
public void testAddBreakpoint() throws Exception {
int breakpointsCount = debugger.getAllBreakpoints().size();
debugger.addBreakpoint(new BreakpointImpl(new LocationImpl("com.HelloWorld", 18), false, null));
DebuggerEvent debuggerEvent = events.take();
assertTrue(debuggerEvent instanceof BreakpointActivatedEvent);
Breakpoint breakpoint = ((BreakpointActivatedEvent) debuggerEvent).getBreakpoint();
assertEquals(breakpoint.getLocation().getLineNumber(), 18);
assertEquals(breakpoint.getLocation().getTarget(), "com.HelloWorld");
assertTrue(breakpoint.isEnabled());
assertEquals(debugger.getAllBreakpoints().size(), breakpointsCount + 1);
}
Aggregations