docs:(fix): normalized

This commit is contained in:
2025-08-03 01:27:29 +08:00
parent 5c09acd707
commit da4d9420b1
10 changed files with 74 additions and 74 deletions

View File

@@ -4,7 +4,7 @@
::: danger ::: danger
We will only maintain the latest API version, if you are using an outdate API version, you voluntarily renounce any possibility of maintenance. We will only maintain the latest API version. If you are using an outdated API version, you voluntarily renounce any possibility of maintenance.
::: :::

View File

@@ -1,22 +1,22 @@
# Looking for Future # Looking Toward the Future
> The future is bright and uncertain, let us look forward to the future development space of `KavaRef`. > The future is bright and uncertain, let us look forward to the future development potential of `KavaRef`.
## Future Plans ## Future Plans
> Features that `KavaRef` may add later are included here. > Features that `KavaRef` may add later are included here.
### Supports Class Filtering through ClassLoader ### Support Class Filtering through ClassLoader
`KavaRef` currently only supports search and calls for reflection APIs such as `Method`, `Field`, and `Constructor`. `KavaRef` currently only supports search and calls for reflection APIs such as `Method`, `Field`, and `Constructor`.
In the future, the ability to filter `Class` by specified type `ClassLoader` may be supported in Java and Android platforms according to requirements. In the future, the ability to filter `Class` by specified `ClassLoader` type may be supported on Java and Android platforms according to requirements.
Currently, you can use [DexKit](https://github.com/LuckyPray/DexKit) to complete this requirement, Currently, you can use [DexKit](https://github.com/LuckyPray/DexKit) to fulfill this requirement,
which also supports more complex searches and calls of reflective APIs such as Method, Field, and Constructor. which also supports more complex searches and calls for reflective APIs such as Method, Field, and Constructor.
### Automatically Generate Reflection Code ### Automatically Generate Reflection Code
**This is a feature that has been initially established in [YukiReflection](https://github.com/HighCapable/YukiReflection), and `KavaRef` is ready to continue to implement it in the possible time in the future.** **This is a feature that was initially established in [YukiReflection](https://github.com/HighCapable/YukiReflection), and `KavaRef` is ready to continue implementing it at some point in the future.**
Use `stub` to create a Kotlin class, and declare the parameters in it, as well as its different states in each version. Use `stub` to create a Kotlin class, and declare the parameters in it, as well as its different states in each version.
@@ -66,7 +66,7 @@ MyClass().resolve().apply {
} }
``` ```
The function to be implemented at present can be directly defined as the following Kotlin class using the reflection function. The function to be implemented can currently be directly defined as the following Kotlin class using the reflection functionality.
> The following example > The following example
@@ -90,7 +90,7 @@ class MyClass {
} }
``` ```
Then we can directly call this defined Kotlin class to implement the reflection function, and the API will automatically generate the reflection code according to the annotation. Then we can directly call this defined Kotlin class to implement the reflection functionality, and the API will automatically generate the reflection code according to the annotations.
> The following example > The following example
@@ -109,6 +109,6 @@ MyClass().also {
::: tip ::: tip
The above functions may change after the actual release, and the functions of the actual version shall prevail. The above functions may change after the actual release, and the features of the actual version shall prevail.
::: :::

View File

@@ -73,30 +73,30 @@ myClass.current().method {
</div> </div>
</div> </div>
`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 polluting their scope.
`KavaRef` provides the `asResolver()` method to directly reference the reflection scope of the instance object, `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`. avoiding pollution 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 reflection results.
"Find" is no longer a finding, but a "filtering". "Find" is no longer finding, but "filtering".
`KavaRef` canceled the `YukiReflection` defined in the resulting instance whether the `Member` obtained is a multiple or a single design scheme, `KavaRef` canceled the design scheme defined in `YukiReflection` for determining whether the `Member` obtained in the resulting instance is multiple or single,
and directly returns the entire `List<MemberResolver>`. and directly returns the entire `List<MemberResolver>`.
The example you see above uses `firstMethod` to get the first match `MethodResolver`, The example you see above uses `firstMethod` to get the first matching `MethodResolver`.
if you need to get all matches, you can change to `method`. If you need to get all matches, you can change to `method`.
The conditional method name of `KavaRef` in `MethodCondition` has been modified from abbreviation The conditional method name in `MethodCondition` of `KavaRef` has been modified from abbreviations
such as `param` before `YukiReflection` to `parameters` to more in line with the naming habit of Java reflection API. such as `param` used previously in `YukiReflection` to `parameters` to better align with the naming conventions of the Java reflection API.
`KavaRef` no longer provides the `param(...).order()` function in the condition, because this function itself is unstable. `KavaRef` no longer provides the `param(...).order()` function in conditions, because this function itself is unstable.
`KavaRef` now uses an iterator for filtering, and the bytecode will no longer be in order, and the bytecode should not be filtered in order. `KavaRef` now uses an iterator for filtering, and the bytecode will no longer be in order, nor should bytecode be filtered by order.
You can use `firstMethod`, `firstField`, or `lastMethod`, `lastField`, etc. to get the first or last match result. You can use `firstMethod`, `firstField`, or `lastMethod`, `lastField`, etc. to get the first or last matching result.
`KavaRef` renames the `get(instance)` method to `of(instance)` because `get(...)` may be confused with the `get(...)` usage of `Field` and is not semantic, `KavaRef` renames the `get(instance)` method to `of(instance)` because `get(...)` may be confused with the `get(...)` usage of `Field` and lacks semantic clarity.
At the same time, `get(instance)` is no longer getting the `MethodFinder.Result.Instance` instance from something like `MethodFinder.Result`, At the same time, `get(instance)` no longer gets the `MethodFinder.Result.Instance` instance from something like `MethodFinder.Result`,
but uses `of(instance)` to always operate and set the instance object to `MemberResolver`. but uses `of(instance)` to consistently operate and set the instance object to `MemberResolver`.
Methods such as `string()`, `int()`, etc. in `MethodFinder.Result.Instance` have been removed in `KavaRef`. Methods such as `string()`, `int()`, etc. in `MethodFinder.Result.Instance` have been removed in `KavaRef`.
You can directly use `get<String>()`, `get<Int>()`, `invoke<String>(...)`, `invoke<Int>(...)`, etc. to get or call the corresponding type results. You can directly use `get<String>()`, `get<Int>()`, `invoke<String>(...)`, `invoke<Int>(...)`, etc. to get or call the corresponding type results.

View File

@@ -2,13 +2,13 @@
> Here are some third-party Member resolvers for reference and use. > Here are some third-party Member resolvers for reference and use.
> >
> Please read [Custom Resolver](../library/kavaref-core.md#custom-resolver) for usage. > Please read [Custom Resolver](../library/kavaref-core.md#custom-resolver) for usage instructions.
## AndroidHiddenApiBypass ## AndroidHiddenApiBypass
[Project URL](https://github.com/LSPosed/AndroidHiddenApiBypass) [Project URL](https://github.com/LSPosed/AndroidHiddenApiBypass)
> LSPass: Bypass restrictions on non-SDK interfaces > LSPosed: Bypass restrictions on non-SDK interfaces
```kotlin ```kotlin
class AndroidHiddenApiBypassResolver : MemberProcessor.Resolver() { class AndroidHiddenApiBypassResolver : MemberProcessor.Resolver() {

View File

@@ -1,6 +1,6 @@
# R8 & Proguard Obfuscate # R8 & ProGuard Obfuscation
> In most scenarios, Android application installation packages can compress volumes through obfuscation. > In most scenarios, Android application installation packages can reduce size through obfuscation.
> Here is a configuration method for obfuscation rules. > Here is a configuration method for obfuscation rules.
`KavaRef` does not require any additional configuration of obfuscation rules in Android projects. `KavaRef` does not require any additional configuration of obfuscation rules in Android projects.

View File

@@ -1,4 +1,4 @@
# Introduce # Introduction
> `KavaRef` is a modern Java reflection API implemented using Kotlin. > `KavaRef` is a modern Java reflection API implemented using Kotlin.
@@ -10,31 +10,31 @@ reflection.
The project icon is designed by [MaiTungTM](https://github.com/Lagrio) and is named from **K**otlinJ**avaRef**lection, meaning Java reflection The project icon is designed by [MaiTungTM](https://github.com/Lagrio) and is named from **K**otlinJ**avaRef**lection, meaning Java reflection
implemented using Kotlin. implemented using Kotlin.
It was firstborn in the [YukiHookAPI](https://github.com/HighCapable/YukiHookAPI), and was later decoupled into It was first born in the [YukiHookAPI](https://github.com/HighCapable/YukiHookAPI), and was later decoupled into
the [YukiReflection](https://github.com/HighCapable/YukiReflection) project. the [YukiReflection](https://github.com/HighCapable/YukiReflection) project.
As you can see, now `KavaRef` is a completely new set of APIs completely refactored with the design idea of `YukiReflection`, As you can see, `KavaRef` is now a completely new set of APIs, completely refactored with the design ideas of `YukiReflection`,
which has no affiliation and will replace `YukiReflection` as a new reflection solution. which has no affiliation and will replace `YukiReflection` as a new reflection solution.
If you are using `YukiReflection` or the `YukiHookAPI` project related to it, you can refer to [here](../config/migration) to migrate the reflection API to `KavaRef`. If you are using `YukiReflection` or the `YukiHookAPI` project related to it, you can refer to [here](../config/migration) to migrate the reflection API to `KavaRef`.
## Usage ## Usage
`KavaRef` is built in Kotlin **lambda** syntax with Java Builder style. `KavaRef` is built with Kotlin **lambda** syntax in a Java Builder style.
It can replace [Java's native Reflection API](https://www.oracle.com/technical-resources/articles/java/javareflection.html) and implement a more complete reflection solution in a more human-friendly language. It can replace [Java's native Reflection API](https://www.oracle.com/technical-resources/articles/java/javareflection.html) and implement a more complete reflection solution with a more human-friendly language.
## Skill Requirements ## Skill Requirements
You must be proficient in Java's native reflection APIs, understand Java's class loading mechanisms, bytecode structures, and how they are used in Kotlin (if you are using Kotlin). You should be proficient with Java's native reflection APIs, understand Java's class loading mechanisms, bytecode structures, and how they are used in Kotlin (if you are using Kotlin).
## Language Requirement ## Language Requirement
It is recommended to use Kotlin. API code composition also supports Java, It is recommended to use Kotlin. API composition also supports Java,
but in pure Java projects `KavaRef` may not be able to play its full functionality and syntactic sugar advantages. but in pure Java projects, `KavaRef` may not be able to demonstrate its full functionality and syntactic sugar advantages.
All the demo sample code in the documentation will be described first using Kotlin. All the demo sample code in the documentation will be described using Kotlin first.
If you don't know how to use Kotlin at all, you may not be able to experience and use the functionality of `KavaRef` more fully. If you don't know how to use Kotlin at all, you may not be able to fully experience and use the functionality of `KavaRef`.
## Contribution ## Contribution
@@ -42,5 +42,5 @@ The maintenance of this project is inseparable from the support and contribution
This project is currently in its early stages, and there may still be some problems or lack of functions you need. This project is currently in its early stages, and there may still be some problems or lack of functions you need.
If possible, feel free to submit a PR to contribute features you think are needed to this project or goto [GitHub Issues](repo://issues) If possible, feel free to submit a PR to contribute features you think are needed to this project or go to [GitHub Issues](repo://issues)
to make suggestions to us. to make suggestions to us.

View File

@@ -4,8 +4,8 @@
## Project Requirements ## Project Requirements
The project needs to be created using `IntelliJ IDEA` or `Android Studio` and be of type Java or Android The project needs to be created using `IntelliJ IDEA` or `Android Studio` and should be a Java or Android
project and have integrated Kotlin environment dependencies. project with integrated Kotlin environment dependencies.
- IntelliJ IDEA (It is recommended to get the latest version [from here](https://www.jetbrains.com/idea)) - IntelliJ IDEA (It is recommended to get the latest version [from here](https://www.jetbrains.com/idea))
@@ -93,5 +93,5 @@ Click the corresponding module below to view detailed feature descriptions.
## Demo ## Demo
You can find some samples [here](repo://tree/main/samples) view the corresponding demo project to better understand how these functions work and quickly You can find some samples [here](repo://tree/main/samples) to view the corresponding demo projects to better understand how these functions work and quickly
select the functions you need. select the functions you need.

View File

@@ -14,8 +14,8 @@ features:
details: A powerful, elegant, beautiful API built with Kotlin lambda can help you quickly implement bytecode filtering and reflection functions. details: A powerful, elegant, beautiful API built with Kotlin lambda can help you quickly implement bytecode filtering and reflection functions.
- title: Fully Compatible - title: Fully Compatible
details: Using native Java APIs to implement reflection functionality, it can be used on any Kotlin on JVM project, and it is no problem on Android. details: Using native Java APIs to implement reflection functionality, it can be used on any Kotlin on JVM project, and it is no problem on Android.
- title: Quickly Started - title: Quick to Start
details: Simple and easy to use it now! Do not need complex configuration and full development experience, Integrate dependencies and enjoy yourself. details: Simple and easy to use right now! No complex configuration or extensive development experience required. Just integrate the dependencies and enjoy!
footer: Apache-2.0 License | Copyright (C) 2019 HighCapable footer: Apache-2.0 License | Copyright (C) 2019 HighCapable
--- ---

View File

@@ -133,16 +133,16 @@ public class Box<T> {
} }
``` ```
Suppose, we want to get the `doTask` method of `Test` and execute it. In KavaRef, you can do it in the following ways. Suppose we want to get the `doTask` method of `Test` and execute it. In KavaRef, you can do it in the following way.
> The following example > The following example
```kotlin ```kotlin
// Suppose this is an instance of this Class. // Suppose this is an instance of this Class.
val test: Test val test: Test
//Reflect it by instantiating Class. // Reflect it by instantiating Class.
// In KavaRef you don't need to convert it to `java.lang.Class`, // In KavaRef you don't need to convert it to `java.lang.Class`,
// It will automatically call KClass.java. // it will automatically call KClass.java.
Test::class Test::class
// Create KavaRef reflections. // Create KavaRef reflections.
.resolve() .resolve()
@@ -157,24 +157,24 @@ Test::class
// instance will be returned. // instance will be returned.
// Here we get the first filtering result. // Here we get the first filtering result.
.first() .first()
// Setting an instance of Test on MethodResolver. // Set an instance of Test on MethodResolver.
.of(test) .of(test)
// Calling methods and passing in parameters. // Call the method and pass in parameters.
.invoke("task_name") .invoke("task_name")
``` ```
In the above writing method, we use `Test::class.resolve()` to get the KavaRef reflection instance of the current `Class`. In the above writing method, we use `Test::class.resolve()` to get the KavaRef reflection instance of the current `Class`.
Then create a method filtering condition `MethodCondition` by `method { ... }`, which sets the method name and parameter type, and returns the `List<MethodResolver>` instance after execution. Then create a method filtering condition `MethodCondition` using `method { ... }`, which sets the method name and parameter type, and returns the `List<MethodResolver>` instance after execution.
Then we use `first()` to get the first matched `MethodResolver` instance, Then we use `first()` to get the first matched `MethodResolver` instance,
Then use `of(test)` to set the current instance of `Class`, and finally use `invoke("task_name")` to execute the method and pass in the parameters. then use `of(test)` to set the current instance of `Class`, and finally use `invoke("task_name")` to execute the method and pass in the parameters.
In this, MethodCondition is inherited from MemberCondition, which allows you to conditionally filter the Method, which contains a conditional image of the Java-core reflection API. In this, MethodCondition is inherited from MemberCondition, which allows you to conditionally filter the Method, containing a conditional image of the Java-core reflection API.
You can view the corresponding comments to understand the native usage of each API. You can view the corresponding comments to understand the native usage of each API.
Similarly, MethodResolver is inherited from `MemberResolver`, which allows you to make reflection calls to `Method` in the filtered result. Similarly, MethodResolver is inherited from `MemberResolver`, which allows you to make reflection calls to `Method` in the filtered result.
Since the reflection requirement here is to obtain a available method result, the call chain of `method { ... }.first()` may be more cumbersome, Since the reflection requirement here is to obtain an available method result, the call chain of `method { ... }.first()` may be more cumbersome,
and at this time there is the following simplification solution. so there is the following simplified solution.
> The following example > The following example
@@ -191,7 +191,7 @@ Test::class
.invoke("task_name") .invoke("task_name")
``` ```
Since we can now get an instance of `Test`, there is also a simplified way to write it, Since we can now get an instance of `Test`, there is also a simplified way to write this:
you can use this instance to create KavaRef reflections directly. you can use this instance to create KavaRef reflections directly.
> The following example > The following example
@@ -212,7 +212,7 @@ Next, we need to get the `isTaskRunning` variable, which can be written in the f
> The following example > The following example
```kotlin ```kotlin
// Suppose this is an example of this Class. // Suppose this is an instance of this Class.
val test: Test val test: Test
// Call and execute with KavaRef. // Call and execute with KavaRef.
val isTaskRunning = test.asResolver() val isTaskRunning = test.asResolver()
@@ -222,15 +222,15 @@ val isTaskRunning = test.asResolver()
}.get<Boolean>() }.get<Boolean>()
``` ```
The constructor in `Test` is privatized, and now we can create an instance of it using the following method. The constructor in `Test` is private, and now we can create an instance of it using the following method.
> The following example > The following example
```kotlin ```kotlin
val test = Test::class.resolve() val test = Test::class.resolve()
.firstConstructor { .firstConstructor {
// For the zero parameter construction method, // For the zero parameter constructor,
// the following conditions can be used to filter. // the following condition can be used to filter.
// It is equivalent to parameterCount = 0. // It is equivalent to parameterCount = 0.
emptyParameters() emptyParameters()
}.create() // Create a new Test instance. }.create() // Create a new Test instance.
@@ -254,13 +254,13 @@ In addition to methods such as `firstMethod`, you can also use methods such as `
After you get the `MemberResolver` instance, you can use `self` to get the `Member` original instance of the current `MemberResolver` to do some of your own operations. After you get the `MemberResolver` instance, you can use `self` to get the `Member` original instance of the current `MemberResolver` to do some of your own operations.
In `MemberResolver` inherited from `InstanceAwareResolver` (for example `MethodResolver` and `FieldResolver`), you can use `of(instance)` In `MemberResolver` inherited from `InstanceAwareResolver` (for example `MethodResolver` and `FieldResolver`), you can use `of(instance)`
To set the current instance, if the reflection is static (static) member, you do not need to set the instance. to set the current instance. If the reflection is a static member, you do not need to set the instance.
::: :::
::: warning ::: warning
The `Any.resolve()` function has been deprecated in `1.0.1` version because it pollutes the namespace (for example `File.resolve("/path/to/file")`), and now use `Any.asResolver()` instead. The `Any.resolve()` function has been deprecated in version `1.0.1` because it pollutes the namespace (for example `File.resolve("/path/to/file")`), and now use `Any.asResolver()` instead.
::: :::
@@ -269,15 +269,15 @@ The `Any.resolve()` function has been deprecated in `1.0.1` version because it p
In `MemberResolver` inherited from `InstanceAwareResolver`, the type of `of(instance)` requires the same type as the currently reflected `Class` instance generic type. In `MemberResolver` inherited from `InstanceAwareResolver`, the type of `of(instance)` requires the same type as the currently reflected `Class` instance generic type.
Unless the `Class` generic type is not specified, or the `Class` generic type is set to `Any`. Unless the `Class` generic type is not specified, or the `Class` generic type is set to `Any`.
If `of(instance)` appears `Required: Nothing?` error (this is usually due to `Class` created via `Class.forName(...)` or `ClassLoader.loadClass(...)`), If `of(instance)` shows a `Required: Nothing?` error (this is usually due to `Class` created via `Class.forName(...)` or `ClassLoader.loadClass(...)`),
then your `Class` is `Class<*>` (in Java it is `Class<?>`). then your `Class` is `Class<*>` (in Java it is `Class<?>`).
At this time, if you do not want to specify the type, please set or convert it to `Class<Any>`, just like the following. At this time, if you do not want to specify the type, please set or convert it to `Class<Any>`, as follows.
> The following example > The following example
```kotlin ```kotlin
val myClass = Class.forName("com.xxx.MyClass") as Class<Any> val myClass = Class.forName("com.xxx.MyClass") as Class<Any>
// Suppose this is an example of this Class. // Suppose this is an instance of this Class.
val myClassInstance: Any val myClassInstance: Any
myClass.resolve() myClass.resolve()
.firstMethod { .firstMethod {
@@ -291,9 +291,9 @@ You can also use [Create Class Object](kavaref-extension.md#create-class-object)
### Vague Conditions ### Vague Conditions
You will notice that there is a `release` method in `Test`, but its method parameters are very long and some types may not be directly obtained. You will notice that there is a `release` method in `Test`, but its method parameters are very long and some types may not be directly obtainable.
At this point, you can use the `parameters(...)` condition to use `VagueType` to fill in the method parameter types you don't want to fill in. At this point, you can use the `parameters(...)` condition with `VagueType` to fill in the method parameter types you don't want to specify.
> The following example > The following example

View File

@@ -65,8 +65,8 @@ You can view the KDoc [click here](kdoc://kavaref-extension).
KavaRef provides some extensions that are more convenient when dealing with `Class` objects. KavaRef provides some extensions that are more convenient when dealing with `Class` objects.
KavaRef also adds the `KClass` extensions to the `Class` extensions, KavaRef also adds `KClass` extensions to the `Class` extensions,
which is used to call `KClass.java`, which is more concise than using `Some::class.java` directly. which is used to call `KClass.java`, making it more concise than using `Some::class.java` directly.
#### Create Class Object #### Create Class Object
@@ -77,7 +77,7 @@ For example, we need to create a `Class` object using the string class name.
```kotlin ```kotlin
val myClass = "com.example.MyClass".toClass() val myClass = "com.example.MyClass".toClass()
// You can use a method with OrNull suffix to return null // You can use a method with OrNull suffix to return null
// when Class is not found instead of throwing an exception. // when the Class is not found instead of throwing an exception.
val myClassOrNull = "com.example.MyClass".toClassOrNull() val myClassOrNull = "com.example.MyClass".toClassOrNull()
``` ```
@@ -94,8 +94,8 @@ You can also manually pass a `ClassLoader` parameter to the `toClass` method to
#### Class Object Reference #### Class Object Reference
Referring to Java Class in Kotlin requires writing a very long statement, Referring to a Java Class in Kotlin requires writing a very long statement,
such as `MyClass::class.java`, which you can simplify in the following ways. such as `MyClass::class.java`, which you can simplify in the following way.
> The following example > The following example