Skip to content

COverride

Lenni0451 edited this page Mar 17, 2024 · 1 revision

The COverride annotation can be used to completely override a method.

Method naming

When overriding a method, the name of the transformer method is matched against the target method.
The target method name can also be specified using the value field of the COverride annotation.

Method signature

The method signature of the transformer method depends on the target method.
When injecting into a static method, the transformer method also needs to be static and vice versa.
All parameters and the return type of the transformer method have to match the target method.

The access modifier of the transformer method has to be the same as the target method or less restrictive.
private < package < protected < public

Current Access Modifier Possible Access Modifiers
private private, package, protected, public
package package, protected, public
protected protected, public
public public

Targeting multiple methods

The value field can be an array of strings to target multiple methods.
The transformer method needs to be compatible with all targeted methods.

@COverride(value = {"method1", "method2"}, ...)
public void transform()

Example

Original method:

private String method(final String arg) {
    return "hello " + arg;
}

Transformer method:

@COverride
public String method(final String arg) {
    return "world";
}