CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-net-sourceforge-pmd--pmd-java

Java language support module for the PMD static code analyzer with AST processing, symbol resolution, type system, metrics, and 400+ built-in rules

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

PMD Java

PMD Java is a comprehensive Java language support module for the PMD static code analyzer. It provides sophisticated Abstract Syntax Tree (AST) parsing, symbol resolution, type checking, code metrics calculation, and over 400 built-in rules for detecting code quality issues. This module enables advanced static analysis of Java code for quality assurance, security analysis, performance optimization, and code style enforcement.

Package Information

  • Package Name: net.sourceforge.pmd:pmd-java
  • Package Type: Maven
  • Language: Java
  • Version: 7.13.0
  • Installation:
    <dependency>
      <groupId>net.sourceforge.pmd</groupId>
      <artifactId>pmd-java</artifactId>
      <version>7.13.0</version>
    </dependency>
  • Java Version Support: Java 1.3 through Java 24 (including preview features)

Core Imports

import net.sourceforge.pmd.lang.java.JavaLanguageModule;
import net.sourceforge.pmd.lang.java.ast.*;
import net.sourceforge.pmd.lang.java.symbols.*;
import net.sourceforge.pmd.lang.java.types.*;
import net.sourceforge.pmd.lang.java.metrics.JavaMetrics;

For AST processing:

import net.sourceforge.pmd.lang.java.ast.JavaNode;
import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
import net.sourceforge.pmd.lang.java.ast.JavaVisitorBase;

For symbol resolution and type system:

import net.sourceforge.pmd.lang.java.symbols.JClassSymbol;
import net.sourceforge.pmd.lang.java.symbols.table.JSymbolTable;
import net.sourceforge.pmd.lang.java.types.JTypeMirror;
import net.sourceforge.pmd.lang.java.types.TypeSystem;

Basic Usage

import net.sourceforge.pmd.lang.java.JavaLanguageModule;
import net.sourceforge.pmd.lang.java.ast.*;
import net.sourceforge.pmd.lang.java.symbols.*;
import net.sourceforge.pmd.lang.java.types.*;

// Get the Java language module instance
JavaLanguageModule javaModule = JavaLanguageModule.getInstance();

// Create a visitor to traverse AST
public class MyJavaVisitor extends JavaVisitorBase<Void, Void> {
    @Override
    public Void visit(ASTMethodCall node, Void data) {
        // Access method information
        String methodName = node.getMethodName();
        JTypeMirror returnType = node.getTypeMirror();
        
        // Access symbol information
        JSymbolTable symbolTable = node.getSymbolTable();
        
        return super.visit(node, data);
    }
    
    @Override
    public Void visit(ASTClassDeclaration node, Void data) {
        // Access class information
        String className = node.getSimpleName();
        JClassSymbol classSymbol = node.getSymbol();
        
        return super.visit(node, data);
    }
}

// Example: Calculate metrics for a compilation unit
ASTCompilationUnit compilationUnit = /* ... parsed AST ... */;
double cyclomaticComplexity = JavaMetrics.CYCLO.computeFor(compilationUnit, null);

Architecture

PMD Java is built around several key components that work together to provide comprehensive Java language analysis:

  • Language Module: Core entry point (JavaLanguageModule) that integrates with the PMD framework and provides language identification, parser creation, and version support
  • AST System: 187+ node types representing all Java language constructs from basic expressions to advanced features like records and pattern matching
  • Symbol Resolution: Sophisticated symbol table system that resolves names to their declarations with full support for scoping rules and overloading
  • Type System: Complete type representation with support for generics, wildcards, intersection types, and type inference
  • Visitor Pattern: Hierarchical visitor implementation for traversing and analyzing AST structures
  • Metrics Engine: 12 built-in metrics with configurable options for measuring code quality and complexity
  • Rule Framework: Infrastructure for implementing over 400 built-in rules plus support for custom rule development

