-
-
Notifications
You must be signed in to change notification settings - Fork 5
CASM
The CASM
annotation can be used to inject into a class or method using direct ASM.
You get direct access to the ClassNode
or MethodNode
and can modify it however you want.
The position of CASM
in the handler chain is at the top or bottom, depending on the shift
value: @CASM(shift = Shift.BOTTOM)
.
The code inside the transformer method is executed isolated from the rest of the transformer. Isolated does not mean the code is sandboxed!
This means that you can't access any fields from the transformer class. Methods are copied over to the isolated class and can be accessed from there.
Due to some issues with the LambdaMetaFactory
, the use of lambdas is not supported.
To transform a class, you need to keep the value
of the annotation empty.
@CASM
public static void transform(final ClassNode classNode) {
//Do something with the class
}
The transformer method has to be static
and needs to have a single parameter of type ClassNode
and must return void
.
To transform a method, you need to specify the method pattern in the value
of the annotation (see Targets for more information).
The value
field is an array of strings, so you can specify multiple methods to transform.
@CASM("methodName")
public static void transform(final MethodNode methodNode) {
//Do something with the method
}
The transformer method has to be static
and needs to have a single parameter of type MethodNode
and must return void
.