net.sourceforge.pmd.renderers.TextPadRenderer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pmd-core Show documentation
Show all versions of pmd-core Show documentation
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 net.sourceforge.pmd.reporting.RuleViolation;
/**
*
* A Renderer for running PMD via a TextPad 'tool'.
* TextPad is a text editor by Helios
* Software Solutions.
*
*
* Output lines are in the form:
*
*
* pathtojavafile(line#, NameOfRule): Specific rule violation message
*
*
* For example:
*
*
* D:\java\pmd\src\src\net\sourceforge\pmd\renderers\TextPadRenderer.java(24, AtLeastOneConstructor): Each class should declare at least one constructor
*
D:\java\pmd\src\src\net\sourceforge\pmd\renderers\TextPadRenderer.java(26, VariableNamingConventionsRule): Variables should start with a lowercase character
*
D:\java\pmd\src\src\net\sourceforge\pmd\renderers\TextPadRenderer.java(31, ShortVariable): Avoid variables with short names
*
*
* @author Jeff Epstein, based upon
* EmacsRenderer, Tuesday, September
* 23, 2003
*/
public class TextPadRenderer extends AbstractIncrementingRenderer {
public static final String NAME = "textpad";
public TextPadRenderer() {
super(NAME, "TextPad integration.");
}
@Override
public String defaultFileExtension() {
return "txt";
}
@Override
public void renderFileViolations(Iterator violations) throws IOException {
StringBuilder buf = new StringBuilder();
while (violations.hasNext()) {
RuleViolation rv = violations.next();
buf.setLength(0);
// Filename
buf.append(determineFileName(rv.getFileId())).append("(");
// Line number
buf.append(rv.getBeginLine()).append(", ");
// Name of violated rule
buf.append(rv.getRule().getName()).append("): ");
// Specific violation message
buf.append(rv.getDescription());
writer.println(buf);
}
}
}