/** * returns the maximal projection of <code>head</code> in <code>root</code> given a {@link * HeadFinder} */ public static Tree maximalProjection(Tree head, Tree root, HeadFinder hf) { Tree projection = head; if (projection == root) { return root; } Tree parent = projection.parent(root); while (hf.determineHead(parent) == projection) { projection = parent; if (projection == root) { return root; } parent = projection.parent(root); } return projection; }
/* applies a TreeVisitor to all projections (including the node itself) of a node in a Tree. * Does nothing if head is not in root. * @return the maximal projection of head in root. */ public static Tree applyToProjections(TreeVisitor v, Tree head, Tree root, HeadFinder hf) { Tree projection = head; Tree parent = projection.parent(root); if (parent == null && projection != root) { return null; } v.visitTree(projection); if (projection == root) { return root; } while (hf.determineHead(parent) == projection) { projection = parent; v.visitTree(projection); if (projection == root) { return root; } parent = projection.parent(root); } return projection; }