From d2d95703dce6de664fd65fcc4ac4c2133fe27f3a Mon Sep 17 00:00:00 2001 From: Fankesyooni <37344460+fankes@users.noreply.github.com> Date: Fri, 5 May 2023 23:45:49 +0800 Subject: [PATCH] Refactor optimize code in ReflectionFactory --- .../hook/factory/ReflectionFactory.kt | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 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 1e842c05..af841122 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,20 +146,12 @@ infix fun Class<*>?.notExtends(other: Class<*>?) = extends(other).not() */ infix fun Class<*>?.implements(other: Class<*>?): Boolean { if (this == null || other == null) return 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 + /** + * 获取当前 [Class] 实现的所有接口类 + * @return [Set]<[Class]> + */ + fun Class<*>.findAllInterfaces(): Set> = mutableSetOf(*interfaces).apply { superclass?.also { addAll(it.findAllInterfaces()) } } + return findAllInterfaces().takeIf { it.isNotEmpty() }?.any { it.name == other.name } ?: false } /**