From 1bb2c4e5a25738b6db7dfb732a3d73b38e397524 Mon Sep 17 00:00:00 2001 From: qingyu <42611305+yangyiyu08@users.noreply.github.com> Date: Fri, 5 May 2023 23:29:15 +0800 Subject: [PATCH] fix get interfaces of class fix get interfaces of class --- .../hook/factory/ReflectionFactory.kt | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/yukihookapi/src/main/java/com/highcapable/yukihookapi/hook/factory/ReflectionFactory.kt b/yukihookapi/src/main/java/com/highcapable/yukihookapi/hook/factory/ReflectionFactory.kt index c4734d96..1e842c05 100644 --- a/yukihookapi/src/main/java/com/highcapable/yukihookapi/hook/factory/ReflectionFactory.kt +++ b/yukihookapi/src/main/java/com/highcapable/yukihookapi/hook/factory/ReflectionFactory.kt @@ -146,7 +146,20 @@ infix fun Class<*>?.notExtends(other: Class<*>?) = extends(other).not() */ infix fun Class<*>?.implements(other: Class<*>?): Boolean { if (this == null || other == null) return false - return interfaces.takeIf { it.isNotEmpty() }?.any { it.name == other.name } ?: false + return getAllInterfaces().takeIf { it.isNotEmpty() }?.any { it.name == other.name } ?: false +} + +/** + * 获取当前 [Class] 实现的所有接口类 + * + * @return [Set]<[Class]<*>> + */ +private fun Class<*>.getAllInterfaces(): Set> { + val interfaces = mutableSetOf(*interfaces) + superclass?.let { superClass -> + interfaces.addAll(superClass.getAllInterfaces()) + } + return interfaces } /** @@ -406,4 +419,4 @@ inline fun Class<*>.allConstructors(isAccessible: Boolean = true, result: (index * @param result 回调 - ([Int] 下标,[Field] 实例) */ inline fun Class<*>.allFields(isAccessible: Boolean = true, result: (index: Int, field: Field) -> Unit) = - declaredFields.forEachIndexed { p, it -> result(p, it.also { e -> e.isAccessible = isAccessible }) } \ No newline at end of file + declaredFields.forEachIndexed { p, it -> result(p, it.also { e -> e.isAccessible = isAccessible }) }