visit method

void visit(
  1. void callback(
    1. String? pkg,
    2. String lib,
    3. String? cls,
    4. String? fun,
    5. ProgramInfoNode n,
    )
)

Recursively visit all function nodes, which have FunctionInfo.info populated.

Implementation

void visit(
    void Function(String? pkg, String lib, String? cls, String? fun,
            ProgramInfoNode n)
        callback) {
  final context = List<String?>.filled(NodeType.values.length, null);

  void recurse(ProgramInfoNode node) {
    final prevContext = context[node._type];
    if (prevContext != null && node._type == NodeType.functionNode.index) {
      context[node._type] = '$prevContext.${node.name}';
    } else {
      context[node._type] = node.name;
    }

    final pkg = context[NodeType.packageNode.index];
    final lib = context[NodeType.libraryNode.index];
    final cls = context[NodeType.classNode.index];
    final mem = context[NodeType.functionNode.index];
    callback(pkg, lib!, cls, mem, node);

    for (var child in node.children.values) {
      recurse(child);
    }

    context[node._type] = prevContext;
  }

  recurse(root);
}