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   
8   import net.sourceforge.pmd.Report;
9   import net.sourceforge.pmd.util.datasource.DataSource;
10  
11  /**
12   * Abstract base class for {@link Renderer} implementations which only produce
13   * output once all source files are processed.  Such {@link Renderer}s use
14   * working memory proportional to the number of violations found, which can
15   * be quite large in some scenarios.  Consider using
16   * {@link AbstractIncrementingRenderer} which can use significantly less memory.
17   * 
18   * Subclasses should implement the {@link #end()} method to output the
19   * {@link #report}.
20   * 
21   * @see AbstractIncrementingRenderer
22   */
23  public abstract class AbstractAccumulatingRenderer extends AbstractRenderer {
24  
25      /**
26       * The accumulated Report.
27       */
28      protected Report report;
29  
30      public AbstractAccumulatingRenderer(String name, String description) {
31  	super(name, description);
32      }
33  
34      /**
35       * {@inheritDoc}
36       */
37      public void start() throws IOException {
38  	report = new Report();
39      }
40  
41      /**
42       * {@inheritDoc}
43       */
44      public void startFileAnalysis(DataSource dataSource) {
45      }
46  
47      /**
48       * {@inheritDoc}
49       */
50      public void renderFileReport(Report report) throws IOException {
51  	this.report.merge(report);
52      }
53  
54      /**
55       * Subclasses should output the {@link #report}.
56       * 
57       * {@inheritDoc}
58       */
59      public abstract void end() throws IOException;
60  }