visitFunctionType method Null safety

  1. @override
StringSink visitFunctionType(
  1. FunctionType spec,
  2. [StringSink? output]
)

Implementation

@override
StringSink visitFunctionType(FunctionType spec, [StringSink? output]) {
  final out = output ??= StringBuffer();
  if (spec.returnType != null) {
    spec.returnType!.accept(this, out);
    out.write(' ');
  }
  out.write('Function');
  if (spec.types.isNotEmpty) {
    out.write('<');
    visitAll<Reference>(spec.types, out, (spec) {
      spec.accept(this, out);
    });
    out.write('>');
  }
  out.write('(');
  visitAll<Reference>(spec.requiredParameters, out, (spec) {
    spec.accept(this, out);
  });
  if (spec.requiredParameters.isNotEmpty &&
      (spec.optionalParameters.isNotEmpty ||
          spec.namedParameters.isNotEmpty)) {
    out.write(', ');
  }
  if (spec.optionalParameters.isNotEmpty) {
    out.write('[');
    visitAll<Reference>(spec.optionalParameters, out, (spec) {
      spec.accept(this, out);
    });
    out.write(']');
  } else if (spec.namedParameters.isNotEmpty) {
    out.write('{');
    visitAll<String>(spec.namedParameters.keys, out, (name) {
      spec.namedParameters[name]!.accept(this, out);
      out
        ..write(' ')
        ..write(name);
    });
    out.write('}');
  }
  out.write(')');
  if (_useNullSafetySyntax && (spec.isNullable ?? false)) {
    out.write('?');
  }
  return out;
}