visitClass method

  1. @override
StringSink visitClass(
  1. Class spec, [
  2. StringSink? output
])
inherited

Implementation

@override
StringSink visitClass(Class spec, [StringSink? output]) {
  final out = output ??= StringBuffer();
  spec.docs.forEach(out.writeln);
  for (var a in spec.annotations) {
    visitAnnotation(a, out);
  }

  void writeModifier() {
    if (spec.modifier != null) {
      out.write('${spec.modifier!.name} ');
    }
  }

  if (spec.sealed) {
    out.write('sealed ');
  } else {
    if (spec.abstract) {
      out.write('abstract ');
    }
    writeModifier();
    if (spec.mixin) {
      out.write('mixin ');
    }
  }
  out.write('class ${spec.name}');
  visitTypeParameters(spec.types.map((r) => r.type), out);
  if (spec.extend != null) {
    out.write(' extends ');
    spec.extend!.type.accept(this, out);
  }
  if (spec.mixins.isNotEmpty) {
    out
      ..write(' with ')
      ..writeAll(
          spec.mixins.map<StringSink>((m) => m.type.accept(this)), ',');
  }
  if (spec.implements.isNotEmpty) {
    out
      ..write(' implements ')
      ..writeAll(
          spec.implements.map<StringSink>((m) => m.type.accept(this)), ',');
  }
  out.write(' {');
  for (var c in spec.constructors) {
    visitConstructor(c, spec.name, out);
    out.writeln();
  }
  for (var f in spec.fields) {
    visitField(f, out);
    out.writeln();
  }
  for (var m in spec.methods) {
    visitMethod(m, out);
    if (_isLambdaMethod(m)) {
      out.writeln(';');
    }
    out.writeln();
  }
  out.writeln(' }');
  return out;
}