feat!: seal abstract class Patch as an interface

This commit is contained in:
oSumAtrIX 2022-10-04 08:26:26 +02:00
parent 8c502448be
commit 4d581811db
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
6 changed files with 24 additions and 32 deletions

View File

@ -11,8 +11,8 @@ import app.revanced.patcher.patch.Patch
import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultError import app.revanced.patcher.patch.PatchResultError
import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.impl.BytecodePatch import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.impl.ResourcePatch import app.revanced.patcher.patch.ResourcePatch
import app.revanced.patcher.util.ListBackedSet import app.revanced.patcher.util.ListBackedSet
import app.revanced.patcher.util.VersionReader import app.revanced.patcher.util.VersionReader
import brut.androlib.Androlib import brut.androlib.Androlib

View File

@ -1,8 +1,9 @@
package app.revanced.patcher.patch package app.revanced.patcher.patch
import app.revanced.patcher.data.Data import app.revanced.patcher.data.Data
import app.revanced.patcher.patch.impl.BytecodePatch import app.revanced.patcher.data.impl.BytecodeData
import app.revanced.patcher.patch.impl.ResourcePatch import app.revanced.patcher.data.impl.ResourceData
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import java.io.Closeable import java.io.Closeable
/** /**
@ -12,11 +13,11 @@ import java.io.Closeable
* If it implements [Closeable], it will be closed after all patches have been executed. * If it implements [Closeable], it will be closed after all patches have been executed.
* Closing will be done in reverse execution order. * Closing will be done in reverse execution order.
*/ */
abstract class Patch<out T : Data> { sealed interface Patch<out T : Data> {
/** /**
* The main function of the [Patch] which the patcher will call. * The main function of the [Patch] which the patcher will call.
*/ */
abstract fun execute(data: @UnsafeVariance T): PatchResult fun execute(data: @UnsafeVariance T): PatchResult
} }
abstract class OptionsContainer { abstract class OptionsContainer {
@ -32,3 +33,16 @@ abstract class OptionsContainer {
return opt return opt
} }
} }
/**
* Resource patch for the Patcher.
*/
interface ResourcePatch : Patch<ResourceData>
/**
* Bytecode patch for the Patcher.
* @param fingerprints A list of [MethodFingerprint] this patch relies on.
*/
abstract class BytecodePatch(
internal val fingerprints: Iterable<MethodFingerprint>? = null
) : Patch<BytecodeData>

View File

@ -1,13 +0,0 @@
package app.revanced.patcher.patch.impl
import app.revanced.patcher.data.impl.BytecodeData
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patcher.patch.Patch
/**
* Bytecode patch for the Patcher.
* @param fingerprints A list of [MethodFingerprint] this patch relies on.
*/
abstract class BytecodePatch(
internal val fingerprints: Iterable<MethodFingerprint>? = null
) : Patch<BytecodeData>()

View File

@ -1,9 +0,0 @@
package app.revanced.patcher.patch.impl
import app.revanced.patcher.data.impl.ResourceData
import app.revanced.patcher.patch.Patch
/**
* Resource patch for the Patcher.
*/
abstract class ResourcePatch : Patch<ResourceData>()

View File

@ -13,7 +13,7 @@ import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patcher.patch.impl.BytecodePatch import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.usage.resource.annotation.ExampleResourceCompatibility import app.revanced.patcher.usage.resource.annotation.ExampleResourceCompatibility
import app.revanced.patcher.util.proxy.mutableTypes.MutableField.Companion.toMutable import app.revanced.patcher.util.proxy.mutableTypes.MutableField.Companion.toMutable
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable

View File

@ -7,7 +7,7 @@ import app.revanced.patcher.data.impl.ResourceData
import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.Patch import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patcher.patch.impl.ResourcePatch import app.revanced.patcher.patch.ResourcePatch
import app.revanced.patcher.usage.resource.annotation.ExampleResourceCompatibility import app.revanced.patcher.usage.resource.annotation.ExampleResourceCompatibility
import org.w3c.dom.Element import org.w3c.dom.Element
@ -16,7 +16,7 @@ import org.w3c.dom.Element
@Description("Example demonstration of a resource patch.") @Description("Example demonstration of a resource patch.")
@ExampleResourceCompatibility @ExampleResourceCompatibility
@Version("0.0.1") @Version("0.0.1")
class ExampleResourcePatch : ResourcePatch() { class ExampleResourcePatch : ResourcePatch {
override fun execute(data: ResourceData): PatchResult { override fun execute(data: ResourceData): PatchResult {
data.xmlEditor["AndroidManifest.xml"].use { editor -> data.xmlEditor["AndroidManifest.xml"].use { editor ->
val element = editor // regular DomFileEditor val element = editor // regular DomFileEditor