diff --git a/api/revanced-patcher.api b/api/revanced-patcher.api index dccb89d..6d4992e 100644 --- a/api/revanced-patcher.api +++ b/api/revanced-patcher.api @@ -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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (Ljava/io/File;)V public fun close ()V diff --git a/src/main/kotlin/app/revanced/patcher/patch/options/PatchOption.kt b/src/main/kotlin/app/revanced/patcher/patch/options/PatchOption.kt index db95ee4..7ddb658 100644 --- a/src/main/kotlin/app/revanced/patcher/patch/options/PatchOption.kt +++ b/src/main/kotlin/app/revanced/patcher/patch/options/PatchOption.kt @@ -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( +@Suppress("MemberVisibilityCanBePrivate", "unused") +open class PatchOption( val key: String, val default: T?, val title: String?, @@ -78,4 +80,239 @@ abstract class PatchOption( 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.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.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.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.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.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.stringArrayPatchOption( + key: String, + default: Array? = null, + title: String? = null, + description: String? = null, + required: Boolean = false, + validator: (Array?) -> 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.intArrayPatchOption( + key: String, + default: Array? = null, + title: String? = null, + description: String? = null, + required: Boolean = false, + validator: (Array?) -> 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.booleanArrayPatchOption( + key: String, + default: Array? = null, + title: String? = null, + description: String? = null, + required: Boolean = false, + validator: (Array?) -> 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.floatArrayPatchOption( + key: String, + default: Array? = null, + title: String? = null, + description: String? = null, + required: Boolean = false, + validator: (Array?) -> 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.longArrayPatchOption( + key: String, + default: Array? = null, + title: String? = null, + description: String? = null, + required: Boolean = false, + validator: (Array?) -> Boolean = { true } + ) = PatchOption(key, default, title, description, required, validator).also { registerOption(it) } + + private fun

> P.registerOption(option: PatchOption<*>) = option.also { options.register(it) } + } } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patcher/patch/options/types/BooleanPatchOption.kt b/src/main/kotlin/app/revanced/patcher/patch/options/types/BooleanPatchOption.kt deleted file mode 100644 index 7744002..0000000 --- a/src/main/kotlin/app/revanced/patcher/patch/options/types/BooleanPatchOption.kt +++ /dev/null @@ -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(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.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) } - } -} diff --git a/src/main/kotlin/app/revanced/patcher/patch/options/types/FloatPatchOption.kt b/src/main/kotlin/app/revanced/patcher/patch/options/types/FloatPatchOption.kt deleted file mode 100644 index 8afd2dd..0000000 --- a/src/main/kotlin/app/revanced/patcher/patch/options/types/FloatPatchOption.kt +++ /dev/null @@ -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(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.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) } - } -} diff --git a/src/main/kotlin/app/revanced/patcher/patch/options/types/IntPatchOption.kt b/src/main/kotlin/app/revanced/patcher/patch/options/types/IntPatchOption.kt deleted file mode 100644 index f59ea86..0000000 --- a/src/main/kotlin/app/revanced/patcher/patch/options/types/IntPatchOption.kt +++ /dev/null @@ -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(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.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) } - } -} diff --git a/src/main/kotlin/app/revanced/patcher/patch/options/types/LongPatchOption.kt b/src/main/kotlin/app/revanced/patcher/patch/options/types/LongPatchOption.kt deleted file mode 100644 index ca8d613..0000000 --- a/src/main/kotlin/app/revanced/patcher/patch/options/types/LongPatchOption.kt +++ /dev/null @@ -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(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.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) } - } -} diff --git a/src/main/kotlin/app/revanced/patcher/patch/options/types/StringPatchOption.kt b/src/main/kotlin/app/revanced/patcher/patch/options/types/StringPatchOption.kt deleted file mode 100644 index dae966a..0000000 --- a/src/main/kotlin/app/revanced/patcher/patch/options/types/StringPatchOption.kt +++ /dev/null @@ -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(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.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) } - } -} diff --git a/src/main/kotlin/app/revanced/patcher/patch/options/types/array/BooleanArrayPatchOption.kt b/src/main/kotlin/app/revanced/patcher/patch/options/types/array/BooleanArrayPatchOption.kt deleted file mode 100644 index 713e6f2..0000000 --- a/src/main/kotlin/app/revanced/patcher/patch/options/types/array/BooleanArrayPatchOption.kt +++ /dev/null @@ -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?, - title: String?, - description: String?, - required: Boolean, - validator: (Array?) -> Boolean -) : PatchOption>(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.booleanArrayPatchOption( - key: String, - default: Array? = null, - title: String? = null, - description: String? = null, - required: Boolean = false, - validator: (Array?) -> Boolean = { true } - ) = BooleanArrayPatchOption(key, default, title, description, required, validator).also { options.register(it) } - } -} diff --git a/src/main/kotlin/app/revanced/patcher/patch/options/types/array/FloatArrayPatchOption.kt b/src/main/kotlin/app/revanced/patcher/patch/options/types/array/FloatArrayPatchOption.kt deleted file mode 100644 index 8cb5a66..0000000 --- a/src/main/kotlin/app/revanced/patcher/patch/options/types/array/FloatArrayPatchOption.kt +++ /dev/null @@ -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?, - title: String?, - description: String?, - required: Boolean, - validator: (Array?) -> Boolean -) : PatchOption>(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.floatArrayPatchOption( - key: String, - default: Array? = null, - title: String? = null, - description: String? = null, - required: Boolean = false, - validator: (Array?) -> Boolean = { true } - ) = FloatArrayPatchOption(key, default, title, description, required, validator).also { options.register(it) } - } -} diff --git a/src/main/kotlin/app/revanced/patcher/patch/options/types/array/IntArrayPatchOption.kt b/src/main/kotlin/app/revanced/patcher/patch/options/types/array/IntArrayPatchOption.kt deleted file mode 100644 index cc3e157..0000000 --- a/src/main/kotlin/app/revanced/patcher/patch/options/types/array/IntArrayPatchOption.kt +++ /dev/null @@ -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?, - title: String?, - description: String?, - required: Boolean, - validator: (Array?) -> Boolean -) : PatchOption>(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.intArrayPatchOption( - key: String, - default: Array? = null, - title: String? = null, - description: String? = null, - required: Boolean = false, - validator: (Array?) -> Boolean = { true } - ) = IntArrayPatchOption(key, default, title, description, required, validator).also { options.register(it) } - } -} diff --git a/src/main/kotlin/app/revanced/patcher/patch/options/types/array/LongArrayPatchOption.kt b/src/main/kotlin/app/revanced/patcher/patch/options/types/array/LongArrayPatchOption.kt deleted file mode 100644 index 5c25f0e..0000000 --- a/src/main/kotlin/app/revanced/patcher/patch/options/types/array/LongArrayPatchOption.kt +++ /dev/null @@ -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?, - title: String?, - description: String?, - required: Boolean, - validator: (Array?) -> Boolean -) : PatchOption>(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.longArrayPatchOption( - key: String, - default: Array? = null, - title: String? = null, - description: String? = null, - required: Boolean = false, - validator: (Array?) -> Boolean = { true } - ) = LongArrayPatchOption(key, default, title, description, required, validator).also { options.register(it) } - } -} diff --git a/src/main/kotlin/app/revanced/patcher/patch/options/types/array/StringArrayPatchOption.kt b/src/main/kotlin/app/revanced/patcher/patch/options/types/array/StringArrayPatchOption.kt deleted file mode 100644 index a1ca299..0000000 --- a/src/main/kotlin/app/revanced/patcher/patch/options/types/array/StringArrayPatchOption.kt +++ /dev/null @@ -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?, - title: String?, - description: String?, - required: Boolean, - validator: (Array?) -> Boolean -) : PatchOption>(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.stringArrayPatchOption( - key: String, - default: Array? = null, - title: String? = null, - description: String? = null, - required: Boolean = false, - validator: (Array?) -> Boolean = { true } - ) = StringArrayPatchOption(key, default, title, description, required, validator).also { options.register(it) } - } -} diff --git a/src/test/kotlin/app/revanced/patcher/patch/options/PatchOptionsTest.kt b/src/test/kotlin/app/revanced/patcher/patch/options/PatchOptionsTest.kt index 95538d1..cf344b9 100644 --- a/src/test/kotlin/app/revanced/patcher/patch/options/PatchOptionsTest.kt +++ b/src/test/kotlin/app/revanced/patcher/patch/options/PatchOptionsTest.kt @@ -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