Introduce AbstractCliOption, rewrite all possible kapt options as enum values
This commit is contained in:
@@ -18,29 +18,41 @@ package org.jetbrains.kotlin.compiler.plugin
|
||||
|
||||
import java.util.regex.Pattern
|
||||
|
||||
interface AbstractCliOption {
|
||||
val optionName: String
|
||||
val valueDescription: String
|
||||
val description: String
|
||||
val required: Boolean
|
||||
val allowMultipleOccurrences: Boolean
|
||||
}
|
||||
|
||||
class CliOption(
|
||||
val name: String,
|
||||
val valueDescription: String,
|
||||
val description: String,
|
||||
val required: Boolean = true,
|
||||
val allowMultipleOccurrences: Boolean = false
|
||||
)
|
||||
override val optionName: String,
|
||||
override val valueDescription: String,
|
||||
override val description: String,
|
||||
override val required: Boolean = true,
|
||||
override val allowMultipleOccurrences: Boolean = false
|
||||
) : AbstractCliOption {
|
||||
@Deprecated("Use optionName instead.", ReplaceWith("optionName"))
|
||||
val name: String
|
||||
get() = optionName
|
||||
}
|
||||
|
||||
open class CliOptionProcessingException(message: String, cause: Throwable? = null): RuntimeException(message, cause)
|
||||
|
||||
class PluginCliOptionProcessingException(
|
||||
val pluginId: String,
|
||||
val options: Collection<CliOption>,
|
||||
val options: Collection<AbstractCliOption>,
|
||||
message: String,
|
||||
cause: Throwable? = null
|
||||
): CliOptionProcessingException(message, cause)
|
||||
|
||||
fun cliPluginUsageString(pluginId: String, options: Collection<CliOption>): String {
|
||||
fun cliPluginUsageString(pluginId: String, options: Collection<AbstractCliOption>): String {
|
||||
val LEFT_INDENT = 2
|
||||
val MAX_OPTION_WIDTH = 26
|
||||
|
||||
val renderedOptions = options.map {
|
||||
val name = "${it.name} ${it.valueDescription}"
|
||||
val name = "${it.optionName} ${it.valueDescription}"
|
||||
val margin = if (name.length > MAX_OPTION_WIDTH) {
|
||||
"\n" + " ".repeat(MAX_OPTION_WIDTH + LEFT_INDENT + 1)
|
||||
} else " ".repeat(1 + MAX_OPTION_WIDTH - name.length)
|
||||
|
||||
+13
-4
@@ -21,9 +21,18 @@ import org.jetbrains.kotlin.config.CompilerConfigurationKey
|
||||
|
||||
interface CommandLineProcessor {
|
||||
val pluginId: String
|
||||
val pluginOptions: Collection<CliOption>
|
||||
val pluginOptions: Collection<AbstractCliOption>
|
||||
|
||||
@Throws(CliOptionProcessingException::class) fun processOption(option: CliOption, value: String, configuration: CompilerConfiguration)
|
||||
@Throws(CliOptionProcessingException::class)
|
||||
fun processOption(option: AbstractCliOption, value: String, configuration: CompilerConfiguration) {
|
||||
@Suppress("DEPRECATION")
|
||||
processOption(option as CliOption, value, configuration)
|
||||
}
|
||||
|
||||
// TODO remove processOption(AbstractCliOption, ...) implementation after removal of this.
|
||||
@Deprecated("Implement processOption(option: AbstractCliOption, value: String, configuration: CompilerConfiguration) instead.")
|
||||
@Throws(CliOptionProcessingException::class)
|
||||
fun processOption(option: CliOption, value: String, configuration: CompilerConfiguration) {}
|
||||
|
||||
fun <T> CompilerConfiguration.appendList(option: CompilerConfigurationKey<List<T>>, value: T) {
|
||||
val paths = getList(option).toMutableList()
|
||||
@@ -37,9 +46,9 @@ interface CommandLineProcessor {
|
||||
put(option, paths)
|
||||
}
|
||||
|
||||
fun CompilerConfiguration.applyOptionsFrom(map: Map<String, List<String>>, pluginOptions: Collection<CliOption>) {
|
||||
fun CompilerConfiguration.applyOptionsFrom(map: Map<String, List<String>>, pluginOptions: Collection<AbstractCliOption>) {
|
||||
for ((key, values) in map) {
|
||||
val option = pluginOptions.firstOrNull { it.name == key } ?: continue
|
||||
val option = pluginOptions.firstOrNull { it.optionName == key } ?: continue
|
||||
|
||||
for (value in values) {
|
||||
processOption(option, value, this)
|
||||
|
||||
Reference in New Issue
Block a user