dev.mokkery.plugin.MokkeryCommandLineProcessor.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mokkery-plugin Show documentation
Show all versions of mokkery-plugin Show documentation
Mokkery is a mocking library for Kotlin Multiplatform, easy to use, boilerplate-free and compiler plugin driven.
The newest version!
package dev.mokkery.plugin
import com.google.auto.service.AutoService
import dev.mokkery.MockMode
import dev.mokkery.MokkeryConfig
import dev.mokkery.verify.VerifyMode
import dev.mokkery.verify.VerifyModeSerializer
import org.jetbrains.kotlin.compiler.plugin.AbstractCliOption
import org.jetbrains.kotlin.compiler.plugin.CliOption
import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.config.CompilerConfigurationKey
val MOCK_MODE_KEY = CompilerConfigurationKey>("mockMode")
val VERIFY_MODE_KEY = CompilerConfigurationKey>("verifyMode")
val ALLOW_INDIRECT_SUPER_CALLS = CompilerConfigurationKey>("allowIndirectSuperCalls")
val IGNORE_INLINE_MEMBERS = CompilerConfigurationKey>("ignoreInlineMembers")
val IGNORE_FINAL_MEMBERS = CompilerConfigurationKey>("ignoreFinalMembers")
@AutoService(CommandLineProcessor::class)
class MokkeryCommandLineProcessor : CommandLineProcessor {
override val pluginId = MokkeryConfig.PLUGIN_ID
override val pluginOptions: Collection = listOf(
CliOption(
optionName = MOCK_MODE_KEY.toString(),
valueDescription = "enum class dev.mokkery.MockMode",
description = "Default MockMode for every mock.",
required = true,
allowMultipleOccurrences = false
),
CliOption(
optionName = VERIFY_MODE_KEY.toString(),
valueDescription = "sealed class dev.mokkery.VerifyMode",
description = "Default VerifyMode for every verify block.",
required = true,
allowMultipleOccurrences = false
),
CliOption(
optionName = ALLOW_INDIRECT_SUPER_CALLS.toString(),
valueDescription = "Boolean",
description = "Dictates if super calls to indirect types should be allowed whenever possible.",
required = true,
allowMultipleOccurrences = false
),
CliOption(
optionName = IGNORE_INLINE_MEMBERS.toString(),
valueDescription = "Boolean",
description = "Ignores inline members of mocked class if raised.",
required = false,
allowMultipleOccurrences = false
),
CliOption(
optionName = IGNORE_FINAL_MEMBERS.toString(),
valueDescription = "Boolean",
description = "Ignores final members of mocked class if raised.",
required = false,
allowMultipleOccurrences = false
)
)
override fun processOption(option: AbstractCliOption, value: String, configuration: CompilerConfiguration) {
return when (option.optionName) {
MOCK_MODE_KEY.toString() -> configuration.add(MOCK_MODE_KEY, MockMode.valueOf(value))
VERIFY_MODE_KEY.toString() -> configuration.add(VERIFY_MODE_KEY, VerifyModeSerializer.deserialize(value))
ALLOW_INDIRECT_SUPER_CALLS.toString() -> configuration.add(ALLOW_INDIRECT_SUPER_CALLS, value.toBoolean())
IGNORE_INLINE_MEMBERS.toString() -> configuration.add(IGNORE_INLINE_MEMBERS, value.toBoolean())
IGNORE_FINAL_MEMBERS.toString() -> configuration.add(IGNORE_FINAL_MEMBERS, value.toBoolean())
else -> error("Unknown config option: $option")
}
}
}