format method

String format(
  1. List<ASTNode> nodes, {
  2. FormatterConfig? config,
})

Implementation

String format(List<ASTNode> nodes, {FormatterConfig? config}) {
  final savedConfig = this.config;
  if (config != null) {
    this.config = config;
  }
  final output = StringBuffer();
  for (var i = 0; i < nodes.length; ++i) {
    final stmt = nodes[i];
    final stmtString = formatAST(stmt);
    if (stmtString.isNotEmpty) {
      if (_lastStmt is ImportExportDecl && stmt is! ImportExportDecl) {
        output.writeln('');
      }
      output.writeln(stmtString);
      if ((i < nodes.length - 1) &&
          (stmt is FuncDecl || stmt is ClassDecl || stmt is EnumDecl)) {
        output.writeln('');
      }
    }
    _lastStmt = stmt;
  }
  final result = output.toString();
  this.config = savedConfig;
  return result;
}