or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

ast-parsing.mdast-traversal.mdcopy-paste-detection.mdindex.mdlanguage-module.mdrule-development.md
tile.json

tessl/maven-net-sourceforge-pmd--pmd-scala-2-12

PMD Scala language support for Scala 2.12 - provides parsing and static analysis capabilities for Scala code as part of the PMD extensible multilanguage static code analyzer

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/net.sourceforge.pmd/pmd-scala_2.12@7.13.x

To install, run

npx @tessl/cli install tessl/maven-net-sourceforge-pmd--pmd-scala-2-12@7.13.0

index.mddocs/

PMD Scala 2.12

PMD Scala 2.12 provides Scala language support for PMD, the extensible multilanguage static code analyzer. It enables parsing of Scala 2.12 source code into abstract syntax trees (AST) for static analysis, code quality checks, and copy-paste detection. The module integrates Scalameta parsers with PMD's rule engine to provide comprehensive Scala code analysis capabilities.

Package Information

  • Package Name: pmd-scala_2.12
  • Package Type: maven
  • Group ID: net.sourceforge.pmd
  • Language: Java/Kotlin (analyzing Scala code)
  • Installation: Add to Maven dependencies:
<dependency>
    <groupId>net.sourceforge.pmd</groupId>
    <artifactId>pmd-scala_2.12</artifactId>
    <version>7.13.0</version>
</dependency>

Core Imports

import net.sourceforge.pmd.lang.scala.ScalaLanguageModule;
import net.sourceforge.pmd.lang.scala.ScalaLanguageHandler;
import net.sourceforge.pmd.lang.scala.ast.ScalaParser;
import net.sourceforge.pmd.lang.scala.ast.ASTSource;
import net.sourceforge.pmd.lang.scala.ast.AbstractScalaNode;
import net.sourceforge.pmd.lang.scala.ast.ScalaNode;
import net.sourceforge.pmd.lang.scala.ast.ScalaVisitor;
import net.sourceforge.pmd.lang.scala.ast.ScalaTreeBuilder;
import net.sourceforge.pmd.lang.scala.rule.ScalaRule;
import net.sourceforge.pmd.lang.scala.cpd.ScalaCpdLexer;
import net.sourceforge.pmd.lang.scala.cpd.ScalaTokenAdapter;

Basic Usage

// Get the Scala language module
ScalaLanguageModule module = ScalaLanguageModule.getInstance();

// Parse Scala source code
ScalaParser parser = new ScalaParser();
ASTSource ast = parser.parse(parserTask);

// Create a custom Scala rule
public class MyScalaRule extends ScalaRule {
    @Override
    public RuleContext visit(ASTDefnClass node, RuleContext data) {
        // Rule logic for class definitions
        return super.visit(node, data);
    }
}

Architecture

The PMD Scala module follows a layered architecture:

  1. Language Integration Layer: Core PMD integration through ScalaLanguageModule and ScalaLanguageHandler
  2. Parsing Layer: Scalameta-based parsing via ScalaParser and ScalaTreeBuilder
  3. AST Layer: 140+ AST node types representing all Scala language constructs
  4. Analysis Layer: Visitor pattern support and rule development framework
  5. Copy-Paste Detection Layer: Tokenization for duplicate code detection

Capabilities

Language Module Registration

Core PMD integration and language module registration for Scala versions 2.10-2.13.

public class ScalaLanguageModule extends SimpleLanguageModuleBase {
    public static ScalaLanguageModule getInstance();
    public CpdLexer createCpdLexer(LanguagePropertyBundle bundle);
}

Language Module

AST Parsing and Processing

Complete Scala source code parsing into PMD-compatible abstract syntax trees using Scalameta.

public final class ScalaParser implements Parser {
    public ASTSource parse(ParserTask task) throws ParseException;
}

public final class ASTSource extends AbstractScalaNode<Source> implements RootNode {
    public AstInfo<ASTSource> getAstInfo();
}

AST Parsing

AST Node Traversal

Comprehensive visitor pattern implementation for traversing and analyzing Scala ASTs.

public interface ScalaVisitor<D, R> extends AstVisitor<D, R> {
    default R visit(ScalaNode<?> node, D data);
    default R visit(ASTSource node, D data);
    // 140+ visit methods for all AST node types
}

public interface ScalaNode<T extends Tree> extends GenericNode<ScalaNode<?>> {
    boolean isImplicit();
}

AST Traversal

Rule Development

Framework for creating custom static analysis rules for Scala code.

public class ScalaRule extends AbstractRule implements ScalaVisitor<RuleContext, RuleContext> {
    public void apply(Node target, RuleContext ctx);
    public RuleContext visitNode(Node node, RuleContext param);
}

Rule Development

Copy-Paste Detection

Scalameta-based tokenization for detecting code duplication in Scala projects.

public class ScalaCpdLexer implements CpdLexer {
    public ScalaCpdLexer(LanguagePropertyBundle bundle);
    public void tokenize(TextDocument document, TokenFactory tokenEntries);
}

Copy-Paste Detection

Types

Core Types

// Language integration
class ScalaLanguageModule extends SimpleLanguageModuleBase
class ScalaLanguageHandler extends AbstractPmdLanguageVersionHandler

// Parsing
class ScalaParser implements Parser
class ScalaTreeBuilder // Internal tree building
class ASTSource extends AbstractScalaNode<Source> implements RootNode

// AST base types
abstract class AbstractScalaNode<T extends Tree> extends AbstractNode<AbstractScalaNode<?>, ScalaNode<?>> implements ScalaNode<T>
interface ScalaNode<T extends Tree> extends GenericNode<ScalaNode<?>>
interface ScalaVisitor<D, R> extends AstVisitor<D, R>
class ScalaVisitorBase implements ScalaVisitor<Object, Object>

// Rule development
class ScalaRule extends AbstractRule implements ScalaVisitor<RuleContext, RuleContext>

// Copy-paste detection  
class ScalaCpdLexer implements CpdLexer
class ScalaTokenAdapter // Token adapter for PMD integration

// Internal utilities
class ScalaDialect // Maps language versions to Scalameta dialects

Supported Scala Versions

  • Scala 2.10
  • Scala 2.11
  • Scala 2.12 (this module's target version)
  • Scala 2.13

Integration Dependencies

  • PMD Core: net.sourceforge.pmd:pmd-core - Core PMD framework
  • Scalameta: org.scalameta:parsers_2.12 and org.scalameta:trees_2.12 - Scala parsing
  • Scala Runtime: org.scala-lang:scala-library:2.12.20 - Scala standard library