From e8b339974f6b10535f30794933a6f4d66d6ae0b8 Mon Sep 17 00:00:00 2001 From: Tom Copeland Date: Fri, 26 Jul 2002 16:37:17 +0000 Subject: [PATCH] tweak git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@527 51baf565-9d33-0410-a72c-fc3788e3496d --- pmd/xdocs/howtowritearule.xml | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) 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. +

+
- +