LinkedList<ProgramStep> steps = new LinkedList<ProgramStep>();
// The result we'll send back to our caller.
SearchResult result = new SearchResult();
ICallerSideEvent event = null;
ICallerSideEvent previousEvent = null;
ILogEvent ile;
ICallerSideEvent validEvent = null;
if (this.events != null && this.events.hasPrevious()) {
// Go backwards. First, position the event log at the first line
// we see that is NOT the line we are currently on.
ILogEvent pointerEvent = null;
do {
ile = events.previous();
if (depth != -1 && (computeDepth(ile) != depth && computeDepth(ile) != depth - 1)) {
continue;
}
if (ile instanceof ICallerSideEvent && !(ile instanceof BehaviorExitEvent)) {
event = (ICallerSideEvent)ile;
int lineNum = TypeUtils.calculateLineNumber(event.getOperationBehavior(), event.getOperationBytecodeIndex());
if (skippable(event) || lineNum == -1) {
continue;
}
if (targetLine == -1 && lineNum != lineNumber) {
targetLine = lineNum;
pointerEvent = event;
} else if (targetLine != -1 && targetLine != lineNum) {
result.lastEvent = event;
break;
}
}
} while (events.hasPrevious());
// Reset the event pointer to the first event on the target line.
if (pointerEvent != null) {
events.setNextTimestamp(pointerEvent.getTimestamp());
ile = pointerEvent;
}
do {
if (depth != -1 && computeDepth(ile) != depth && computeDepth(ile) != depth - 1) {
ile = events.previous();
continue;
}
if (ile instanceof ICallerSideEvent && !(ile instanceof BehaviorExitEvent)) {
if (!skippable(ile) && this.isEventOnLine(ile, targetLine)) {
previousEvent = event;
event = (ICallerSideEvent) ile;
int lineNum = TypeUtils.calculateLineNumber(event.getOperationBehavior(), event.getOperationBytecodeIndex());
if (lineNum != -1 ) {
validEvent = event;
ProgramStep step = ProgramStepFactory.stepFromTOD(this.getTODSession(), event, false, false);
if (step != null) {
steps.addLast(step);
}
}
} else if (!this.isEventOnLine(ile, targetLine)) {
break;
}
}
if (events.hasPrevious()) {
ile = events.previous();
}
} while (events.hasPrevious());
// Don't skip any events! If the last event wasn't on this line,
// go forward so that it will be seen again.
if (!this.isEventOnLine(ile, targetLine)) {
events.next();
}
}
if (validEvent == null) {
result.behavior = this.behavior; // TODO: might break
} else {
result.newLine = TypeUtils.calculateLineNumber(validEvent.getOperationBehavior(), validEvent.getOperationBytecodeIndex());
result.targetEvent = validEvent;
result.lastEvent = validEvent;
result.behavior = validEvent.getOperationBehavior();
}
// Generate the conditional test event, if any.
ProgramStep step = ProgramStepFactory.conditionalStep(session, event, lastLine, result.newLine, false);
if (step != null) {