forked from ReVanced/revanced-patcher
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: utility functions to get metadata of patch & sigs
- Loading branch information
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
src/main/kotlin/app/revanced/patcher/extensions/AnnotationExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |