fix(compiler-plugin): add workaround for nested logger resolution
This commit is contained in:
parent
2913b1e92d
commit
eb583b983c
|
@ -8,7 +8,6 @@ import com.tschuchort.compiletesting.SourceFile.Companion.kotlin
|
||||||
import org.jetbrains.kotlin.compiler.plugin.CliOption
|
import org.jetbrains.kotlin.compiler.plugin.CliOption
|
||||||
import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor
|
import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor
|
||||||
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
|
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
|
||||||
import org.junit.jupiter.api.Disabled
|
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
@OptIn(ExperimentalCompilerApi::class)
|
@OptIn(ExperimentalCompilerApi::class)
|
||||||
|
@ -107,9 +106,8 @@ class DebugLogTransformerTest {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Disabled
|
|
||||||
@Test
|
@Test
|
||||||
fun `nested logger function fails to resolve`() {
|
fun `nested logger function`() {
|
||||||
val annotationSrcFile =
|
val annotationSrcFile =
|
||||||
kotlin(
|
kotlin(
|
||||||
"DebugLog.kt",
|
"DebugLog.kt",
|
||||||
|
@ -157,9 +155,11 @@ class DebugLogTransformerTest {
|
||||||
kotlin(
|
kotlin(
|
||||||
"Logger.kt",
|
"Logger.kt",
|
||||||
"""
|
"""
|
||||||
|
package com.example
|
||||||
object Logger {
|
object Logger {
|
||||||
val messages = mutableListOf<String>()
|
val messages = mutableListOf<String>()
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
fun recordMessage(message: Any?) {
|
fun recordMessage(message: Any?) {
|
||||||
messages += message.toString()
|
messages += message.toString()
|
||||||
}
|
}
|
||||||
|
@ -176,7 +176,7 @@ class DebugLogTransformerTest {
|
||||||
add(
|
add(
|
||||||
processor.option(
|
processor.option(
|
||||||
TracingCommandLineProcessor.OPTION_LOGGER_FUNCTION,
|
TracingCommandLineProcessor.OPTION_LOGGER_FUNCTION,
|
||||||
"Logger.recordMessage"
|
"com.example.Logger.recordMessage"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
add(
|
add(
|
||||||
|
@ -204,7 +204,7 @@ class DebugLogTransformerTest {
|
||||||
assertThat(retVal).isInstanceOf(String::class.java)
|
assertThat(retVal).isInstanceOf(String::class.java)
|
||||||
assertThat(retVal).isEqualTo("Return value!")
|
assertThat(retVal).isEqualTo("Return value!")
|
||||||
|
|
||||||
val loggerClazz = result.classLoader.loadClass("LoggerKt")
|
val loggerClazz = result.classLoader.loadClass("com.example.Logger")
|
||||||
val msgField = loggerClazz.declaredFields.first { it.name == "messages" }
|
val msgField = loggerClazz.declaredFields.first { it.name == "messages" }
|
||||||
msgField.isAccessible = true
|
msgField.isAccessible = true
|
||||||
val messages = msgField.get(null) as? List<*>
|
val messages = msgField.get(null) as? List<*>
|
||||||
|
|
Loading…
Reference in New Issue