or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

tessl/maven-net-sourceforge-pmd--pmd-swift

PMD Swift language module for copy-paste-detector (CPD) functionality

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/net.sourceforge.pmd/pmd-swift@6.55.x

To install, run

npx @tessl/cli install tessl/maven-net-sourceforge-pmd--pmd-swift@6.55.0

0

# PMD Swift

1

2

PMD Swift is a deprecated Java language module that provides basic Swift language support for PMD's Copy-Paste Detector (CPD). It enables duplicate code detection in Swift source files through tokenization and language registration within the PMD static analysis toolkit.

3

4

## Package Information

5

6

- **Package Name**: pmd-swift

7

- **Package Type**: Maven

8

- **Language**: Java

9

- **Group ID**: net.sourceforge.pmd

10

- **Artifact ID**: pmd-swift

11

- **Version**: 6.55.0

12

- **Installation**: Add Maven dependency in `pom.xml`

13

14

```xml

15

<dependency>

16

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

17

<artifactId>pmd-swift</artifactId>

18

<version>6.55.0</version>

19

</dependency>

20

```

21

22

## Core Imports

23

24

```java

25

import net.sourceforge.pmd.lang.swift.SwiftLanguageModule;

26

import net.sourceforge.pmd.cpd.SwiftLanguage;

27

import net.sourceforge.pmd.cpd.SwiftTokenizer;

28

```

29

30

## Basic Usage

31

32

PMD Swift integrates automatically with PMD through the Java Service Provider Interface (SPI). The module registers Swift as a supported language for copy-paste detection:

33

34

```java

35

// PMD automatically discovers Swift language support via SPI

36

// No manual registration required

37

38

// Direct usage for custom implementations

39

SwiftLanguage swiftLanguage = new SwiftLanguage();

40

SwiftTokenizer tokenizer = new SwiftTokenizer();

41

42

// Language module for PMD integration

43

SwiftLanguageModule languageModule = new SwiftLanguageModule();

44

```

45

46

## Architecture

47

48

PMD Swift follows PMD's plugin architecture pattern:

49

50

- **Language Module**: `SwiftLanguageModule` registers Swift as a supported language in PMD

51

- **CPD Language**: `SwiftLanguage` provides copy-paste detection capabilities

52

- **Tokenizer**: `SwiftTokenizer` handles Swift source code parsing using ANTLR

53

- **ANTLR Grammar**: `Swift.g4` defines Swift language syntax for lexical analysis

54

- **Service Registration**: META-INF services enable automatic discovery by PMD

55

56

## Capabilities

57

58

### Swift Language Module

59

60

Core language registration for PMD framework integration.

61

62

```java { .api }

63

/**

64

* Language Module for Swift - registers Swift language support in PMD

65

* @deprecated There is no full PMD support for Swift

66

*/

67

@Deprecated

68

public class SwiftLanguageModule extends BaseLanguageModule {

69

/** The language name constant */

70

public static final String NAME = "Swift";

71

72

/** The terse name constant */

73

public static final String TERSE_NAME = "swift";

74

75

/**

76

* Create a new instance of Swift Language Module

77

*/

78

public SwiftLanguageModule();

79

}

80

```

81

82

### CPD Swift Language

83

84

Language implementation for copy-paste detection functionality.

85

86

```java { .api }

87

/**

88

* Language implementation for Swift in CPD system

89

*/

90

public class SwiftLanguage extends AbstractLanguage {

91

/**

92

* Creates a new Swift Language instance with tokenizer and file extension

93

*/

94

public SwiftLanguage();

95

}

96

```

97

98

### Swift Tokenizer

99

100

ANTLR-based tokenizer for Swift source code analysis.

101

102

```java { .api }

103

/**

104

* SwiftTokenizer for parsing Swift source code using ANTLR

105

*/

106

public class SwiftTokenizer extends AntlrTokenizer {

107

/**

108

* Get lexer for given source code

109

* @param sourceCode The source code to tokenize

110

* @return AntlrTokenManager for token processing

111

*/

112

@Override

113

protected AntlrTokenManager getLexerForSource(final SourceCode sourceCode);

114

}

115

```

116

117

### ANTLR Generated Components

118

119

Generated lexer from Swift grammar definition.

120

121

```java { .api }

122

/**

123

* ANTLR-generated lexer for Swift language

124

* Generated from Swift.g4 grammar file during Maven compilation

125

* Located at: net.sourceforge.pmd.lang.swift.antlr4.SwiftLexer

126

*/

127

public class SwiftLexer extends org.antlr.v4.runtime.Lexer {

128

/**

129

* Create lexer with character stream input

130

* @param input Character stream from Swift source code

131

*/

132

public SwiftLexer(CharStream input);

133

}

134

```

135

136

## Types

137

138

```java { .api }

139

// Core PMD types used by Swift module

140

import net.sourceforge.pmd.lang.BaseLanguageModule;

141

import net.sourceforge.pmd.cpd.AbstractLanguage;

142

import net.sourceforge.pmd.cpd.AntlrTokenizer;

143

import net.sourceforge.pmd.lang.antlr.AntlrTokenManager;

144

import net.sourceforge.pmd.cpd.SourceCode;

145

import org.antlr.v4.runtime.CharStream;

146

import net.sourceforge.pmd.lang.swift.antlr4.SwiftLexer;

147

```

148

149

## Service Provider Registration

150

151

PMD Swift uses Java SPI for automatic discovery:

152

153

**Language Module Service** (`META-INF/services/net.sourceforge.pmd.lang.Language`):

154

```

155

net.sourceforge.pmd.lang.swift.SwiftLanguageModule

156

```

157

158

**CPD Language Service** (`META-INF/services/net.sourceforge.pmd.cpd.Language`):

159

```

160

net.sourceforge.pmd.cpd.SwiftLanguage

161

```

162

163

## Limitations and Status

164

165

⚠️ **Important**: This module is **deprecated** and has significant limitations:

166

167

- **No full PMD support**: Only provides CPD (copy-paste detection) functionality

168

- **No static analysis rules**: Cannot detect Swift-specific code issues or violations

169

- **Limited Swift version support**: Grammar may not support latest Swift language features

170

- **Maintenance status**: No active development or updates planned

171

- **Functionality scope**: Restricted to duplicate code detection only

172

173

## Dependencies

174

175

- **pmd-core**: Core PMD functionality and base classes

176

- **antlr4-runtime**: ANTLR runtime for lexer execution

177

- **Swift.g4**: ANTLR grammar definition for Swift language parsing

178

179

## Usage in PMD

180

181

When pmd-swift is on the classpath, PMD automatically:

182

183

1. Discovers Swift language support via SPI

184

2. Registers `.swift` file extension for processing

185

3. Enables CPD duplicate detection for Swift files

186

4. Uses SwiftTokenizer for parsing Swift source code

187

188

Example PMD command line usage:

189

```bash

190

pmd cpd --minimum-tokens 100 --language swift --files /path/to/swift/files

191

```