CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-net-sourceforge-pmd--pmd-vm

PMD language module for static analysis of Apache Velocity Template Language (VTL) files

Pending
Overview
Eval results
Files

language-integration.mddocs/

Language Module Integration

Core integration components that connect the Velocity template analysis module with PMD's multi-language framework, providing language registration, parsing coordination, and rule violation handling.

Capabilities

Language Module Registration

Main entry point for registering Velocity template support within PMD's language framework.

/**
 * Main language module class that registers Velocity template support in PMD.
 * Extends BaseLanguageModule to integrate with PMD's multi-language architecture.
 */
public class VmLanguageModule extends BaseLanguageModule {
    /** Language identifier constant used throughout PMD */
    public static final String NAME = "VM";
    /** Short language identifier for command-line and configuration */
    public static final String TERSE_NAME = "vm";
    
    /**
     * Constructor that registers the Velocity language module with PMD.
     * Automatically called during PMD initialization.
     */
    public VmLanguageModule();
}

Usage Example:

// PMD automatically discovers and registers language modules
// No manual instantiation required for standard PMD usage
VmLanguageModule module = new VmLanguageModule();

// Access language constants
String languageName = VmLanguageModule.NAME; // "VM"
String shortName = VmLanguageModule.TERSE_NAME; // "vm"

Language Version Handler

Coordinates parsing, AST dumping, and rule violation creation for Velocity templates.

/**
 * Language version handler that manages parsing and analysis coordination
 * for Velocity templates within PMD's processing pipeline.
 */
public class VmHandler extends AbstractLanguageVersionHandler {
    
    /**
     * Returns the rule violation factory for creating Velocity-specific violations.
     * @return VmRuleViolationFactory singleton instance
     */
    public RuleViolationFactory getRuleViolationFactory();
    
    /**
     * Creates a parser instance for processing Velocity template source code.
     * @param parserOptions Configuration options for parsing behavior
     * @return VmParser instance configured with the specified options
     */
    public Parser getParser(ParserOptions parserOptions);
    
    /**
     * Creates a visitor for dumping AST structure to output stream.
     * Used for debugging and analysis of parsed template structure.
     * @param writer Output writer for AST dump
     * @param prefix String prefix for formatting output
     * @param recurse Whether to recursively dump child nodes
     * @return VisitorStarter for AST dumping
     */
    public VisitorStarter getDumpFacade(Writer writer, String prefix, boolean recurse);
}

Usage Example:

import java.io.StringWriter;
import net.sourceforge.pmd.lang.Parser;
import net.sourceforge.pmd.lang.ParserOptions;

// Get handler instance (typically done by PMD framework)
VmHandler handler = new VmHandler();

// Create parser for Velocity templates
ParserOptions options = new ParserOptions();
Parser parser = handler.getParser(options);

// Get rule violation factory
RuleViolationFactory factory = handler.getRuleViolationFactory();

// Create AST dump facility for debugging
StringWriter writer = new StringWriter();
VisitorStarter dumper = handler.getDumpFacade(writer, "  ", true);

Rule Violation Factory

Singleton factory for creating standardized rule violations specific to Velocity templates.

/**
 * Factory class for creating rule violations specific to Velocity templates.
 * Ensures consistent violation formatting and metadata.
 * @deprecated See RuleViolationFactory
 * @InternalApi This class is intended for internal PMD use
 */
@Deprecated
@InternalApi
public class VmRuleViolationFactory implements RuleViolationFactory {
    /** Singleton instance for creating Velocity rule violations */
    public static final VmRuleViolationFactory INSTANCE;
    
    // Implementation methods inherited from RuleViolationFactory
    // Used internally by PMD framework for violation creation
}

Usage Example:

import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.rule.RuleViolationFactory;

// Access singleton factory
RuleViolationFactory factory = VmRuleViolationFactory.INSTANCE;

// Factory is typically used internally by PMD during rule execution
// Custom rules use addViolation() method on AbstractVmRule instead

Rule Chain Visitor

Optimized visitor implementation for efficient processing of multiple rules across Velocity template ASTs.

/**
 * Specialized visitor that efficiently processes multiple rules in a single
 * AST traversal pass, improving performance for large templates.
 * @deprecated for removal with PMD 7. A language dependent rule chain visitor is not needed anymore.
 *      See RuleChainVisitor.
 */
@Deprecated
public class VmRuleChainVisitor extends AbstractRuleChainVisitor {
    // Implementation details are internal to PMD's rule processing pipeline
    // Automatically used by PMD for multi-rule analysis optimization
}

Integration Examples

Custom Language Handler Extension

import net.sourceforge.pmd.lang.Parser;
import net.sourceforge.pmd.lang.ParserOptions;

public class CustomVmHandler extends VmHandler {
    
    @Override
    public Parser getParser(ParserOptions parserOptions) {
        // Customize parser behavior if needed
        Parser parser = super.getParser(parserOptions);
        // Apply custom configuration
        return parser;
    }
}

PMD Configuration Integration

<!-- PMD ruleset configuration -->
<ruleset name="velocity-rules">
    <description>Rules for Velocity templates</description>
    
    <!-- PMD automatically detects VM language support -->
    <rule ref="category/vm/bestpractices.xml/AvoidReassigningParameters"/>
    <rule ref="category/vm/design.xml/ExcessiveTemplateLength"/>
</ruleset>

Programmatic PMD Integration

import net.sourceforge.pmd.PMD;
import net.sourceforge.pmd.PMDConfiguration;
import net.sourceforge.pmd.lang.LanguageRegistry;

// PMD automatically registers VmLanguageModule
PMDConfiguration config = new PMDConfiguration();
config.setInputPaths("src/main/resources/templates");

// Language is available via registry
LanguageRegistry registry = LanguageRegistry.getDefaultRegistry();
Language vmLanguage = registry.getLanguageByTerseName("vm");

Install with Tessl CLI

npx tessl i tessl/maven-net-sourceforge-pmd--pmd-vm

docs

ast-nodes.md

builtin-rules.md

index.md

language-integration.md

parsing.md

rule-development.md

tile.json