From 54511a4fc6417d7fe0c868d441e7d6b0ec9e218d Mon Sep 17 00:00:00 2001 From: Lucaskyy Date: Wed, 25 May 2022 22:54:20 +0200 Subject: [PATCH] feat: utility functions to get metadata of patch & sigs --- .../extensions/AnnotationExtensions.kt | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patcher/extensions/AnnotationExtensions.kt diff --git a/src/main/kotlin/app/revanced/patcher/extensions/AnnotationExtensions.kt b/src/main/kotlin/app/revanced/patcher/extensions/AnnotationExtensions.kt new file mode 100644 index 0000000..13f3104 --- /dev/null +++ b/src/main/kotlin/app/revanced/patcher/extensions/AnnotationExtensions.kt @@ -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 Any.firstAnnotation() = + this::class.annotations.first { it is T } as T + +private inline fun Any.recursiveAnnotation() = + this::class.java.findAnnotationRecursively(T::class.java)!! + +object PatchExtensions { + val Patch<*>.name get() = firstAnnotation().name + val Patch<*>.version get() = firstAnnotation().version + val Patch<*>.description get() = firstAnnotation().description + val Patch<*>.compatiblePackages get() = recursiveAnnotation().compatiblePackages +} + +object MethodSignatureExtensions { + val MethodSignature.name get() = firstAnnotation().name + val MethodSignature.version get() = firstAnnotation().version + val MethodSignature.description get() = firstAnnotation().description + val MethodSignature.compatiblePackages get() = recursiveAnnotation().compatiblePackages + val MethodSignature.matchingMethod get() = firstAnnotation() + val MethodSignature.fuzzyThreshold get() = firstAnnotation().threshold +} \ No newline at end of file