or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

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

index.mddocs/

PMD Swift

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.

Package Information

  • Package Name: pmd-swift
  • Package Type: Maven
  • Language: Java
  • Group ID: net.sourceforge.pmd
  • Artifact ID: pmd-swift
  • Version: 6.55.0
  • Installation: Add Maven dependency in pom.xml
<dependency>
    <groupId>net.sourceforge.pmd</groupId>
    <artifactId>pmd-swift</artifactId>
    <version>6.55.0</version>
</dependency>

Core Imports

import net.sourceforge.pmd.lang.swift.SwiftLanguageModule;
import net.sourceforge.pmd.cpd.SwiftLanguage;
import net.sourceforge.pmd.cpd.SwiftTokenizer;

Basic Usage

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:

// PMD automatically discovers Swift language support via SPI
// No manual registration required

// Direct usage for custom implementations
SwiftLanguage swiftLanguage = new SwiftLanguage();
SwiftTokenizer tokenizer = new SwiftTokenizer();

// Language module for PMD integration
SwiftLanguageModule languageModule = new SwiftLanguageModule();

Architecture

PMD Swift follows PMD's plugin architecture pattern:

  • Language Module: SwiftLanguageModule registers Swift as a supported language in PMD
  • CPD Language: SwiftLanguage provides copy-paste detection capabilities
  • Tokenizer: SwiftTokenizer handles Swift source code parsing using ANTLR
  • ANTLR Grammar: Swift.g4 defines Swift language syntax for lexical analysis
  • Service Registration: META-INF services enable automatic discovery by PMD

Capabilities

Swift Language Module

Core language registration for PMD framework integration.

/**
 * Language Module for Swift - registers Swift language support in PMD
 * @deprecated There is no full PMD support for Swift
 */
@Deprecated
public class SwiftLanguageModule extends BaseLanguageModule {
    /** The language name constant */
    public static final String NAME = "Swift";
    
    /** The terse name constant */
    public static final String TERSE_NAME = "swift";
    
    /**
     * Create a new instance of Swift Language Module
     */
    public SwiftLanguageModule();
}

CPD Swift Language

Language implementation for copy-paste detection functionality.

/**
 * Language implementation for Swift in CPD system
 */
public class SwiftLanguage extends AbstractLanguage {
    /**
     * Creates a new Swift Language instance with tokenizer and file extension
     */
    public SwiftLanguage();
}

Swift Tokenizer

ANTLR-based tokenizer for Swift source code analysis.

/**
 * SwiftTokenizer for parsing Swift source code using ANTLR
 */
public class SwiftTokenizer extends AntlrTokenizer {
    /**
     * Get lexer for given source code
     * @param sourceCode The source code to tokenize
     * @return AntlrTokenManager for token processing
     */
    @Override
    protected AntlrTokenManager getLexerForSource(final SourceCode sourceCode);
}

ANTLR Generated Components

Generated lexer from Swift grammar definition.

/**
 * ANTLR-generated lexer for Swift language
 * Generated from Swift.g4 grammar file during Maven compilation
 * Located at: net.sourceforge.pmd.lang.swift.antlr4.SwiftLexer
 */
public class SwiftLexer extends org.antlr.v4.runtime.Lexer {
    /**
     * Create lexer with character stream input
     * @param input Character stream from Swift source code
     */
    public SwiftLexer(CharStream input);
}

Types

// Core PMD types used by Swift module
import net.sourceforge.pmd.lang.BaseLanguageModule;
import net.sourceforge.pmd.cpd.AbstractLanguage;
import net.sourceforge.pmd.cpd.AntlrTokenizer;
import net.sourceforge.pmd.lang.antlr.AntlrTokenManager;
import net.sourceforge.pmd.cpd.SourceCode;
import org.antlr.v4.runtime.CharStream;
import net.sourceforge.pmd.lang.swift.antlr4.SwiftLexer;

Service Provider Registration

PMD Swift uses Java SPI for automatic discovery:

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

net.sourceforge.pmd.lang.swift.SwiftLanguageModule

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

net.sourceforge.pmd.cpd.SwiftLanguage

Limitations and Status

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

  • No full PMD support: Only provides CPD (copy-paste detection) functionality
  • No static analysis rules: Cannot detect Swift-specific code issues or violations
  • Limited Swift version support: Grammar may not support latest Swift language features
  • Maintenance status: No active development or updates planned
  • Functionality scope: Restricted to duplicate code detection only

Dependencies

  • pmd-core: Core PMD functionality and base classes
  • antlr4-runtime: ANTLR runtime for lexer execution
  • Swift.g4: ANTLR grammar definition for Swift language parsing

Usage in PMD

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

  1. Discovers Swift language support via SPI
  2. Registers .swift file extension for processing
  3. Enables CPD duplicate detection for Swift files
  4. Uses SwiftTokenizer for parsing Swift source code

Example PMD command line usage:

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