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