Skip to content

Commit

Permalink
refactor: Do not reify generic type
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Sep 6, 2023
1 parent 67b7dff commit 81d1d7f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions revanced-patcher/api/revanced-patcher.api
Original file line number Diff line number Diff line change
Expand Up @@ -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 synthetic fun remove (Ljava/lang/Object;)Ljava/lang/Object;
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 values ()Ljava/util/Collection;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,18 @@ class PatchOptions internal constructor(
* @param value The value.
* @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]

if (option.value !is T) throw PatchOptionException.InvalidValueTypeException(
T::class.java.name,
option.value?.let { it::class.java.name } ?: "null",
)

@Suppress("UNCHECKED_CAST")
(option as PatchOption<T>).value = value
try {
@Suppress("UNCHECKED_CAST")
(option as PatchOption<T>).value = value
} catch (e: ClassCastException) {
throw PatchOptionException.InvalidValueTypeException(
value?.let { it::class.java.name } ?: "null",
option.value?.let { it::class.java.name } ?: "null",
)
}
}

/**
Expand Down

0 comments on commit 81d1d7f

Please sign in to comment.