1 4 package net.sourceforge.pmd.renderers; 5 6 import net.sourceforge.pmd.IRuleViolation; 7 import net.sourceforge.pmd.PMD; 8 import net.sourceforge.pmd.Report; 9 10 import java.io.IOException ; 11 import java.io.Writer ; 12 import java.util.Iterator ; 13 14 public class TextRenderer extends AbstractRenderer { 15 16 public void render(Writer writer, Report report) throws IOException { 17 StringBuffer buf = new StringBuffer (); 18 19 if (report.isEmpty()) { 20 buf.append("No problems found!"); 21 if (showSuppressedViolations) { 22 addSuppressed(report, buf); 23 } 24 writer.write(buf.toString()); 25 return; 26 } 27 Iterator i; 28 29 for (i = report.iterator(); i.hasNext();) { 30 buf.setLength(0); 31 IRuleViolation rv = (IRuleViolation) i.next(); 32 buf.append(PMD.EOL).append(rv.getFilename()); 33 buf.append(':').append(Integer.toString(rv.getBeginLine())); 34 buf.append('\t').append(rv.getDescription()); 35 writer.write(buf.toString()); 36 } 37 38 for (i = report.errors(); i.hasNext();) { 39 buf.setLength(0); 40 Report.ProcessingError error = (Report.ProcessingError) i.next(); 41 buf.append(PMD.EOL).append(error.getFile()); 42 buf.append("\t-\t").append(error.getMsg()); 43 writer.write(buf.toString()); 44 } 45 46 if (showSuppressedViolations) { 47 buf.setLength(0); 48 addSuppressed(report, buf); 49 writer.write(buf.toString()); 50 } 51 } 52 53 private void addSuppressed(Report report, StringBuffer buf) { 54 55 Report.SuppressedViolation excluded; 56 57 for (Iterator i = report.getSuppressedRuleViolations().iterator(); i.hasNext();) { 58 excluded = (Report.SuppressedViolation) i.next(); 59 buf.append(PMD.EOL); 60 buf.append(excluded.getRuleViolation().getRule().getName()); 61 buf.append(" rule violation suppressed by "); 62 buf.append(excluded.suppressedByNOPMD() ? "//NOPMD" : "Annotation"); 63 buf.append(" in ").append(excluded.getRuleViolation().getFilename()); 64 } 65 } 66 } 67 | Popular Tags |