mirror of
https://github.com/ReVanced/revanced-patcher.git
synced 2024-11-10 01:02:22 +01:00
feat: utility functions to get metadata of patch & sigs
This commit is contained in:
parent
fc03639b26
commit
72f16b7785
1 changed files with 32 additions and 0 deletions
|
@ -0,0 +1,32 @@
|
|||
package app.revanced.patcher.extensions
|
||||
|
||||
import app.revanced.patcher.annotation.Compatibility
|
||||
import app.revanced.patcher.annotation.Description
|
||||
import app.revanced.patcher.annotation.Name
|
||||
import app.revanced.patcher.annotation.Version
|
||||
import app.revanced.patcher.patch.base.Patch
|
||||
import app.revanced.patcher.signature.implementation.method.MethodSignature
|
||||
import app.revanced.patcher.signature.implementation.method.annotation.FuzzyPatternScanMethod
|
||||
import app.revanced.patcher.signature.implementation.method.annotation.MatchingMethod
|
||||
|
||||
private inline fun <reified T : Annotation> Any.firstAnnotation() =
|
||||
this::class.annotations.first { it is T } as T
|
||||
|
||||
private inline fun <reified T : Annotation> Any.recursiveAnnotation() =
|
||||
this::class.java.findAnnotationRecursively(T::class.java)!!
|
||||
|
||||
object PatchExtensions {
|
||||
val Patch<*>.name get() = firstAnnotation<Name>().name
|
||||
val Patch<*>.version get() = firstAnnotation<Version>().version
|
||||
val Patch<*>.description get() = firstAnnotation<Description>().description
|
||||
val Patch<*>.compatiblePackages get() = recursiveAnnotation<Compatibility>().compatiblePackages
|
||||
}
|
||||
|
||||
object MethodSignatureExtensions {
|
||||
val MethodSignature.name get() = firstAnnotation<Name>().name
|
||||
val MethodSignature.version get() = firstAnnotation<Version>().version
|
||||
val MethodSignature.description get() = firstAnnotation<Description>().description
|
||||
val MethodSignature.compatiblePackages get() = recursiveAnnotation<Compatibility>().compatiblePackages
|
||||
val MethodSignature.matchingMethod get() = firstAnnotation<MatchingMethod>()
|
||||
val MethodSignature.fuzzyThreshold get() = firstAnnotation<FuzzyPatternScanMethod>().threshold
|
||||
}
|
Loading…
Reference in a new issue