TextPadRenderer.java
01 /**
02  * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
03  */
04 package net.sourceforge.pmd.renderers;
05 
06 import java.io.IOException;
07 import java.io.Writer;
08 import java.util.Iterator;
09 import java.util.Properties;
10 
11 import net.sourceforge.pmd.PMD;
12 import net.sourceforge.pmd.RuleViolation;
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 AbstractIncrementingRenderer {
30 
31     public static final String NAME = "textpad";
32 
33     public TextPadRenderer(Properties properties) {
34   super(NAME, "TextPad integration.", properties);
35     }
36 
37     /**
38      * {@inheritDoc}
39      */
40     @Override
41     public void renderFileViolations(Iterator<RuleViolation> violationsthrows IOException {
42   Writer writer = getWriter();
43   StringBuffer buf = new StringBuffer();
44   while (violations.hasNext()) {
45       RuleViolation rv = violations.next();
46       buf.setLength(0);
47       //Filename
48       buf.append(rv.getFilename() "(");
49       //Line number
50       buf.append(Integer.toString(rv.getBeginLine())).append(",  ");
51       //Name of violated rule
52       buf.append(rv.getRule().getName()).append("):  ");
53       //Specific violation message
54       buf.append(rv.getDescription()).append(PMD.EOL);
55       writer.write(buf.toString());
56   }
57     }
58 }