public class ProgramStepFactory {
public static TestConditionalStep conditionalStep(TODSession session, ICallerSideEvent event, int newLine, int lastLineNumber, boolean forward) {
// Did the conditional evaluate to true or false?
boolean conditionalTrue;
BlockScope targetScope;
if (event == null) {
return null;
}
if(event.getOperationBehavior() == null){
return null;
}
// Gather information about i) the class we're in,
// ii) the last scope we were in (from lastLineNumber) and
// iii) the current scope we are in.
ClassInfo classInfo = session.getClassInformationProvider().getClassInfo(event.getOperationBehavior().getDeclaringType());
SourceInfo sourceInfo = classInfo.getSourceInfo();
BlockScope lastScope = sourceInfo.findScope(lastLineNumber);
BlockScope newScope = sourceInfo.findScope(newLine);
if (newScope == null && lastScope == null) {
return null;
}
// We want to generate a test conditional step under the following cases:
// i) We just entered the body of an if/elseif/else;
// ii) We skipped over the body of an if/elseif.
// If we weren't in a scope on lastLine, then don't worry about it--
// just skip.
if (lastScope != null) {
// If the lastLineNumber was the start of an if/elseif...
if (lastLineNumber == lastScope.getStartLine()) {
// ...and we're in the same scope now, then it's true.
if (newScope != null && newScope.getEndLine() <= lastScope.getEndLine()) {
conditionalTrue = true;
targetScope = lastScope;
} else {
// We're not in that scope, so it was false.
// Is our current scope an else? If so, the "else"
// has evaluated to true.
if (newScope != null && newScope.getType() == Scope.ELSE) {
conditionalTrue = true;
targetScope = newScope;
} else {
conditionalTrue = false;
targetScope = lastScope;