SourceElement constructor

SourceElement(
  1. SourceElementType type,
  2. String name,
  3. int startPos, {
  4. required File file,
  5. String className = '',
  6. List<SourceLine>? comment,
  7. int startLine = -1,
  8. List<CodeSample>? samples,
  9. bool override = false,
})

A factory constructor for SourceElements.

This uses a factory so that the default for the comment and samples lists can be modifiable lists.

Implementation

factory SourceElement(
  SourceElementType type,
  String name,
  int startPos, {
  required File file,
  String className = '',
  List<SourceLine>? comment,
  int startLine = -1,
  List<CodeSample>? samples,
  bool override = false,
}) {
  comment ??= <SourceLine>[];
  samples ??= <CodeSample>[];
  final List<String> commentLines =
      comment.map<String>((SourceLine line) => line.text).toList();
  final String commentString = commentLines.join('\n');
  return SourceElement._(
    type,
    name,
    startPos,
    file: file,
    className: className,
    comment: comment,
    startLine: startLine,
    samples: samples,
    override: override,
    commentString: commentString,
    commentStringWithoutTools: _getCommentStringWithoutTools(commentString),
    commentStringWithoutCode: _getCommentStringWithoutCode(commentString),
    commentLines: commentLines,
  );
}