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