-
-
Notifications
You must be signed in to change notification settings - Fork 5
CShadow
Lenni0451 edited this page Mar 17, 2024
·
1 revision
The CShadow
annotation is used to allow the usage of fields and methods of the target class in the transformer.
The name of the field/method is automatically inferred from the name of the annotated field/method.
If you want to set it manually you can use the value
field.
//Shadowing the field "field" of the target class
@CShadow
private String field;
//Manually setting the name of the shadowed field
@CShadow("field")
private String otherName;
When shadowing a method the body of the method is ignored if it is present.
An easy way to skip the method body is to make the method abstract
or native
.\
//Shadowing the method "method" of the target class
@CShadow
private native void method();
//Manually setting the name of the shadowed method
@CShadow("method")
private void otherName();
The shadow annotation also allows making fields/methods public by setting the makePublic
field to true
.
Example:
@CShadow(makePublic = true)
private String field;
@CShadow
private String field;
@CShadow
private native void method(final String s);
@Inject(method = "test", at = @CTarget("HEAD"))
public void injectTest() {
//Access the private field
System.out.println(this.field);
//Access the private method
this.method("test");
}