lookupDeclarationMetaData method Null safety

List<Object> lookupDeclarationMetaData(
  1. DeclarationMirror? declarationMirror
)

Implementation

List<Object> lookupDeclarationMetaData(DeclarationMirror? declarationMirror) {
  if (declarationMirror == null) {
    return [];
  }
  final result = [...declarationMirror.metadata];
  final parentClassMirror = _safeGetParentClassMirror(declarationMirror);
  if (parentClassMirror == null) {
    return result;
  }

  for (var element in [
    parentClassMirror,
    _safeGetSuperClassMirror(parentClassMirror),
    ...parentClassMirror.superinterfaces
  ]) {
    if (element == null) {
      continue;
    }
    final parentDeclarationMirror =
        ClassInfo(element).getDeclarationMirror(declarationMirror.simpleName);
    result.addAll(parentClassMirror.isTopLevel
        ? parentDeclarationMirror != null
            ? parentDeclarationMirror.metadata
            : []
        : lookupDeclarationMetaData(parentDeclarationMirror));
  }

  return result;
}