or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

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

language-module.mddocs/

0

# Language Module

1

2

The JSP Language Module registers JSP as a supported language in the PMD framework and provides configuration for file extensions and copy-paste detection capabilities.

3

4

## Language Registration

5

6

### JspLanguageModule

7

8

Main class that registers JSP language with PMD framework.

9

10

```java { .api }

11

public class JspLanguageModule extends SimpleLanguageModuleBase implements CpdCapableLanguage {

12

public JspLanguageModule();

13

public static JspLanguageModule getInstance();

14

public CpdLexer createCpdLexer(LanguagePropertyBundle bundle);

15

}

16

```

17

18

**Usage:**

19

20

```java

21

import net.sourceforge.pmd.lang.jsp.JspLanguageModule;

22

import net.sourceforge.pmd.lang.LanguageRegistry;

23

24

// Get the JSP language module instance

25

JspLanguageModule jspModule = JspLanguageModule.getInstance();

26

27

// Or get via language registry

28

JspLanguageModule module = (JspLanguageModule) LanguageRegistry.PMD.getLanguageById("jsp");

29

```

30

31

**Methods:**

32

33

- `getInstance()`: Returns the singleton instance of the JSP language module

34

- `createCpdLexer(LanguagePropertyBundle)`: Creates a lexer for copy-paste detection

35

36

**File Extensions:**

37

- `.jsp`: JavaServer Pages

38

- `.jspx`: JSP XML format

39

- `.jspf`: JSP fragment files

40

- `.tag`: JSP tag files

41

42

**Language Versions:**

43

- Version 2: Legacy JSP

44

- Version 3: Default version (modern JSP)

45

46

### JspHandler

47

48

Language version handler that provides parser instances.

49

50

```java { .api }

51

public class JspHandler extends AbstractPmdLanguageVersionHandler {

52

public Parser getParser();

53

}

54

```

55

56

**Usage:**

57

58

```java

59

import net.sourceforge.pmd.lang.jsp.JspHandler;

60

import net.sourceforge.pmd.lang.jsp.ast.JspParser;

61

62

JspHandler handler = new JspHandler();

63

Parser parser = handler.getParser(); // Returns JspParser instance

64

```

65

66

**Methods:**

67

68

- `getParser()`: Returns a new `JspParser` instance for parsing JSP files

69

70

## Service Registration

71

72

The language module is automatically registered with PMD through the service loader mechanism:

73

74

**File:** `/META-INF/services/net.sourceforge.pmd.lang.Language`

75

```

76

net.sourceforge.pmd.lang.jsp.JspLanguageModule

77

```

78

79

This enables PMD to automatically discover and load the JSP language support when the module is on the classpath.

80

81

## Integration with PMD Framework

82

83

The JSP language module integrates with PMD's core framework:

84

85

1. **Language Registry**: Automatically registers JSP language with ID "jsp"

86

2. **File Processing**: Associates JSP file extensions with the language

87

3. **Parser Integration**: Provides JSP parser through the handler

88

4. **CPD Integration**: Enables copy-paste detection for JSP files

89

5. **Rule Processing**: Enables JSP-specific rules to be applied to JSP files

90

91

## Examples

92

93

### Basic Language Module Usage

94

95

```java

96

import net.sourceforge.pmd.lang.jsp.JspLanguageModule;

97

import net.sourceforge.pmd.cpd.CpdLexer;

98

import net.sourceforge.pmd.lang.LanguagePropertyBundle;

99

100

// Get language module

101

JspLanguageModule module = JspLanguageModule.getInstance();

102

103

// Create CPD lexer for duplicate detection

104

LanguagePropertyBundle bundle = // ... PMD configuration

105

CpdLexer lexer = module.createCpdLexer(bundle);

106

```

107

108

### Programmatic Integration

109

110

```java

111

import net.sourceforge.pmd.lang.LanguageRegistry;

112

import net.sourceforge.pmd.lang.Language;

113

114

// Check if JSP language is available

115

Language jspLang = LanguageRegistry.PMD.getLanguageById("jsp");

116

if (jspLang != null) {

117

System.out.println("JSP language supported");

118

System.out.println("Extensions: " + jspLang.getExtensions());

119

}

120

```

121

122

The language module provides the foundation for all JSP analysis capabilities in PMD, enabling the framework to recognize JSP files and route them to the appropriate parser and rules.