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.RuleViolation;
11  
12  /**
13   * Renderer to GNU Emacs parsable format.
14   */
15  public class EmacsRenderer extends AbstractIncrementingRenderer {
16  
17      public static final String NAME = "emacs";
18  
19      protected static final String EOL = System.getProperty("line.separator", "\n");
20  
21      public EmacsRenderer() {
22      	super(NAME, "GNU Emacs integration.");
23      }
24  
25      public String defaultFileExtension() { return "emacs"; }
26      
27      /**
28       * {@inheritDoc}
29       */
30      @Override
31      public void renderFileViolations(Iterator<RuleViolation> violations) throws IOException {
32  		Writer writer = getWriter();
33  		StringBuilder buf = new StringBuilder();
34  		while (violations.hasNext()) {
35  		    RuleViolation rv = violations.next();
36  		    buf.setLength(0);
37  		    buf.append(rv.getFilename());
38  		    buf.append(':').append(Integer.toString(rv.getBeginLine()));
39  		    buf.append(": ").append(rv.getDescription()).append(EOL);
40  		    writer.write(buf.toString());
41  		}
42      }
43  }