mirror of
https://github.com/HighCapable/YukiHookAPI.git
synced 2025-09-04 09:45:19 +08:00
Added ignored params in current method in ReflectionFactory and CurrentClass
This commit is contained in:
@@ -551,11 +551,11 @@ inner class Instance internal constructor(private val instance: Any?, private va
|
||||
##### current *- method*
|
||||
|
||||
```kotlin
|
||||
fun current(): CurrentClass?
|
||||
fun current(ignored: Boolean): CurrentClass?
|
||||
```
|
||||
|
||||
```kotlin
|
||||
inline fun current(initiate: CurrentClass.() -> Unit): Any?
|
||||
inline fun current(ignored: Boolean, initiate: CurrentClass.() -> Unit): Any?
|
||||
```
|
||||
|
||||
**变更记录**
|
||||
@@ -564,7 +564,7 @@ inline fun current(initiate: CurrentClass.() -> Unit): Any?
|
||||
|
||||
**功能描述**
|
||||
|
||||
> 获得当前 `Field` 自身 `self` 实例的类操作对象。
|
||||
> 获得当前 `Field` 自身 `self` 实例的类操作对象 `CurrentClass`。
|
||||
|
||||
##### cast *- method*
|
||||
|
||||
|
@@ -442,11 +442,11 @@ inline fun Class<*>.constructor(initiate: ConstructorCondition): ConstructorFind
|
||||
### Any.current *- ext-method*
|
||||
|
||||
```kotlin
|
||||
inline fun <reified T : Any> T.current(): CurrentClass
|
||||
inline fun <reified T : Any> T.current(ignored: Boolean): CurrentClass
|
||||
```
|
||||
|
||||
```kotlin
|
||||
inline fun <reified T : Any> T.current(initiate: CurrentClass.() -> Unit): T
|
||||
inline fun <reified T : Any> T.current(ignored: Boolean, initiate: CurrentClass.() -> Unit): T
|
||||
```
|
||||
|
||||
**变更记录**
|
||||
@@ -455,6 +455,8 @@ inline fun <reified T : Any> T.current(initiate: CurrentClass.() -> Unit): T
|
||||
|
||||
`v1.0.93` `新增`
|
||||
|
||||
新增 `ignored` 参数,可以忽略在 `CurrentClass` 中出现的异常
|
||||
|
||||
新增不使用 `current { ... }` 调用域直接使用 `current()` 得到实例的类操作对象
|
||||
|
||||
**功能描述**
|
||||
|
@@ -43,6 +43,10 @@ import com.highcapable.yukihookapi.hook.factory.method
|
||||
*/
|
||||
class CurrentClass @PublishedApi internal constructor(@PublishedApi internal val classSet: Class<*>, @PublishedApi internal val instance: Any) {
|
||||
|
||||
/** 是否开启忽略错误警告功能 */
|
||||
@PublishedApi
|
||||
internal var isShutErrorPrinting = false
|
||||
|
||||
/**
|
||||
* 获得当前 [classSet] 的 [Class.getName]
|
||||
* @return [String]
|
||||
@@ -66,14 +70,14 @@ class CurrentClass @PublishedApi internal constructor(@PublishedApi internal val
|
||||
* @param initiate 查找方法体
|
||||
* @return [FieldFinder.Result.Instance]
|
||||
*/
|
||||
inline fun field(initiate: FieldCondition) = classSet.field(initiate).get(instance)
|
||||
inline fun field(initiate: FieldCondition) = classSet.field(initiate).result { if (isShutErrorPrinting) ignored() }.get(instance)
|
||||
|
||||
/**
|
||||
* 调用当前实例中的方法
|
||||
* @param initiate 查找方法体
|
||||
* @return [MethodFinder.Result.Instance]
|
||||
*/
|
||||
inline fun method(initiate: MethodCondition) = classSet.method(initiate).get(instance)
|
||||
inline fun method(initiate: MethodCondition) = classSet.method(initiate).result { if (isShutErrorPrinting) ignored() }.get(instance)
|
||||
|
||||
/**
|
||||
* 当前类的父类实例的类操作对象
|
||||
@@ -82,33 +86,41 @@ class CurrentClass @PublishedApi internal constructor(@PublishedApi internal val
|
||||
*/
|
||||
inner class SuperClass internal constructor() {
|
||||
|
||||
/**
|
||||
* 获取 [classSet] 的 [Class.getSuperclass] 对象
|
||||
* @return [Class]
|
||||
*/
|
||||
@PublishedApi
|
||||
internal val superClassSet
|
||||
get() = classSet.superclass
|
||||
|
||||
/**
|
||||
* 获得当前 [classSet] 中父类的 [Class.getName]
|
||||
* @return [String]
|
||||
*/
|
||||
val name get() = classSet.superclass.name ?: instance.javaClass.superclass.name ?: ""
|
||||
val name get() = superClassSet.name ?: instance.javaClass.superclass.name ?: ""
|
||||
|
||||
/**
|
||||
* 获得当前 [classSet] 中父类的 [Class.getSimpleName]
|
||||
* @return [String]
|
||||
*/
|
||||
val simpleName get() = classSet.superclass.simpleName ?: instance.javaClass.superclass.simpleName ?: ""
|
||||
val simpleName get() = superClassSet.simpleName ?: instance.javaClass.superclass.simpleName ?: ""
|
||||
|
||||
/**
|
||||
* 调用父类实例中的变量
|
||||
* @param initiate 查找方法体
|
||||
* @return [FieldFinder.Result.Instance]
|
||||
*/
|
||||
inline fun field(initiate: FieldCondition) = classSet.superclass.field(initiate).get(instance)
|
||||
inline fun field(initiate: FieldCondition) = superClassSet.field(initiate).result { if (isShutErrorPrinting) ignored() }.get(instance)
|
||||
|
||||
/**
|
||||
* 调用父类实例中的方法
|
||||
* @param initiate 查找方法体
|
||||
* @return [MethodFinder.Result.Instance]
|
||||
*/
|
||||
inline fun method(initiate: MethodCondition) = classSet.superclass.method(initiate).get(instance)
|
||||
inline fun method(initiate: MethodCondition) = superClassSet.method(initiate).result { if (isShutErrorPrinting) ignored() }.get(instance)
|
||||
|
||||
override fun toString() = "CurrentClass super [${classSet.superclass}]"
|
||||
override fun toString() = "CurrentClass super [${superClassSet}]"
|
||||
}
|
||||
|
||||
override fun toString() = "CurrentClass [$classSet]"
|
||||
|
@@ -476,16 +476,18 @@ class FieldFinder @PublishedApi internal constructor(
|
||||
|
||||
/**
|
||||
* 获得当前 [Field] 自身 [self] 实例的类操作对象
|
||||
* @param ignored 是否开启忽略错误警告功能 - 默认否
|
||||
* @return [CurrentClass] or null
|
||||
*/
|
||||
fun current() = self?.current()
|
||||
fun current(ignored: Boolean = false) = self?.current(ignored)
|
||||
|
||||
/**
|
||||
* 获得当前 [Field] 自身 [self] 实例的类操作对象
|
||||
* @param ignored 是否开启忽略错误警告功能 - 默认否
|
||||
* @param initiate 方法体
|
||||
* @return [Any] or null
|
||||
*/
|
||||
inline fun current(initiate: CurrentClass.() -> Unit) = self?.current(initiate)
|
||||
inline fun current(ignored: Boolean = false, initiate: CurrentClass.() -> Unit) = self?.current(ignored, initiate)
|
||||
|
||||
/**
|
||||
* 得到当前 [Field] 实例
|
||||
|
@@ -167,20 +167,22 @@ inline fun Class<*>.constructor(initiate: ConstructorCondition = { emptyParam()
|
||||
|
||||
/**
|
||||
* 获得当前实例的类操作对象
|
||||
* @param ignored 是否开启忽略错误警告功能 - 默认否
|
||||
* @return [CurrentClass]
|
||||
*/
|
||||
inline fun <reified T : Any> T.current(): CurrentClass {
|
||||
inline fun <reified T : Any> T.current(ignored: Boolean = false): CurrentClass {
|
||||
javaClass.checkingInternal()
|
||||
return CurrentClass(javaClass, instance = this)
|
||||
return CurrentClass(javaClass, instance = this).apply { isShutErrorPrinting = ignored }
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得当前实例的类操作对象
|
||||
* @param ignored 是否开启忽略错误警告功能 - 默认否
|
||||
* @param initiate 方法体
|
||||
* @return [T]
|
||||
*/
|
||||
inline fun <reified T : Any> T.current(initiate: CurrentClass.() -> Unit): T {
|
||||
current().apply(initiate)
|
||||
inline fun <reified T : Any> T.current(ignored: Boolean = false, initiate: CurrentClass.() -> Unit): T {
|
||||
current(ignored).apply(initiate)
|
||||
return this
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user