From aa45a0490e31778d0eef3494d79b9d2da27e1b00 Mon Sep 17 00:00:00 2001
From: Baratali Izmailov
- Javadoc by specification could contain any HTML tags that to let user generate content hi needs.
+ Javadoc by specification could contain any HTML tags that to let user generate content he needs.
Checkstyle can not parse something that looks like an HTML, so limitation appear.
The comment should be written in XHTML to be correctly processed by Checkstyle. This means that every HTML tag should have matching closed HTML tag or it is self-closed one (singlton tag).
The only exceptions are <p>, <li>, <tr>, <td>, <th>, <body>, <colgroup>, <dd>, <dt>, <head>, <html>, <option>,
@@ -58,6 +58,10 @@ public class MyClass {
Javadoc parser requires XHTML to be used in Javadoc comments, i.e. if there is some open tag(for example <div>) then there have to be its close tag </div>.
This means that if Javadoc comment has incorrect XHTML structure then Javadoc Parser will fail processing the comment, therefore, your new Check can't get its parse tree and process anything from this Javadoc comment. For more details and examples go to "HTML code in Javadoc comments" section.
+ Javadoc grammar requires XHTML, but it can also parse some parts of HTML code (like some unclosed tags). However result tree will be unpredictable.
+ It is done just to not fail on every Javadoc comment, because there are tons of using unclosed tags, etc.
+
+ In Javadoc comment every whitespace matters, so parse tree contains whitespace nodes (WS javadoc token type).
+ So do CHAR javadoc token that presents single character. The only redundancy Javadoc tree has because of this is that TEXT node
+ consists of CHAR and WS nodes which is useless, but it is implementation nuance. (In future we will try to resolve this).
+
For example, to write a JavadocCheck that verifies @param tags in Javadoc comment of a method definition, you also need all method's parameter names. To get method definition AST you should access main DetailAST tree throuth block comment AST. For this purpose use getBlockCommentAst() method that returns DetailAST node.
+ Example:
+
- Examples:
- 1) Unclosed paragraph HTML tag. As you see in the tree, content of the paragraph tag is not nested to this tag. That is because HTML tags are not closed by pair tag </p>, and Checkstyle requires XHTML to predictably parse Javadoc comments.
-
| + 1) Unclosed paragraph HTML tag. As you see in the tree, content of the paragraph tag is not nested to this tag. + That is because HTML tags are not closed by pair tag </p>, and Checkstyle requires XHTML to predictably parse Javadoc comments. + | ++ 2) Here is correct version with open and closed HTML tags. + | +
|
+ Second - ]]> |
+
+ Second + ]]> |
+
|
+ First\r\n Second [0:0]
| `--P_TAG_OPEN -> [0:0]
@@ -248,15 +310,10 @@ JAVADOC -> First\r\n Second - 2) Here is correct version with open and closed HTML tags. - -Second - ]]> |
+
+ First \r\nSecond First [0:0] | `--PARAGRAPH ->First [0:0] @@ -299,7 +356,10 @@ JAVADOC ->First \r\nSecond |
+