diff --git a/docs-source/src/en/api/features.md b/docs-source/src/en/api/features.md index 7672f31..418e9e2 100644 --- a/docs-source/src/en/api/features.md +++ b/docs-source/src/en/api/features.md @@ -1537,11 +1537,7 @@ For more functions, please refer to [CurrentClass.generic](../api/public/com/hig #### Restrictive Find Conditions -::: danger - -In find conditions you can only use **index** function once except **order**. - -::: +In find conditions you can **only** use `index` function once except `order`. > The following example @@ -1568,12 +1564,8 @@ method { #### Necessary Find Conditions -::: danger - In common method find conditions, **even methods without parameters need to set find conditions**. -::: - Suppose we have the following `Class`. > The following example @@ -1623,9 +1615,13 @@ TestFoo::class.java.method { At this point, the above example will perfectly match the `public void foo()` method. -#### Abbreviated Find Conditions +::: tip Compatibility Notes -> In the construction method find conditions, **constructors without parameters do not need to fill in the find conditions**. +In the past historical versions of the API, it was allowed to match the method without writing the default matching no-parameter method, but the latest version has corrected this problem, please make sure that you are using the latest API version. + +::: + +In the find conditions for constructors, **even constructors without parameters need to set find conditions**. Suppose we have the following `Class`. @@ -1640,7 +1636,7 @@ public class TestFoo { } ``` -We want to get the `public TestFoo()` constructor, which can be written as follows. +To get the `public TestFoo()` constructor, we must write it in the following form. > The following example @@ -1648,23 +1644,57 @@ We want to get the `public TestFoo()` constructor, which can be written as follo TestFoo::class.java.constructor { emptyParam() } ``` -The above example can successfully obtain the `public TestFoo()` constructor, but it feels a bit cumbersome. +The above example can successfully obtain the `public TestFoo()` constructor. -Unlike normal methods, since the constructor does not need to consider the `name`, when the constructor has no parameters, we can omit the `emptyParam` parameter. +If you write `constructor()` and miss `emptyParam()`, the result found at this time will be the first one in bytecode order, **may not be parameterless** . + +::: tip Compatibility Notes + +In past historical versions of the API, if the constructor does not fill in any search parameters, the constructor will not be found directly. + +**This is a BUG and has been fixed in the latest version**, please make sure you are using the latest API version. + +::: + +::: danger API Behavior Changes + +In **1.2.0** and later versions, the behavior of **constructor()** is no longer **constructor { emptyParam() }** but **constructor {}**, please pay attention to the behavior change reasonably adjust the find parameters. + +::: + +#### No Find Conditions + +Without setting find conditions, using `field()`, `constructor()`, `method()` will return all members under the current `Class`. + +Using `get(...)` or `give()` will only get the first bit in bytecode order. > The following example ```kotlin -TestFoo::class.java.constructor() +Test::class.java.field().get(...) +Test::class.java.method().give() ``` +If you want to get all members, you can use `all(...)` or `giveAll()` + +> The following example + +```kotlin +Test::class.java.field().all(...) +Test::class.java.method().giveAll() +``` + +::: tip Compatibility Notes + +In past historical versions of the API, failure to set find conditions will throw an exception. + +This feature was added in **1.2.0** and later versions. + +::: + #### Bytecode Type -::: danger - -In the bytecode call result, the **cast** method can only specify the type corresponding to the bytecode. - -::: +In the bytecode call result, the **cast** method can **only** specify the type corresponding to the bytecode. For example we want to get a field of type `Boolean` and cast it to `String`. diff --git a/docs-source/src/zh-cn/api/features.md b/docs-source/src/zh-cn/api/features.md index 65cb963..73cda74 100644 --- a/docs-source/src/zh-cn/api/features.md +++ b/docs-source/src/zh-cn/api/features.md @@ -1480,11 +1480,7 @@ TestGeneric::class.java.generic()?.argument()?.method { #### 限制性查找条件 -::: danger - -在查找条件中,除了 **order** 你只能使用一次 **index** 功能。 - -::: +在查找条件中,除了 `order` 你**只能**使用一次 `index` 功能。 > 示例如下 @@ -1511,12 +1507,8 @@ method { #### 必要的查找条件 -::: danger - 在普通方法查找条件中,**即使是无参的方法也需要设置查找条件**。 -::: - 假设我们有如下的 `Class`。 > 示例如下 @@ -1566,9 +1558,13 @@ TestFoo::class.java.method { 至此,上述的示例将可以完美地匹配到 `public void foo()` 方法。 -#### 可简写查找条件 +::: tip 兼容性说明 -> 在构造方法查找条件中,**无参的构造方法可以不需要填写查找条件**。 +在过往历史版本的 API 中是允许匹配不写默认匹配无参方法的做法的,但是最新版本更正了这一问题,请确保你使用的是最新的 API 版本。 + +::: + +在构造方法查找条件中,**即使是无参的构造方法也需要设置查找条件**。 假设我们有如下的 `Class`。 @@ -1583,7 +1579,7 @@ public class TestFoo { } ``` -我们要得到其中的 `public TestFoo()` 构造方法,可以写作如下形式。 +我们要得到其中的 `public TestFoo()` 构造方法,必须写作如下形式。 > 示例如下 @@ -1591,23 +1587,53 @@ public class TestFoo { TestFoo::class.java.constructor { emptyParam() } ``` -上面的例子可以成功获取到 `public TestFoo()` 构造方法,但是感觉有一些繁琐。 +上面的例子可以成功获取到 `public TestFoo()` 构造方法。 -与普通方法不同,由于构造方法不需要考虑 `name` 名称,当构造方法没有参数的时候,我们可以省略 `emptyParam` 参数。 +如果你写作 `constructor()` 而丢失了 `emptyParam()`,此时查找到的结果会是按照字节码顺序排列的的第一位,**可能并不是无参的**。 + +::: tip 兼容性说明 + +在过往历史版本的 API 中构造方法不填写任何查找参数会直接找不到构造方法,**这是一个 BUG,最新版本已经进行修复**,请确保你使用的是最新的 API 版本。 + +::: + +::: danger API 行为变更 + +在 **1.2.0** 及之后的版本中,**constructor()** 的行为不再是 **constructor { emptyParam() }** 而是 **constructor {}**,请注意行为变更合理调整查找参数。 + +::: + +#### 不设置查找条件 + +在不设置查找条件的情况下,使用 `field()`、`constructor()`、`method()` 将返回当前 `Class` 下的所有成员对象。 + +使用 `get(...)` 或 `give()` 的方式获取将只能得到按照字节码顺序排列的的第一位。 > 示例如下 ```kotlin -TestFoo::class.java.constructor() +Test::class.java.field().get(...) +Test::class.java.method().give() ``` +如果你想得到全部成员对象,你可以使用 `all(...)` 或 `giveAll()` + +> 示例如下 + +```kotlin +Test::class.java.field().all(...) +Test::class.java.method().giveAll() +``` + +::: tip 兼容性说明 + +在过往历史版本的 API 中,不设置查找条件将抛出异常,此特性在 **1.2.0** 及之后的版本中加入。 + +::: + #### 字节码类型 -::: danger - -在字节码调用结果中,**cast** 方法只能指定字节码对应的类型。 - -::: +在字节码调用结果中,**cast** 方法**只能**指定字节码对应的类型。 例如我们想得到一个 `Boolean` 类型的变量,把他转换为 `String`。