-
-
Notifications
You must be signed in to change notification settings - Fork 5
CInline
Lenni0451 edited this page Mar 17, 2024
·
1 revision
The CInline
annotation allows you to inline any method in the transformer into the caller methods.
This works with all injection methods (except for CASM
) and other methods inside the transformer.
The inlined method will be removed from the class after the transformer is applied.
Make sure that:
- The inlined method is only called inside the transformer/target class.
- The inlined method is not called recursively.
This example inlines the injectTest()
method into the test()
method.
Original method:
public String test() {
return "Test";
}
Transformer method:
@CInline
@CInject(method = "test", target = @CTarget("HEAD"), cancellable = true)
public void injectTest(InjectionCallback ic) {
ic.setReturnValue("Hello World!");
}
Injected code:
public String test() {
InjectionCallback ic = new InjectionCallback();
injectTest(ic);
if (ic.isCancelled()) {
return (String) ic.getReturnValue();
}
return "Test";
}
Inlined code:
public String test() {
InjectionCallback ic = new InjectionCallback();
ic.setReturnValue("Hello World!");
if (ic.isCancelled()) {
return (String) ic.getReturnValue();
}
return "Test";
}