public static String parentheticRepresentation(InspectableTree T, Position v) {
  String s = v.element().toString(); // elements must implement toString
  if (T.isInternal(v)) {
    PositionIterator children = T.children(v);
    // open parenthesis and recursively process the first subtree
    s += " ( " + parentheticRepresentation(T, children.nextPosition());
    while (children.hasNext())
      // recursively process the remaining subtrees
      s += ", " + parentheticRepresentation(T, children.nextPosition());
    s += " )"; // close parenthesis
  }
  return s;
}