PMD language module that provides static code analysis capabilities for Salesforce Visualforce pages and components
—
Core language module registration and configuration for integrating Visualforce analysis into PMD. This capability handles language registration, parser creation, and configuration management.
Main entry point for PMD's Visualforce language support. This singleton class registers the Visualforce language with PMD and provides core services.
/**
* Main language module for Visualforce that extends PMD's language framework
* Implements CpdCapableLanguage for copy-paste detection support
*/
public class VfLanguageModule extends SimpleLanguageModuleBase implements CpdCapableLanguage {
/** Language identifier constant */
static final String ID = "visualforce";
/** Display name constant */
static final String NAME = "Salesforce Visualforce";
/**
* Get the singleton instance of the Visualforce language module
* @return VfLanguageModule instance registered with PMD
*/
public static VfLanguageModule getInstance();
/**
* Create a CPD lexer for copy-paste detection in Visualforce files
* @param bundle Language property configuration
* @return CpdLexer instance for Visualforce tokenization
*/
@Override
public CpdLexer createCpdLexer(LanguagePropertyBundle bundle);
/**
* Create a new property bundle with default Visualforce configuration
* @return VfLanguageProperties with default settings
*/
@Override
public LanguagePropertyBundle newPropertyBundle();
}Usage Example:
import net.sourceforge.pmd.lang.visualforce.VfLanguageModule;
import net.sourceforge.pmd.lang.LanguageRegistry;
// Get the Visualforce language module instance
VfLanguageModule vfModule = VfLanguageModule.getInstance();
// Check if Visualforce language is registered
boolean isRegistered = LanguageRegistry.PMD.getLanguageById("visualforce") != null;
// Create CPD lexer for copy-paste detection
VfLanguageProperties properties = new VfLanguageProperties();
CpdLexer lexer = vfModule.createCpdLexer(properties);Configuration properties for Visualforce language analysis, including paths to Apex classes and Salesforce objects for type resolution.
/**
* Language-specific properties for Visualforce analysis configuration
* Extends PMD's LanguagePropertyBundle with Visualforce-specific settings
*/
public class VfLanguageProperties extends LanguagePropertyBundle {
/**
* Directory paths containing Apex classes referenced from Visualforce pages
* Environment variable: PMD_VF_APEX_DIRECTORIES
* Default: "../classes" (relative to Visualforce directory)
*/
public static final PropertyDescriptor<List<String>> APEX_DIRECTORIES_DESCRIPTOR =
PropertyFactory.stringListProperty("apexDirectories")
.desc("Location of Apex Class directories. Absolute or relative to the Visualforce directory.")
.defaultValues("../classes")
.build();
/**
* Directory paths containing Custom Object definitions referenced from Visualforce pages
* Environment variable: PMD_VF_OBJECTS_DIRECTORIES
* Default: "../objects" (relative to Visualforce directory)
*/
public static final PropertyDescriptor<List<String>> OBJECTS_DIRECTORIES_DESCRIPTOR =
PropertyFactory.stringListProperty("objectsDirectories")
.desc("Location of Custom Object directories. Absolute or relative to the Visualforce directory.")
.defaultValues("../objects")
.build();
/**
* Create new VfLanguageProperties with default configuration
*/
public VfLanguageProperties();
}Usage Example:
import net.sourceforge.pmd.lang.visualforce.VfLanguageProperties;
import java.util.Arrays;
// Create properties with default configuration
VfLanguageProperties properties = new VfLanguageProperties();
// Configure custom Apex directories
properties.setProperty(VfLanguageProperties.APEX_DIRECTORIES_DESCRIPTOR,
Arrays.asList("/path/to/apex/classes", "/another/apex/path"));
// Configure custom Object directories
properties.setProperty(VfLanguageProperties.OBJECTS_DIRECTORIES_DESCRIPTOR,
Arrays.asList("/path/to/objects"));Language version handler that provides parser instances for Visualforce analysis.
/**
* Language version handler for Visualforce
* Implements PMD's LanguageVersionHandler interface
*/
public class VfHandler implements LanguageVersionHandler {
/**
* Create new handler with specified properties
* @param properties Configuration properties for parsing
*/
public VfHandler(VfLanguageProperties properties);
/**
* Get parser instance for Visualforce content
* @return VfParser configured with current properties
*/
@Override
public Parser getParser();
}Usage Example:
import net.sourceforge.pmd.lang.visualforce.*;
// Create language properties and handler
VfLanguageProperties properties = new VfLanguageProperties();
VfHandler handler = new VfHandler(properties);
// Get parser from handler
Parser parser = handler.getParser();Specialized lexer for detecting code duplication in Visualforce files.
/**
* CPD lexer for Visualforce files
* Previously known as VfTokenizer in PMD 6
* Extends JavaccCpdLexer for token-based copy-paste detection
*/
public class VfCpdLexer extends JavaccCpdLexer {
/**
* Create token manager for Visualforce content
* @param doc Text document to tokenize
* @return TokenManager for Visualforce tokens
*/
@Override
protected TokenManager<JavaccToken> makeLexerImpl(TextDocument doc);
}Usage Example:
import net.sourceforge.pmd.lang.visualforce.cpd.VfCpdLexer;
import net.sourceforge.pmd.lang.document.TextDocument;
// Create CPD lexer for copy-paste detection
VfCpdLexer lexer = new VfCpdLexer();
// Use with PMD's CPD engine to detect duplicated Visualforce markup
// (typically handled automatically by PMD framework)The Visualforce language module is automatically registered with PMD through Java's ServiceLoader mechanism:
META-INF/services/net.sourceforge.pmd.lang.Languagenet.sourceforge.pmd.lang.visualforce.VfLanguageModuleThis enables automatic discovery and registration when the pmd-visualforce JAR is on the classpath.
Install with Tessl CLI
npx tessl i tessl/maven-net-sourceforge-pmd--pmd-visualforce