getSampleStats function

SampleStats getSampleStats(
  1. SourceElement element
)

Implementation

SampleStats getSampleStats(SourceElement element) {
  if (element.comment.isEmpty) {
    return const SampleStats();
  }
  final int total = element.sampleCount;
  if (total == 0) {
    return const SampleStats();
  }
  final int dartpads = element.dartpadSampleCount;
  final int snippets = element.snippetCount;
  final int applications = element.applicationSampleCount;
  final String sampleCount = <String>[
    if (snippets > 0) '$snippets snippet${snippets != 1 ? 's' : ''}',
    if (applications > 0)
      '$applications application sample${applications != 1 ? 's' : ''}',
    if (dartpads > 0) '$dartpads dartpad sample${dartpads != 1 ? 's' : ''}'
  ].join(', ');
  final int wordCount = element.wordCount;
  final int lineCount = element.lineCount;
  final int linkCount = element.referenceCount;
  final String description = <String>[
    'Documentation has $wordCount ${wordCount == 1 ? 'word' : 'words'} on ',
    '$lineCount ${lineCount == 1 ? 'line' : 'lines'}',
    if (linkCount > 0 && element.hasSeeAlso) ', ',
    if (linkCount > 0 && !element.hasSeeAlso) ' and ',
    if (linkCount > 0)
      'refers to $linkCount other ${linkCount == 1 ? 'symbol' : 'symbols'}',
    if (linkCount > 0 && element.hasSeeAlso) ', and ',
    if (linkCount == 0 && element.hasSeeAlso) 'and ',
    if (element.hasSeeAlso) 'has a "See also:" section',
    '.',
  ].join();
  return SampleStats(
    totalSamples: total,
    dartpadSamples: dartpads,
    snippetSamples: snippets,
    applicationSamples: applications,
    wordCount: wordCount,
    lineCount: lineCount,
    linkCount: linkCount,
    description: 'Has $sampleCount. $description',
  );
}