getEnclosingFunctionBody method

FunctionBody? getEnclosingFunctionBody()
inherited

Returns the function body of the most deeply nested method or function that encloses the node, or null if the node is not in a method or function.

Implementation

FunctionBody? getEnclosingFunctionBody() {
  var closure = node.thisOrAncestorOfType<FunctionExpression>();
  if (closure != null) {
    return closure.body;
  }
  var function = node.thisOrAncestorOfType<FunctionDeclaration>();
  if (function != null) {
    return function.functionExpression.body;
  }
  var constructor = node.thisOrAncestorOfType<ConstructorDeclaration>();
  if (constructor != null) {
    return constructor.body;
  }
  var method = node.thisOrAncestorOfType<MethodDeclaration>();
  if (method != null) {
    return method.body;
  }
  return null;
}