diff options
4 files changed, 19 insertions, 3 deletions
diff --git a/example/src/main/kotlin/OtherTest.kt b/example/src/main/kotlin/OtherTest.kt new file mode 100644 index 0000000..fe31a16 --- /dev/null +++ b/example/src/main/kotlin/OtherTest.kt @@ -0,0 +1,6 @@ +package moe.nea.mcautotranslations.example + +class OtherTest { + + fun testFunc(x: Int, y: Text) = tr("other-test.test-func", "Hello $y: $x") +} diff --git a/example/src/main/kotlin/Test2.kt b/example/src/main/kotlin/Test2.kt new file mode 100644 index 0000000..40d23db --- /dev/null +++ b/example/src/main/kotlin/Test2.kt @@ -0,0 +1,5 @@ +package moe.nea.mcautotranslations.example + +object Test2 { + fun x() = tr("test2.object", "Hehheehe") +} diff --git a/example/src/main/kotlin/test.kt b/example/src/main/kotlin/test.kt index cb5ddfa..c5132d4 100644 --- a/example/src/main/kotlin/test.kt +++ b/example/src/main/kotlin/test.kt @@ -10,15 +10,18 @@ val resources = class Text(val key: String, val args: Array<out Any>) { override fun toString(): String { - return resources[key]!!.format(*args) + return (resources[key] ?: error("Unresolved key $key")).format(*args) } } @Suppress("UNUSED") fun trResolved(key: String, vararg args: Any) = Text(key, args) -fun tr(key: String, default: String): Text = error("Did not run compiler plugin") +@Suppress("UNUSED") +fun tr(key: String, default: String): Text = error("Did not run compiler plugin for key '$key' with default '$default'") fun main() { println(tr("test1", "Hiiiiiii")) println(tr("test2", "Hello ${Math.random()}")) println(tr("test3", "Goodbye ${Math.random()} ${Math.E}")) + println(OtherTest().testFunc(10, tr("lol", "Lolnea"))) + println(Test2.x()) } diff --git a/kotlin-plugin/src/main/kotlin/moe/nea/mcautotranslations/kotlin/MCAutoTranslationsCallTransformerAndCollector.kt b/kotlin-plugin/src/main/kotlin/moe/nea/mcautotranslations/kotlin/MCAutoTranslationsCallTransformerAndCollector.kt index fc1acc1..d87648d 100644 --- a/kotlin-plugin/src/main/kotlin/moe/nea/mcautotranslations/kotlin/MCAutoTranslationsCallTransformerAndCollector.kt +++ b/kotlin-plugin/src/main/kotlin/moe/nea/mcautotranslations/kotlin/MCAutoTranslationsCallTransformerAndCollector.kt @@ -10,6 +10,7 @@ import org.jetbrains.kotlin.cli.common.messages.MessageCollector import org.jetbrains.kotlin.ir.builders.irCall import org.jetbrains.kotlin.ir.builders.irCallConstructor import org.jetbrains.kotlin.ir.builders.irVararg +import org.jetbrains.kotlin.ir.declarations.IrClass import org.jetbrains.kotlin.ir.declarations.IrFile import org.jetbrains.kotlin.ir.expressions.IrCall import org.jetbrains.kotlin.ir.expressions.IrConst @@ -128,7 +129,8 @@ class MCAutoTranslationsCallTransformerAndCollector( putValueArgument(1, constString(it.value)) } } - file.annotations = annotations + file.annotations + val annotationContainer = file.declarations.singleOrNull()?.takeIf { it is IrClass } ?: file + annotationContainer.annotations = annotations + annotationContainer.annotations } |