/** * @return breakpoints of one of the category: LINE_BREAKPOINTS, EXCEPTION_BREAKPOINTS, * FIELD_BREAKPOINTS, METHOD_BREAKPOINTS */ public <T extends Breakpoint> Breakpoint[] getBreakpoints(@NotNull final Key<T> category) { ApplicationManager.getApplication().assertIsDispatchThread(); removeInvalidBreakpoints(); final ArrayList<Breakpoint> breakpoints = new ArrayList<Breakpoint>(); for (Breakpoint breakpoint : getBreakpoints()) { if (category.equals(breakpoint.getCategory())) { breakpoints.add(breakpoint); } } return breakpoints.toArray(new Breakpoint[breakpoints.size()]); }
/** @param category breakpoint category, null if the category does not matter */ @Nullable public <T extends BreakpointWithHighlighter> T findBreakpoint( final Document document, final int offset, @Nullable final Key<T> category) { for (final Breakpoint breakpoint : getBreakpoints()) { if (breakpoint instanceof BreakpointWithHighlighter && ((BreakpointWithHighlighter) breakpoint).isAt(document, offset)) { if (category == null || category.equals(breakpoint.getCategory())) { //noinspection CastConflictsWithInstanceof,unchecked return (T) breakpoint; } } } return null; }
public void applyThreadFilter( @NotNull final DebugProcessImpl debugProcess, @Nullable ThreadReference newFilterThread) { final RequestManagerImpl requestManager = debugProcess.getRequestsManager(); final ThreadReference oldFilterThread = requestManager.getFilterThread(); if (Comparing.equal(newFilterThread, oldFilterThread)) { // the filter already added return; } requestManager.setFilterThread(newFilterThread); if (newFilterThread == null || oldFilterThread != null) { final List<Breakpoint> breakpoints = getBreakpoints(); for (Breakpoint breakpoint : breakpoints) { if (LineBreakpoint.CATEGORY.equals(breakpoint.getCategory()) || MethodBreakpoint.CATEGORY.equals(breakpoint.getCategory())) { requestManager.deleteRequest(breakpoint); breakpoint.createRequest(debugProcess); } } } else { // important! need to add filter to _existing_ requests, otherwise Requestor->Request mapping // will be lost // and debugger trees will not be restored to original state abstract class FilterSetter<T extends EventRequest> { void applyFilter(@NotNull final List<T> requests, final ThreadReference thread) { for (T request : requests) { try { final boolean wasEnabled = request.isEnabled(); if (wasEnabled) { request.disable(); } addFilter(request, thread); if (wasEnabled) { request.enable(); } } catch (InternalException e) { LOG.info(e); } } } protected abstract void addFilter(final T request, final ThreadReference thread); } final EventRequestManager eventRequestManager = requestManager.getVMRequestManager(); new FilterSetter<BreakpointRequest>() { @Override protected void addFilter( @NotNull final BreakpointRequest request, final ThreadReference thread) { request.addThreadFilter(thread); } }.applyFilter(eventRequestManager.breakpointRequests(), newFilterThread); new FilterSetter<MethodEntryRequest>() { @Override protected void addFilter( @NotNull final MethodEntryRequest request, final ThreadReference thread) { request.addThreadFilter(thread); } }.applyFilter(eventRequestManager.methodEntryRequests(), newFilterThread); new FilterSetter<MethodExitRequest>() { @Override protected void addFilter( @NotNull final MethodExitRequest request, final ThreadReference thread) { request.addThreadFilter(thread); } }.applyFilter(eventRequestManager.methodExitRequests(), newFilterThread); } }