mirror of
https://github.com/revanced/revanced-patcher.git
synced 2025-04-30 05:14:26 +02:00
feat: Add getter for default option value
This commit is contained in:
parent
c1f4c0445a
commit
c7922e90d0
@ -362,6 +362,7 @@ public abstract interface annotation class app/revanced/patcher/patch/annotation
|
|||||||
|
|
||||||
public abstract class app/revanced/patcher/patch/options/PatchOption {
|
public abstract class app/revanced/patcher/patch/options/PatchOption {
|
||||||
public fun <init> (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;)V
|
public fun <init> (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;)V
|
||||||
|
public final fun getDefault ()Ljava/lang/Object;
|
||||||
public final fun getDescription ()Ljava/lang/String;
|
public final fun getDescription ()Ljava/lang/String;
|
||||||
public final fun getKey ()Ljava/lang/String;
|
public final fun getKey ()Ljava/lang/String;
|
||||||
public final fun getRequired ()Z
|
public final fun getRequired ()Z
|
||||||
|
@ -15,7 +15,7 @@ import kotlin.reflect.KProperty
|
|||||||
*/
|
*/
|
||||||
abstract class PatchOption<T>(
|
abstract class PatchOption<T>(
|
||||||
val key: String,
|
val key: String,
|
||||||
default: T?,
|
val default: T?,
|
||||||
val title: String?,
|
val title: String?,
|
||||||
val description: String?,
|
val description: String?,
|
||||||
val required: Boolean,
|
val required: Boolean,
|
||||||
@ -25,12 +25,42 @@ abstract class PatchOption<T>(
|
|||||||
* The value of the [PatchOption].
|
* The value of the [PatchOption].
|
||||||
*/
|
*/
|
||||||
var value: T? = default
|
var value: T? = default
|
||||||
|
/**
|
||||||
|
* Set the value of the [PatchOption].
|
||||||
|
*
|
||||||
|
* @param value The value to set.
|
||||||
|
*
|
||||||
|
* @throws PatchOptionException.ValueRequiredException If the value is required but null.
|
||||||
|
* @throws PatchOptionException.ValueValidationException If the value is invalid.
|
||||||
|
*/
|
||||||
set(value) {
|
set(value) {
|
||||||
if (required && value == null) throw PatchOptionException.ValueRequiredException(this)
|
assertRequiredButNotNull(value)
|
||||||
if (!validator(value)) throw PatchOptionException.ValueValidationException(value, this)
|
assertValid(value)
|
||||||
|
|
||||||
field = value
|
field = value
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Get the value of the [PatchOption].
|
||||||
|
*
|
||||||
|
* @return The value.
|
||||||
|
*
|
||||||
|
* @throws PatchOptionException.ValueRequiredException If the value is required but null.
|
||||||
|
* @throws PatchOptionException.ValueValidationException If the value is invalid.
|
||||||
|
*/
|
||||||
|
get() {
|
||||||
|
assertRequiredButNotNull(field)
|
||||||
|
assertValid(field)
|
||||||
|
|
||||||
|
return field
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun assertRequiredButNotNull(value: T?) {
|
||||||
|
if (required && value == null) throw PatchOptionException.ValueRequiredException(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun assertValid(value: T?) {
|
||||||
|
if (!validator(value)) throw PatchOptionException.ValueValidationException(value, this)
|
||||||
|
}
|
||||||
|
|
||||||
operator fun getValue(thisRef: Any?, property: KProperty<*>) = value
|
operator fun getValue(thisRef: Any?, property: KProperty<*>) = value
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user