getAnnotations function

void getAnnotations({
  1. required Element element,
  2. required List<OnMatch> onMatch,
  3. NonMatch? onNonMatch,
})

Implementation

void getAnnotations({
  required Element element,
  required List<OnMatch> onMatch,
  NonMatch? onNonMatch,
}) {
  for (var i = 0; i < element.metadata.length; i++) {
    final value = _computeConstantValue(
      element,
      i,
    );

    if (value == null) {
      continue;
    }

    if (value.type case final type?) {
      var found = false;
      for (final onClass in onMatch) {
        if (onClass.predicate(type)) {
          final annotation = element.metadata[i];

          onClass.convert(value, annotation);
          found = true;
          break;
        }
      }

      if (found) {
        continue;
      }

      if (onNonMatch == null) {
        continue;
      }

      if (onNonMatch.ignore.any((ignore) => ignore.predicate(type))) {
        continue;
      }

      onNonMatch.convert(value, element.metadata[i]);
    }
  }
}