/**
* 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<>();
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;
}
JavadocDetailNodeParser.java 文件源码
java
阅读 26
收藏 0
点赞 0
评论 0
项目:checkstyle
作者:
评论列表
文章目录