final String stringAst = AstTreeStringPrinter.printFileAst(file, JavaParser.Options.WITHOUT_COMMENTS); System.out.print(stringAst); final String stringAst = AstTreeStringPrinter.printFileAst(file, JavaParser.Options.WITH_COMMENTS); System.out.print(stringAst);
/** * Performs verification of the given text ast tree representation. * @param expectedTextPrintFileName expected text ast tree representation. * @param actualJavaFileName actual text ast tree representation. * @param withComments whether to perform verification of comment nodes in tree. * @throws Exception if exception occurs during verification. */ protected static void verifyAst(String expectedTextPrintFileName, String actualJavaFileName, JavaParser.Options withComments) throws Exception { final String expectedContents = readFile(expectedTextPrintFileName); final String actualContents = AstTreeStringPrinter.printFileAst( new File(actualJavaFileName), withComments).replaceAll(CRLF_REGEX, LF_REGEX); assertEquals("Generated AST from Java file should match pre-defined AST", expectedContents, actualContents); }
@Test public void testParseFileThrowable() throws Exception { final File input = new File(getNonCompilablePath("InputAstTreeStringPrinter.java")); try { AstTreeStringPrinter.printFileAst(input, JavaParser.Options.WITHOUT_COMMENTS); Assert.fail("exception expected"); } catch (CheckstyleException ex) { Assert.assertSame("Invalid class", NoViableAltException.class, ex.getCause().getClass()); Assert.assertEquals("Invalid exception message", input.getAbsolutePath() + ":2:1: unexpected token: classD", ex.getCause().toString()); } }
final String stringAst = AstTreeStringPrinter.printFileAst(file, JavaParser.Options.WITHOUT_COMMENTS); System.out.print(stringAst); final String stringAst = AstTreeStringPrinter.printFileAst(file, JavaParser.Options.WITH_COMMENTS); System.out.print(stringAst);