Added GenericClass and generic function in CurrentClass and ReflectionFactory

This commit is contained in:
2022-09-20 11:58:00 +08:00
parent 87a4b02e4a
commit 9b7a767e71
6 changed files with 228 additions and 4 deletions

View File

@@ -48,6 +48,38 @@ val simpleName: String
> 获得当前 `classSet` 的 `Class.getSimpleName`。
## generic <span class="symbol">- method</span>
```kotlin:no-line-numbers
fun generic(): GenericClass?
```
**变更记录**
`v1.1.0` `新增`
**功能描述**
> 获得当前实例中的泛型父类。
如果当前实例不存在泛型将返回 `null`。
## generic <span class="symbol">- method</span>
```kotlin:no-line-numbers
inline fun generic(initiate: GenericClass.() -> Unit): GenericClass?
```
**变更记录**
`v1.1.0` `新增`
**功能描述**
> 获得当前实例中的泛型父类。
如果当前实例不存在泛型将返回 `null`。
## superClass <span class="symbol">- method</span>
```kotlin:no-line-numbers
@@ -136,6 +168,38 @@ val simpleName: String
> 获得当前 `classSet` 中父类的 `Class.getSimpleName`。
### generic <span class="symbol">- method</span>
```kotlin:no-line-numbers
fun generic(): GenericClass?
```
**变更记录**
`v1.1.0` `新增`
**功能描述**
> 获得当前实例父类中的泛型父类。
如果当前实例不存在泛型将返回 `null`。
### generic <span class="symbol">- method</span>
```kotlin:no-line-numbers
inline fun generic(initiate: GenericClass.() -> Unit): GenericClass?
```
**变更记录**
`v1.1.0` `新增`
**功能描述**
> 获得当前实例父类中的泛型父类。
如果当前实例不存在泛型将返回 `null`。
### field <span class="symbol">- method</span>
```kotlin:no-line-numbers

View File

@@ -0,0 +1,31 @@
---
pageClass: code-page
---
# GenericClass <span class="symbol">- class</span>
```kotlin:no-line-numbers
class GenericClass internal constructor(private val type: ParameterizedType)
```
**变更记录**
`v1.1.0` `新增`
**功能描述**
> 当前 `Class` 的泛型父类操作对象。
## argument <span class="symbol">- method</span>
```kotlin:no-line-numbers
fun argument(index: Int): Class<*>
```
**变更记录**
`v1.1.0` `新增`
**功能描述**
> 获得泛型参数数组下标的 `Class` 实例。

View File

