/** * 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); }
/** * Parses Java source file. * @param file the file to parse * @param options {@link Options} to control inclusion of comment nodes * @return DetailAST tree * @throws IOException if the file could not be read * @throws CheckstyleException if the file is not a valid Java source file */ public static DetailAST parseFile(File file, Options options) throws IOException, CheckstyleException { final FileText text = new FileText(file.getAbsoluteFile(), System.getProperty("file.encoding", StandardCharsets.UTF_8.name())); return parseFileText(text, options); }
/** * Prints generated suppressions. * @param file the file to process. * @param suppressionLineColumnNumber line and column number of the suppression * @param tabWidth length of the tab character * @return generated suppressions. * @throws IOException if the file could not be read. * @throws CheckstyleException if the file is not a Java source. */ public static String printSuppressions(File file, String suppressionLineColumnNumber, int tabWidth) throws IOException, CheckstyleException { final Matcher matcher = VALID_SUPPRESSION_LINE_COLUMN_NUMBER_REGEX.matcher(suppressionLineColumnNumber); if (matcher.matches()) { final FileText fileText = new FileText(file.getAbsoluteFile(), System.getProperty("file.encoding", StandardCharsets.UTF_8.name())); final DetailAST detailAST = JavaParser.parseFileText(fileText, JavaParser.Options.WITH_COMMENTS); final int lineNumber = Integer.parseInt(matcher.group(1)); final int columnNumber = Integer.parseInt(matcher.group(2)); return generate(fileText, detailAST, lineNumber, columnNumber, tabWidth); } else { final String exceptionMsg = String.format(Locale.ROOT, "%s does not match valid format 'line:column'.", suppressionLineColumnNumber); throw new IllegalStateException(exceptionMsg); } }
/** * 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); }
/** * Parses Java source file. * @param file the file to parse * @param options {@link Options} to control inclusion of comment nodes * @return DetailAST tree * @throws IOException if the file could not be read * @throws CheckstyleException if the file is not a valid Java source file */ public static DetailAST parseFile(File file, Options options) throws IOException, CheckstyleException { final FileText text = new FileText(file.getAbsoluteFile(), System.getProperty("file.encoding", StandardCharsets.UTF_8.name())); return parseFileText(text, options); }
/** * Prints generated suppressions. * @param file the file to process. * @param suppressionLineColumnNumber line and column number of the suppression * @param tabWidth length of the tab character * @return generated suppressions. * @throws IOException if the file could not be read. * @throws CheckstyleException if the file is not a Java source. */ public static String printSuppressions(File file, String suppressionLineColumnNumber, int tabWidth) throws IOException, CheckstyleException { final Matcher matcher = VALID_SUPPRESSION_LINE_COLUMN_NUMBER_REGEX.matcher(suppressionLineColumnNumber); if (matcher.matches()) { final FileText fileText = new FileText(file.getAbsoluteFile(), System.getProperty("file.encoding", StandardCharsets.UTF_8.name())); final DetailAST detailAST = JavaParser.parseFileText(fileText, JavaParser.Options.WITH_COMMENTS); final int lineNumber = Integer.parseInt(matcher.group(1)); final int columnNumber = Integer.parseInt(matcher.group(2)); return generate(fileText, detailAST, lineNumber, columnNumber, tabWidth); } else { final String exceptionMsg = String.format(Locale.ROOT, "%s does not match valid format 'line:column'.", suppressionLineColumnNumber); throw new IllegalStateException(exceptionMsg); } }