From 511c4e0bfccd4aa3d6d4ec256b443df787470baf Mon Sep 17 00:00:00 2001 From: Sigurd Meldgaard Date: Tue, 4 Nov 2025 19:17:10 +0100 Subject: [PATCH] Remove dead code from snippet_generator (#174440) Randomly stumbled on code that seems to no longer have clients. --- dev/snippets/lib/src/snippet_generator.dart | 98 --------------------- 1 file changed, 98 deletions(-) diff --git a/dev/snippets/lib/src/snippet_generator.dart b/dev/snippets/lib/src/snippet_generator.dart index 4bb64f9e266..b432261375c 100644 --- a/dev/snippets/lib/src/snippet_generator.dart +++ b/dev/snippets/lib/src/snippet_generator.dart @@ -92,104 +92,6 @@ class SnippetGenerator { }); } - /// Consolidates all of the snippets and the assumptions into one snippet, in - /// order to create a compilable result. - Iterable consolidateSnippets(List samples, {bool addMarkers = false}) { - if (samples.isEmpty) { - return []; - } - final Iterable snippets = samples.whereType(); - final List snippetLines = [...snippets.first.assumptions]; - for (final SnippetSample sample in snippets) { - parseInput(sample); - snippetLines.addAll(_processBlocks(sample)); - } - return snippetLines; - } - - /// A RegExp that matches a Dart constructor. - static final RegExp _constructorRegExp = RegExp(r'(const\s+)?_*[A-Z][a-zA-Z0-9<>._]*\('); - - /// A serial number so that we can create unique expression names when we - /// generate them. - int _expressionId = 0; - - List _surround(String prefix, Iterable body, String suffix) { - return [ - if (prefix.isNotEmpty) SourceLine(prefix), - ...body, - if (suffix.isNotEmpty) SourceLine(suffix), - ]; - } - - /// Process one block of sample code (the part inside of "```" markers). - /// Splits any sections denoted by "// ..." into separate blocks to be - /// processed separately. Uses a primitive heuristic to make sample blocks - /// into valid Dart code. - List _processBlocks(CodeSample sample) { - final List block = sample.parts - .expand((SkeletonInjection injection) => injection.contents) - .toList(); - if (block.isEmpty) { - return []; - } - return _processBlock(block); - } - - List _processBlock(List block) { - final String firstLine = block.first.text; - if (firstLine.startsWith('new ') || firstLine.startsWith(_constructorRegExp)) { - _expressionId += 1; - return _surround('dynamic expression$_expressionId = ', block, ';'); - } else if (firstLine.startsWith('await ')) { - _expressionId += 1; - return _surround('Future expression$_expressionId() async { ', block, ' }'); - } else if (block.first.text.startsWith('class ') || block.first.text.startsWith('enum ')) { - return block; - } else if ((block.first.text.startsWith('_') || block.first.text.startsWith('final ')) && - block.first.text.contains(' = ')) { - _expressionId += 1; - return _surround('void expression$_expressionId() { ', block.toList(), ' }'); - } else { - final List buffer = []; - int blocks = 0; - SourceLine? subLine; - final List subsections = []; - for (int index = 0; index < block.length; index += 1) { - // Each section of the dart code that is either split by a blank line, or with - // '// ...' is treated as a separate code block. - if (block[index].text.trim().isEmpty || block[index].text == '// ...') { - if (subLine == null) { - continue; - } - blocks += 1; - subsections.addAll(_processBlock(buffer)); - buffer.clear(); - assert(buffer.isEmpty); - subLine = null; - } else if (block[index].text.startsWith('// ')) { - if (buffer.length > 1) { - // don't include leading comments - // so that it doesn't start with "// " and get caught in this again - buffer.add(SourceLine('/${block[index].text}')); - } - } else { - subLine ??= block[index]; - buffer.add(block[index]); - } - } - if (blocks > 0) { - if (subLine != null) { - subsections.addAll(_processBlock(buffer)); - } - // Combine all of the subsections into one section, now that they've been processed. - return subsections; - } else { - return block; - } - } - } - /// Parses the input for the various code and description segments, and /// returns a set of skeleton injections in the order found. List parseInput(CodeSample sample) {