or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

index.md

index.mddocs/

0

# PMD Julia Language Module

1

2

PMD Julia is a Java library that provides Julia language support for PMD's Copy-Paste-Detector (CPD) functionality. It enables static code analysis and duplicate code detection for Julia source files (.jl extension) by integrating with PMD's extensible language architecture through ANTLR-based parsing.

3

4

## Package Information

5

6

- **Package Name**: pmd-julia

7

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

8

- **Artifact ID**: pmd-julia

9

- **Package Type**: maven

10

- **Language**: Java

11

- **Installation**: Add dependency to Maven pom.xml:

12

13

```xml

14

<dependency>

15

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

16

<artifactId>pmd-julia</artifactId>

17

<version>7.13.0</version>

18

</dependency>

19

```

20

21

## Core Imports

22

23

```java

24

import net.sourceforge.pmd.lang.julia.JuliaLanguageModule;

25

import net.sourceforge.pmd.lang.julia.cpd.JuliaCpdLexer;

26

import net.sourceforge.pmd.cpd.CpdLexer;

27

import net.sourceforge.pmd.lang.LanguagePropertyBundle;

28

import net.sourceforge.pmd.lang.LanguageRegistry;

29

```

30

31

## Basic Usage

32

33

```java

34

import net.sourceforge.pmd.lang.julia.JuliaLanguageModule;

35

import net.sourceforge.pmd.cpd.CpdLexer;

36

import net.sourceforge.pmd.lang.LanguagePropertyBundle;

37

38

// Get the Julia language module instance

39

JuliaLanguageModule juliaModule = JuliaLanguageModule.getInstance();

40

41

// Create a CPD lexer for Julia source code analysis

42

LanguagePropertyBundle bundle = // ... configure as needed

43

CpdLexer lexer = juliaModule.createCpdLexer(bundle);

44

45

// Use the lexer for tokenizing Julia code for duplicate detection

46

// The lexer will parse .jl files and generate tokens for CPD analysis

47

```

48

49

## Architecture

50

51

The PMD Julia module is built around PMD's language extension architecture:

52

53

- **Language Module**: `JuliaLanguageModule` extends `CpdOnlyLanguageModuleBase` to register Julia as a supported language

54

- **CPD Integration**: Uses ANTLR-generated lexer for tokenization and duplicate code detection

55

- **Language Registry**: Integrates with PMD's `LanguageRegistry.CPD` for language discovery

56

- **File Association**: Automatically handles `.jl` file extensions for Julia source code

57

58

## Capabilities

59

60

### Language Module Management

61

62

Core functionality for registering and managing Julia language support within PMD.

63

64

```java { .api }

65

/**

66

* Main language module for Julia support in PMD.

67

* Extends CpdOnlyLanguageModuleBase to provide Julia language integration.

68

*/

69

public class JuliaLanguageModule extends CpdOnlyLanguageModuleBase {

70

/**

71

* Creates a new Julia Language instance.

72

* Configures language with ID "julia", name "Julia", and ".jl" file extension.

73

*/

74

public JuliaLanguageModule();

75

76

/**

77

* Gets the singleton instance of the Julia language module.

78

* @return JuliaLanguageModule instance from the CPD language registry

79

*/

80

public static JuliaLanguageModule getInstance();

81

82

/**

83

* Creates a CPD lexer for Julia source code analysis.

84

* @param bundle Language property configuration bundle

85

* @return CpdLexer instance specifically configured for Julia tokenization

86

*/

87

@Override

88

public CpdLexer createCpdLexer(LanguagePropertyBundle bundle);

89

}

90

```

91

92

### Copy-Paste Detection

93

94

Tokenization functionality for duplicate code detection in Julia source files.

95

96

```java { .api }

97

/**

98

* Julia tokenizer for copy-paste detection.

99

* Extends AntlrCpdLexer to provide ANTLR-based tokenization.

100

* Note: Previously called JuliaTokenizer in PMD 6.

101

*/

102

public class JuliaCpdLexer extends AntlrCpdLexer {

103

/**

104

* Creates a lexer instance for the given character stream.

105

* @param charStream Input character stream containing Julia source code

106

* @return Lexer instance configured for Julia language tokenization

107

*/

108

@Override

109

protected Lexer getLexerForSource(CharStream charStream);

110

}

111

```

112

113

## Types

114

115

### Core PMD Integration Types

116

117

These types are provided by PMD core and used by the Julia module:

118

119

```java { .api }

120

/**

121

* Base class for language modules that only support CPD functionality.

122

*/

123

abstract class CpdOnlyLanguageModuleBase {

124

/**

125

* Constructor for CPD-only language modules.

126

* @param metadata Language metadata configuration

127

*/

128

protected CpdOnlyLanguageModuleBase(LanguageMetadata metadata);

129

}

130

131

/**

132

* Language property configuration bundle.

133

*/

134

interface LanguagePropertyBundle {

135

// Implementation provided by PMD core

136

}

137

138

/**

139

* Interface for CPD lexers that tokenize source code.

140

*/

141

interface CpdLexer {

142

// Implementation provided by PMD core

143

}

144

145

/**

146

* ANTLR-based CPD lexer base class.

147

*/

148

abstract class AntlrCpdLexer implements CpdLexer {

149

// Implementation provided by PMD core

150

}

151

152

/**

153

* Base interface for PMD language implementations.

154

*/

155

interface Language {

156

// Implementation provided by PMD core

157

}

158

159

/**

160

* Language registry for PMD language modules.

161

*/

162

class LanguageRegistry {

163

/**

164

* Registry instance for CPD-only languages.

165

*/

166

public static final LanguageRegistry CPD;

167

168

/**

169

* Gets a language module by its identifier.

170

* @param id Language identifier (e.g., "julia")

171

* @return Language module instance or null if not found

172

*/

173

public Language getLanguageById(String id);

174

}

175

```

