View Javadoc

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   
9   import java.io.IOException;
10  import java.io.Writer;
11  import java.util.Iterator;
12  
13  /**
14   * <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>
15   * <p/>
16   * <P>Output lines are in the form:</P>
17   * <p/>
18   * <P><CODE>pathtojavafile(line#, NameOfRule):&nbsp; Specific rule violation message</CODE></P>
19   * <p/>
20   * <P>For example:</P>
21   * <p/>
22   * <P><CODE>D:\java\pmd\src\src\net\sourceforge\pmd\renderers\TextPadRenderer.java(24, AtLeastOneConstructor):&nbsp; Each class should declare at least one constructor
23   * <br>D:\java\pmd\src\src\net\sourceforge\pmd\renderers\TextPadRenderer.java(26, VariableNamingConventionsRule):&nbsp; Variables should start with a lowercase character
24   * <br>D:\java\pmd\src\src\net\sourceforge\pmd\renderers\TextPadRenderer.java(31, ShortVariable):&nbsp; Avoid variables with short names</CODE></P>
25   *
26   * @author Jeff Epstein, based upon <a href="EmacsRenderer.html">EmacsRenderer</a>, Tuesday, September 23, 2003
27   */
28  public class TextPadRenderer extends OnTheFlyRenderer {
29  
30      public void start() throws IOException {}
31  
32      public void renderFileViolations(Iterator<IRuleViolation> violations) throws IOException {
33          Writer writer = getWriter();
34          StringBuffer buf = new StringBuffer();
35          while (violations.hasNext()) {
36              IRuleViolation rv = violations.next();
37              buf.setLength(0);
38              //Filename
39              buf.append(PMD.EOL).append(rv.getFilename() + "(");
40              //Line number
41              buf.append(Integer.toString(rv.getBeginLine())).append(",  ");
42              //Name of violated rule
43              buf.append(rv.getRule().getName()).append("):  ");
44              //Specific violation message
45              buf.append(rv.getDescription());
46              writer.write(buf.toString());
47          }
48      }
49  
50      public void end() throws IOException {}
51  }