/** * Parse a file and print the parse tree. * @param text the text to parse. * @param options {@link JavaParser.Options} to control the inclusion of comment nodes. * @return the AST of the file in String form. * @throws CheckstyleException if the file is not a Java source. */ public static String printAst(FileText text, JavaParser.Options options) throws CheckstyleException { final DetailAST ast = JavaParser.parseFileText(text, options); return printTree(ast); }
/** * Parse a file and print the parse tree. * @param file the file to print. * @param options {@link JavaParser.Options} to control the inclusion of comment nodes. * @return the AST of the file in String form. * @throws IOException if the file could not be read. * @throws CheckstyleException if the file is not a Java source. */ public static String printFileAst(File file, JavaParser.Options options) throws IOException, CheckstyleException { return printTree(JavaParser.parseFile(file, options)); }
/** * Print AST. * @param ast the root AST node. * @return string AST. */ private static String printTree(DetailAST ast) { final StringBuilder messageBuilder = new StringBuilder(1024); DetailAST node = ast; while (node != null) { messageBuilder.append(getIndentation(node)) .append(getNodeInfo(node)) .append(LINE_SEPARATOR) .append(printTree(node.getFirstChild())); node = node.getNextSibling(); } return messageBuilder.toString(); }
/** * Parse a file and print the parse tree. * @param file the file to print. * @param options {@link JavaParser.Options} to control the inclusion of comment nodes. * @return the AST of the file in String form. * @throws IOException if the file could not be read. * @throws CheckstyleException if the file is not a Java source. */ public static String printFileAst(File file, JavaParser.Options options) throws IOException, CheckstyleException { return printTree(JavaParser.parseFile(file, options)); }
/** * Parse a file and print the parse tree. * @param text the text to parse. * @param options {@link JavaParser.Options} to control the inclusion of comment nodes. * @return the AST of the file in String form. * @throws CheckstyleException if the file is not a Java source. */ public static String printAst(FileText text, JavaParser.Options options) throws CheckstyleException { final DetailAST ast = JavaParser.parseFileText(text, options); return printTree(ast); }
/** * Print AST. * @param ast the root AST node. * @return string AST. */ private static String printTree(DetailAST ast) { final StringBuilder messageBuilder = new StringBuilder(1024); DetailAST node = ast; while (node != null) { messageBuilder.append(getIndentation(node)) .append(getNodeInfo(node)) .append(LINE_SEPARATOR) .append(printTree(node.getFirstChild())); node = node.getNextSibling(); } return messageBuilder.toString(); }