JavadocDetailNodeParser.java 文件源码

java
阅读 29 收藏 0 点赞 0 评论 0

项目:checkstyle-backport-jre6 作者:
/**
 * Method to get the missed HTML tag to generate more informative error message for the user.
 * This method doesn't concern itself with
 * <a href="https://www.w3.org/TR/html51/syntax.html#void-elements">void elements</a>
 * since it is forbidden to close them.
 * Missed HTML tags for the following tags will <i>not</i> generate an error message from ANTLR:
 * {@code
 * <p>
 * <li>
 * <tr>
 * <td>
 * <th>
 * <body>
 * <colgroup>
 * <dd>
 * <dt>
 * <head>
 * <html>
 * <option>
 * <tbody>
 * <thead>
 * <tfoot>
 * }
 * @param exception {@code NoViableAltException} object catched while parsing javadoc
 * @return returns appropriate {@link Token} if a HTML close tag is missed;
 *     null otherwise
 */
private static Token getMissedHtmlTag(RecognitionException exception) {
    Token htmlTagNameStart = null;
    final Interval sourceInterval = exception.getCtx().getSourceInterval();
    final List<Token> tokenList = ((BufferedTokenStream) exception.getInputStream())
            .getTokens(sourceInterval.a, sourceInterval.b);
    final Deque<Token> stack = new ArrayDeque<Token>();
    for (int i = 0; i < tokenList.size(); i++) {
        final Token token = tokenList.get(i);
        if (token.getType() == JavadocTokenTypes.HTML_TAG_NAME
                && tokenList.get(i - 1).getType() == JavadocTokenTypes.START) {
            stack.push(token);
        }
        else if (token.getType() == JavadocTokenTypes.HTML_TAG_NAME && !stack.isEmpty()) {
            if (stack.peek().getText().equals(token.getText())) {
                stack.pop();
            }
            else {
                htmlTagNameStart = stack.pop();
            }
        }
    }
    if (htmlTagNameStart == null) {
        htmlTagNameStart = stack.pop();
    }
    return htmlTagNameStart;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号