From 523f67b238646caaa9b7676a0e238ce82adbdda4 Mon Sep 17 00:00:00 2001 From: Sculas Date: Sun, 31 Jul 2022 15:07:23 +0200 Subject: [PATCH] feat: add Patch#dependsOn extension --- .../revanced/patcher/extensions/AnnotationExtensions.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/app/revanced/patcher/extensions/AnnotationExtensions.kt b/src/main/kotlin/app/revanced/patcher/extensions/AnnotationExtensions.kt index 8963b017..d5dc5c61 100644 --- a/src/main/kotlin/app/revanced/patcher/extensions/AnnotationExtensions.kt +++ b/src/main/kotlin/app/revanced/patcher/extensions/AnnotationExtensions.kt @@ -36,13 +36,18 @@ private fun Class<*>.findAnnotationRecursively( } object PatchExtensions { - val Class>.patchName: String - get() = recursiveAnnotation(Name::class)?.name ?: this.javaClass.simpleName + val Class>.patchName: String get() = recursiveAnnotation(Name::class)?.name ?: this.javaClass.simpleName val Class>.version get() = recursiveAnnotation(Version::class)?.version val Class>.include get() = recursiveAnnotation(app.revanced.patcher.patch.annotations.Patch::class)!!.include val Class>.description get() = recursiveAnnotation(Description::class)?.description val Class>.dependencies get() = recursiveAnnotation(app.revanced.patcher.patch.annotations.Dependencies::class)?.dependencies val Class>.compatiblePackages get() = recursiveAnnotation(Compatibility::class)?.compatiblePackages + + @JvmStatic + fun Class>.dependsOn(patch: Class>): Boolean { + if (this.patchName == patch.patchName) throw IllegalArgumentException("thisval and patch may not be the same") + return this.dependencies?.any { it.java.patchName == this@dependsOn.patchName } == true + } } object MethodFingerprintExtensions {