mirror of
https://github.com/HighCapable/YukiHookAPI.git
synced 2025-09-06 02:35:40 +08:00
Added name, simpleName, toString function in CurrentClass and inline function in ReflectionFactory
This commit is contained in:
@@ -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]"
|
||||
}
|
@@ -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 <reified T : Any> T.current(initiate: CurrentClass.() -> Unit): T {
|
||||
javaClass.checkingInternal()
|
||||
CurrentClass(javaClass, instance = this).apply(initiate)
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得当前实例的类操作对象
|
||||
* @return [CurrentClass]
|
||||
@@ -185,6 +174,16 @@ inline fun <reified T : Any> T.current(): CurrentClass {
|
||||
return CurrentClass(javaClass, instance = this)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得当前实例的类操作对象
|
||||
* @param initiate 方法体
|
||||
* @return [T]
|
||||
*/
|
||||
inline fun <reified T : Any> T.current(initiate: CurrentClass.() -> Unit): T {
|
||||
current().apply(initiate)
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过构造方法创建新实例 - 任意类型 [Any]
|
||||
* @param param 方法参数
|
||||
|
Reference in New Issue
Block a user