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 java.io.IOException;
    7   import java.io.Writer;
    8   import java.util.Iterator;
    9
    10  import net.sourceforge.pmd.PMD;
    11  import net.sourceforge.pmd.RuleViolation;
    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 AbstractIncrementingRenderer {
    29
    30      public static final String NAME = "textpad";
    31
    32      public TextPadRenderer() {
    33  	super(NAME, "TextPad integration.");
    34      }
    35
    36      public String defaultFileExtension() { return "txt"; }
    37
    38      /**
    39       * {@inheritDoc}
    40       */
    41      @Override
    42      public void renderFileViolations(Iterator<RuleViolation> violations) throws IOException {
    43  	Writer writer = getWriter();
    44  	StringBuffer buf = new StringBuffer();
    45  	while (violations.hasNext()) {
    46  	    RuleViolation rv = violations.next();
    47  	    buf.setLength(0);
    48  	    //Filename
    49  	    buf.append(rv.getFilename() + "(");
    50  	    //Line number
    51  	    buf.append(Integer.toString(rv.getBeginLine())).append(",  ");
    52  	    //Name of violated rule
    53  	    buf.append(rv.getRule().getName()).append("):  ");
    54  	    //Specific violation message
    55  	    buf.append(rv.getDescription()).append(PMD.EOL);
    56  	    writer.write(buf.toString());
    57  	}
    58      }
    59  }