From 371f0c4d0bf96e7f6db35085efccaed3000a096c Mon Sep 17 00:00:00 2001 From: Sculas Date: Tue, 2 Aug 2022 22:32:55 +0200 Subject: [PATCH] feat: PatchOptions#nullify to nullify an option --- .../kotlin/app/revanced/patcher/patch/PatchOption.kt | 8 ++++++++ .../app/revanced/patcher/patch/PatchOptionsTest.kt | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/src/main/kotlin/app/revanced/patcher/patch/PatchOption.kt b/src/main/kotlin/app/revanced/patcher/patch/PatchOption.kt index 2d47507..fbb4026 100644 --- a/src/main/kotlin/app/revanced/patcher/patch/PatchOption.kt +++ b/src/main/kotlin/app/revanced/patcher/patch/PatchOption.kt @@ -42,6 +42,14 @@ class PatchOptions(vararg val options: PatchOption<*>) : Iterable opt.value = value } + /** + * Sets the value of a [PatchOption] to `null`. + * @param key The key of the [PatchOption]. + */ + fun nullify(key: String) { + get(key).value = null + } + override fun iterator() = options.iterator() } diff --git a/src/test/kotlin/app/revanced/patcher/patch/PatchOptionsTest.kt b/src/test/kotlin/app/revanced/patcher/patch/PatchOptionsTest.kt index 3a41555..140c3c0 100644 --- a/src/test/kotlin/app/revanced/patcher/patch/PatchOptionsTest.kt +++ b/src/test/kotlin/app/revanced/patcher/patch/PatchOptionsTest.kt @@ -36,6 +36,15 @@ internal class PatchOptionsTest { println(options["key1"].value) } + @Test + fun `should be able to set value to null`() { + // Sadly, doing: + // > options["key1"] = null + // is not possible because Kotlin + // cannot reify the type "Nothing?". + options.nullify("key1") + } + @Test fun `should fail because the option does not exist`() { assertThrows {