Skip to content

Kotlin support (and a trap in adding it) #2

Open

Description

@aminHZDEV

dryer does not read Kotlin. .kt is not in discover.py, so a Kotlin project reports:

No source files to analyze.

The obvious fix, .kt in discover.py plus a _kotlin_nodes picker in extract.py, is not enough. With only that, every Kotlin function that has the same control flow scores 1.0, whatever it calls.

Measured

Two functions with the same shape that call different methods, scored with dryer's own normalize() and fingerprints() on tree-sitter's Kotlin grammar:

fun saveUser(repo: Repo, user: User): Boolean {
    val ok = repo.validate(user)
    if (ok) repo.insert(user)
    return audit.record(user)
}

fun dropUser(repo: Repo, user: User): Boolean {
    val ok = repo.authorize(user)
    if (ok) repo.delete(user)
    return mailer.notify(user)
}
Code Score
Same two methods in Java 0.37
Kotlin, with the obvious fix 1.00

Cause

astnorm.py keeps the call or method name and drops locals by node type, and Kotlin's tree uses different types:

  • identifiers are simple_identifier, not identifier;
  • repo.insert(user) is call_expression -> navigation_expression -> navigation_suffix -> simple_identifier, so the name sits one level deeper than in Java's method_invocation or TypeScript's member_expression;
  • arguments are call_suffix -> value_arguments, not argument_list;
  • real_literal, long_literal, hex_literal, bin_literal and unsigned_literal are not in _LITERALS;
  • Kotlin operators ?:, !!, .., ..<, in, is, as, as? are not in _OPERATORS.

Adding the types to the sets is not enough: the call and member handling has to find the name inside navigation_suffix.

Proposed

  • discover.py: .kt.
  • extract.py: _kotlin_nodes, the functions crapper scores: every fun with a body, not one nested in another function, a lambda, an anonymous object, or a local class.
  • astnorm.py: the Kotlin types above, and member handling for navigation_suffix.
  • Tests: renamed locals and literals in Kotlin score 1.0; the same skeleton with different callees scores about what Java does.

Activity

  1. elijulian commented on Nov 9, 2026

    @elijulian

    this would be a huge help, i want to use this for my kotlin repos too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions