getDeclarationMirror method Null safety

DeclarationMirror? getDeclarationMirror(
  1. String name
)

Implementation

DeclarationMirror? getDeclarationMirror(String name) {
  DeclarationMirror? result;
  try {
    result = classMirror!.declarations[name] as VariableMirror?;
  } catch (error) {
    result = null;
  }
  if (result == null) {
    try {
      result = classMirror!.declarations[name] as MethodMirror?;
    } catch (error) {
      result = null;
    }
  }
  if (result == null) {
    try {
      classMirror!.instanceMembers
          .forEach((memberName, MethodMirror methodMirror) {
        if (memberName == name) {
          result = methodMirror;
        }
      });
    } catch (error) {
      result = null;
    }
  }
  return result;
}