Skip to content

Kotlin

Managed Regex since v1.0

๐ŸŸช Everything public by default. Skips private, internal, and protected. Companion objects stay out.

.kt.kts

What gets detected

The public surface spec-sync tracks for Kotlin.

  • Top-level fun / class / object / interface / typealias / val / var
  • data class / sealed class / enum class / annotation class
  • suspend fun / inline fun

Detection rules

Public by default

Kotlin's visibility default is public. Any top-level declaration without private/internal/protected is captured.

fun createAuth(config: Config): Auth {}
class AuthService {}
object AuthManager {}
interface Authenticator {}
typealias Token = String
val DEFAULT_TTL = 3600

Visibility exclusions

Lines starting with private, internal, or protected are skipped regardless of the declaration type.

private fun internalHelper() {}   // excluded
internal fun packageHelper() {}   // excluded
protected fun subclassHelper() {} // excluded
public fun explicitPublic() {}    // included

Data, sealed, enum, annotation classes

All class variants are captured. The class name is extracted regardless of modifier prefix.

data class UserProfile(val name: String)
sealed class AuthState {}
enum class Status { ACTIVE, EXPIRED }
annotation class Cacheable

Suspend and inline functions

Coroutine and inline functions are captured under their function name.

suspend fun fetchData(): Data {}
public suspend fun loadProfile(): Profile {}
inline fun <reified T> parse(json: String): T {}

Example: spec & source

The *.spec.md contract on the left, the Kotlin source it documents on the right. spec-sync matches the two.

Spec (*.spec.md)

---
module: auth
version: 1
status: stable
files:
  - src/main/kotlin/com/example/auth/AuthService.kt
---

## Purpose

Kotlin auth service for the Android/JVM platform.

## Public API

| Symbol | Kind | Description |
|--------|------|-------------|
| `createAuth` | fun | Creates an Auth instance |
| `AuthService` | class | Auth service class |
| `AuthState` | sealed class | Auth state union type |
| `DEFAULT_TTL` | val | Default TTL constant |

## Change Log

| Date | Change |
|------|--------|
| 2026-01-01 | Initial |

Source

package com.example.auth

fun createAuth(config: Config): Auth = Auth(config)

class AuthService {
    fun validate(token: String): Boolean = token.isNotEmpty()
}

sealed class AuthState {
    object Active : AuthState()
    object Expired : AuthState()
}

val DEFAULT_TTL = 3600

Test-file patterns

Files matching these are excluded from the detected surface.

Pattern Explanation
**/*Test.kt JUnit test classes: auto-excluded
**/*Spec.kt Spec-style test files: auto-excluded

Caveats

  • Companion objects (companion object { ... }) are skipped as standalone exports.
  • Extension functions are captured if they are top-level and public.
  • Operator overloads (operator fun ...) are included under their function name.

Related languages