01: package net.sourceforge.pmd.renderers;
02:
03: import java.io.IOException;
04: import java.io.Writer;
05: import java.util.Iterator;
06: import java.util.LinkedList;
07: import java.util.List;
08:
09: import net.sourceforge.pmd.IRuleViolation;
10: import net.sourceforge.pmd.Report;
11:
12: public abstract class OnTheFlyRenderer extends AbstractRenderer {
13:
14: protected List<Report.ProcessingError> errors = new LinkedList<Report.ProcessingError>();
15:
16: protected List<Report.SuppressedViolation> suppressed = new LinkedList<Report.SuppressedViolation>();
17:
18: public void render(Writer writer, Report report) throws IOException {
19: setWriter(writer);
20: start();
21: renderFileReport(report);
22: end();
23: }
24:
25: public void renderFileReport(Report report) throws IOException {
26: Iterator<IRuleViolation> violations = report.iterator();
27: if (violations.hasNext()) {
28: renderFileViolations(violations);
29: getWriter().flush();
30: }
31:
32: /*
33: * errors and suppressed violations are inserted in lists and will be
34: * processed when all files have been analyzed, i.e. in the end() method.
35: */
36: for (Iterator<Report.ProcessingError> i = report.errors(); i
37: .hasNext();) {
38: errors.add(i.next());
39: }
40:
41: if (showSuppressedViolations) {
42: suppressed.addAll(report.getSuppressedRuleViolations());
43: }
44: }
45:
46: public abstract void start() throws IOException;
47:
48: public abstract void renderFileViolations(
49: Iterator<IRuleViolation> violations) throws IOException;
50:
51: public abstract void end() throws IOException;
52:
53: }
|