Skip to content

Score Kotlin functions and join their JaCoCo coverage - #5

Open
aminHZDEV wants to merge 7 commits into
unclebob:masterfrom
aminHZDEV:feat/kotlin
Open

aminHZDEV wants to merge 7 commits into
unclebob:masterfrom
aminHZDEV:feat/kotlin

Conversation

@aminHZDEV

@aminHZDEV aminHZDEV commented Oct 26, 2026 •

Copy link
Copy Markdown

Fixes #4

Depends on #3. This branch is built on it, so the first two commits are the
Gradle ones; review the last two.

Problem:
.kt files were skipped, so on a Kotlin or mixed Kotlin/Java project
crapper scored nothing in the Kotlin code.

Fix:

  • A Kotlin reader in languages/kotlin.py, following java.py. Every
    fun with a body is an entry: top-level, member, extension, expression
    body, and inside object / companion object. Local functions and
    lambdas stay in the enclosing function. Secondary constructors, init
    blocks, anonymous objects and local classes are left out.
  • Decisions: if, for, while, do, catch, each when entry
    (including else, like Java's default), &&, ||, ?: and each ?.
    (like TypeScript's ?? and ?.). !! is not counted.
  • :namespace is the class JaCoCo reports, so coverage joins:
    pkg.Outer.Inner, pkg.Class.Companion, and pkg.FileNameKt or the
    @file:JvmName for a top-level function. Coverage lookup also covers
    I$DefaultImpls, enum entry classes, @file:JvmMultifileClass parts,
    and mangled names (name$module, name-hash).
  • Java and Kotlin share one Maven or Gradle JaCoCo run per module, so a
    mixed project runs its tests once.
  • A file with a parse error is still scored, with a warning on stderr.
  • README and --help describe Kotlin.

Tested:

  • 12 new tests. 170 pass; the 2 failures were there before (they need bb
    and uml-viewer).
  • Real Gradle run (Gradle 8.5, Kotlin 1.9.22): every function joined its
    JaCoCo class, including Shape$DefaultImpls and hidden$ktdemo.
  • kotlinx.coroutines outside test folders: 2,678 functions in 0.4 s, one
    file with a parse error.

Not covered:

  • A function-level @JvmName does not join, so it scores 0%.
  • Property accessors with a body (get() { ... }) are not entries, so
    their decisions count nowhere.
  • Multiplatform and Android builds have no test jacocoTestReport tasks,
    so they warn and score 0%.

@x950827

x950827 commented Oct 29, 2026

Copy link
Copy Markdown

I built the same thing in parallel (#17, now closed) before I saw this. A few things it handled that this branch doesn't, in case they're useful:

  • Kover: build/reports/kover/report.xml is JaCoCo XML too, so it can go in the same merge.
  • When a module has more than one report (a stale jacocoTestReport.xml next to a fresh Kover one), the newest by mtime should win; today the first exact line match does.
  • kotlinc sanitizes the facade name: my-utils.kt compiles to My_utilsKt, 1st.kt to _1stKt. Here they become My-utilsKt and 1stKt, so coverage misses.
  • _JVM_NAME and _MULTIFILE match inside comments (// see @file:JvmName("Nope") renames the facade). The parse tree has file_annotation nodes, which also cover @file:[JvmName("X")].

Happy to send these as a follow-up once this lands.

@x950827 x950827 mentioned this pull request Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Kotlin support for crapper and then dryer, mutator, uml-viewer

2 participants