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.PMD;
7 import net.sourceforge.pmd.Report;
8 import net.sourceforge.pmd.RuleViolation;
9
10 import java.util.Iterator;
11
12 /***
13 <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>
14
15 <P>Output lines are in the form:</P>
16
17 <P><CODE>pathtojavafile(line#, NameOfRule): Specific rule violation message</CODE></P>
18
19 <P>For example:</P>
20
21 <P><CODE>D:\java\pmd\src\src\net\sourceforge\pmd\renderers\TextPadRenderer.java(24, AtLeastOneConstructor): Each class should declare at least one constructor
22 <br>D:\java\pmd\src\src\net\sourceforge\pmd\renderers\TextPadRenderer.java(26, VariableNamingConventionsRule): Variables should start with a lowercase character
23 <br>D:\java\pmd\src\src\net\sourceforge\pmd\renderers\TextPadRenderer.java(31, ShortVariable): Avoid variables with short names</CODE></P>
24
25 @author Jeff Epstein, based upon <a href="EmacsRenderer.html">EmacsRenderer</a>, Tuesday, September 23, 2003
26 **/
27 public class TextPadRenderer implements Renderer {
28
29 /***
30 <P>Get a string containing all errors as detected by PMD.</P>
31
32 @param report The report containing the errors. May not be null.
33 **/
34 public String render(Report report) {
35
36 StringBuffer buf = new StringBuffer();
37
38 Iterator i = null;
39 try {
40 i = report.iterator();
41 } catch(NullPointerException npx) {
42 throw new NullPointerException("ERROR in " + this.getClass().getName() + ".render: Parameter report is null.");
43 }
44
45 while(i.hasNext()) {
46 RuleViolation rv = (RuleViolation) i.next();
47
48
49 buf.append(PMD.EOL).append(rv.getFilename() + "(");
50
51
52 buf.append(Integer.toString(rv.getLine())).append(", ");
53
54
55 buf.append(rv.getRule().getName()).append("): ");
56
57
58 buf.append(rv.getDescription());
59 }
60
61 return buf.toString();
62 }
63 }