SamWithReceiver: Add general-purpose plugin and Gradle/Maven integrations
This commit is contained in:
committed by
Yan Zhulanow
parent
db3172a750
commit
d07fd52c43
@@ -29,17 +29,26 @@ import org.jetbrains.kotlin.container.get
|
||||
import org.jetbrains.kotlin.extensions.StorageComponentContainerContributor
|
||||
import org.jetbrains.kotlin.load.java.sam.SamWithReceiverResolver
|
||||
import org.jetbrains.kotlin.samWithReceiver.SamWithReceiverConfigurationKeys.ANNOTATION
|
||||
import org.jetbrains.kotlin.samWithReceiver.SamWithReceiverConfigurationKeys.PRESET
|
||||
import org.jetbrains.kotlin.samWithReceiver.SamWithReceiverCommandLineProcessor.Companion.SUPPORTED_PRESETS
|
||||
|
||||
object SamWithReceiverConfigurationKeys {
|
||||
val ANNOTATION: CompilerConfigurationKey<List<String>> =
|
||||
CompilerConfigurationKey.create("annotation qualified name")
|
||||
|
||||
val PRESET: CompilerConfigurationKey<List<String>> = CompilerConfigurationKey.create("annotation preset")
|
||||
}
|
||||
|
||||
class SamWithReceiverCommandLineProcessor : CommandLineProcessor {
|
||||
companion object {
|
||||
val SUPPORTED_PRESETS = emptyMap<String, List<String>>()
|
||||
|
||||
val ANNOTATION_OPTION = CliOption("annotation", "<fqname>", "Annotation qualified names",
|
||||
required = false, allowMultipleOccurrences = true)
|
||||
|
||||
val PRESET_OPTION = CliOption("preset", "<name>", "Preset name (${SUPPORTED_PRESETS.keys.joinToString()})",
|
||||
required = false, allowMultipleOccurrences = true)
|
||||
|
||||
val PLUGIN_ID = "org.jetbrains.kotlin.samWithReceiver"
|
||||
}
|
||||
|
||||
@@ -48,13 +57,17 @@ class SamWithReceiverCommandLineProcessor : CommandLineProcessor {
|
||||
|
||||
override fun processOption(option: CliOption, value: String, configuration: CompilerConfiguration) = when (option) {
|
||||
ANNOTATION_OPTION -> configuration.appendList(ANNOTATION, value)
|
||||
PRESET_OPTION -> configuration.appendList(PRESET, value)
|
||||
else -> throw CliOptionProcessingException("Unknown option: ${option.name}")
|
||||
}
|
||||
}
|
||||
|
||||
class SamWithReceiverComponentRegistrar : ComponentRegistrar {
|
||||
override fun registerProjectComponents(project: MockProject, configuration: CompilerConfiguration) {
|
||||
val annotations = configuration.get(SamWithReceiverConfigurationKeys.ANNOTATION) ?: return
|
||||
val annotations = configuration.get(ANNOTATION)?.toMutableList() ?: mutableListOf()
|
||||
configuration.get(PRESET)?.forEach { preset ->
|
||||
SUPPORTED_PRESETS[preset]?.let { annotations += it }
|
||||
}
|
||||
if (annotations.isEmpty()) return
|
||||
|
||||
StorageComponentContainerContributor.registerExtension(project, CliSamWithReceiverComponentContributor(annotations))
|
||||
|
||||
Reference in New Issue
Block a user