code: public static void addLazyDefinitions(SourceBuilder code) {
      Set<Declaration> defined = new HashSet<>();
  
      // Definitions may lazily declare new names; ensure we add them all
      List<Declaration> declarations =
          code.scope().keysOfType(Declaration.class).stream().sorted().collect(toList());
      while (!defined.containsAll(declarations)) {
        for (Declaration declaration : declarations) {
          if (defined.add(declaration)) {
            code.add(code.scope().get(declaration).definition);
          }
        }
        declarations = code.scope().keysOfType(Declaration.class).stream().sorted().collect(toList());
      }
    }
docs: Finds all lazily-declared classes and methods and adds their definitions to the source.