176

177

### ANTLR Integration Types

178

179

```java { .api }

180

/**

181

* Language metadata configuration for PMD language modules.

182

*/

183

class LanguageMetadata {

184

/**

185

* Creates language metadata with specified ID.

186

* @param id Language identifier (e.g., "julia")

187

* @return LanguageMetadata builder for further configuration

188

*/

189

public static LanguageMetadata withId(String id);

190

191

/**

192

* Sets the display name for the language.

193

* @param name Human-readable language name

194

* @return LanguageMetadata builder for method chaining

195

*/

196

public LanguageMetadata name(String name);

197

198

/**

199

* Sets file extensions associated with the language.

200

* @param extensions File extensions without dots (e.g., "jl")

201

* @return Configured LanguageMetadata instance

202

*/

203

public LanguageMetadata extensions(String... extensions);

204

}

205

206

/**

207

* ANTLR character stream interface for input processing.

208

*/

209

interface CharStream {

210

// Implementation provided by ANTLR runtime

211

}

212

213

/**

214

* ANTLR lexer base class for tokenization.

215

*/

216

abstract class Lexer {

217

// Implementation provided by ANTLR runtime

218

}

219

220

/**

221

* ANTLR-generated lexer for Julia language tokenization.

222

* This class is generated from the Julia.g4 grammar file.

223

*/

224

class JuliaLexer extends Lexer {

225

/**

226

* Creates a Julia lexer for the given character stream.

227

* @param input Character stream containing Julia source code

228

*/

229

public JuliaLexer(CharStream input);

230

}

231

```

232

233

## Deprecated AST Classes

234

235

**Note**: The following AST classes are deprecated since PMD 7.8.0 and will be removed with no replacement. They were ANTLR-generated classes that were never intended for public use.

236

237

### Parser Classes

238

239

The following parser and AST classes are available but deprecated:

240

241

```java { .api }

242

/**

243

* ANTLR-generated parser for Julia language.

244

* @deprecated Since 7.8.0. Will be removed with no replacement.

245

*/

246

@Deprecated

247

public class JuliaParser extends Parser {

248

// Various parsing methods for Julia syntax elements

249

// Implementation is ANTLR-generated and not intended for direct use

250

}

251

```

252

253

### Visitor Pattern Classes

254

255

```java { .api }

256

/**

257

* Visitor interface for Julia parse tree traversal.

258

* @param <T> Return type of visit operations

259

* @deprecated Since 7.8.0. Will be removed with no replacement.

260

*/

261

@Deprecated

262

public interface JuliaVisitor<T> extends ParseTreeVisitor<T> {

263

// Visit methods for all Julia AST node types

264

}

265

266

/**

267

* Base visitor implementation with default behaviors.

268

* @param <T> Return type of visit operations

269

* @deprecated Since 7.8.0. Will be removed with no replacement.

270

*/

271

@Deprecated

272

public class JuliaBaseVisitor<T> extends AbstractParseTreeVisitor<T>

273

implements JuliaVisitor<T> {

274

// Default implementations for all visit methods

275

}

276

```

277

278

### Listener Pattern Classes

279

280

```java { .api }

281

/**

282

* Listener interface for Julia parse tree events.

283

* @deprecated Since 7.8.0. Will be removed with no replacement.

284

*/

285

@Deprecated

286

public interface JuliaListener extends ParseTreeListener {

287

// Enter/exit methods for all Julia AST node types

288

}

289

290

/**

291

* Base listener implementation with empty default methods.

292

* @deprecated Since 7.8.0. Will be removed with no replacement.

293

*/

294

@Deprecated

295

public class JuliaBaseListener implements JuliaListener {

296

// Empty default implementations for all listener methods

297

}

298

```

299

300

## Dependencies

301

302

The Julia language module requires the following dependencies:

303

304

- **PMD Core**: `net.sourceforge.pmd:pmd-core` - Core PMD functionality and language framework

305

- **ANTLR Runtime**: `org.antlr:antlr4-runtime` - ANTLR parser runtime for Julia grammar processing

306

307

## File Extensions

308

309

- `.jl` - Julia source files supported by the language module

310

311

## Error Handling

312

313

The module integrates with PMD's error handling mechanisms. Parsing errors and lexing issues are reported through PMD's standard error reporting system. No specific exceptions are thrown by the public API - errors are handled internally by the ANTLR lexer and PMD framework.

314

315

## Build Integration

316

317

The module includes Maven build configuration with:

318

- ANTLR4 Maven plugin for grammar generation

319

- Custom ANT tasks for CPD language registration

320

- Resource filtering for language metadata

321

322

This module is designed for integration into larger PMD-based static analysis workflows and CI/CD pipelines for Julia code quality assessment.