docComment property Null safety

String? docComment

The subset of lines in text that are marked as part of the documentation comments by beginning with '///'.

The leading slashes and space on each line is removed. Returns null when there is no documentation comment.


String? get docComment {
  var buffer = StringBuffer();
  for (var line in text.split('\n')) {
    var scanner = StringScanner(line.trim());
    if (!scanner.scan('///')) continue;
    scanner.scan(' ');
  var comment = buffer.toString().trimRight();

  return comment.isNotEmpty ? comment : null;