Capabilities

AST Processing

Complete Abstract Syntax Tree processing with 187+ node types covering all Java language constructs. Provides visitor pattern support for tree traversal and analysis.

public interface JavaNode extends JjtreeNode<JavaNode> {
    ASTTypeDeclaration getEnclosingType();
    @NonNull ASTCompilationUnit getRoot();
    @NonNull JSymbolTable getSymbolTable();
    TypeSystem getTypeSystem();
}

public class JavaVisitorBase<P, R> extends AstVisitorBase<P, R> implements JavaVisitor<P, R> {
    // Visit methods for all 187+ AST node types
    public R visit(ASTCompilationUnit node, P data);
    public R visit(ASTClassDeclaration node, P data);
    public R visit(ASTMethodDeclaration node, P data);
    // ... and 180+ more visit methods
}

AST Processing

Symbol Resolution and Type System

Advanced symbol resolution with comprehensive type system supporting generics, wildcards, and type inference. Enables semantic analysis and cross-reference resolution.

public interface JElementSymbol {
    String getSimpleName();
    boolean nameEquals(@NonNull String name);
    TypeSystem getTypeSystem();
    boolean isUnresolved();
}

public interface JTypeMirror {
    boolean isSubtypeOf(@NonNull JTypeMirror other);
    JTypeMirror getErasure();
    boolean isPrimitive();
    boolean isArray();
    boolean isClassOrInterface();
}

Symbols and Types

Code Metrics

Built-in metrics system with 12 configurable metrics for measuring code quality, complexity, and maintainability.

public final class JavaMetrics {
    public static final Metric<ASTAnyTypeDeclaration, Double> CYCLO;
    public static final Metric<ASTAnyTypeDeclaration, Integer> LINES_OF_CODE;
    public static final Metric<ASTAnyTypeDeclaration, Integer> NCSS;
    public static final Metric<ASTAnyTypeDeclaration, Integer> NPATH;
    // ... 8 more metrics
}

Metrics

Rule Framework

Infrastructure for rule definition and execution with support for visitor-based rules, XPath rules, and custom rule development.

public class JavaLanguageModule extends LanguageModuleBase 
    implements PmdCapableLanguage, CpdCapableLanguage {
    
    public static JavaLanguageModule getInstance();
    public LanguageProcessor createProcessor(LanguagePropertyBundle bundle);
    public CpdLexer createCpdLexer(LanguagePropertyBundle bundle);
}

Rule Framework

Language Support

Core language module capabilities including parsing, copy-paste detection, and multi-version Java support from 1.3 to 24.

public class JavaLanguageModule extends LanguageModuleBase {
    public static JavaLanguageModule getInstance();
    public LanguagePropertyBundle newPropertyBundle();
    public LanguageProcessor createProcessor(LanguagePropertyBundle bundle);
}

Language Support

Common Types

// Core AST interfaces
public interface JavaNode extends JjtreeNode<JavaNode> {
    ASTTypeDeclaration getEnclosingType();
    @NonNull ASTCompilationUnit getRoot();
    @NonNull JSymbolTable getSymbolTable();
    TypeSystem getTypeSystem();
}

// Modifier enumeration
public enum JModifier {
    PUBLIC, PROTECTED, PRIVATE, SEALED, NON_SEALED, ABSTRACT, STATIC, 
    FINAL, SYNCHRONIZED, NATIVE, DEFAULT, STRICTFP, TRANSIENT, VOLATILE;
    
    String getToken();
    int getReflectMod();
}

// Visibility enumeration
public enum Visibility {
    PRIVATE(1), PACKAGE(2), PROTECTED(3), PUBLIC(4);
    
    boolean isAtLeast(Visibility other);
    boolean isAtMost(Visibility other);
}
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/net.sourceforge.pmd/pmd-java@7.13.x
Publish Source
CLI
Badge
tessl/maven-net-sourceforge-pmd--pmd-java badge