getResolver method

  1. @protected
Resolver? getResolver(
  1. Source source
)

Retrieves the Resolver associated with a given source (parameter).

The search follows these rules:

  1. Collect all direct annotations on the source.
  2. For each annotation, check if it is a RequestParameter or is meta-annotated with RequestParameter.
  3. Inspect the annotation’s metadata for a ResolvedBy annotation.
  4. 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;
}