or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

ast-node-types.mdcopy-paste-detection.mdindex.mdjsp-parser-ast.mdlanguage-module.mdrule-development.mdvisitor-pattern.md
tile.json

tessl/maven-net-sourceforge-pmd--pmd-jsp

PMD JSP language module providing static code analysis capabilities for JavaServer Pages files with lexical analysis, AST parsing, and rule-based code quality checks.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/net.sourceforge.pmd/pmd-jsp@7.13.x

To install, run

npx @tessl/cli install tessl/maven-net-sourceforge-pmd--pmd-jsp@7.13.0

index.mddocs/

PMD JSP Language Module

PMD 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.

Package Information

  • Package Name: pmd-jsp
  • Package Type: Maven
  • Group ID: net.sourceforge.pmd
  • Artifact ID: pmd-jsp
  • Language: Java
  • Installation: Add to pom.xml:
<dependency>
    <groupId>net.sourceforge.pmd</groupId>
    <artifactId>pmd-jsp</artifactId>
    <version>7.13.0</version>
</dependency>

Core Imports

import net.sourceforge.pmd.lang.jsp.JspLanguageModule;
import net.sourceforge.pmd.lang.jsp.ast.*;
import net.sourceforge.pmd.lang.jsp.rule.AbstractJspRule;

Basic Usage

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);

Architecture

The PMD JSP module is built on several key components:

  • Language Registration: JspLanguageModule registers JSP as a supported language in PMD
  • Parser: JspParser converts JSP source into Abstract Syntax Trees using generated JavaCC parser
  • AST Nodes: Comprehensive set of AST node classes representing all JSP/HTML elements
  • Visitor Pattern: JspVisitor interface and JspVisitorBase for AST traversal
  • Rule Framework: AbstractJspRule base class for implementing custom JSP analysis rules
  • CPD Support: JspCpdLexer for copy-paste detection in JSP files

Capabilities

Language Module Registration

Register 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);
}

Language Module

JSP Parsing and AST

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();
}

JSP Parser and AST

AST Node Types

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();
}

AST Node Types

Visitor Pattern

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);
}

Visitor Pattern

Rule Development

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);
}

Rule Development

Copy-Paste Detection

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);
}

Copy-Paste Detection

Built-in Rules

The module includes pre-built rules organized into categories:

  • Best Practices: JSF nesting, class attributes, HTML comments, JSP forwards
  • Security: Unsanitized JSP expressions, iframe attributes
  • Design: Inline styles, scriptlets, long scripts
  • Code Style: Duplicate imports
  • Error Prone: Encoding issues

All rules are defined in XML rulesets and can be configured through PMD's standard rule configuration mechanisms.

Types

Core Interfaces

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
}

Base Classes

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 {
}

Language Registration

public class JspHandler extends AbstractPmdLanguageVersionHandler {
    public Parser getParser();
}

Exception Types

// Standard PMD parsing exceptions apply
import net.sourceforge.pmd.lang.ast.ParseException;