/** * Declares an intent to release control to another thread in the future, or performs the actual * release now. The behaviour depends on whether a method has been invoked on the control object. * (See {@link #object}.) If it has, then the release is scheduled when the position represented * by the control call has been reached, and the state of the control object is cleared. * Otherwise, the release is performed immediately. * * <p>Releasing control will block this script, and allow the released script to start, or to * resume execution. This script will remain blocked until another script releases control back to * it, or until the first Script belonging to the {@link Scripter} is released. * * <p>Note that it is only possible to release to another Script that is being run by the same * {@link Scripter}. */ public void releaseTo(Script<T> other) { if (this == other) { throw new IllegalArgumentException("Cannot release control to the same script"); } if (!running()) { // If we're not running, then we must be scheduling a future // release. (Calling recorder.position() will throw an // IllegalStateException if a valid position has not been specified, so no // need to check here. // futureTargets.add(new ScriptTarget<T>(recorder.position(), other)); } else { // If the scripter has been set, then we are either releasing control or // preparing to do so, depending on whether a position has been specified. CodePosition cp = recorder.getPositionIfAny(); if (cp == null) { doRelease(other); } else { Breakpoint breakPoint = getInstrumentedObject().createBreakpoint(cp, thread); breakPoint.setHandler(new ReleasingHandler(other)); synchronized (breakPoints) { breakPoints.add(breakPoint); } } } }
@Override public void onBreakpointAdded(Breakpoint newBreakpoint) { if (shouldProcessBreakpoint(newBreakpoint) && !breakpoints.contains(newBreakpoint)) { anchorBreakpointAndUpdateSidebar(newBreakpoint); debuggingModelRenderer.renderBreakpointOnGutter( newBreakpoint.getLineNumber(), newBreakpoint.isActive()); } debuggerState.setBreakpoint(newBreakpoint); debuggingSidebar.addBreakpoint(newBreakpoint); }
private void anchorBreakpoints() { JsonArray<Breakpoint> allBreakpoints = debuggingModel.getBreakpoints(); for (int i = 0; i < allBreakpoints.size(); ++i) { Breakpoint breakpoint = allBreakpoints.get(i); if (path.equals(breakpoint.getPath())) { anchorBreakpointAndUpdateSidebar(breakpoint); debuggingModelRenderer.renderBreakpointOnGutter( breakpoint.getLineNumber(), breakpoint.isActive()); } } }
/** * Prepares this ScriptedThread to be executed by the given scripter in the given thread. Creates * Breakpoints for all of the release positions that have been predefined. This method is invoked * by the owning Scripter before calling {@link #runTasks}. */ void prepare(Scripter<T> theScripter, TestThread theThread) { this.scripter = theScripter; ObjectInstrumentation<T> instrumented = getInstrumentedObject(); breakPoints = new ArrayList<Breakpoint>(futureTargets.size()); for (ScriptTarget<T> target : futureTargets) { Breakpoint breakPoint = instrumented.createBreakpoint(target.codePosition, theThread); breakPoint.setHandler(new ReleasingHandler(target.script)); breakPoints.add(breakPoint); } this.thread = theThread; }
@Override public void onBreakpointRemoved(Breakpoint oldBreakpoint) { if (shouldProcessBreakpoint(oldBreakpoint) && breakpoints.contains(oldBreakpoint)) { breakpoints.removeBreakpoint(oldBreakpoint); debuggingModelRenderer.removeBreakpointOnGutter(oldBreakpoint.getLineNumber()); } debuggerState.removeBreakpoint(oldBreakpoint); debuggingSidebar.removeBreakpoint(oldBreakpoint); }
/** * Removes a breakpoint. * * @param breakpoint breakpoint to be removed */ public void removeBreakpoint(Breakpoint breakpoint) { if (breakpoint == null) { return; } ActivityNode activitynode = breakpoint.getActivityNode(); if (activitynode == null || activitynode.activity == null) { return; } this.breakpoints.remove(activitynode); }
/** * Adds a breakpoint for the specified activity node. * * @param breakpoint Breakpoint that shall be added */ public void addBreakpoint(Breakpoint breakpoint) { if (breakpoint == null) { return; } ActivityNode activitynode = breakpoint.getActivityNode(); if (activitynode == null || activitynode.activity == null) { return; } breakpoints.put(activitynode, breakpoint); }
@Override public void onClick(int y) { int lineNumber = editor.getBuffer().convertYToLineNumber(y, true); for (int i = 0; i < breakpoints.size(); ++i) { Breakpoint breakpoint = breakpoints.get(i); if (breakpoint.getLineNumber() == lineNumber) { debuggingModel.removeBreakpoint(breakpoint); return; } } if (!isCurrentDocumentEligibleForDebugging()) { return; } Breakpoint breakpoint = new Breakpoint.Builder(path, lineNumber).build(); debuggingModel.addBreakpoint(breakpoint); // Show the sidebar if the very first breakpoint has just been set. maybeShowSidebar(); }
private Breakpoint setLineBreakpointImpl(int ignoreCount, Object key, int line, boolean oneShot) throws IOException { Breakpoint breakpoint = breakpointPerLocation.get(new BreakpointLocation(key, line)); if (breakpoint != null) { if (ignoreCount == breakpoint.getIgnoreCount()) { throw new IOException("Breakpoint already set for " + key + " line: " + line); } breakpoint.setIgnoreCount(ignoreCount); return breakpoint; } Breakpoint.Builder builder; if (key instanceof Source) { builder = Breakpoint.newBuilder((Source) key); } else { assert key instanceof URI; builder = Breakpoint.newBuilder((URI) key); } builder.lineIs(line); if (oneShot) { builder.oneShot(); } breakpoint = builder.build(); breakpointPerLocation.put(breakpoint.getLocationKey(), breakpoint); getLegacySession().install(breakpoint); return breakpoint; }
private boolean shouldProcessBreakpoint(Breakpoint breakpoint) { return path != null && path.equals(breakpoint.getPath()); }
@Override public void onBreakpointLineClick(Breakpoint breakpoint) { maybeNavigateToDocument(breakpoint.getPath(), breakpoint.getLineNumber()); }
@Override public void onBreakpointIconClick(Breakpoint breakpoint) { Breakpoint newBreakpoint = new Breakpoint.Builder(breakpoint).setActive(!breakpoint.isActive()).build(); debuggingModel.updateBreakpoint(breakpoint, newBreakpoint); }
void disposeBreakpoint(Breakpoint breakpoint) { if (breakpoint.getSession() == getLegacySession()) { breakpointPerLocation.remove(breakpoint.getLocationKey()); } }