visitSwitchStatement method

  1. @override
StringSink visitSwitchStatement(
  1. SwitchStatement statement, [
  2. StringSink? output
])
inherited

Implementation

@override
StringSink visitSwitchStatement(
  SwitchStatement statement, [
  StringSink? output,
]) {
  output ??= StringBuffer();
  if (statement.label != null) {
    output.writeln('${statement.label}:');
  }
  output.write('switch (');
  statement.value.accept(this, output);
  output.writeln(') {');

  for (final c in statement.cases) {
    if (c.label != null) {
      output.writeln('${c.label}:');
    }
    output.write('case ');
    c.pattern.accept(this, output);
    if (c.guard != null) {
      output.write(' when ');
      c.guard!.accept(this, output);
    }
    output.writeln(':');
    if (c.body != null) {
      c.body!.accept(this, output);
    }
  }

  if (statement.defaultCase != null) {
    output.writeln('default:');
    statement.defaultCase!.accept(this, output);
  }

  output.write(' }');
  return output;
}