toString method
A string representation of this object.
Some classes have a default textual representation,
often paired with a static parse
function (like int.parse).
These classes will provide the textual representation as
their string representation.
Other classes have no meaningful textual representation
that a program will care about.
Such classes will typically override toString
to provide
useful information when inspecting the object,
mainly for debugging or logging.
Implementation
@override
String toString() {
final buffer = StringBuffer()
..writeln('This builder requires Dart inputs without syntax errors.')
..writeln('However, ${assetId.uri} (or an existing part) contains the '
'following errors.');
// Avoid generating too much output for syntax errors. The user likely has
// an editor that shows them anyway.
final entries = errorToResult.entries.toList();
for (final errorAndResult in entries.take(_maxErrorsInToString)) {
final error = errorAndResult.key;
// Use a short name: We present the full context by including the asset id
// and this is easier to skim through
final sourceName = error.source.shortName;
final lineInfo = errorAndResult.value.lineInfo;
final position = lineInfo.getLocation(error.offset);
// Output messages like "foo.dart:3:4: Expected a semicolon here."
buffer.writeln(
'$sourceName:${position.lineNumber}:${position.columnNumber}: '
'${error.message}');
}
final additionalErrors = entries.length - _maxErrorsInToString;
if (additionalErrors > 0) {
buffer.writeln('And $additionalErrors more...');
}
buffer.writeln('\nTry fixing the errors and re-running the build.');
return buffer.toString();
}