diff --git a/docs/api/public/CurrentClass.md b/docs/api/public/CurrentClass.md index c064b51b..01517585 100644 --- a/docs/api/public/CurrentClass.md +++ b/docs/api/public/CurrentClass.md @@ -16,6 +16,34 @@ class CurrentClass internal constructor(internal val classSet: Class<*>, interna > 当前实例的类操作对象。 +### name [field] + +```kotlin +val name: String +``` + +**变更记录** + +`v1.0.93` `新增` + +**功能描述** + +> 获得当前 `classSet` 的 `Class.getName`。 + +### simpleName [field] + +```kotlin +val simpleName: String +``` + +**变更记录** + +`v1.0.93` `新增` + +**功能描述** + +> 获得当前 `classSet` 的 `Class.getSimpleName`。 + ### superClass [method] ```kotlin @@ -72,6 +100,34 @@ inner class SuperClass internal constructor() > 当前类的父类实例的类操作对象。 +#### name [field] + +```kotlin +val name: String +``` + +**变更记录** + +`v1.0.93` `新增` + +**功能描述** + +> 获得当前 `classSet` 中父类的 `Class.getName`。 + +#### simpleName [field] + +```kotlin +val simpleName: String +``` + +**变更记录** + +`v1.0.93` `新增` + +**功能描述** + +> 获得当前 `classSet` 中父类的 `Class.getSimpleName`。 + #### field [method] ```kotlin diff --git a/docs/api/public/ReflectionFactory.md b/docs/api/public/ReflectionFactory.md index 5cfc255e..66e8a70d 100644 --- a/docs/api/public/ReflectionFactory.md +++ b/docs/api/public/ReflectionFactory.md @@ -442,11 +442,11 @@ inline fun Class<*>.constructor(initiate: ConstructorCondition): ConstructorFind ### current [method] ```kotlin -inline fun T.current(initiate: CurrentClass.() -> Unit): T +inline fun T.current(): CurrentClass ``` ```kotlin -inline fun T.current(): CurrentClass +inline fun T.current(initiate: CurrentClass.() -> Unit): T ``` **变更记录** diff --git a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/bean/CurrentClass.kt b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/bean/CurrentClass.kt index 602c56c8..baf53b44 100644 --- a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/bean/CurrentClass.kt +++ b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/bean/CurrentClass.kt @@ -25,6 +25,8 @@ * * This file is Created by fankes on 2022/4/4. */ +@file:Suppress("unused") + package com.highcapable.yukihookapi.hook.bean import com.highcapable.yukihookapi.hook.core.finder.FieldFinder @@ -41,6 +43,18 @@ import com.highcapable.yukihookapi.hook.factory.method */ class CurrentClass @PublishedApi internal constructor(@PublishedApi internal val classSet: Class<*>, @PublishedApi internal val instance: Any) { + /** + * 获得当前 [classSet] 的 [Class.getName] + * @return [String] + */ + val name get() = classSet.name ?: instance.javaClass.name ?: "" + + /** + * 获得当前 [classSet] 的 [Class.getSimpleName] + * @return [String] + */ + val simpleName get() = classSet.simpleName ?: instance.javaClass.simpleName ?: "" + /** * 调用父类实例 * @return [SuperClass] @@ -68,6 +82,18 @@ class CurrentClass @PublishedApi internal constructor(@PublishedApi internal val */ inner class SuperClass internal constructor() { + /** + * 获得当前 [classSet] 中父类的 [Class.getName] + * @return [String] + */ + val name get() = classSet.superclass.name ?: instance.javaClass.superclass.name ?: "" + + /** + * 获得当前 [classSet] 中父类的 [Class.getSimpleName] + * @return [String] + */ + val simpleName get() = classSet.superclass.simpleName ?: instance.javaClass.superclass.simpleName ?: "" + /** * 调用父类实例中的变量 * @param initiate 查找方法体 @@ -81,5 +107,9 @@ class CurrentClass @PublishedApi internal constructor(@PublishedApi internal val * @return [MethodFinder.Result.Instance] */ inline fun method(initiate: MethodCondition) = classSet.superclass.method(initiate).get(instance) + + override fun toString() = "CurrentClass super [${classSet.superclass}]" } + + override fun toString() = "CurrentClass [$classSet]" } \ No newline at end of file diff --git a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/factory/ReflectionFactory.kt b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/factory/ReflectionFactory.kt index c0e6d3f0..8647c9e0 100644 --- a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/factory/ReflectionFactory.kt +++ b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/factory/ReflectionFactory.kt @@ -165,17 +165,6 @@ inline fun Class<*>.method(initiate: MethodCondition) = MethodFinder(classSet = */ inline fun Class<*>.constructor(initiate: ConstructorCondition = { emptyParam() }) = ConstructorFinder(classSet = this).apply(initiate).build() -/** - * 获得当前实例的类操作对象 - * @param initiate 方法体 - * @return [T] - */ -inline fun T.current(initiate: CurrentClass.() -> Unit): T { - javaClass.checkingInternal() - CurrentClass(javaClass, instance = this).apply(initiate) - return this -} - /** * 获得当前实例的类操作对象 * @return [CurrentClass] @@ -185,6 +174,16 @@ inline fun T.current(): CurrentClass { return CurrentClass(javaClass, instance = this) } +/** + * 获得当前实例的类操作对象 + * @param initiate 方法体 + * @return [T] + */ +inline fun T.current(initiate: CurrentClass.() -> Unit): T { + current().apply(initiate) + return this +} + /** * 通过构造方法创建新实例 - 任意类型 [Any] * @param param 方法参数