visitConstructor method
Implementation
@override
StringSink visitConstructor(Constructor spec, String clazz,
[StringSink? output]) {
output ??= StringBuffer();
spec.docs.forEach(output.writeln);
for (var a in spec.annotations) {
visitAnnotation(a, output);
}
if (spec.external) {
output.write('external ');
}
if (spec.constant) {
output.write('const ');
}
if (spec.factory) {
output.write('factory ');
}
output.write(clazz);
if (spec.name != null) {
output
..write('.')
..write(spec.name);
}
output.write('(');
final hasMultipleParameters =
spec.requiredParameters.length + spec.optionalParameters.length > 1;
if (spec.requiredParameters.isNotEmpty) {
var count = 0;
for (final p in spec.requiredParameters) {
count++;
_visitParameter(p, output);
if (hasMultipleParameters ||
spec.requiredParameters.length != count ||
spec.optionalParameters.isNotEmpty) {
output.write(', ');
}
}
}
if (spec.optionalParameters.isNotEmpty) {
final named = spec.optionalParameters.any((p) => p.named);
if (named) {
output.write('{');
} else {
output.write('[');
}
var count = 0;
for (final p in spec.optionalParameters) {
count++;
_visitParameter(p, output, optional: true, named: named);
if (hasMultipleParameters || spec.optionalParameters.length != count) {
output.write(', ');
}
}
if (named) {
output.write('}');
} else {
output.write(']');
}
}
output.write(')');
if (spec.initializers.isNotEmpty) {
output.write(' : ');
var count = 0;
for (final initializer in spec.initializers) {
count++;
initializer.accept(this, output);
if (count != spec.initializers.length) {
output.write(', ');
}
}
}
if (spec.redirect != null) {
output.write(' = ');
spec.redirect!.type.accept(this, output);
output.write(';');
} else if (spec.body != null) {
if (_isLambdaConstructor(spec)) {
output.write(' => ');
spec.body!.accept(this, output);
output.write(';');
} else {
output.write(' { ');
spec.body!.accept(this, output);
output.write(' }');
}
} else {
output.write(';');
}
output.writeln();
return output;
}