public static int endPos(JCTree tree) {
        if (tree.getTag() == JCTree.BLOCK && ((JCBlock) tree).endpos != Position.NOPOS)
            return ((JCBlock) tree).endpos;
        else if (tree.getTag() == JCTree.SYNCHRONIZED)
            return endPos(((JCSynchronized) tree).body);
        else if (tree.getTag() == JCTree.TRY) {
            JCTry t = (JCTry) tree;
            return endPos((t.finalizer != null)
                          ? t.finalizer
                          : t.catchers.last().body);
        } else
            return tree.pos;
    }