View Javadoc

    1   package net.sourceforge.pmd.renderers;
    2
    3   import java.io.IOException;
    4   import java.io.Writer;
    5   import java.util.Iterator;
    6   import java.util.LinkedList;
    7   import java.util.List;
    8
    9   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.hasNext();) {
    37              errors.add(i.next());
    38          }
    39
    40          if (showSuppressedViolations) {
    41              suppressed.addAll(report.getSuppressedRuleViolations());
    42          }
    43      }
    44
    45      public abstract void start() throws IOException;
    46
    47      public abstract void renderFileViolations(Iterator<IRuleViolation> violations) throws IOException;
    48
    49      public abstract void end() throws IOException;
    50
    51  }