git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@535 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Tom Copeland
2002-07-26 21:40:25 +00:00
parent 4c29c04781
commit ed6976cc69

View File

@ -126,8 +126,8 @@ WhileStatement
]]>
</source>
<p>
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 has a Statement that's not followed by a Block, and we've got a rule violation.
Ah ha! We see that the curly braces add a couple more AST elements - a <code>Block</code> and a <code>BlockStatement</code>. So all we have
to do is write a rule to detect a <code>WhileStatement</code> that has a <code>Statement</code> that's not followed by a <code>Block</code>, and we've got a rule violation.
</p>
</subsection>
@ -143,7 +143,7 @@ public class WhileLoopsMustUseBracesRule extends AbstractRule {
</source>
<p>
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:
for any type it's interested in. So let's make sure our rule gets called whenever the AST traversal finds a <code>WhileStatement</code>:
</p>
<source>
<![CDATA[
@ -163,7 +163,7 @@ public class WhileLoopsMustUseBracesRule extends AbstractRule {
<subsection name="Put the WhileLoopsMustUseBracesRule rule in a ruleset file">
<p>
Now our rule is written - at least, the shell of it is - and now we need to tell PMD about it. We need
to add it to a rule set XML file. Look at rulesets/basic.xml; it's got lots of rule definitions that look like this:
to add it to a rule set XML file. Look at <code>rulesets/basic.xml</code>; it's got lots of rule definitions that look like this:
</p>
<source>
<![CDATA[
@ -200,13 +200,13 @@ which should either be acted on or reported.
</ul>
</subsection>
<p>
We'll just leave this rule in the rulesets/basic.xml ruleset for now. If you write rules for your own
project that aren't applicable to other projects (rules to catch Thread creation, for example, or rules to catch
System.out.println() usages) you might want to make a new ruleset <code>myproject.xml</code> and put your rules in there.
We'll just leave this rule in the <code>rulesets/basic.xml</code> ruleset for now. If you write rules for your own
project that aren't applicable to other projects (rules to catch <code>Thread</code> creation, for example, or rules to catch
<code>System.out.println()</code> usages) you might want to make a new ruleset <code>myproject.xml</code> and put your rules in there.
</p>
<subsection name="Run PMD using your new ruleset">
<p>
Remember when we ran go.bat over the Example.java file? Do it again. This time your "hello world" will show up right after the
Remember when we ran <code>go.bat</code> over the <code>Example.java</code>? Do it again. This time your "hello world" will show up right after the
AST gets printed out. If it doesn't, post a message to
<a href="http://sourceforge.net/forum/forum.php?forum_id=188192">the forum</a> so we can improve this document :-)
</p>