firstAnnotationOfExact method

DartObject? firstAnnotationOfExact(
  1. Element element, {
  2. bool throwOnUnresolved = true,
})

Returns the first constant annotating element that is exactly this type.

Throws UnresolvedAnnotationException on unresolved annotations unless throwOnUnresolved is explicitly set to false (default is true).

Implementation

DartObject? firstAnnotationOfExact(
  Element element, {
  bool throwOnUnresolved = true,
}) {
  if (element.metadata.isEmpty) {
    return null;
  }
  final results =
      annotationsOfExact(element, throwOnUnresolved: throwOnUnresolved);
  return results.isEmpty ? null : results.first;
}