getMaxDepth method

int? getMaxDepth()

Retrieve the maximum depth of the DartBlock program across its main and custom functions, if the program is not empty.

The counting is performed using the tree-based representation of the program.

Implementation

int? getMaxDepth() {
  int? maxDepth = buildTree()
      .findNodeByKey(mainFunction.hashCode)
      ?.getMaxDepth();
  for (final customFunction in customFunctions) {
    final int? customFunctionDepth = buildTree()
        .findNodeByKey(customFunction.hashCode)
        ?.getMaxDepth();
    maxDepth ??= customFunctionDepth;
    if (maxDepth != null &&
        customFunctionDepth != null &&
        customFunctionDepth > maxDepth) {
      maxDepth = customFunctionDepth;
    }
  }

  return maxDepth;
}