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

net.sourceforge.pmd.renderers.AbstractIncrementingRenderer 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.Iterator;
import java.util.LinkedList;
import java.util.List;

import net.sourceforge.pmd.lang.document.TextFile;
import net.sourceforge.pmd.reporting.Report;
import net.sourceforge.pmd.reporting.RuleViolation;

/**
 * Abstract base class for {@link Renderer} implementations which can produce
 * output incrementally for {@link RuleViolation}s as source files are
 * processed. Such {@link Renderer}s are able to produce large reports with
 * significantly less working memory at any given time. Variations in the
 * delivery of source file reports are reflected in the output of the
 * {@link Renderer}, so report output can be different between runs.
 *
 * 

Only processing errors and suppressed violations are accumulated across all * files. These are intended to be processed in the {@link #end()} method. */ public abstract class AbstractIncrementingRenderer extends AbstractRenderer { /** * Accumulated processing errors. */ protected List errors = new LinkedList<>(); /** * Accumulated configuration errors. */ protected List configErrors = new LinkedList<>(); /** * Accumulated suppressed violations. */ protected List suppressed = new LinkedList<>(); public AbstractIncrementingRenderer(String name, String description) { super(name, description); } @Override public void start() throws IOException { // does nothing - override if necessary } @Override public void startFileAnalysis(TextFile dataSource) { // does nothing - override if necessary } @Override public void renderFileReport(Report report) throws IOException { Iterator violations = report.getViolations().iterator(); if (violations.hasNext()) { renderFileViolations(violations); getWriter().flush(); } errors.addAll(report.getProcessingErrors()); configErrors.addAll(report.getConfigurationErrors()); if (showSuppressedViolations) { suppressed.addAll(report.getSuppressedViolations()); } } /** * Render a series of {@link RuleViolation}s. * * @param violations * The iterator of violations to render. * @throws IOException */ public abstract void renderFileViolations(Iterator violations) throws IOException; @Override public void end() throws IOException { // does nothing - override if necessary } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy