mirror of
https://github.com/ReVanced/revanced-patcher.git
synced 2026-01-23 11:11:04 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
db2804270e | ||
|
|
2572cd04b5 |
@@ -1,3 +1,10 @@
|
|||||||
|
# [3.3.0](https://github.com/revanced/revanced-patcher/compare/v3.2.1...v3.3.0) (2022-08-02)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add getValue & setValue for PatchOption ([2572cd0](https://github.com/revanced/revanced-patcher/commit/2572cd04b5da4eeae738c8dde31493177edf0bf8))
|
||||||
|
|
||||||
## [3.2.1](https://github.com/revanced/revanced-patcher/compare/v3.2.0...v3.2.1) (2022-08-02)
|
## [3.2.1](https://github.com/revanced/revanced-patcher/compare/v3.2.0...v3.2.1) (2022-08-02)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
kotlin.code.style = official
|
kotlin.code.style = official
|
||||||
version = 3.2.1
|
version = 3.3.0
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
@file:Suppress("CanBeParameter", "MemberVisibilityCanBePrivate")
|
@file:Suppress("CanBeParameter", "MemberVisibilityCanBePrivate", "UNCHECKED_CAST")
|
||||||
|
|
||||||
package app.revanced.patcher.patch
|
package app.revanced.patcher.patch
|
||||||
|
|
||||||
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
class NoSuchOptionException(val option: String) : Exception("No such option: $option")
|
class NoSuchOptionException(val option: String) : Exception("No such option: $option")
|
||||||
class IllegalValueException(val value: Any?) : Exception("Illegal value: $value")
|
class IllegalValueException(val value: Any?) : Exception("Illegal value: $value")
|
||||||
class InvalidTypeException(val got: String, val expected: String) :
|
class InvalidTypeException(val got: String, val expected: String) :
|
||||||
Exception("Invalid option value type: $got, expected $expected")
|
Exception("Invalid option value type: $got, expected $expected")
|
||||||
|
|
||||||
class RequirementNotMetException : Exception("null was passed into an option that requires a value")
|
class RequirementNotMetException : Exception("null was passed into an option that requires a value")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -82,6 +85,24 @@ sealed class PatchOption<T>(
|
|||||||
field = value
|
field = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of the option.
|
||||||
|
* Please note that using the wrong value type results in a runtime error.
|
||||||
|
*/
|
||||||
|
operator fun <T> getValue(thisRef: Nothing?, property: KProperty<*>) = value as T
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of the option.
|
||||||
|
* Please note that using the wrong value type results in a runtime error.
|
||||||
|
*/
|
||||||
|
inline operator fun <reified V> setValue(thisRef: Any?, property: KProperty<*>, new: V) {
|
||||||
|
if (value !is V) throw InvalidTypeException(
|
||||||
|
V::class.java.canonicalName,
|
||||||
|
value?.let { it::class.java.canonicalName } ?: "null"
|
||||||
|
)
|
||||||
|
value = new as T
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A [PatchOption] representing a [String].
|
* A [PatchOption] representing a [String].
|
||||||
* @see PatchOption
|
* @see PatchOption
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package app.revanced.patcher.patch
|
|||||||
import app.revanced.patcher.usage.bytecode.ExampleBytecodePatch
|
import app.revanced.patcher.usage.bytecode.ExampleBytecodePatch
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.jupiter.api.assertThrows
|
import org.junit.jupiter.api.assertThrows
|
||||||
|
import kotlin.test.assertNotEquals
|
||||||
|
|
||||||
internal class PatchOptionsTest {
|
internal class PatchOptionsTest {
|
||||||
private val options = ExampleBytecodePatch().options
|
private val options = ExampleBytecodePatch().options
|
||||||
@@ -31,9 +32,18 @@ internal class PatchOptionsTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println(options["key1"].value)
|
val option = options["key1"]
|
||||||
|
println(option.value)
|
||||||
options["key1"] = "Hello, world!"
|
options["key1"] = "Hello, world!"
|
||||||
println(options["key1"].value)
|
println(option.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `should return a different value when changed`() {
|
||||||
|
var value: String by options["key1"]
|
||||||
|
val current = value + "" // force a copy
|
||||||
|
value = "Hello, world!"
|
||||||
|
assertNotEquals(current, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user