Refactor optimize code in ReflectionFactory

This commit is contained in:
Fankesyooni
2023-05-05 23:45:49 +08:00
committed by GitHub
parent 1bb2c4e5a2
commit d2d95703dc

View File

@@ -146,20 +146,12 @@ infix fun Class<*>?.notExtends(other: Class<*>?) = extends(other).not()
*/ */
infix fun Class<*>?.implements(other: Class<*>?): Boolean { infix fun Class<*>?.implements(other: Class<*>?): Boolean {
if (this == null || other == null) return false if (this == null || other == null) return false
return getAllInterfaces().takeIf { it.isNotEmpty() }?.any { it.name == other.name } ?: false /**
}
/**
* 获取当前 [Class] 实现的所有接口类 * 获取当前 [Class] 实现的所有接口类
* * @return [Set]<[Class]>
* @return [Set]<[Class]<*>>
*/ */
private fun Class<*>.getAllInterfaces(): Set<Class<*>> { fun Class<*>.findAllInterfaces(): Set<Class<*>> = mutableSetOf(*interfaces).apply { superclass?.also { addAll(it.findAllInterfaces()) } }
val interfaces = mutableSetOf(*interfaces) return findAllInterfaces().takeIf { it.isNotEmpty() }?.any { it.name == other.name } ?: false
superclass?.let { superClass ->
interfaces.addAll(superClass.getAllInterfaces())
}
return interfaces
} }
/** /**