From 3c76dbdd3615ce86ea47eeee70ab0efac7992e2f Mon Sep 17 00:00:00 2001 From: fankesyooni Date: Thu, 5 Jan 2023 19:09:15 +0800 Subject: [PATCH] Modify add argument generics method in GenericClass --- .../yukihookapi/hook/bean/GenericClass.md | 8 ++++++++ .../yukihookapi/hook/bean/GenericClass.md | 8 ++++++++ .../yukihookapi/hook/bean/GenericClass.kt | 14 ++++++++++++-- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/bean/GenericClass.md b/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/bean/GenericClass.md index 64bb9a40..976553ce 100644 --- a/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/bean/GenericClass.md +++ b/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/bean/GenericClass.md @@ -30,10 +30,18 @@ class GenericClass internal constructor(private val type: ParameterizedType) fun argument(index: Int): Class<*> ``` +```kotlin:no-line-numbers +inline fun argument(index: Int): Class +``` + **Change Records** `v1.1.0` `added` +`v1.1.5` `modified` + +新增泛型返回值 `Class` 方法 + **Function Illustrate** > 获得泛型参数数组下标的 `Class` 实例。 \ No newline at end of file diff --git a/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/bean/GenericClass.md b/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/bean/GenericClass.md index 975dbfe2..8c94e188 100644 --- a/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/bean/GenericClass.md +++ b/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/bean/GenericClass.md @@ -22,10 +22,18 @@ class GenericClass internal constructor(private val type: ParameterizedType) fun argument(index: Int): Class<*> ``` +```kotlin:no-line-numbers +inline fun argument(index: Int): Class +``` + **变更记录** `v1.1.0` `新增` +`v1.1.5` `修改` + +新增泛型返回值 `Class` 方法 + **功能描述** > 获得泛型参数数组下标的 `Class` 实例。 \ No newline at end of file diff --git a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/bean/GenericClass.kt b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/bean/GenericClass.kt index 934267d0..741f82a5 100644 --- a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/bean/GenericClass.kt +++ b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/bean/GenericClass.kt @@ -25,7 +25,7 @@ * * This file is Created by fankes on 2022/9/20. */ -@file:Suppress("unused") +@file:Suppress("unused", "UNCHECKED_CAST") package com.highcapable.yukihookapi.hook.bean @@ -35,7 +35,7 @@ import java.lang.reflect.ParameterizedType * 当前 [Class] 的泛型父类操作对象 * @param type 类型声明实例 */ -class GenericClass internal constructor(private val type: ParameterizedType) { +class GenericClass internal constructor(@PublishedApi internal val type: ParameterizedType) { /** * 获得泛型参数数组下标的 [Class] 实例 @@ -43,4 +43,14 @@ class GenericClass internal constructor(private val type: ParameterizedType) { * @return [Class] */ fun argument(index: Int = 0) = type.actualTypeArguments[index] as Class<*> + + /** + * 获得泛型参数数组下标的 [Class] 实例 + * @param index 数组下标 - 默认 0 + * @return [Class]<[T]> + * @throws IllegalStateException 如果 [Class] 的类型不为 [T] + */ + @JvmName("argument_Generics") + inline fun argument(index: Int = 0) = + type.actualTypeArguments[index] as? Class ?: error("Target Class type cannot cast to ${T::class.java}") } \ No newline at end of file