refactor: Change PatchOption from abstract to open class

BREAKING CHANGE: This gets rid of the existing basic implementations of the `PatchOptions` type and moves extension functions.
This commit is contained in:
oSumAtrIX 2023-10-22 01:54:33 +02:00
parent ebbaafb78e
commit 09cd6aa568
No known key found for this signature in database
GPG key ID: A9B3094ACDB604B4
13 changed files with 266 additions and 611 deletions

View file

@ -360,7 +360,8 @@ public abstract interface annotation class app/revanced/patcher/patch/annotation
public abstract fun use ()Z
}
public abstract class app/revanced/patcher/patch/options/PatchOption {
public class app/revanced/patcher/patch/options/PatchOption {
public static final field PatchExtensions Lapp/revanced/patcher/patch/options/PatchOption$PatchExtensions;
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;
@ -375,6 +376,29 @@ public abstract class app/revanced/patcher/patch/options/PatchOption {
public final fun setValue (Ljava/lang/Object;Lkotlin/reflect/KProperty;Ljava/lang/Object;)V
}
public final class app/revanced/patcher/patch/options/PatchOption$PatchExtensions {
public final fun booleanArrayPatchOption (Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;[Ljava/lang/Boolean;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;)Lapp/revanced/patcher/patch/options/PatchOption;
public static synthetic fun booleanArrayPatchOption$default (Lapp/revanced/patcher/patch/options/PatchOption$PatchExtensions;Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;[Ljava/lang/Boolean;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lapp/revanced/patcher/patch/options/PatchOption;
public final fun booleanPatchOption (Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;Ljava/lang/Boolean;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;)Lapp/revanced/patcher/patch/options/PatchOption;
public static synthetic fun booleanPatchOption$default (Lapp/revanced/patcher/patch/options/PatchOption$PatchExtensions;Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;Ljava/lang/Boolean;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lapp/revanced/patcher/patch/options/PatchOption;
public final fun floatArrayPatchOption (Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;[Ljava/lang/Float;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;)Lapp/revanced/patcher/patch/options/PatchOption;
public static synthetic fun floatArrayPatchOption$default (Lapp/revanced/patcher/patch/options/PatchOption$PatchExtensions;Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;[Ljava/lang/Float;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lapp/revanced/patcher/patch/options/PatchOption;
public final fun floatPatchOption (Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;Ljava/lang/Float;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;)Lapp/revanced/patcher/patch/options/PatchOption;
public static synthetic fun floatPatchOption$default (Lapp/revanced/patcher/patch/options/PatchOption$PatchExtensions;Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;Ljava/lang/Float;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lapp/revanced/patcher/patch/options/PatchOption;
public final fun intArrayPatchOption (Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;[Ljava/lang/Integer;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;)Lapp/revanced/patcher/patch/options/PatchOption;
public static synthetic fun intArrayPatchOption$default (Lapp/revanced/patcher/patch/options/PatchOption$PatchExtensions;Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;[Ljava/lang/Integer;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lapp/revanced/patcher/patch/options/PatchOption;
public final fun intPatchOption (Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;)Lapp/revanced/patcher/patch/options/PatchOption;
public static synthetic fun intPatchOption$default (Lapp/revanced/patcher/patch/options/PatchOption$PatchExtensions;Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lapp/revanced/patcher/patch/options/PatchOption;
public final fun longArrayPatchOption (Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;[Ljava/lang/Long;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;)Lapp/revanced/patcher/patch/options/PatchOption;
public static synthetic fun longArrayPatchOption$default (Lapp/revanced/patcher/patch/options/PatchOption$PatchExtensions;Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;[Ljava/lang/Long;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lapp/revanced/patcher/patch/options/PatchOption;
public final fun longPatchOption (Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;Ljava/lang/Long;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;)Lapp/revanced/patcher/patch/options/PatchOption;
public static synthetic fun longPatchOption$default (Lapp/revanced/patcher/patch/options/PatchOption$PatchExtensions;Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;Ljava/lang/Long;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lapp/revanced/patcher/patch/options/PatchOption;
public final fun stringArrayPatchOption (Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;)Lapp/revanced/patcher/patch/options/PatchOption;
public static synthetic fun stringArrayPatchOption$default (Lapp/revanced/patcher/patch/options/PatchOption$PatchExtensions;Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lapp/revanced/patcher/patch/options/PatchOption;
public final fun stringPatchOption (Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;)Lapp/revanced/patcher/patch/options/PatchOption;
public static synthetic fun stringPatchOption$default (Lapp/revanced/patcher/patch/options/PatchOption$PatchExtensions;Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lapp/revanced/patcher/patch/options/PatchOption;
}
public abstract class app/revanced/patcher/patch/options/PatchOptionException : java/lang/Exception {
public synthetic fun <init> (Ljava/lang/String;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
}
@ -424,106 +448,6 @@ public final class app/revanced/patcher/patch/options/PatchOptions : java/util/M
public final fun values ()Ljava/util/Collection;
}
public final class app/revanced/patcher/patch/options/types/BooleanPatchOption : app/revanced/patcher/patch/options/PatchOption {
public static final field Companion Lapp/revanced/patcher/patch/options/types/BooleanPatchOption$Companion;
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/Boolean;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
}
public final class app/revanced/patcher/patch/options/types/BooleanPatchOption$Companion {
public final fun booleanPatchOption (Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;Ljava/lang/Boolean;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;)Lapp/revanced/patcher/patch/options/types/BooleanPatchOption;
public static synthetic fun booleanPatchOption$default (Lapp/revanced/patcher/patch/options/types/BooleanPatchOption$Companion;Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;Ljava/lang/Boolean;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lapp/revanced/patcher/patch/options/types/BooleanPatchOption;
}
public final class app/revanced/patcher/patch/options/types/FloatPatchOption : app/revanced/patcher/patch/options/PatchOption {
public static final field Companion Lapp/revanced/patcher/patch/options/types/FloatPatchOption$Companion;
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/Float;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
}
public final class app/revanced/patcher/patch/options/types/FloatPatchOption$Companion {
public final fun floatPatchOption (Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;Ljava/lang/Float;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;)Lapp/revanced/patcher/patch/options/types/FloatPatchOption;
public static synthetic fun floatPatchOption$default (Lapp/revanced/patcher/patch/options/types/FloatPatchOption$Companion;Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;Ljava/lang/Float;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lapp/revanced/patcher/patch/options/types/FloatPatchOption;
}
public final class app/revanced/patcher/patch/options/types/IntPatchOption : app/revanced/patcher/patch/options/PatchOption {
public static final field Companion Lapp/revanced/patcher/patch/options/types/IntPatchOption$Companion;
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
}
public final class app/revanced/patcher/patch/options/types/IntPatchOption$Companion {
public final fun intPatchOption (Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;)Lapp/revanced/patcher/patch/options/types/IntPatchOption;
public static synthetic fun intPatchOption$default (Lapp/revanced/patcher/patch/options/types/IntPatchOption$Companion;Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lapp/revanced/patcher/patch/options/types/IntPatchOption;
}
public final class app/revanced/patcher/patch/options/types/LongPatchOption : app/revanced/patcher/patch/options/PatchOption {
public static final field Companion Lapp/revanced/patcher/patch/options/types/LongPatchOption$Companion;
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/Long;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
}
public final class app/revanced/patcher/patch/options/types/LongPatchOption$Companion {
public final fun longPatchOption (Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;Ljava/lang/Long;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;)Lapp/revanced/patcher/patch/options/types/LongPatchOption;
public static synthetic fun longPatchOption$default (Lapp/revanced/patcher/patch/options/types/LongPatchOption$Companion;Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;Ljava/lang/Long;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lapp/revanced/patcher/patch/options/types/LongPatchOption;
}
public final class app/revanced/patcher/patch/options/types/StringPatchOption : app/revanced/patcher/patch/options/PatchOption {
public static final field Companion Lapp/revanced/patcher/patch/options/types/StringPatchOption$Companion;
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
}
public final class app/revanced/patcher/patch/options/types/StringPatchOption$Companion {
public final fun stringPatchOption (Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;)Lapp/revanced/patcher/patch/options/types/StringPatchOption;
public static synthetic fun stringPatchOption$default (Lapp/revanced/patcher/patch/options/types/StringPatchOption$Companion;Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lapp/revanced/patcher/patch/options/types/StringPatchOption;
}
public final class app/revanced/patcher/patch/options/types/array/BooleanArrayPatchOption : app/revanced/patcher/patch/options/PatchOption {
public static final field Companion Lapp/revanced/patcher/patch/options/types/array/BooleanArrayPatchOption$Companion;
public synthetic fun <init> (Ljava/lang/String;[Ljava/lang/Boolean;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
}
public final class app/revanced/patcher/patch/options/types/array/BooleanArrayPatchOption$Companion {
public final fun booleanArrayPatchOption (Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;[Ljava/lang/Boolean;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;)Lapp/revanced/patcher/patch/options/types/array/BooleanArrayPatchOption;
public static synthetic fun booleanArrayPatchOption$default (Lapp/revanced/patcher/patch/options/types/array/BooleanArrayPatchOption$Companion;Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;[Ljava/lang/Boolean;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lapp/revanced/patcher/patch/options/types/array/BooleanArrayPatchOption;
}
public final class app/revanced/patcher/patch/options/types/array/FloatArrayPatchOption : app/revanced/patcher/patch/options/PatchOption {
public static final field Companion Lapp/revanced/patcher/patch/options/types/array/FloatArrayPatchOption$Companion;
public synthetic fun <init> (Ljava/lang/String;[Ljava/lang/Float;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
}
public final class app/revanced/patcher/patch/options/types/array/FloatArrayPatchOption$Companion {
public final fun floatArrayPatchOption (Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;[Ljava/lang/Float;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;)Lapp/revanced/patcher/patch/options/types/array/FloatArrayPatchOption;
public static synthetic fun floatArrayPatchOption$default (Lapp/revanced/patcher/patch/options/types/array/FloatArrayPatchOption$Companion;Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;[Ljava/lang/Float;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lapp/revanced/patcher/patch/options/types/array/FloatArrayPatchOption;
}
public final class app/revanced/patcher/patch/options/types/array/IntArrayPatchOption : app/revanced/patcher/patch/options/PatchOption {
public static final field Companion Lapp/revanced/patcher/patch/options/types/array/IntArrayPatchOption$Companion;
public synthetic fun <init> (Ljava/lang/String;[Ljava/lang/Integer;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
}
public final class app/revanced/patcher/patch/options/types/array/IntArrayPatchOption$Companion {
public final fun intArrayPatchOption (Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;[Ljava/lang/Integer;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;)Lapp/revanced/patcher/patch/options/types/array/IntArrayPatchOption;
public static synthetic fun intArrayPatchOption$default (Lapp/revanced/patcher/patch/options/types/array/IntArrayPatchOption$Companion;Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;[Ljava/lang/Integer;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lapp/revanced/patcher/patch/options/types/array/IntArrayPatchOption;
}
public final class app/revanced/patcher/patch/options/types/array/LongArrayPatchOption : app/revanced/patcher/patch/options/PatchOption {
public static final field Companion Lapp/revanced/patcher/patch/options/types/array/LongArrayPatchOption$Companion;
public synthetic fun <init> (Ljava/lang/String;[Ljava/lang/Long;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
}
public final class app/revanced/patcher/patch/options/types/array/LongArrayPatchOption$Companion {
public final fun longArrayPatchOption (Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;[Ljava/lang/Long;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;)Lapp/revanced/patcher/patch/options/types/array/LongArrayPatchOption;
public static synthetic fun longArrayPatchOption$default (Lapp/revanced/patcher/patch/options/types/array/LongArrayPatchOption$Companion;Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;[Ljava/lang/Long;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lapp/revanced/patcher/patch/options/types/array/LongArrayPatchOption;
}
public final class app/revanced/patcher/patch/options/types/array/StringArrayPatchOption : app/revanced/patcher/patch/options/PatchOption {
public static final field Companion Lapp/revanced/patcher/patch/options/types/array/StringArrayPatchOption$Companion;
public synthetic fun <init> (Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
}
public final class app/revanced/patcher/patch/options/types/array/StringArrayPatchOption$Companion {
public final fun stringArrayPatchOption (Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;)Lapp/revanced/patcher/patch/options/types/array/StringArrayPatchOption;
public static synthetic fun stringArrayPatchOption$default (Lapp/revanced/patcher/patch/options/types/array/StringArrayPatchOption$Companion;Lapp/revanced/patcher/patch/Patch;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lapp/revanced/patcher/patch/options/types/array/StringArrayPatchOption;
}
public final class app/revanced/patcher/util/DomFileEditor : java/io/Closeable {
public fun <init> (Ljava/io/File;)V
public fun close ()V

View file

@ -5,6 +5,7 @@ import kotlin.reflect.KProperty
/**
* A [Patch] option.
*
* @param key The identifier.
* @param default The default value.
* @param title The title.
@ -13,7 +14,8 @@ import kotlin.reflect.KProperty
* @param validator The function to validate the option value.
* @param T The value type of the option.
*/
abstract class PatchOption<T>(
@Suppress("MemberVisibilityCanBePrivate", "unused")
open class PatchOption<T>(
val key: String,
val default: T?,
val title: String?,
@ -78,4 +80,239 @@ abstract class PatchOption<T>(
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: T?) {
this.value = value
}
@Suppress("unused")
companion object PatchExtensions {
/**
* Create a new [PatchOption] with a string value and add it to the current [Patch].
*
* @param key The identifier.
* @param default The default value.
* @param title The title.
* @param description A description.
* @param required Whether the option is required.
* @param validator The function to validate the option value.
*
* @return The created [PatchOption].
*
* @see PatchOption
*/
fun <P : Patch<*>> P.stringPatchOption(
key: String,
default: String? = null,
title: String? = null,
description: String? = null,
required: Boolean = false,
validator: (String?) -> Boolean = { true }
) = PatchOption(key, default, title, description, required, validator).also { registerOption(it) }
/**
* Create a new [PatchOption] with an integer value and add it to the current [Patch].
*
* @param key The identifier.
* @param default The default value.
* @param title The title.
* @param description A description.
* @param required Whether the option is required.
* @param validator The function to validate the option value.
*
* @return The created [PatchOption].
*
* @see PatchOption
*/
fun <P : Patch<*>> P.intPatchOption(
key: String,
default: Int? = null,
title: String? = null,
description: String? = null,
required: Boolean = false,
validator: (Int?) -> Boolean = { true }
) = PatchOption(key, default, title, description, required, validator).also { registerOption(it) }
/**
* Create a new [PatchOption] with a boolean value and add it to the current [Patch].
*
* @param key The identifier.
* @param default The default value.
* @param title The title.
* @param description A description.
* @param required Whether the option is required.
* @param validator The function to validate the option value.
*
* @return The created [PatchOption].
*
* @see PatchOption
*/
fun <P : Patch<*>> P.booleanPatchOption(
key: String,
default: Boolean? = null,
title: String? = null,
description: String? = null,
required: Boolean = false,
validator: (Boolean?) -> Boolean = { true }
) = PatchOption(key, default, title, description, required, validator).also { registerOption(it) }
/**
* Create a new [PatchOption] with a float value and add it to the current [Patch].
*
* @param key The identifier.
* @param default The default value.
* @param title The title.
* @param description A description.
* @param required Whether the option is required.
* @param validator The function to validate the option value.
*
* @return The created [PatchOption].
*
* @see PatchOption
*/
fun <P : Patch<*>> P.floatPatchOption(
key: String,
default: Float? = null,
title: String? = null,
description: String? = null,
required: Boolean = false,
validator: (Float?) -> Boolean = { true }
) = PatchOption(key, default, title, description, required, validator).also { registerOption(it) }
/**
* Create a new [PatchOption] with a long value and add it to the current [Patch].
*
* @param key The identifier.
* @param default The default value.
* @param title The title.
* @param description A description.
* @param required Whether the option is required.
* @param validator The function to validate the option value.
*
* @return The created [PatchOption].
*
* @see PatchOption
*/
fun <P : Patch<*>> P.longPatchOption(
key: String,
default: Long? = null,
title: String? = null,
description: String? = null,
required: Boolean = false,
validator: (Long?) -> Boolean = { true }
) = PatchOption(key, default, title, description, required, validator).also { registerOption(it) }
/**
* Create a new [PatchOption] with a string array value and add it to the current [Patch].
*
* @param key The identifier.
* @param default The default value.
* @param title The title.
* @param description A description.
* @param required Whether the option is required.
* @param validator The function to validate the option value.
*
* @return The created [PatchOption].
*
* @see PatchOption
*/
fun <P : Patch<*>> P.stringArrayPatchOption(
key: String,
default: Array<String>? = null,
title: String? = null,
description: String? = null,
required: Boolean = false,
validator: (Array<String>?) -> Boolean = { true }
) = PatchOption(key, default, title, description, required, validator).also { registerOption(it) }
/**
* Create a new [PatchOption] with an integer array value and add it to the current [Patch].
*
* @param key The identifier.
* @param default The default value.
* @param title The title.
* @param description A description.
* @param required Whether the option is required.
* @param validator The function to validate the option value.
*
* @return The created [PatchOption].
*
* @see PatchOption
*/
fun <P : Patch<*>> P.intArrayPatchOption(
key: String,
default: Array<Int>? = null,
title: String? = null,
description: String? = null,
required: Boolean = false,
validator: (Array<Int>?) -> Boolean = { true }
) = PatchOption(key, default, title, description, required, validator).also { registerOption(it) }
/**
* Create a new [PatchOption] with a boolean array value and add it to the current [Patch].
*
* @param key The identifier.
* @param default The default value.
* @param title The title.
* @param description A description.
* @param required Whether the option is required.
* @param validator The function to validate the option value.
*
* @return The created [PatchOption].
*
* @see PatchOption
*/
fun <P : Patch<*>> P.booleanArrayPatchOption(
key: String,
default: Array<Boolean>? = null,
title: String? = null,
description: String? = null,
required: Boolean = false,
validator: (Array<Boolean>?) -> Boolean = { true }
) = PatchOption(key, default, title, description, required, validator).also { registerOption(it) }
/**
* Create a new [PatchOption] with a float array value and add it to the current [Patch].
*
* @param key The identifier.
* @param default The default value.
* @param title The title.
* @param description A description.
* @param required Whether the option is required.
* @param validator The function to validate the option value.
*
* @return The created [PatchOption].
*
* @see PatchOption
*/
fun <P : Patch<*>> P.floatArrayPatchOption(
key: String,
default: Array<Float>? = null,
title: String? = null,
description: String? = null,
required: Boolean = false,
validator: (Array<Float>?) -> Boolean = { true }
) = PatchOption(key, default, title, description, required, validator).also { registerOption(it) }
/**
* Create a new [PatchOption] with a long array value and add it to the current [Patch].
*
* @param key The identifier.
* @param default The default value.
* @param title The title.
* @param description A description.
* @param required Whether the option is required.
* @param validator The function to validate the option value.
*
* @return The created [PatchOption].
*
* @see PatchOption
*/
fun <P : Patch<*>> P.longArrayPatchOption(
key: String,
default: Array<Long>? = null,
title: String? = null,
description: String? = null,
required: Boolean = false,
validator: (Array<Long>?) -> Boolean = { true }
) = PatchOption(key, default, title, description, required, validator).also { registerOption(it) }
private fun <P : Patch<*>> P.registerOption(option: PatchOption<*>) = option.also { options.register(it) }
}
}

View file

@ -1,49 +0,0 @@
package app.revanced.patcher.patch.options.types
import app.revanced.patcher.patch.Patch
import app.revanced.patcher.patch.options.PatchOption
/**
* A [PatchOption] representing a [Boolean].
*
* @param key The identifier.
* @param default The default value.
* @param title The title.
* @param description A description.
* @param required Whether the option is required.
* @param validator The function to validate the option value.
*
* @see PatchOption
*/
class BooleanPatchOption private constructor(
key: String,
default: Boolean?,
title: String?,
description: String?,
required: Boolean,
validator: (Boolean?) -> Boolean
) : PatchOption<Boolean>(key, default, title, description, required, validator) {
companion object {
/**
* Create a new [BooleanPatchOption] and add it to the current [Patch].
*
* @param key The identifier.
* @param default The default value.
* @param title The title.
* @param description A description.
* @param required Whether the option is required.
* @return The created [BooleanPatchOption].
*
* @see BooleanPatchOption
* @see PatchOption
*/
fun <T : Patch<*>> T.booleanPatchOption(
key: String,
default: Boolean? = null,
title: String? = null,
description: String? = null,
required: Boolean = false,
validator: (Boolean?) -> Boolean = { true }
) = BooleanPatchOption(key, default, title, description, required, validator).also { options.register(it) }
}
}

View file

@ -1,51 +0,0 @@
package app.revanced.patcher.patch.options.types
import app.revanced.patcher.patch.Patch
import app.revanced.patcher.patch.options.PatchOption
/**
* A [PatchOption] representing a [Float].
*
* @param key The identifier.
* @param default The default value.
* @param title The title.
* @param description A description.
* @param required Whether the option is required.
* @param validator The function to validate the option value.
*
* @see PatchOption
*/
class FloatPatchOption private constructor(
key: String,
default: Float?,
title: String?,
description: String?,
required: Boolean,
validator: (Float?) -> Boolean
) : PatchOption<Float>(key, default, title, description, required, validator) {
companion object {
/**
* Create a new [FloatPatchOption] and add it to the current [Patch].
*
* @param key The identifier.
* @param default The default value.
* @param title The title.
* @param description A description.
* @param required Whether the option is required.
* @param validator The function to validate the option value.
*
* @return The created [FloatPatchOption].
*
* @see FloatPatchOption
* @see PatchOption
*/
fun <T : Patch<*>> T.floatPatchOption(
key: String,
default: Float? = null,
title: String? = null,
description: String? = null,
required: Boolean = false,
validator: (Float?) -> Boolean = { true }
) = FloatPatchOption(key, default, title, description, required, validator).also { options.register(it) }
}
}

View file

@ -1,51 +0,0 @@
package app.revanced.patcher.patch.options.types
import app.revanced.patcher.patch.Patch
import app.revanced.patcher.patch.options.PatchOption
/**
* A [PatchOption] representing an [Integer].
*
* @param key The identifier.
* @param default The default value.
* @param title The title.
* @param description A description.
* @param required Whether the option is required.
* @param validator The function to validate the option value.
*
* @see PatchOption
*/
class IntPatchOption private constructor(
key: String,
default: Int?,
title: String?,
description: String?,
required: Boolean,
validator: (Int?) -> Boolean
) : PatchOption<Int>(key, default, title, description, required, validator) {
companion object {
/**
* Create a new [IntPatchOption] and add it to the current [Patch].
*
* @param key The identifier.
* @param default The default value.
* @param title The title.
* @param description A description.
* @param required Whether the option is required.
* @param validator The function to validate the option value.
*
* @return The created [IntPatchOption].
*
* @see IntPatchOption
* @see PatchOption
*/
fun <T : Patch<*>> T.intPatchOption(
key: String,
default: Int? = null,
title: String? = null,
description: String? = null,
required: Boolean = false,
validator: (Int?) -> Boolean = { true }
) = IntPatchOption(key, default, title, description, required, validator).also { options.register(it) }
}
}

View file

@ -1,49 +0,0 @@
package app.revanced.patcher.patch.options.types
import app.revanced.patcher.patch.Patch
import app.revanced.patcher.patch.options.PatchOption
/**
* A [PatchOption] representing a [Long].
*
* @param key The identifier.
* @param default The default value.
* @param title The title.
* @param description A description.
* @param required Whether the option is required.
* @param validator The function to validate the option value.
*
* @see PatchOption
*/
class LongPatchOption private constructor(
key: String,
default: Long?,
title: String?,
description: String?,
required: Boolean,
validator: (Long?) -> Boolean
) : PatchOption<Long>(key, default, title, description, required, validator) {
companion object {
/**
* Create a new [LongPatchOption] and add it to the current [Patch].
*
* @param key The identifier.
* @param default The default value.
* @param title The title.
* @param description A description.
* @param required Whether the option is required.
* @return The created [LongPatchOption].
*
* @see LongPatchOption
* @see PatchOption
*/
fun <T : Patch<*>> T.longPatchOption(
key: String,
default: Long? = null,
title: String? = null,
description: String? = null,
required: Boolean = false,
validator: (Long?) -> Boolean = { true }
) = LongPatchOption(key, default, title, description, required, validator).also { options.register(it) }
}
}

View file

@ -1,51 +0,0 @@
package app.revanced.patcher.patch.options.types
import app.revanced.patcher.patch.Patch
import app.revanced.patcher.patch.options.PatchOption
/**
* A [PatchOption] representing a [String].
*
* @param key The identifier.
* @param default The default value.
* @param title The title.
* @param description A description.
* @param required Whether the option is required.
* @param validator The function to validate the option value.
*
* @see PatchOption
*/
class StringPatchOption private constructor(
key: String,
default: String?,
title: String?,
description: String?,
required: Boolean,
validator: (String?) -> Boolean
) : PatchOption<String>(key, default, title, description, required, validator) {
companion object {
/**
* Create a new [StringPatchOption] and add it to the current [Patch].
*
* @param key The identifier.
* @param default The default value.
* @param title The title.
* @param description A description.
* @param required Whether the option is required.
* @param validator The function to validate the option value.
*
* @return The created [StringPatchOption].
*
* @see StringPatchOption
* @see PatchOption
*/
fun <T : Patch<*>> T.stringPatchOption(
key: String,
default: String? = null,
title: String? = null,
description: String? = null,
required: Boolean = false,
validator: (String?) -> Boolean = { true }
) = StringPatchOption(key, default, title, description, required, validator).also { options.register(it) }
}
}

View file

@ -1,51 +0,0 @@
package app.revanced.patcher.patch.options.types.array
import app.revanced.patcher.patch.Patch
import app.revanced.patcher.patch.options.PatchOption
/**
* A [PatchOption] representing a [Boolean] array.
*
* @param key The identifier.
* @param default The default value.
* @param title The title.
* @param description A description.
* @param required Whether the option is required.
* @param validator The function to validate the option value.
*
* @see PatchOption
*/
class BooleanArrayPatchOption private constructor(
key: String,
default: Array<Boolean>?,
title: String?,
description: String?,
required: Boolean,
validator: (Array<Boolean>?) -> Boolean
) : PatchOption<Array<Boolean>>(key, default, title, description, required, validator) {
companion object {
/**
* Create a new [BooleanArrayPatchOption] and add it to the current [Patch].
*
* @param key The identifier.
* @param default The default value.
* @param title The title.
* @param description A description.
* @param required Whether the option is required.
* @param validator The function to validate the option value.
*
* @return The created [BooleanArrayPatchOption].
*
* @see BooleanArrayPatchOption
* @see PatchOption
*/
fun <T : Patch<*>> T.booleanArrayPatchOption(
key: String,
default: Array<Boolean>? = null,
title: String? = null,
description: String? = null,
required: Boolean = false,
validator: (Array<Boolean>?) -> Boolean = { true }
) = BooleanArrayPatchOption(key, default, title, description, required, validator).also { options.register(it) }
}
}

View file

@ -1,51 +0,0 @@
package app.revanced.patcher.patch.options.types.array
import app.revanced.patcher.patch.Patch
import app.revanced.patcher.patch.options.PatchOption
/**
* A [PatchOption] representing a [Float] array.
*
* @param key The identifier.
* @param default The default value.
* @param title The title.
* @param description A description.
* @param required Whether the option is required.
* @param validator The function to validate the option value.
*
* @see PatchOption
*/
class FloatArrayPatchOption private constructor(
key: String,
default: Array<Float>?,
title: String?,
description: String?,
required: Boolean,
validator: (Array<Float>?) -> Boolean
) : PatchOption<Array<Float>>(key, default, title, description, required, validator) {
companion object {
/**
* Create a new [FloatArrayPatchOption] and add it to the current [Patch].
*
* @param key The identifier.
* @param default The default value.
* @param title The title.
* @param description A description.
* @param required Whether the option is required.
* @param validator The function to validate the option value.
*
* @return The created [FloatArrayPatchOption].
*
* @see FloatArrayPatchOption
* @see PatchOption
*/
fun <T : Patch<*>> T.floatArrayPatchOption(
key: String,
default: Array<Float>? = null,
title: String? = null,
description: String? = null,
required: Boolean = false,
validator: (Array<Float>?) -> Boolean = { true }
) = FloatArrayPatchOption(key, default, title, description, required, validator).also { options.register(it) }
}
}

View file

@ -1,51 +0,0 @@
package app.revanced.patcher.patch.options.types.array
import app.revanced.patcher.patch.Patch
import app.revanced.patcher.patch.options.PatchOption
/**
* A [PatchOption] representing an [Integer] array.
*
* @param key The identifier.
* @param default The default value.
* @param title The title.
* @param description A description.
* @param required Whether the option is required.
* @param validator The function to validate the option value.
*
* @see PatchOption
*/
class IntArrayPatchOption private constructor(
key: String,
default: Array<Int>?,
title: String?,
description: String?,
required: Boolean,
validator: (Array<Int>?) -> Boolean
) : PatchOption<Array<Int>>(key, default, title, description, required, validator) {
companion object {
/**
* Create a new [IntArrayPatchOption] and add it to the current [Patch].
*
* @param key The identifier.
* @param default The default value.
* @param title The title.
* @param description A description.
* @param required Whether the option is required.
* @param validator The function to validate the option value.
*
* @return The created [IntArrayPatchOption].
*
* @see IntArrayPatchOption
* @see PatchOption
*/
fun <T : Patch<*>> T.intArrayPatchOption(
key: String,
default: Array<Int>? = null,
title: String? = null,
description: String? = null,
required: Boolean = false,
validator: (Array<Int>?) -> Boolean = { true }
) = IntArrayPatchOption(key, default, title, description, required, validator).also { options.register(it) }
}
}

View file

@ -1,51 +0,0 @@
package app.revanced.patcher.patch.options.types.array
import app.revanced.patcher.patch.Patch
import app.revanced.patcher.patch.options.PatchOption
/**
* A [PatchOption] representing a [Long] array.
*
* @param key The identifier.
* @param default The default value.
* @param title The title.
* @param description A description.
* @param required Whether the option is required.
* @param validator The function to validate the option value.
*
* @see PatchOption
*/
class LongArrayPatchOption private constructor(
key: String,
default: Array<Long>?,
title: String?,
description: String?,
required: Boolean,
validator: (Array<Long>?) -> Boolean
) : PatchOption<Array<Long>>(key, default, title, description, required, validator) {
companion object {
/**
* Create a new [LongArrayPatchOption] and add it to the current [Patch].
*
* @param key The identifier.
* @param default The default value.
* @param title The title.
* @param description A description.
* @param required Whether the option is required.
* @param validator The function to validate the option value.
*
* @return The created [LongArrayPatchOption].
*
* @see LongArrayPatchOption
* @see PatchOption
*/
fun <T : Patch<*>> T.longArrayPatchOption(
key: String,
default: Array<Long>? = null,
title: String? = null,
description: String? = null,
required: Boolean = false,
validator: (Array<Long>?) -> Boolean = { true }
) = LongArrayPatchOption(key, default, title, description, required, validator).also { options.register(it) }
}
}

View file

@ -1,51 +0,0 @@
package app.revanced.patcher.patch.options.types.array
import app.revanced.patcher.patch.Patch
import app.revanced.patcher.patch.options.PatchOption
/**
* A [PatchOption] representing a [String] array.
*
* @param key The identifier.
* @param default The default value.
* @param title The title.
* @param description A description.
* @param required Whether the option is required.
* @param validator The function to validate the option value.
*
* @see PatchOption
*/
class StringArrayPatchOption private constructor(
key: String,
default: Array<String>?,
title: String?,
description: String?,
required: Boolean,
validator: (Array<String>?) -> Boolean
) : PatchOption<Array<String>>(key, default, title, description, required, validator) {
companion object {
/**
* Create a new [StringArrayPatchOption] and add it to the current [Patch].
*
* @param key The identifier.
* @param default The default value.
* @param title The title.
* @param description A description.
* @param required Whether the option is required.
* @param validator The function to validate the option value.
*
* @return The created [StringArrayPatchOption].
*
* @see StringArrayPatchOption
* @see PatchOption
*/
fun <T : Patch<*>> T.stringArrayPatchOption(
key: String,
default: Array<String>? = null,
title: String? = null,
description: String? = null,
required: Boolean = false,
validator: (Array<String>?) -> Boolean = { true }
) = StringArrayPatchOption(key, default, title, description, required, validator).also { options.register(it) }
}
}

View file

@ -2,9 +2,9 @@ package app.revanced.patcher.patch.options
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.options.types.BooleanPatchOption.Companion.booleanPatchOption
import app.revanced.patcher.patch.options.types.StringPatchOption.Companion.stringPatchOption
import app.revanced.patcher.patch.options.types.array.StringArrayPatchOption.Companion.stringArrayPatchOption
import app.revanced.patcher.patch.options.PatchOption.PatchExtensions.booleanPatchOption
import app.revanced.patcher.patch.options.PatchOption.PatchExtensions.stringArrayPatchOption
import app.revanced.patcher.patch.options.PatchOption.PatchExtensions.stringPatchOption
import org.junit.jupiter.api.assertDoesNotThrow
import org.junit.jupiter.api.assertThrows
import kotlin.test.Test