KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > pmd > renderers > TextPadRenderer


1 /**
2  * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3  */

4 package net.sourceforge.pmd.renderers;
5
6 import net.sourceforge.pmd.IRuleViolation;
7 import net.sourceforge.pmd.PMD;
8 import net.sourceforge.pmd.Report;
9
10 import java.io.IOException JavaDoc;
11 import java.io.Writer JavaDoc;
12 import java.util.Iterator JavaDoc;
13
14 /**
15  * <P>A Renderer for running PMD via a TextPad 'tool'. <a HREF="http://www.textpad.com">TextPad</a> is a text editor by Helios Software Solutions.</P>
16  * <p/>
17  * <P>Output lines are in the form:</P>
18  * <p/>
19  * <P><CODE>pathtojavafile(line#, NameOfRule):&nbsp; Specific rule violation message</CODE></P>
20  * <p/>
21  * <P>For example:</P>
22  * <p/>
23  * <P><CODE>D:\java\pmd\src\src\net\sourceforge\pmd\renderers\TextPadRenderer.java(24, AtLeastOneConstructor):&nbsp; Each class should declare at least one constructor
24  * <br>D:\java\pmd\src\src\net\sourceforge\pmd\renderers\TextPadRenderer.java(26, VariableNamingConventionsRule):&nbsp; Variables should start with a lowercase character
25  * <br>D:\java\pmd\src\src\net\sourceforge\pmd\renderers\TextPadRenderer.java(31, ShortVariable):&nbsp; Avoid variables with short names</CODE></P>
26  *
27  * @author Jeff Epstein, based upon <a HREF="EmacsRenderer.html">EmacsRenderer</a>, Tuesday, September 23, 2003
28  */

29 public class TextPadRenderer extends AbstractRenderer {
30     public void render(Writer JavaDoc writer, Report report) throws IOException JavaDoc {
31         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
32         Iterator JavaDoc i;
33         try {
34             i = report.iterator();
35         } catch (NullPointerException JavaDoc npx) {
36             throw new NullPointerException JavaDoc("ERROR in " + this.getClass().getName() + ".render: Parameter report is null.");
37         }
38         while (i.hasNext()) {
39             IRuleViolation rv = (IRuleViolation) i.next();
40             buf.setLength(0);
41             //Filename
42
buf.append(PMD.EOL).append(rv.getFilename() + "(");
43             //Line number
44
buf.append(Integer.toString(rv.getBeginLine())).append(", ");
45             //Name of violated rule
46
buf.append(rv.getRule().getName()).append("): ");
47             //Specific violation message
48
buf.append(rv.getDescription());
49             writer.write(buf.toString());
50         }
51     }
52 }
53
Popular Tags