parseAndAddAssumptions method

void parseAndAddAssumptions(
  1. Iterable<SourceElement> elements,
  2. File assumptionsFile, {
  3. bool silent = true,
})

Parses the assumptions in the "Examples can assume:" block at the top of the assumptionsFile and adds them to the code samples contained in the given elements iterable.

Implementation

void parseAndAddAssumptions(
  Iterable<SourceElement> elements,
  File assumptionsFile, {
  bool silent = true,
}) {
  final List<SourceLine> assumptions = parseAssumptions(assumptionsFile);
  for (final CodeSample sample in elements
      .expand<CodeSample>((SourceElement element) => element.samples)) {
    if (sample is SnippetSample) {
      sample.assumptions = assumptions;
    }
    sample.metadata.addAll(<String, Object?>{
      'id': '${sample.element}.${sample.index}',
      'element': sample.element,
      'sourcePath': assumptionsFile.path,
      'sourceLine': sample.start.line,
    });
  }
}