refactor: convert Patch to abstract class

BREAKING CHANGE: Patch class is now an abstract class. You must implement it. You can use anonymous implements, like done in the tests.
This commit is contained in:
Lucaskyy 2022-03-20 21:57:20 +01:00 committed by oSumAtrIX
parent 428f7f4dec
commit cb9b1b9416
No known key found for this signature in database
GPG key ID: A9B3094ACDB604B4
2 changed files with 56 additions and 57 deletions

View file

@ -1,9 +1,5 @@
package net.revanced.patcher.patch
class Patch(val patchName: String, val fn: () -> PatchResult) {
fun execute(): PatchResult {
return fn()
abstract class Patch(val patchName: String) {
abstract fun execute(): PatchResult
}
}

View file

@ -1,6 +1,7 @@
package net.revanced.patcher
import net.revanced.patcher.patch.Patch
import net.revanced.patcher.patch.PatchResult
import net.revanced.patcher.patch.PatchResultSuccess
import net.revanced.patcher.signature.Signature
import net.revanced.patcher.util.ExtraTypes
@ -46,7 +47,8 @@ internal class PatcherTest {
val patcher = Patcher(testData, testSigs)
patcher.addPatches(
Patch ("TestPatch") {
object : Patch("TestPatch") {
override fun execute(): PatchResult {
// Get the method from the resolver cache
val mainMethod = patcher.cache.methods["mainMethod"]
// Get the instruction list
@ -101,7 +103,8 @@ internal class PatcherTest {
// You can also return PatchResultError with a message.
// If an exception is thrown inside this function,
// a PatchResultError will be returned with the error message.
PatchResultSuccess()
return PatchResultSuccess()
}
}
)