/** Abstracts out the simpleChunkVisitor callback-triggering logic. * Note that a null value of "prev" is assumed to mean we're the last node. */ @SuppressFBWarnings(value="NP_LOAD_OF_KNOWN_NULL_VALUE", justification = "FindBugs doesn't like passing nulls to a method that can take null") static void fireVisitChunkCallbacks(@CheckForNull FlowNode next, @Nonnull FlowNode current, @CheckForNull FlowNode prev, @Nonnull SimpleChunkVisitor visitor, @Nonnull ChunkFinder finder, @Nonnull ForkScanner scanner) { boolean boundary = false; if (prev == null && finder.isStartInsideChunk()) { // Last node, need to fire end event to start inside chunk visitor.chunkEnd(current, prev, scanner); boundary = true; if (finder.isChunkStart(current, prev)) { visitor.chunkStart(current, next, scanner); } } else { // Not starting inside chunk, OR not at end if (finder.isChunkStart(current, prev)) { visitor.chunkStart(current, next, scanner); boundary = true; } if (finder.isChunkEnd(current, prev)) { // Null for previous means we're the last node. visitor.chunkEnd(current, prev, scanner); boundary = true; } } if (!boundary) { visitor.atomNode(next, current, prev, scanner); } }