Class RequestAnnotationProcessor
java.lang.Object
javax.annotation.processing.AbstractProcessor
io.fluxcapacitor.javaclient.tracking.handling.RequestAnnotationProcessor
- All Implemented Interfaces:
Processor
@SupportedAnnotationTypes({"io.fluxcapacitor.javaclient.tracking.handling.HandleQuery","io.fluxcapacitor.javaclient.tracking.handling.HandleCommand","io.fluxcapacitor.javaclient.tracking.handling.HandleCustom"})
@AutoService(javax.annotation.processing.Processor.class)
public class RequestAnnotationProcessor
extends AbstractProcessor
Annotation processor that validates whether handler methods annotated with
HandleCommand
, HandleQuery
or HandleCustom
correctly match the response type declared by a Request
payload.
The processor enforces compile-time consistency between:
- The generic type
R
inRequest<R>
- The actual return type of the handler method (or
Future<R>
)
Validation Rules
- If a handler method accepts a
Request<R>
as a parameter, its return type must matchR
- Asynchronous handlers that return
Future<R>
are also supported - Handlers marked as
passive=true
are skipped - Errors are reported at compile time with descriptive messages
Example
@HandleQuery
UserProfile handle(GetUser query) {
return FluxCapacitor.search(UserProfile.class).match(query.getUserId()).fetchFirstOrNull();
}
If the method were to return e.g. String
instead of UserProfile
, a compile-time error would be raised.
Supported Annotations
This processor is automatically registered via @AutoService(Processor.class)
and does not require manual configuration.
-
Field Summary
Fields inherited from class javax.annotation.processing.AbstractProcessor
processingEnv
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
process
(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) protected void
validateMethod
(Element method, TypeMirror requestType) protected void
validateReturnType
(Element method, TypeMirror payloadType, TypeMirror requestType) Methods inherited from class javax.annotation.processing.AbstractProcessor
getCompletions, getSupportedAnnotationTypes, getSupportedOptions, init, isInitialized
-
Constructor Details
-
RequestAnnotationProcessor
public RequestAnnotationProcessor()
-
-
Method Details
-
process
- Specified by:
process
in interfaceProcessor
- Specified by:
process
in classAbstractProcessor
-
validateMethod
-
validateReturnType
-
getSupportedSourceVersion
- Specified by:
getSupportedSourceVersion
in interfaceProcessor
- Overrides:
getSupportedSourceVersion
in classAbstractProcessor
-