PMD JSP language module providing static code analysis capabilities for JavaServer Pages files with lexical analysis, AST parsing, and rule-based code quality checks.
npx @tessl/cli install tessl/maven-net-sourceforge-pmd--pmd-jsp@7.13.0PMD JSP Language Module provides static code analysis capabilities for JavaServer Pages (JSP) files. This module implements a complete JSP language parser, generates Abstract Syntax Trees (AST) for JSP documents, and includes comprehensive rule-based code quality checks specifically designed for JSP syntax and best practices.
pom.xml:<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-jsp</artifactId>
<version>7.13.0</version>
</dependency>import net.sourceforge.pmd.lang.jsp.JspLanguageModule;
import net.sourceforge.pmd.lang.jsp.ast.*;
import net.sourceforge.pmd.lang.jsp.rule.AbstractJspRule;import net.sourceforge.pmd.lang.jsp.JspLanguageModule;
import net.sourceforge.pmd.lang.jsp.ast.ASTCompilationUnit;
import net.sourceforge.pmd.lang.jsp.ast.JspParser;
import net.sourceforge.pmd.lang.ast.Parser;
// Get the JSP language module instance
JspLanguageModule jspModule = JspLanguageModule.getInstance();
// Create parser for JSP files
Parser parser = new JspParser();
// Parse JSP content into AST (requires PMD framework setup)
// ASTCompilationUnit ast = parser.parse(parserTask);The PMD JSP module is built on several key components:
JspLanguageModule registers JSP as a supported language in PMDJspParser converts JSP source into Abstract Syntax Trees using generated JavaCC parserJspVisitor interface and JspVisitorBase for AST traversalAbstractJspRule base class for implementing custom JSP analysis rulesJspCpdLexer for copy-paste detection in JSP filesRegister JSP language with PMD framework and configure file extensions.
public class JspLanguageModule extends SimpleLanguageModuleBase implements CpdCapableLanguage {
public JspLanguageModule();
public static JspLanguageModule getInstance();
public CpdLexer createCpdLexer(LanguagePropertyBundle bundle);
}Parse JSP files into Abstract Syntax Trees with comprehensive node types for all JSP constructs.
public final class JspParser extends JjtreeParserAdapter<ASTCompilationUnit> {
public JspParser();
protected ASTCompilationUnit parseImpl(CharStream cs, ParserTask task) throws ParseException;
}
public interface JspNode extends JjtreeNode<JspNode> {
}
public final class ASTCompilationUnit extends AbstractJspNode implements RootNode {
public AstInfo<ASTCompilationUnit> getAstInfo();
}Comprehensive set of AST node classes for JSP elements, HTML structures, and embedded expressions.
public final class ASTElement extends AbstractJspNode {
public String getName();
public boolean isHasNamespacePrefix();
public String getNamespacePrefix();
public String getLocalName();
public boolean isEmpty();
public boolean isUnclosed();
}
public final class ASTJspExpression extends AbstractExpression {
public String getContent();
}
public final class ASTElExpression extends AbstractExpression {
public String getContent();
}Traverse and analyze JSP AST using the visitor pattern for custom analysis logic.
public class JspVisitorBase<P, R> extends AstVisitorBase<P, R> implements JspVisitor<P, R> {
}
public abstract class AbstractJspNode extends AbstractJjtreeNode<AbstractJspNode, JspNode> implements JspNode {
public final <P, R> R acceptVisitor(AstVisitor<? super P, ? extends R> visitor, P data);
protected abstract <P, R> R acceptVisitor(JspVisitor<? super P, ? extends R> visitor, P data);
}Create custom JSP analysis rules using the rule framework for code quality checks.
public abstract class AbstractJspRule extends AbstractRule implements JspVisitor<Object, Object> {
public void apply(Node target, RuleContext ctx);
public Object visitNode(Node node, Object param);
}Tokenize JSP files for duplicate code detection with PMD's CPD (Copy-Paste Detector).
public class JspCpdLexer extends JavaccCpdLexer {
protected TokenManager<JavaccToken> makeLexerImpl(TextDocument doc);
}The module includes pre-built rules organized into categories:
All rules are defined in XML rulesets and can be configured through PMD's standard rule configuration mechanisms.
public interface JspNode extends JjtreeNode<JspNode> {
// Marker interface for all JSP AST nodes
// Extends JjtreeNode to provide standard AST node functionality
}
public interface JspVisitor<P, R> {
// Generated interface for visiting JSP AST nodes
// Contains visit methods for all concrete AST node types
}public abstract class AbstractJspNode extends AbstractJjtreeNode<AbstractJspNode, JspNode> implements JspNode {
protected AbstractJspNode(int id);
public final <P, R> R acceptVisitor(AstVisitor<? super P, ? extends R> visitor, P data);
protected abstract <P, R> R acceptVisitor(JspVisitor<? super P, ? extends R> visitor, P data);
public String getXPathNodeName();
}
public abstract class AbstractContentNode extends AbstractJspNode {
public String getContent();
}
public abstract class AbstractExpression extends AbstractContentNode {
}public class JspHandler extends AbstractPmdLanguageVersionHandler {
public Parser getParser();
}// Standard PMD parsing exceptions apply
import net.sourceforge.pmd.lang.ast.ParseException;