io.gitlab.arturbosch.detekt.api.SingleAssign.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of detekt-api Show documentation
Show all versions of detekt-api Show documentation
Static code analysis for Kotlin
The newest version!
package io.gitlab.arturbosch.detekt.api
import kotlin.reflect.KProperty
/**
* Allows to assign a property just once.
* Further assignments result in [IllegalStateException]'s.
*/
class SingleAssign {
private lateinit var _value: T
/**
* Returns the [_value] if it was set before. Else an error is thrown.
*/
operator fun getValue(thisRef: Any?, property: KProperty<*>): T {
check(this::_value.isInitialized) { "Property ${property.name} has not been assigned yet!" }
return _value
}
/**
* Sets [_value] to the given [value]. If it was set before, an error is thrown.
*/
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: T) {
check(!this::_value.isInitialized) { "Property ${property.name} has already been assigned!" }
_value = value
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy