Custom Processors
Write your own annotation processor on top of BasicStaticProxyAnnotationProcessor.
The five built-in @Static* annotations cover the common shapes — logging,
metrics, virtual, adapter, builder. When you need something the built-ins do
not give you — a security wrapper, audit-trail emission, multi-tenancy
guard — extend BasicStaticProxyAnnotationProcessor<T> and write your own.
What you get from the base class
- Boilerplate handling of the annotation-processing round.
- Helpers for naming, parameter extraction, delegator field generation, return-statement generation.
- The safety rules (final classes, final/private/static methods, Object methods) are enforced automatically.
- Three composition slots —
beforeDelegation,aroundDelegation,afterDelegation— for combining several method-level annotations on the same method.
What you write
The minimal custom processor declares which annotation it handles and how to emit the method body for each method on the target type:
public final class SecuredAnnotationProcessor
extends BasicStaticProxyAnnotationProcessor<Secured> {
@Override
public Class<Secured> responsibleFor() { return Secured.class; }
@Override
protected CodeBlock defineMethodImplementation(ExecutableElement methodElement,
String methodName2Delegate,
TypeElement targetType) {
return CodeBlock.builder()
.addStatement(delegatorStatementWithReturn(methodElement, methodName2Delegate))
.build();
}
}
That alone produces a working XxxSecured proxy class for any interface
annotated with @Secured. Add helpers as you need them.
Next
- Basics — the full minimum-viable
processor, plus the helpers from
BasicAnnotationProcessor. - Method decorators — how to
combine
before,aroundandafterslots on the same method. - Processor options — the compiler-arg surface and how to extend it.
In this section
- Basics
The minimum viable annotation processor on top of BasicStaticProxyAnnotationProcessor.
- Method decorators
Combine before/around/after slots in a single processor to stack several method-level annotations.
- Processor options
Compiler arguments recognised by the base processor and how to add your own.