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

io.gitlab.arturbosch.detekt.api.LazyRegex.kt Maven / Gradle / Ivy

package io.gitlab.arturbosch.detekt.api

import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty

/**
 * LazyRegex class provides a lazy evaluation of a Regex pattern for usages inside Rules.
 * It computes the value once when reaching the point of its usage and returns the same
 * value when requested again.
 *
 * `key` & `default` are used to retrieve a value from config.
 */
@Deprecated("Use config property delegate with transformer instead.")
class LazyRegex(
    private val key: String,
    private val default: String
) : ReadOnlyProperty {

    private var lazyRegexValue: Regex? = null

    override fun getValue(thisRef: Rule, property: KProperty<*>): Regex {
        return lazyRegexValue ?: createRegex(thisRef).also { lazyRegexValue = it }
    }

    private fun createRegex(rule: Rule): Regex {
        return Regex(rule.valueOrDefault(key = key, default = default))
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy