private void visitChildren ( Node parent , Collection < Class < ? extends Node > > includeNodes ) { Node child = parent . getFirstChild ( ) ; while ( child != null ) { // A subclass of this visitor might modify the node, resulting in getNext returning a different node or no // node after visiting it. So get the next node before visiting. Node next = child . getNext ( ) ; if ( includeNodes . contains ( child . getClass ( ) ) ) { child . accept ( this ) ; } else { visitChildren ( child , includeNodes ) ; } child = next ; } }
Recursively visit the children of the node processing only those specified by the parameter includeNodes .