All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sourceforge.pmd.renderers.AbstractAccumulatingRenderer Maven / Gradle / Ivy

Go to download

PMD is an extensible multilanguage static code analyzer. It finds common programming flaws like unused variables, empty catch blocks, unnecessary object creation, and so forth. It's mainly concerned with Java and Apex, but supports 16 other languages. It comes with 400+ built-in rules. It can be extended with custom rules. It uses JavaCC and Antlr to parse source files into abstract syntax trees (AST) and runs rules against them to find violations. Rules can be written in Java or using a XPath query. Currently, PMD supports Java, JavaScript, Salesforce.com Apex and Visualforce, Kotlin, Swift, Modelica, PLSQL, Apache Velocity, JSP, WSDL, Maven POM, HTML, XML and XSL. Scala is supported, but there are currently no Scala rules available. Additionally, it includes CPD, the copy-paste-detector. CPD finds duplicated code in Coco, C/C++, C#, Dart, Fortran, Gherkin, Go, Groovy, HTML, Java, JavaScript, JSP, Julia, Kotlin, Lua, Matlab, Modelica, Objective-C, Perl, PHP, PLSQL, Python, Ruby, Salesforce.com Apex and Visualforce, Scala, Swift, T-SQL, Typescript, Apache Velocity, WSDL, XML and XSL.

The newest version!
/**
 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
 */

package net.sourceforge.pmd.renderers;

import java.io.IOException;
import java.util.Objects;

import net.sourceforge.pmd.benchmark.TimeTracker;
import net.sourceforge.pmd.benchmark.TimedOperation;
import net.sourceforge.pmd.benchmark.TimedOperationCategory;
import net.sourceforge.pmd.lang.document.TextFile;
import net.sourceforge.pmd.reporting.FileAnalysisListener;
import net.sourceforge.pmd.reporting.GlobalAnalysisListener;
import net.sourceforge.pmd.reporting.Report;
import net.sourceforge.pmd.reporting.Report.ConfigurationError;
import net.sourceforge.pmd.reporting.Report.GlobalReportBuilderListener;

/**
 * Abstract base class for {@link Renderer} implementations which only produce
 * output once all source files are processed. Such {@link Renderer}s use
 * working memory proportional to the number of violations found, which can be
 * quite large in some scenarios. Consider using
 * {@link AbstractIncrementingRenderer} which can use significantly less memory.
 *
 * 

Subclasses should only implement the {@link #outputReport(Report)} method to output the * complete {@link Report} in the end. * * @see AbstractIncrementingRenderer */ public abstract class AbstractAccumulatingRenderer extends AbstractRenderer { public AbstractAccumulatingRenderer(String name, String description) { super(name, description); } @Override public void start() throws IOException { // do nothing } @Override public void end() throws IOException { // do nothing } @Override public void startFileAnalysis(TextFile dataSource) { Objects.requireNonNull(dataSource); } /** * {@inheritDoc} * * @implNote The implementation in this class does nothing. All the reported violations and * errors are accumulated and can be rendered once with {@link #outputReport(Report)} in the * end. Subclasses of {@link AbstractAccumulatingRenderer} cannot override this method * anymore. */ @Override public final void renderFileReport(Report report) throws IOException { // do nothing, final because it will never be called by the listener Objects.requireNonNull(report); } /** * Output the report, called once at the end of the analysis. * * {@inheritDoc} */ protected abstract void outputReport(Report report) throws IOException; @Override public GlobalAnalysisListener newListener() throws IOException { try (TimedOperation ignored = TimeTracker.startOperation(TimedOperationCategory.REPORTING)) { this.start(); } return new GlobalAnalysisListener() { final GlobalReportBuilderListener reportBuilder = new GlobalReportBuilderListener(); @Override public FileAnalysisListener startFileAnalysis(TextFile file) { AbstractAccumulatingRenderer.this.startFileAnalysis(file); return reportBuilder.startFileAnalysis(file); } @Override public void onConfigError(ConfigurationError error) { reportBuilder.onConfigError(error); } @Override public void close() throws Exception { reportBuilder.close(); try (TimedOperation ignored = TimeTracker.startOperation(TimedOperationCategory.REPORTING)) { outputReport(reportBuilder.getResult()); end(); flush(); } } }; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy