From 6f097dc8f6aa1284e6edf895877bc415ddaee5b6 Mon Sep 17 00:00:00 2001 From: Ilya Kirillov Date: Wed, 8 Nov 2023 11:16:58 +0100 Subject: [PATCH] Introduce utility function for specifying compiler argument names ^KT-63294 --- .../cli/common/arguments/CommonToolArguments.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonToolArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonToolArguments.kt index ac4a6f8be72..1608ebbbf1b 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonToolArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonToolArguments.kt @@ -17,6 +17,8 @@ package org.jetbrains.kotlin.cli.common.arguments import java.io.Serializable +import kotlin.reflect.KProperty1 +import kotlin.reflect.jvm.javaField abstract class CommonToolArguments : Freezable(), Serializable { companion object { @@ -100,3 +102,15 @@ abstract class CommonToolArguments : Freezable(), Serializable { // the previous commit. This method can be removed after some time. override fun equals(other: Any?): Boolean = super.equals(other) } + + +/** + * An argument which should be passed to Kotlin compiler to enable [this] compiler option + */ +val KProperty1.cliArgument: String + get() { + val javaField = javaField + ?: error("Java field should be present for $this") + val argumentAnnotation = javaField.getAnnotation(Argument::class.java) + return argumentAnnotation.value + } \ No newline at end of file