docs: update migration

This commit is contained in:
2025-07-06 20:05:25 +08:00
parent fca8bf31b5
commit 43c4830932
2 changed files with 18 additions and 17 deletions

View File

@@ -44,7 +44,7 @@ MyClass::class.resolve().firstMethod {
parameters(String::class) parameters(String::class)
}.of(myClass).invoke("Hello, KavaRef!") }.of(myClass).invoke("Hello, KavaRef!")
// Direct reference to instance. // Direct reference to instance.
myClass.resolve().firstMethod { myClass.asResolver().firstMethod {
name = "myMethod" name = "myMethod"
parameters(String::class) parameters(String::class)
}.invoke("Hello, KavaRef!") }.invoke("Hello, KavaRef!")
@@ -76,6 +76,9 @@ myClass.current().method {
`KavaRef` starts reflection at any time, you need to use `resolve()` to create a reflection scope. `KavaRef` starts reflection at any time, you need to use `resolve()` to create a reflection scope.
You no longer directly extend the related `method` and `constructor` methods to avoid contaminating their scope. You no longer directly extend the related `method` and `constructor` methods to avoid contaminating their scope.
`KavaRef` provides the `asResolver()` method to directly reference the reflection scope of the instance object,
avoiding contamination caused by the creation of uncontrollable instance objects by the `current()` method in `YukiReflection`.
`KavaRef` abandons the "Finder" design concept and uses the "Filter" design concept to obtain reflected results. `KavaRef` abandons the "Finder" design concept and uses the "Filter" design concept to obtain reflected results.
"Find" is no longer a finding, but a "filtering". "Find" is no longer a finding, but a "filtering".
@@ -161,8 +164,7 @@ corresponding type when `of(instance)` and `create(...)`, and type checking will
// Assume that's your MyClass instance. // Assume that's your MyClass instance.
val myClass: MyClass val myClass: MyClass
// Using KavaRef to call and execute. // Using KavaRef to call and execute.
MyClass::class MyClass::class.resolve()
.resolve()
.firstMethod { .firstMethod {
name = "myMethod" name = "myMethod"
parameters(String::class) parameters(String::class)
@@ -180,7 +182,7 @@ MyClass::class
The following functionality is provided in `YukiReflection` but is not implemented and no longer provided in `KavaRef`: The following functionality is provided in `YukiReflection` but is not implemented and no longer provided in `KavaRef`:
- Preset reflection type constant classes, such as `StringClass`, `IntType`, etc - Preset reflection type constant classes, such as `StringClass`, `IntType`, etc
- You can use Kotlin class references such as `String::class`, `Int::class`, etc. to replace it. - You can use Kotlin class references such as `String::class`, `Int::class`, etc. to instead it.
For primitive types and wrapper classes, `IntType` is equivalent to `Int::class`, and `IntClass` is equivalent to `JInteger::class` For primitive types and wrapper classes, `IntType` is equivalent to `Int::class`, and `IntClass` is equivalent to `JInteger::class`
- `DexClassFinder` function - `DexClassFinder` function
@@ -204,7 +206,7 @@ The following functionality is provided in `YukiReflection` but is not implement
- There is conceptual confusion in functional design and will no longer be provided - There is conceptual confusion in functional design and will no longer be provided
- `"com.some.clazz".hasClass(loader)` function - `"com.some.clazz".hasClass(loader)` function
- You can use `loader.hasClass("com.some.clazz")` to replace it - You can use `loader.hasClass("com.some.clazz")` to instead it
- `Class.hasField`, `Class.hasMethod`, `Class.hasConstructor` functions - `Class.hasField`, `Class.hasMethod`, `Class.hasConstructor` functions
- Due to design defects, no longer provided - Due to design defects, no longer provided
@@ -216,11 +218,11 @@ The following functionality is provided in `YukiReflection` but is not implement
- If you just want to get generic parameters of the superclass, you can use `Class.genericSuperclassTypeArguments()`. - If you just want to get generic parameters of the superclass, you can use `Class.genericSuperclassTypeArguments()`.
Due to design defects, no longer provided Due to design defects, no longer provided
- `Class.current()`, `CurrentClass` functions - `Any.current()`, `CurrentClass` functions
- Merged into the core function of `KavaRef.resolve()` and is no longer provided separately - You can use `Any.asResolver()` to instead it
- `Class.buildOf(...)` function - `Class.buildOf(...)` function
- You can use `Class.createInstance(...)` to replace it - You can use `Class.createInstance(...)` to instead it
- `Class.allMethods()`, `Class.allFields()`, `Class.allConstructors()` functions - `Class.allMethods()`, `Class.allFields()`, `Class.allConstructors()` functions
- Due to its pollution scope, no longer provided - Due to its pollution scope, no longer provided
@@ -240,8 +242,7 @@ When no valid members are filtered, `KavaRef` will throw an exception directly u
// Assume that's your MyClass instance. // Assume that's your MyClass instance.
val myClass: MyClass val myClass: MyClass
// Using KavaRef to call and execute. // Using KavaRef to call and execute.
MyClass::class MyClass::class.resolve()
.resolve()
.optional() // Declare as optional, do not throw exceptions. .optional() // Declare as optional, do not throw exceptions.
// Use firstMethodOrNull instead of firstMethod, // Use firstMethodOrNull instead of firstMethod,
// because the NoSuchElementException of Kotlin itself will be thrown. // because the NoSuchElementException of Kotlin itself will be thrown.

View File

@@ -45,7 +45,7 @@ MyClass::class.resolve().firstMethod {
parameters(String::class) parameters(String::class)
}.of(myClass).invoke("Hello, KavaRef!") }.of(myClass).invoke("Hello, KavaRef!")
// 直接引用实例方式 // 直接引用实例方式
myClass.resolve().firstMethod { myClass.asResolver().firstMethod {
name = "myMethod" name = "myMethod"
parameters(String::class) parameters(String::class)
}.invoke("Hello, KavaRef!") }.invoke("Hello, KavaRef!")
@@ -76,6 +76,8 @@ myClass.current().method {
`KavaRef` 在任何时候开始反射都需要使用 `resolve()` 来创建反射作用域,不再对 `Class` 等实例直接进行扩展相关 `method`、`constructor` 方法以避免污染其作用域。 `KavaRef` 在任何时候开始反射都需要使用 `resolve()` 来创建反射作用域,不再对 `Class` 等实例直接进行扩展相关 `method`、`constructor` 方法以避免污染其作用域。
`KavaRef` 提供了 `asResolver()` 方法来直接引用实例对象的反射作用域,避免了 `YukiReflection` 中的 `current()` 方法创建不可控实例对象造成的污染。
`KavaRef` 抛弃了 "Finder" 的设计理念,使用 "Filter" (过滤器) 的设计理念来获取反射结果,“查找” 不再是查找,而是 “过滤”。 `KavaRef` 抛弃了 "Finder" 的设计理念,使用 "Filter" (过滤器) 的设计理念来获取反射结果,“查找” 不再是查找,而是 “过滤”。
`KavaRef` 取消了 `YukiReflection` 在结果实例中定义获取的 `Member` 为多重还是单一的设计方案,直接返回整个 `List<MemberResolver>` `KavaRef` 取消了 `YukiReflection` 在结果实例中定义获取的 `Member` 为多重还是单一的设计方案,直接返回整个 `List<MemberResolver>`
@@ -146,8 +148,7 @@ MyClass::class.resolve()
// 假设这就是你的 MyClass 实例 // 假设这就是你的 MyClass 实例
val myClass: MyClass val myClass: MyClass
// 使用 KavaRef 调用并执行 // 使用 KavaRef 调用并执行
MyClass::class MyClass::class.resolve()
.resolve()
.firstMethod { .firstMethod {
name = "myMethod" name = "myMethod"
parameters(String::class) parameters(String::class)
@@ -196,8 +197,8 @@ MyClass::class
- `Class.generic()`、`GenericClass` 功能 - `Class.generic()`、`GenericClass` 功能
- 如果只是希望获取超类的泛型参数,你可以使用 `Class.genericSuperclassTypeArguments()`,由于设计缺陷,不再提供 - 如果只是希望获取超类的泛型参数,你可以使用 `Class.genericSuperclassTypeArguments()`,由于设计缺陷,不再提供
- `Class.current()`、`CurrentClass` 功能 - `Any.current()`、`CurrentClass` 功能
- 已合并到 `KavaRef.resolve()` 的核心功能中,不再单独提供 - 你可以使用 `Any.asResolver()` 来取代它
- `Class.buildOf(...)` 功能 - `Class.buildOf(...)` 功能
- 你可以使用 `Class.createInstance(...)` 来取代它 - 你可以使用 `Class.createInstance(...)` 来取代它
@@ -218,8 +219,7 @@ MyClass::class
// 假设这就是你的 MyClass 实例 // 假设这就是你的 MyClass 实例
val myClass: MyClass val myClass: MyClass
// 使用 KavaRef 调用并执行 // 使用 KavaRef 调用并执行
MyClass::class MyClass::class.resolve()
.resolve()
.optional() // 声明为可选,不要抛出异常 .optional() // 声明为可选,不要抛出异常
// 使用 firstMethodOrNull 替代 firstMethod因为找不到会抛出 Kotlin 自身的 NoSuchElementException // 使用 firstMethodOrNull 替代 firstMethod因为找不到会抛出 Kotlin 自身的 NoSuchElementException
.firstMethodOrNull { .firstMethodOrNull {