or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

ast-parsing.mdindex.mdlanguage-module.mdrule-development.mdtype-analysis.md

index.mddocs/

0

# PMD Visualforce

1

2

PMD Visualforce is a specialized language module for PMD that enables static code analysis of Salesforce Visualforce markup files (.page and .component). It extends PMD's core functionality to parse and analyze Visualforce pages and components, providing developers with code quality analysis capabilities specific to Visualforce development within the Salesforce ecosystem.

3

4

## Package Information

5

6

- **Package Name**: net.sourceforge.pmd:pmd-visualforce

7

- **Package Type**: Maven library

8

- **Language**: Java

9

- **Installation**: Add dependency to your Maven project:

10

11

```xml

12

<dependency>

13

<groupId>net.sourceforge.pmd</groupId>

14

<artifactId>pmd-visualforce</artifactId>

15

<version>7.13.0</version>

16

</dependency>

17

```

18

19

## Core Imports

20

21

```java

22

import net.sourceforge.pmd.lang.visualforce.VfLanguageModule;

23

import net.sourceforge.pmd.lang.visualforce.ast.*;

24

import net.sourceforge.pmd.lang.visualforce.rule.AbstractVfRule;

25

```

26

27

## Basic Usage

28

29

```java

30

import net.sourceforge.pmd.lang.visualforce.VfLanguageModule;

31

import net.sourceforge.pmd.lang.visualforce.ast.VfParser;

32

import net.sourceforge.pmd.lang.visualforce.VfLanguageProperties;

33

34

// Get the Visualforce language module instance

35

VfLanguageModule languageModule = VfLanguageModule.getInstance();

36

37

// Create parser with properties

38

VfLanguageProperties properties = new VfLanguageProperties();

39

VfParser parser = new VfParser(properties);

40

41

// Parse Visualforce content (typically done by PMD framework)

42

// ASTCompilationUnit ast = parser.parse(visualforceContent);

43

```

44

45

## Architecture

46

47

PMD Visualforce follows PMD's standard language module architecture:

48

49

- **Language Module**: `VfLanguageModule` registers the language with PMD and provides core services

50

- **Parser Infrastructure**: `VfParser` and `VfHandler` handle parsing Visualforce markup into AST

51

- **AST Hierarchy**: 20+ specialized node types representing different Visualforce constructs

52

- **Rule Framework**: `AbstractVfRule` base class for creating custom analysis rules

53

- **Type System**: Integration with Salesforce metadata for type-aware analysis

54

- **CPD Support**: `VfCpdLexer` enables copy-paste detection in Visualforce files

55

56

The package integrates seamlessly with PMD's analysis engine and depends on the Apex language module for comprehensive Salesforce analysis workflows.

57

58

## Capabilities

59

60

### Language Module Setup

61

62

Core language module registration and configuration for integrating Visualforce analysis into PMD.

63

64

```java { .api }

65

public class VfLanguageModule extends SimpleLanguageModuleBase implements CpdCapableLanguage {

66

public static VfLanguageModule getInstance();

67

public CpdLexer createCpdLexer(LanguagePropertyBundle bundle);

68

public LanguagePropertyBundle newPropertyBundle();

69

}

70

71

public class VfLanguageProperties extends LanguagePropertyBundle {

72

public static final PropertyDescriptor<List<String>> APEX_DIRECTORIES_DESCRIPTOR;

73

public static final PropertyDescriptor<List<String>> OBJECTS_DIRECTORIES_DESCRIPTOR;

74

}

75

```

76

77

[Language Module Setup](./language-module.md)

78

79

### AST Parsing and Node Types

80

81

Complete Abstract Syntax Tree generation with specialized node types for parsing and representing Visualforce markup structures.

82

83

```java { .api }

84

public final class VfParser extends JjtreeParserAdapter<ASTCompilationUnit> {

85

public VfParser(VfLanguageProperties vfProperties);

86

}

87

88

public interface VfNode extends JjtreeNode<VfNode> {}

89

90

public final class ASTCompilationUnit extends AbstractVfNode implements RootNode {

91

public AstInfo<ASTCompilationUnit> getAstInfo();

92

}

93

94

public final class ASTElement extends AbstractVfNode {

95

public boolean isHasNamespacePrefix();

96

public String getName();

97

public boolean isEmpty();

98

public boolean isUnclosed();

99

}

100

```

101

102

[AST Parsing and Node Types](./ast-parsing.md)

103

104

### Rule Development Framework

105

106

Infrastructure for creating custom PMD rules to analyze Visualforce code quality and security issues.

107

108

```java { .api }

109

public abstract class AbstractVfRule extends AbstractRule implements VfVisitor<Object, Object> {

110

public void apply(Node target, RuleContext ctx);

111

public Object visitNode(Node node, Object param);

112

}

113

114

public abstract class VfVisitorBase<P, R> extends AstVisitorBase<P, R> implements VfVisitor<P, R> {}

115

```

116

117

[Rule Development Framework](./rule-development.md)

118

119

### Type Analysis and Salesforce Integration

120

121

Type system integration with Salesforce metadata for context-aware analysis of Visualforce expressions and data binding.

122

123

```java { .api }

124

public enum DataType {

125

AutoNumber, Checkbox, Currency, Date, DateTime, Email, Text, /* ... */;

126

127

public final boolean requiresEscaping;

128

129

public static DataType fromString(String value);

130

public static DataType fromTypeName(String value);

131

}

132

133

public class VfExpressionTypeVisitor {

134

// Internal visitor for adding type information to AST

135

}

136

```

137

138

[Type Analysis and Salesforce Integration](./type-analysis.md)

139

140

## Types

141

142

```java { .api }

143

// Core AST interfaces

144

public interface VfNode extends JjtreeNode<VfNode> {}

145

146

public interface VfVisitor<P, R> {

147

R visit(ASTCompilationUnit node, P data);

148

R visit(ASTElement node, P data);

149

R visit(ASTElExpression node, P data);

150

R visit(ASTAttribute node, P data);

151

// ... visitor methods for all AST node types

152

}

153

154

// Language properties

155

public class VfLanguageProperties extends LanguagePropertyBundle {

156

public VfLanguageProperties();

157

}

158

159

// Rule context

160

public abstract class AbstractVfRule extends AbstractRule implements VfVisitor<Object, Object> {}

161

```