/** * Traverses itself and child expressions, notifying visitor via callback methods as it goes. This * is an Expression-specific implementation of the "Visitor" design pattern. * * @since 1.1 */ public void traverse(TraversalHandler visitor) { if (visitor == null) { throw new NullPointerException("Null Visitor."); } traverse(null, visitor); }
/** * Traverses itself and child expressions, notifying visitor via callback methods as it goes. * * @since 1.1 */ protected void traverse(Expression parentExp, TraversalHandler visitor) { visitor.startNode(this, parentExp); // recursively traverse each child int count = getOperandCount(); for (int i = 0; i < count; i++) { Object child = getOperand(i); if (child instanceof Expression) { Expression childExp = (Expression) child; childExp.traverse(this, visitor); } else { visitor.objectNode(child, this); } visitor.finishedChild(this, i, i < count - 1); } visitor.endNode(this, parentExp); }