Skip to content

Commit 43c4830

Browse files
committed
docs: update migration
1 parent fca8bf3 commit 43c4830

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

docs-source/src/en/config/migration.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ MyClass::class.resolve().firstMethod {
4444
parameters(String::class)
4545
}.of(myClass).invoke("Hello, KavaRef!")
4646
// Direct reference to instance.
47-
myClass.resolve().firstMethod {
47+
myClass.asResolver().firstMethod {
4848
name = "myMethod"
4949
parameters(String::class)
5050
}.invoke("Hello, KavaRef!")
@@ -76,6 +76,9 @@ myClass.current().method {
7676
`KavaRef` starts reflection at any time, you need to use `resolve()` to create a reflection scope.
7777
You no longer directly extend the related `method` and `constructor` methods to avoid contaminating their scope.
7878

79+
`KavaRef` provides the `asResolver()` method to directly reference the reflection scope of the instance object,
80+
avoiding contamination caused by the creation of uncontrollable instance objects by the `current()` method in `YukiReflection`.
81+
7982
`KavaRef` abandons the "Finder" design concept and uses the "Filter" design concept to obtain reflected results.
8083
"Find" is no longer a finding, but a "filtering".
8184

@@ -161,8 +164,7 @@ corresponding type when `of(instance)` and `create(...)`, and type checking will
161164
// Assume that's your MyClass instance.
162165
val myClass: MyClass
163166
// Using KavaRef to call and execute.
164-
MyClass::class
165-
.resolve()
167+
MyClass::class.resolve()
166168
.firstMethod {
167169
name = "myMethod"
168170
parameters(String::class)
@@ -180,7 +182,7 @@ MyClass::class
180182
The following functionality is provided in `YukiReflection` but is not implemented and no longer provided in `KavaRef`:
181183

182184
- Preset reflection type constant classes, such as `StringClass`, `IntType`, etc
183-
- You can use Kotlin class references such as `String::class`, `Int::class`, etc. to replace it.
185+
- You can use Kotlin class references such as `String::class`, `Int::class`, etc. to instead it.
184186
For primitive types and wrapper classes, `IntType` is equivalent to `Int::class`, and `IntClass` is equivalent to `JInteger::class`
185187

186188
- `DexClassFinder` function
@@ -204,7 +206,7 @@ The following functionality is provided in `YukiReflection` but is not implement
204206
- There is conceptual confusion in functional design and will no longer be provided
205207

206208
- `"com.some.clazz".hasClass(loader)` function
207-
- You can use `loader.hasClass("com.some.clazz")` to replace it
209+
- You can use `loader.hasClass("com.some.clazz")` to instead it
208210

209211
- `Class.hasField`, `Class.hasMethod`, `Class.hasConstructor` functions
210212
- Due to design defects, no longer provided
@@ -216,11 +218,11 @@ The following functionality is provided in `YukiReflection` but is not implement
216218
- If you just want to get generic parameters of the superclass, you can use `Class.genericSuperclassTypeArguments()`.
217219
Due to design defects, no longer provided
218220

219-
- `Class.current()`, `CurrentClass` functions
220-
- Merged into the core function of `KavaRef.resolve()` and is no longer provided separately
221+
- `Any.current()`, `CurrentClass` functions
222+
- You can use `Any.asResolver()` to instead it
221223

222224
- `Class.buildOf(...)` function
223-
- You can use `Class.createInstance(...)` to replace it
225+
- You can use `Class.createInstance(...)` to instead it
224226

225227
- `Class.allMethods()`, `Class.allFields()`, `Class.allConstructors()` functions
226228
- 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
240242
// Assume that's your MyClass instance.
241243
val myClass: MyClass
242244
// Using KavaRef to call and execute.
243-
MyClass::class
244-
.resolve()
245+
MyClass::class.resolve()
245246
.optional() // Declare as optional, do not throw exceptions.
246247
// Use firstMethodOrNull instead of firstMethod,
247248
// because the NoSuchElementException of Kotlin itself will be thrown.

docs-source/src/zh-cn/config/migration.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ MyClass::class.resolve().firstMethod {
4545
parameters(String::class)
4646
}.of(myClass).invoke("Hello, KavaRef!")
4747
// 直接引用实例方式
48-
myClass.resolve().firstMethod {
48+
myClass.asResolver().firstMethod {
4949
name = "myMethod"
5050
parameters(String::class)
5151
}.invoke("Hello, KavaRef!")
@@ -76,6 +76,8 @@ myClass.current().method {
7676

7777
`KavaRef` 在任何时候开始反射都需要使用 `resolve()` 来创建反射作用域,不再对 `Class` 等实例直接进行扩展相关 `method``constructor` 方法以避免污染其作用域。
7878

79+
`KavaRef` 提供了 `asResolver()` 方法来直接引用实例对象的反射作用域,避免了 `YukiReflection` 中的 `current()` 方法创建不可控实例对象造成的污染。
80+
7981
`KavaRef` 抛弃了 "Finder" 的设计理念,使用 "Filter" (过滤器) 的设计理念来获取反射结果,“查找” 不再是查找,而是 “过滤”。
8082

8183
`KavaRef` 取消了 `YukiReflection` 在结果实例中定义获取的 `Member` 为多重还是单一的设计方案,直接返回整个 `List<MemberResolver>`
@@ -146,8 +148,7 @@ MyClass::class.resolve()
146148
// 假设这就是你的 MyClass 实例
147149
val myClass: MyClass
148150
// 使用 KavaRef 调用并执行
149-
MyClass::class
150-
.resolve()
151+
MyClass::class.resolve()
151152
.firstMethod {
152153
name = "myMethod"
153154
parameters(String::class)
@@ -196,8 +197,8 @@ MyClass::class
196197
- `Class.generic()``GenericClass` 功能
197198
- 如果只是希望获取超类的泛型参数,你可以使用 `Class.genericSuperclassTypeArguments()`,由于设计缺陷,不再提供
198199

199-
- `Class.current()``CurrentClass` 功能
200-
- 已合并到 `KavaRef.resolve()` 的核心功能中,不再单独提供
200+
- `Any.current()``CurrentClass` 功能
201+
- 你可以使用 `Any.asResolver()` 来取代它
201202

202203
- `Class.buildOf(...)` 功能
203204
- 你可以使用 `Class.createInstance(...)` 来取代它
@@ -218,8 +219,7 @@ MyClass::class
218219
// 假设这就是你的 MyClass 实例
219220
val myClass: MyClass
220221
// 使用 KavaRef 调用并执行
221-
MyClass::class
222-
.resolve()
222+
MyClass::class.resolve()
223223
.optional() // 声明为可选,不要抛出异常
224224
// 使用 firstMethodOrNull 替代 firstMethod,因为找不到会抛出 Kotlin 自身的 NoSuchElementException
225225
.firstMethodOrNull {

0 commit comments

Comments
 (0)