refactor: Do not reify generic type

This commit is contained in:
oSumAtrIX 2023-09-06 06:34:38 +02:00
parent 67b7dff67a
commit 81d1d7f544
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
2 changed files with 11 additions and 8 deletions

View File

@ -407,6 +407,7 @@ public final class app/revanced/patcher/patch/options/PatchOptions : java/util/M
public final fun remove (Ljava/lang/Object;)Lapp/revanced/patcher/patch/options/PatchOption; public final fun remove (Ljava/lang/Object;)Lapp/revanced/patcher/patch/options/PatchOption;
public final synthetic fun remove (Ljava/lang/Object;)Ljava/lang/Object; public final synthetic fun remove (Ljava/lang/Object;)Ljava/lang/Object;
public fun remove (Ljava/lang/String;)Lapp/revanced/patcher/patch/options/PatchOption; public fun remove (Ljava/lang/String;)Lapp/revanced/patcher/patch/options/PatchOption;
public final fun set (Ljava/lang/String;Ljava/lang/Object;)V
public final fun size ()I public final fun size ()I
public final fun values ()Ljava/util/Collection; public final fun values ()Ljava/util/Collection;
} }

View File

@ -23,16 +23,18 @@ class PatchOptions internal constructor(
* @param value The value. * @param value The value.
* @throws PatchOptionException.PatchOptionNotFoundException If the option does not exist. * @throws PatchOptionException.PatchOptionNotFoundException If the option does not exist.
*/ */
inline operator fun <reified T: Any> set(key: String, value: T?) { operator fun <T : Any> set(key: String, value: T?) {
val option = this[key] val option = this[key]
if (option.value !is T) throw PatchOptionException.InvalidValueTypeException( try {
T::class.java.name, @Suppress("UNCHECKED_CAST")
option.value?.let { it::class.java.name } ?: "null", (option as PatchOption<T>).value = value
) } catch (e: ClassCastException) {
throw PatchOptionException.InvalidValueTypeException(
@Suppress("UNCHECKED_CAST") value?.let { it::class.java.name } ?: "null",
(option as PatchOption<T>).value = value option.value?.let { it::class.java.name } ?: "null",
)
}
} }
/** /**