JakeWharton / JakeWharton/cite

Support fully qualified type names

Open
#19 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
371
Forks
10
Avg merge
18h 7m
Merged PRs (30d)
13

Description

Logging frameworks such as [oshai/kotlin\-logging](https://github.com/oshai/kotlin-logging) use invocations like this to automatically assign a logger name:
```kotlin
private val logger = KotlinLogging.logger {}
```

Behind the scenes, they use `KClass.qualifiedName` which does not produce a fully qualified name on Js.

This plugin could solve that, e.g.:

* A file-level logger in `MyFile.kt`

```kotlin
package com.example

val logger = Logger(__QUALIFIED_CLASS__) // "com.example.MyFileKt"
```

* A class-level logger

```kotlin
package com.example

class MyClass {
companion object {
val logger = Logger(__QUALIFIED_CLASS__) // "com.example.MyClass"
}
}
```

In an internal project, I had created an annotation-based compiler plugin to generate logger names (also via a `IrElementTransformerVoidWithContext` derivative). The relevant qualified class name (including Kotlin's invisible file-level classes) was retrieved like so:

```kotlin
val qualifiedSurroundingClassName = allScopes.reversed().firstNotNullOfOrNull {
it.scope.scopeOwnerSymbol.owner.qualifiedClassName()
}
if (qualifiedSurroundingClassName == null) {
reportError("Could not find a qualified class name", call)
return super.visitCall(call)
}
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by tracing the compiler plugin's IR transformation around logger calls, using the IrElementTransformerVoidWithContext and qualifiedClassName approach shown in the issue. Check the file-level and class-level examples, including Kotlin's invisible file-level classes. Done means logger names include the expected fully qualified names on Js.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.