Julia language module for PMD static code analyzer, providing Copy-Paste-Detector (CPD) support for Julia source code analysis
npx @tessl/cli install tessl/maven-net-sourceforge-pmd--pmd-julia@7.13.0PMD 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.
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-julia</artifactId>
<version>7.13.0</version>
</dependency>import net.sourceforge.pmd.lang.julia.JuliaLanguageModule;
import net.sourceforge.pmd.lang.julia.cpd.JuliaCpdLexer;
import net.sourceforge.pmd.cpd.CpdLexer;
import net.sourceforge.pmd.lang.LanguagePropertyBundle;
import net.sourceforge.pmd.lang.LanguageRegistry;import net.sourceforge.pmd.lang.julia.JuliaLanguageModule;
import net.sourceforge.pmd.cpd.CpdLexer;
import net.sourceforge.pmd.lang.LanguagePropertyBundle;
// Get the Julia language module instance
JuliaLanguageModule juliaModule = JuliaLanguageModule.getInstance();
// Create a CPD lexer for Julia source code analysis
LanguagePropertyBundle bundle = // ... configure as needed
CpdLexer lexer = juliaModule.createCpdLexer(bundle);
// Use the lexer for tokenizing Julia code for duplicate detection
// The lexer will parse .jl files and generate tokens for CPD analysisThe PMD Julia module is built around PMD's language extension architecture:
JuliaLanguageModule extends CpdOnlyLanguageModuleBase to register Julia as a supported languageLanguageRegistry.CPD for language discovery.jl file extensions for Julia source codeCore functionality for registering and managing Julia language support within PMD.
/**
* Main language module for Julia support in PMD.
* Extends CpdOnlyLanguageModuleBase to provide Julia language integration.
*/
public class JuliaLanguageModule extends CpdOnlyLanguageModuleBase {
/**
* Creates a new Julia Language instance.
* Configures language with ID "julia", name "Julia", and ".jl" file extension.
*/
public JuliaLanguageModule();
/**
* Gets the singleton instance of the Julia language module.
* @return JuliaLanguageModule instance from the CPD language registry
*/
public static JuliaLanguageModule getInstance();
/**
* Creates a CPD lexer for Julia source code analysis.
* @param bundle Language property configuration bundle
* @return CpdLexer instance specifically configured for Julia tokenization
*/
@Override
public CpdLexer createCpdLexer(LanguagePropertyBundle bundle);
}Tokenization functionality for duplicate code detection in Julia source files.
/**
* Julia tokenizer for copy-paste detection.
* Extends AntlrCpdLexer to provide ANTLR-based tokenization.
* Note: Previously called JuliaTokenizer in PMD 6.
*/
public class JuliaCpdLexer extends AntlrCpdLexer {
/**
* Creates a lexer instance for the given character stream.
* @param charStream Input character stream containing Julia source code
* @return Lexer instance configured for Julia language tokenization
*/
@Override
protected Lexer getLexerForSource(CharStream charStream);
}These types are provided by PMD core and used by the Julia module:
/**
* Base class for language modules that only support CPD functionality.
*/
abstract class CpdOnlyLanguageModuleBase {
/**
* Constructor for CPD-only language modules.
* @param metadata Language metadata configuration
*/
protected CpdOnlyLanguageModuleBase(LanguageMetadata metadata);
}
/**
* Language property configuration bundle.
*/
interface LanguagePropertyBundle {
// Implementation provided by PMD core
}
/**
* Interface for CPD lexers that tokenize source code.
*/
interface CpdLexer {
// Implementation provided by PMD core
}
/**
* ANTLR-based CPD lexer base class.
*/
abstract class AntlrCpdLexer implements CpdLexer {
// Implementation provided by PMD core
}
/**
* Base interface for PMD language implementations.
*/
interface Language {
// Implementation provided by PMD core
}
/**
* Language registry for PMD language modules.
*/
class LanguageRegistry {
/**
* Registry instance for CPD-only languages.
*/
public static final LanguageRegistry CPD;
/**
* Gets a language module by its identifier.
* @param id Language identifier (e.g., "julia")
* @return Language module instance or null if not found
*/
public Language getLanguageById(String id);
}/**
* Language metadata configuration for PMD language modules.
*/
class LanguageMetadata {
/**
* Creates language metadata with specified ID.
* @param id Language identifier (e.g., "julia")
* @return LanguageMetadata builder for further configuration
*/
public static LanguageMetadata withId(String id);
/**
* Sets the display name for the language.
* @param name Human-readable language name
* @return LanguageMetadata builder for method chaining
*/
public LanguageMetadata name(String name);
/**
* Sets file extensions associated with the language.
* @param extensions File extensions without dots (e.g., "jl")
* @return Configured LanguageMetadata instance
*/
public LanguageMetadata extensions(String... extensions);
}
/**
* ANTLR character stream interface for input processing.
*/
interface CharStream {
// Implementation provided by ANTLR runtime
}
/**
* ANTLR lexer base class for tokenization.
*/
abstract class Lexer {
// Implementation provided by ANTLR runtime
}
/**
* ANTLR-generated lexer for Julia language tokenization.
* This class is generated from the Julia.g4 grammar file.
*/
class JuliaLexer extends Lexer {
/**
* Creates a Julia lexer for the given character stream.
* @param input Character stream containing Julia source code
*/
public JuliaLexer(CharStream input);
}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.
The following parser and AST classes are available but deprecated:
/**
* ANTLR-generated parser for Julia language.
* @deprecated Since 7.8.0. Will be removed with no replacement.
*/
@Deprecated
public class JuliaParser extends Parser {
// Various parsing methods for Julia syntax elements
// Implementation is ANTLR-generated and not intended for direct use
}/**
* Visitor interface for Julia parse tree traversal.
* @param <T> Return type of visit operations
* @deprecated Since 7.8.0. Will be removed with no replacement.
*/
@Deprecated
public interface JuliaVisitor<T> extends ParseTreeVisitor<T> {
// Visit methods for all Julia AST node types
}
/**
* Base visitor implementation with default behaviors.
* @param <T> Return type of visit operations
* @deprecated Since 7.8.0. Will be removed with no replacement.
*/
@Deprecated
public class JuliaBaseVisitor<T> extends AbstractParseTreeVisitor<T>
implements JuliaVisitor<T> {
// Default implementations for all visit methods
}/**
* Listener interface for Julia parse tree events.
* @deprecated Since 7.8.0. Will be removed with no replacement.
*/
@Deprecated
public interface JuliaListener extends ParseTreeListener {
// Enter/exit methods for all Julia AST node types
}
/**
* Base listener implementation with empty default methods.
* @deprecated Since 7.8.0. Will be removed with no replacement.
*/
@Deprecated
public class JuliaBaseListener implements JuliaListener {
// Empty default implementations for all listener methods
}The Julia language module requires the following dependencies:
net.sourceforge.pmd:pmd-core - Core PMD functionality and language frameworkorg.antlr:antlr4-runtime - ANTLR parser runtime for Julia grammar processing.jl - Julia source files supported by the language moduleThe 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.
The module includes Maven build configuration with:
This module is designed for integration into larger PMD-based static analysis workflows and CI/CD pipelines for Julia code quality assessment.