mirror of
https://github.com/HighCapable/YukiHookAPI.git
synced 2025-09-04 09:45:19 +08:00
Added name, simpleName, toString function in CurrentClass and inline function in ReflectionFactory
This commit is contained in:
@@ -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
|
||||
|
@@ -442,11 +442,11 @@ inline fun Class<*>.constructor(initiate: ConstructorCondition): ConstructorFind
|
||||
### current [method]
|
||||
|
||||
```kotlin
|
||||
inline fun <reified T : Any> T.current(initiate: CurrentClass.() -> Unit): T
|
||||
inline fun <reified T : Any> T.current(): CurrentClass
|
||||
```
|
||||
|
||||
```kotlin
|
||||
inline fun <reified T : Any> T.current(): CurrentClass
|
||||
inline fun <reified T : Any> T.current(initiate: CurrentClass.() -> Unit): T
|
||||
```
|
||||
|
||||
**变更记录**
|
||||
|
@@ -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