mirror of
https://github.com/HighCapable/YukiHookAPI.git
synced 2025-09-04 09:45:19 +08:00
Added GenericClass and generic function in CurrentClass and ReflectionFactory
This commit is contained in:
@@ -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 查找方法体
|
||||
|
@@ -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<*>
|
||||
}
|
@@ -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 是否开启忽略错误警告功能 - 默认否
|
||||
|
Reference in New Issue
Block a user