All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.gitlab.arturbosch.detekt.api.internal.RuleSetConfigProperty.kt Maven / Gradle / Ivy

The newest version!
package io.gitlab.arturbosch.detekt.api.internal

import io.gitlab.arturbosch.detekt.api.Config
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty

fun  ruleSetConfig(defaultValue: T): ReadOnlyProperty> =
    RuleSetConfigPropertyDelegate(defaultValue)

private class RuleSetConfigPropertyDelegate(
    val defaultValue: T
) : ReadOnlyProperty> {

    @Volatile private var _value: RuleSetConfigProperty? = null

    override fun getValue(thisRef: Any?, property: KProperty<*>): RuleSetConfigProperty =
        _value ?: RuleSetConfigProperty(property.name, defaultValue).also { _value = it }
}

class RuleSetConfigProperty(val key: String, val defaultValue: T) {
    fun value(config: Config): T =
        config.valueOrDefault(key, defaultValue)
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy