public static <T extends Tree>T enclosingOfClass(final TreePath path,final Class<T> treeClass){
  TreePath p=path;
  while (p != null) {
    Tree leaf=p.getLeaf();
    if (treeClass.isInstance(leaf)) {
      return treeClass.cast(leaf);
    }
    p=p.getParentPath();
  }
  return null;
}

public static < T extends Tree > T enclosingOfClass ( final TreePath path , final Class < T > treeClass ) { TreePath p = path ; while ( p != null ) { Tree leaf = p . getLeaf ( ) ; if ( treeClass . isInstance ( leaf ) ) { return treeClass . cast ( leaf ) ; } p = p . getParentPath ( ) ; } return null ; }
gets the first enclosing tree in path , of the specified class
