/** * Parse javadoc comment to DetailNode tree. * @param javadocComment javadoc comment content * @return tree */ private static DetailNode parseJavadocAsDetailNode(String javadocComment) { final DetailAST blockComment = CommonUtil.createBlockCommentNode(javadocComment); return parseJavadocAsDetailNode(blockComment); }
/** * Parse a file and return the parse tree. * @param file the file to parse. * @return the root node of the parse tree. * @throws IOException if the file could not be read. */ private static DetailNode parseFile(File file) throws IOException { final FileText text = new FileText(file.getAbsoluteFile(), System.getProperty("file.encoding", StandardCharsets.UTF_8.name())); return parseJavadocAsDetailNode(text.getFullText().toString()); }
/** * Parses block comment as javadoc and prints its tree. * @param node block comment begin * @return string javadoc tree */ private static String parseAndPrintJavadocTree(DetailAST node) { final DetailAST javadocBlock = node.getParent(); final DetailNode tree = DetailNodeTreeStringPrinter.parseJavadocAsDetailNode(javadocBlock); String baseIndentation = getIndentation(node); baseIndentation = baseIndentation.substring(0, baseIndentation.length() - 2); final String rootPrefix = baseIndentation + " `--"; final String prefix = baseIndentation + " "; return DetailNodeTreeStringPrinter.printTree(tree, rootPrefix, prefix); }
/** * Extracts the first sentence as HTML formatted text from the comment of an DetailAST. * The end of the sentence is determined by the symbol "period", "exclamation mark" or * "question mark", followed by a space or the end of the text. Inline tags @code and @literal * are converted to HTML code. * @param ast to extract the first sentence * @return the first sentence of the inner {@code TokenTypes.BLOCK_COMMENT_BEGIN} node * or {@code null} if the first sentence is absent or malformed (does not end with period) * @throws CheckstyleException if a javadoc comment can not be parsed or an unsupported inline * tag found */ private static String getFirstJavadocSentence(DetailAST ast) throws CheckstyleException { String firstSentence = null; for (DetailAST child = ast.getFirstChild(); child != null && firstSentence == null; child = child.getNextSibling()) { // If there is an annotation, the javadoc comment will be a child of it. if (child.getType() == TokenTypes.ANNOTATION) { firstSentence = getFirstJavadocSentence(child); } // Otherwise, the javadoc comment will be right here. else if (child.getType() == TokenTypes.BLOCK_COMMENT_BEGIN && JavadocUtil.isJavadocComment(child)) { final DetailNode tree = DetailNodeTreeStringPrinter.parseJavadocAsDetailNode(child); firstSentence = getFirstJavadocSentence(tree); } } return firstSentence; }
/** * Parse javadoc comment to DetailNode tree. * @param javadocComment javadoc comment content * @return tree */ private static DetailNode parseJavadocAsDetailNode(String javadocComment) { final DetailAST blockComment = CommonUtil.createBlockCommentNode(javadocComment); return parseJavadocAsDetailNode(blockComment); }
/** * Parse a file and return the parse tree. * @param file the file to parse. * @return the root node of the parse tree. * @throws IOException if the file could not be read. */ private static DetailNode parseFile(File file) throws IOException { final FileText text = new FileText(file.getAbsoluteFile(), System.getProperty("file.encoding", StandardCharsets.UTF_8.name())); return parseJavadocAsDetailNode(text.getFullText().toString()); }
/** * Parses block comment as javadoc and prints its tree. * @param node block comment begin * @return string javadoc tree */ private static String parseAndPrintJavadocTree(DetailAST node) { final DetailAST javadocBlock = node.getParent(); final DetailNode tree = DetailNodeTreeStringPrinter.parseJavadocAsDetailNode(javadocBlock); String baseIndentation = getIndentation(node); baseIndentation = baseIndentation.substring(0, baseIndentation.length() - 2); final String rootPrefix = baseIndentation + " `--"; final String prefix = baseIndentation + " "; return DetailNodeTreeStringPrinter.printTree(tree, rootPrefix, prefix); }
/** * Extracts the first sentence as HTML formatted text from the comment of an DetailAST. * The end of the sentence is determined by the symbol "period", "exclamation mark" or * "question mark", followed by a space or the end of the text. Inline tags @code and @literal * are converted to HTML code. * @param ast to extract the first sentence * @return the first sentence of the inner {@code TokenTypes.BLOCK_COMMENT_BEGIN} node * or {@code null} if the first sentence is absent or malformed (does not end with period) * @throws CheckstyleException if a javadoc comment can not be parsed or an unsupported inline * tag found */ private static String getFirstJavadocSentence(DetailAST ast) throws CheckstyleException { String firstSentence = null; for (DetailAST child = ast.getFirstChild(); child != null && firstSentence == null; child = child.getNextSibling()) { // If there is an annotation, the javadoc comment will be a child of it. if (child.getType() == TokenTypes.ANNOTATION) { firstSentence = getFirstJavadocSentence(child); } // Otherwise, the javadoc comment will be right here. else if (child.getType() == TokenTypes.BLOCK_COMMENT_BEGIN && JavadocUtil.isJavadocComment(child)) { final DetailNode tree = DetailNodeTreeStringPrinter.parseJavadocAsDetailNode(child); firstSentence = getFirstJavadocSentence(tree); } } return firstSentence; }