package jetbrains.mps.debugger.java.runtime.breakpoints; /*Generated by MPS */ import org.apache.log4j.Logger; import org.apache.log4j.LogManager; import com.intellij.openapi.project.Project; import jetbrains.mps.debugger.java.runtime.engine.events.EventsProcessor; import com.sun.jdi.ReferenceType; import jetbrains.mps.debugger.java.runtime.engine.RequestManager; import com.sun.jdi.request.ExceptionRequest; import com.sun.jdi.ClassNotPreparedException; import com.sun.jdi.ObjectCollectedException; import com.sun.jdi.InternalException; import jetbrains.mps.debugger.java.runtime.engine.events.EventContext; import com.sun.jdi.event.LocatableEvent; import org.jetbrains.annotations.NotNull; public class ExceptionBreakpoint extends JavaBreakpoint { private static final Logger LOG = LogManager.getLogger(ExceptionBreakpoint.class); private final String myExceptionName; public ExceptionBreakpoint(String exceptionName, Project project) { super(project); myExceptionName = exceptionName; } @Override protected String getClassNameToPrepare() { return myExceptionName; } @Override protected void createRequestForPreparedClass(EventsProcessor debugProcess, ReferenceType classType) { RequestManager requestManager = debugProcess.getRequestManager(); try { ExceptionRequest request = requestManager.createExceptionRequest(this, classType); requestManager.enableRequest(request); } catch (ClassNotPreparedException ex) { LOG.warn("ClassNotPreparedException: " + ex.getMessage()); // there's a chance to add a breakpoint when the class is prepared } catch (ObjectCollectedException ex) { LOG.warn("ObjectCollectedException: " + ex.getMessage()); // there's a chance to add a breakpoint when the class is prepared } catch (InternalException ex) { LOG.error(null, ex); } catch (Exception ex) { LOG.error(null, ex); } } @Override public boolean isRequestHitByEvent(EventContext context, LocatableEvent event) { return true; } @NotNull @Override public JavaBreakpointKind getKind() { return JavaBreakpointKind.EXCEPTION_BREAKPOINT; } @Override public boolean isValid() { return true; } @Override public String getPresentation() { return myExceptionName; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } return eq_bv30lc_a0d0j(myExceptionName, ((ExceptionBreakpoint) o).myExceptionName); } @Override public int hashCode() { int result = 0; result = 31 * result + ((myExceptionName != null ? String.valueOf(myExceptionName).hashCode() : 0)); return result; } public static class ExceptionBreakpointInfo { public String myExceptionName; public long myCreationTime; public int mySuspendPolicy; public boolean myIsLogMessage; public boolean myIsEnabled; public ExceptionBreakpointInfo(ExceptionBreakpoint breakpoint) { myExceptionName = breakpoint.myExceptionName; myCreationTime = breakpoint.myCreationTime; myIsEnabled = breakpoint.isEnabled(); mySuspendPolicy = breakpoint.getSuspendPolicy(); myIsLogMessage = breakpoint.isLogMessage(); } public ExceptionBreakpointInfo() { } public void initBreakpoint(ExceptionBreakpoint breakpoint) { breakpoint.setEnabled(myIsEnabled); breakpoint.setCreationTime(myCreationTime); breakpoint.setSuspendPolicy(mySuspendPolicy); breakpoint.setLogMessage(myIsLogMessage); } } private static boolean eq_bv30lc_a0d0j(Object a, Object b) { return (a != null ? a.equals(b) : a == b); } }