[Gradle] Fix CompilerOptionsIT.passesOptInAnnotationNative

KTIJ-24976
This commit is contained in:
Sebastian Sellmair
2023-03-28 15:18:41 +02:00
committed by Space Team
parent e76f3fb925
commit 2c8491cf27
4 changed files with 49 additions and 9 deletions
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.cli.common.CompilerSystemProperties
import org.jetbrains.kotlin.utils.SmartList
import kotlin.reflect.KClass
import kotlin.reflect.KMutableProperty1
import kotlin.reflect.cast
import kotlin.reflect.full.memberProperties
@Target(AnnotationTarget.PROPERTY)
@@ -63,6 +64,19 @@ data class ArgumentParseErrors(
val internalArgumentsParsingProblems: MutableList<String> = SmartList()
)
inline fun <reified T : CommonToolArguments> parseCommandLineArguments(args: List<String>): T {
return parseCommandLineArguments(T::class, args)
}
fun <T : CommonToolArguments> parseCommandLineArguments(clazz: KClass<T>, args: List<String>): T {
val constructor = clazz.java.constructors.find { it.parameters.isEmpty() }
?: error("Missing empty constructor on '${clazz.java.name}")
val arguments = clazz.cast(constructor.newInstance())
parseCommandLineArguments(args, arguments)
return arguments
}
// Parses arguments into the passed [result] object. Errors related to the parsing will be collected into [CommonToolArguments.errors].
fun <A : CommonToolArguments> parseCommandLineArguments(args: List<String>, result: A, overrideArguments: Boolean = false) {
val errors = lazy { result.errors ?: ArgumentParseErrors().also { result.errors = it } }