public boolean visit(ForDirective node) throws IOException, ParseException {
Object data = popExpressionResult(node.getOffset());
boolean result = ClassUtils.isTrue(data);
Context.getContext().put(ifVariable, result);
Iterator<?> iterator = CollectionUtils.toIterator(data);
Status status = new Status((Status) Context.getContext().get(forVariable[0]), data);
for (String var : forVariable) {
Context.getContext().put(var, status);
}
loop: while (iterator.hasNext()) {
Object item = iterator.next();
Context.getContext().put(node.getName(), item);
for (Node child : node.getChildren()) {
child.accept(this);
if (ClassUtils.isTrue(Context.getContext().get(breakVariable))) {
Context.getContext().remove(breakVariable);
break loop;
}
}
status.increment();
}
for (String var : forVariable) {
Context.getContext().put(var, status.getParent());
}
return false;
}