getResolver method
Retrieves the Resolver associated with a given source (parameter).
The search follows these rules:
- Collect all direct annotations on the
source. - For each annotation, check if it is a RequestParameter or is meta-annotated with RequestParameter.
- Inspect the annotation’s metadata for a ResolvedBy annotation.
- If found, return the Resolver provided by ResolvedBy.
Returns null if no suitable resolver is found.
Implementation
@protected
Resolver? getResolver(Source source) {
final parent = Class<RequestParameter>(null, PackageNames.WEB);
for (final ann in source.getAllDirectAnnotations()) {
final annClass = ann.getDeclaringClass();
if (parent.isAssignableFrom(annClass) || ann.matches<RequestParameter>()) {
for (final meta in annClass.getAllAnnotations()) {
try {
final metaClass = meta.getDeclaringClass();
// If the annotation on the annotation class is a ResolvedBy, extract it
if (Class<ResolvedBy>(null, PackageNames.WEB).isAssignableFrom(metaClass)) {
final instance = meta.getInstance();
if (instance is ResolvedBy) {
return instance.resolver;
}
}
} catch (e) {
// ignore reflection failures
}
}
}
}
return null;
}