.filter(JumpStep::unRollable)
// TODO: filter() when do unroll and when not to depending on the depth of looping?
.forEach(toStep -> {
if (toStep.isDoWhile()) {
// DO WHILE SEMANTICS
final Step fromStep = TraversalHelper.getStep(toStep.getJumpLabel(), traversal);
final List<Step> stepsToClone = TraversalHelper.isolateSteps(fromStep, toStep);
stepsToClone.forEach(stepToClone -> TraversalHelper.removeStep(stepToClone, traversal));
for (int i = 0; i < (short) toStep.getJumpLoops().getValue0(); i++) {
for (int j = stepsToClone.size() - 1; j >= 0; j--) {
try {
final Step clonedStep = stepsToClone.get(j).clone();
TraversalHelper.insertStep(clonedStep, traversal.getSteps().indexOf(fromStep) + 1, traversal);
} catch (final CloneNotSupportedException e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
}
if (TraversalHelper.isLabeled(toStep))
toStep.getPreviousStep().setLabel(toStep.getLabel());
TraversalHelper.removeStep(toStep, traversal);
} else {
// WHILE DO SEMANTICS
final JumpStep fromStep = (JumpStep) TraversalHelper.getStep(toStep.getJumpLabel(), traversal);
final List<Step> stepsToClone = TraversalHelper.isolateSteps(toStep, fromStep);
stepsToClone.forEach(stepToClone -> TraversalHelper.removeStep(stepToClone, traversal));
for (int i = 0; i < ((short) toStep.getJumpLoops().getValue0() + 1); i++) {
for (int j = stepsToClone.size() - 1; j >= 0; j--) {
try {
final Step clonedStep = stepsToClone.get(j).clone();
TraversalHelper.insertStep(clonedStep, traversal.getSteps().indexOf(fromStep) + 1, traversal);
} catch (final CloneNotSupportedException e) {
throw new IllegalStateException(e.getMessage(), e);
}
}