diff --git a/pmd/xdocs/howtowritearule.xml b/pmd/xdocs/howtowritearule.xml index b7490cdcea..85071ec1ce 100644 --- a/pmd/xdocs/howtowritearule.xml +++ b/pmd/xdocs/howtowritearule.xml @@ -126,14 +126,40 @@ WhileStatement
Ah ha! We see that the curly braces add a couple more AST elements - a Block and a BlockStatement. So all we have - to do is write a rule to detect a WhileStatement that's not followed by a Block, and we've got it. + to do is write a rule to detect a WhileStatement that has a Statement that's not followed by a Block, and we've got a rule violation.
+ Create a new Java class that extends net.sourceforge.pmd.AbstractRule
:
+
+ That was easy. PMD works by creating the AST and then traverses it recursively so a rule can get a callback + for any type it's interested in. So let's make sure our rule gets called whenever the AST traversal finds a WhileStatement: +
+ +
+ We stuck a println()
in there for now so we can see when our rule gets hit.
+