@@ -542,6 +542,38 @@ inline fun Class<*>.constructor(initiate: ConstructorConditions): ConstructorFin
`v1.0.2` `移除`
## Class.generic <span class="symbol">- ext-method</span>
```kotlin:no-line-numbers
fun Class<*>.generic(): GenericClass?
```
**变更记录**
`v1.1.0` `新增`
**功能描述**
> 获得当前 `Class` 的泛型父类。
如果当前实例不存在泛型将返回 `null`。
## Class.generic <span class="symbol">- ext-method</span>
```kotlin:no-line-numbers
inline fun Class<*>.generic(initiate: GenericClass.() -> Unit): GenericClass?
```
**变更记录**
`v1.1.0` `新增`
**功能描述**
> 获得当前 `Class` 的泛型父类。
如果当前实例不存在泛型将返回 `null`。
## Any.current <span class="symbol">- ext-method</span>
```kotlin:no-line-numbers

View File

@@ -34,6 +34,7 @@ import com.highcapable.yukihookapi.hook.core.finder.members.MethodFinder
import com.highcapable.yukihookapi.hook.core.finder.type.factory.FieldConditions
import com.highcapable.yukihookapi.hook.core.finder.type.factory.MethodConditions
import com.highcapable.yukihookapi.hook.factory.field
import com.highcapable.yukihookapi.hook.factory.generic
import com.highcapable.yukihookapi.hook.factory.method
/**
@@ -59,6 +60,23 @@ class CurrentClass @PublishedApi internal constructor(@PublishedApi internal val
*/
val simpleName get() = classSet.simpleName ?: instance.javaClass.simpleName ?: ""
/**
* 获得当前实例中的泛型父类
*
* 如果当前实例不存在泛型将返回 null
* @return [GenericClass] or null
*/
fun generic() = classSet.generic()
/**
* 获得当前实例中的泛型父类
*
* 如果当前实例不存在泛型将返回 null
* @param initiate 实例方法体
* @return [GenericClass] or null
*/
inline fun generic(initiate: GenericClass.() -> Unit) = classSet.generic(initiate)
/**
* 调用父类实例
* @return [SuperClass]
@@ -99,6 +117,23 @@ class CurrentClass @PublishedApi internal constructor(@PublishedApi internal val
*/
val simpleName get() = superClassSet.simpleName ?: ""
/**
* 获得当前实例父类中的泛型父类
*
* 如果当前实例不存在泛型将返回 null
* @return [GenericClass] or null
*/
fun generic() = superClassSet.generic()
/**
* 获得当前实例父类中的泛型父类
*
* 如果当前实例不存在泛型将返回 null
* @param initiate 实例方法体
* @return [GenericClass] or null
*/
inline fun generic(initiate: GenericClass.() -> Unit) = superClassSet.generic(initiate)
/**
* 调用父类实例中的变量
* @param initiate 查找方法体

View File

@@ -0,0 +1,44 @@
/*
* YukiHookAPI - An efficient Kotlin version of the Xposed Hook API.
* Copyright (C) 2019-2022 HighCapable
* https://github.com/fankes/YukiHookAPI
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* This file is Created by fankes on 2022/9/20.
*/
package com.highcapable.yukihookapi.hook.bean
import java.lang.reflect.ParameterizedType
/**
* 当前 [Class] 的泛型父类操作对象
* @param type 类型声明实例
*/
class GenericClass internal constructor(private val type: ParameterizedType) {
/**
* 获得泛型参数数组下标的 [Class] 实例
* @param index 数组下标 - 默认 0
* @return [Class]
*/
fun argument(index: Int = 0) = type.actualTypeArguments[index] as Class<*>
}

View File

@@ -31,6 +31,7 @@ package com.highcapable.yukihookapi.hook.factory
import com.highcapable.yukihookapi.YukiHookAPI
import com.highcapable.yukihookapi.hook.bean.CurrentClass
import com.highcapable.yukihookapi.hook.bean.GenericClass
import com.highcapable.yukihookapi.hook.core.finder.base.rules.ModifierRules
import com.highcapable.yukihookapi.hook.core.finder.members.ConstructorFinder
import com.highcapable.yukihookapi.hook.core.finder.members.FieldFinder
@@ -42,10 +43,7 @@ import com.highcapable.yukihookapi.hook.core.finder.type.factory.MethodCondition
import com.highcapable.yukihookapi.hook.core.finder.type.factory.ModifierConditions
import com.highcapable.yukihookapi.hook.xposed.bridge.status.YukiHookModuleStatus
import com.highcapable.yukihookapi.hook.xposed.parasitic.AppParasitics
import java.lang.reflect.Constructor
import java.lang.reflect.Field
import java.lang.reflect.Member
import java.lang.reflect.Method
import java.lang.reflect.*
/**
* 定义一个 [Class] 中的 [Member] 类型
@@ -170,6 +168,26 @@ inline fun Class<*>.method(initiate: MethodConditions) = MethodFinder(classSet =
*/
inline fun Class<*>.constructor(initiate: ConstructorConditions = { emptyParam() }) = ConstructorFinder(classSet = this).apply(initiate).build()
/**
* 获得当前 [Class] 的泛型父类
*
* 如果当前实例不存在泛型将返回 null
* @return [GenericClass] or null
*/
fun Class<*>.generic(): GenericClass? {
checkingInternal()
return genericSuperclass?.let { (it as? ParameterizedType?)?.let { e -> GenericClass(e) } }
}
/**
* 获得当前 [Class] 的泛型父类
*
* 如果当前实例不存在泛型将返回 null
* @param initiate 实例方法体
* @return [GenericClass] or null
*/
inline fun Class<*>.generic(initiate: GenericClass.() -> Unit) = generic()?.apply(initiate)
/**
* 获得当前实例的类操作对象
* @param ignored 是否开启忽略错误警告功能 - 默认否