class InjectionHandle internal constructor( val id: String )注册注入的句柄,用于回滚操作。
Properties
| Property | Description |
|---|---|
id | 注入注册 ID,用于回滚。 |
class InjectionHandle internal constructor( val id: String )注册注入的句柄,用于回滚操作。
| Property | Description |
|---|---|
id | 注入注册 ID,用于回滚。 |
class InjectionInvocationContext internal constructor( private val delegate: InjectionManager.InjectionInvocation )传给不安全回调的调用上下文。
可访问正在调用的方法、接收实例、参数,并控制调用流程。
| Property | Description |
|---|---|
delegate | 底层的注入调用委托。 |
val method: Method当前正在调用的方法。
val instance: Any?方法接收实例;对于静态方法则为 null。
val arguments: Array<Any?>原始参数数组。
val owner: String?这次调用绑定的脚本归属。
fun setArgument(index: Int, value: Any?)修改当前调用中指定位置的参数。
| Parameter | Description |
|---|---|
index | 要修改的参数下标。 |
value | 参数的新值。 |
fun cancel()取消当前调用。若未覆写返回值,则使用该类型的默认值。
fun cancelWith(returnValue: Any?)取消当前调用,并立即指定返回值。
| Parameter | Description |
|---|---|
returnValue | 用来替代方法执行结果的返回值。 |
fun setReturnValue(returnValue: Any?)在 after 阶段覆写返回值。
| Parameter | Description |
|---|---|
returnValue | 用来替代原始结果的返回值。 |
class ConstructorInvocationContext internal constructor( private val delegate: InjectionManager.ConstructorInvocation )传给不安全构造器回调的构造器调用上下文。
| Property | Description |
|---|---|
delegate | 底层的构造器调用委托。 |
val constructor: Constructor<*>当前正在调用的构造器。
val instance: Any?已构造的实例(this),如果可用。
val arguments: Array<Any?>Raw constructor argument array.
val owner: String?Bound script owner for this invocation.
fun injectBefore(targetClassName: String, methodName: String, parameterTypeNames: List<String> = emptyList(), owner: String? = null, handler: (InjectionInvocationContext) -> Unit): InjectionHandleInjects a callback before target method execution (string-based overload).
| Parameter | Description |
|---|---|
targetClassName | target class fully-qualified name |
methodName | target method name |
parameterTypeNames | parameter type names, e.g. int, java.lang.String |
owner | script owner (nullable, auto-resolved from script context if null) |
handler | before callback |
injection handle, usable by [rollbackUnsafe]
fun injectBefore(method: Method, owner: String? = null, handler: (InjectionInvocationContext) -> Unit): InjectionHandleInjects a callback before target method execution (Method overload).
Prefer this overload when a reflected [Method] is already available, to avoid string-signature assembly errors.
fun injectAfter(targetClassName: String, methodName: String, parameterTypeNames: List<String> = emptyList(), owner: String? = null, handler: (InjectionInvocationContext, Any?, Throwable?) -> Unit): InjectionHandleInjects a callback after target method execution (string-based overload).
| Parameter | Description |
|---|---|
targetClassName | target class fully-qualified name |
methodName | target method name |
parameterTypeNames | parameter type names, e.g. int, java.lang.String |
owner | script owner (nullable, auto-resolved from script context if null) |
handler | after callback with result and throwable |
injection handle, usable by [rollbackUnsafe]
fun injectConstructorBefore(targetClassName: String, parameterTypeNames: List<String> = emptyList(), owner: String? = null, handler: (ConstructorInvocationContext) -> Unit): InjectionHandleInjects a callback before constructor execution (string-based overload).
| Parameter | Description |
|---|---|
targetClassName | target class fully-qualified name |
parameterTypeNames | constructor parameter type names, e.g. int, java.lang.String |
owner | script owner (nullable, auto-resolved from script context if null) |
handler | constructor-before callback |
injection handle, usable by [rollbackUnsafe]
fun injectConstructorBefore(constructor: Constructor<*>, owner: String? = null, handler: (ConstructorInvocationContext) -> Unit): InjectionHandleInjects a callback before constructor execution (Constructor overload).
fun injectConstructorAfter(targetClassName: String, parameterTypeNames: List<String> = emptyList(), owner: String? = null, handler: (ConstructorInvocationContext) -> Unit): InjectionHandleInjects a callback after constructor execution (string-based overload).
| Parameter | Description |
|---|---|
targetClassName | target class fully-qualified name |
parameterTypeNames | constructor parameter type names, e.g. int, java.lang.String |
owner | script owner (nullable, auto-resolved from script context if null) |
handler | constructor-after callback |
injection handle, usable by [rollbackUnsafe]
fun injectConstructorAfter(constructor: Constructor<*>, owner: String? = null, handler: (ConstructorInvocationContext) -> Unit): InjectionHandleInjects a callback after constructor execution (Constructor overload).
fun injectAfter(method: Method, owner: String? = null, handler: (InjectionInvocationContext, Any?, Throwable?) -> Unit): InjectionHandleInjects a callback after target method execution (Method overload).
Prefer this overload when a reflected [Method] is already available.
| Parameter | Description |
|---|---|
method | The target Method to inject into |
owner | Script owner (nullable, auto-resolved from script context if null) |
handler | After callback with result and throwable |
Injection handle, usable by [rollbackUnsafe]
fun replace(targetClassName: String, methodName: String, parameterTypeNames: List<String> = emptyList(), owner: String? = null, handler: (InjectionInvocationContext) -> Any?): InjectionHandleReplaces entire target method body (string-based overload).
The handler return value becomes the method return value. This completely bypasses the original method implementation.
| Parameter | Description |
|---|---|
targetClassName | Target class fully-qualified name |
methodName | Target method name |
parameterTypeNames | Parameter type names, e.g. int, java.lang.String |
owner | Script owner (nullable, auto-resolved from script context if null) |
handler | Replacement handler that returns the method result |
Injection handle, usable by [rollbackUnsafe]
fun replace(method: Method, owner: String? = null, handler: (InjectionInvocationContext) -> Any?): InjectionHandleReplaces entire target method body (Method overload).
| Parameter | Description |
|---|---|
method | The target Method to replace |
owner | Script owner (nullable, auto-resolved from script context if null) |
handler | Replacement handler that returns the method result |
Injection handle, usable by [rollbackUnsafe]
fun redirect(sourceClassName: String, sourceMethodName: String, sourceParameterTypeNames: List<String> = emptyList(), targetClassName: String, targetMethodName: String, targetParameterTypeNames: List<String> = emptyList(), owner: String? = null): InjectionHandleRedirects a source method to another target method (string-based overload).
All calls to the source method will be redirected to the target method instead.
| Parameter | Description |
|---|---|
sourceClassName | Source class fully-qualified name |
sourceMethodName | Source method name to redirect from |
sourceParameterTypeNames | Source method parameter type names |
targetClassName | Target class fully-qualified name |
targetMethodName | Target method name to redirect to |
targetParameterTypeNames | Target method parameter type names |
owner | Script owner (nullable, auto-resolved from script context if null) |
Injection handle, usable by [rollbackUnsafe]
fun redirect(sourceMethod: Method, targetMethod: Method, owner: String? = null): InjectionHandleRedirects a source method to another target method (Method overload).
| Parameter | Description |
|---|---|
sourceMethod | The source Method to redirect from |
targetMethod | The target Method to redirect to |
owner | Script owner (nullable, auto-resolved from script context if null) |
Injection handle, usable by [rollbackUnsafe]
fun rollbackUnsafeByOwner(owner: String)Rolls back all unsafe injections by owner.
| Parameter | Description |
|---|---|
owner | The script owner whose injections should be removed |