Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fabf4e3

Browse files
gspencergoogfluttergithubbot
authored andcommittedJan 8, 2020
Reverse the sense of the terms snippet and sample. (flutter#48254)
1 parent dbed575 commit fabf4e3

File tree

156 files changed

+581
-581
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

156 files changed

+581
-581
lines changed
 

‎dartdoc_options.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ dartdoc:
44
# The dev/tools/dartdoc.dart script does this automatically.
55
tools:
66
snippet:
7-
command: ["dev/snippets/lib/main.dart", "--type=application"]
8-
description: "Creates application sample code documentation output from embedded documentation samples."
7+
command: ["dev/snippets/lib/main.dart", "--type=snippet"]
8+
description: "Creates sample code documentation output from embedded documentation samples."
99
sample:
1010
command: ["dev/snippets/lib/main.dart", "--type=sample"]
11-
description: "Creates sample code documentation output from embedded documentation samples."
11+
description: "Creates full application sample code documentation output from embedded documentation samples."
1212
dartpad:
13-
command: ["dev/snippets/lib/main.dart", "--type=application", "--dartpad"]
14-
description: "Creates sample code documentation output from embedded documentation samples and displays it in an embedded DartPad."
13+
command: ["dev/snippets/lib/main.dart", "--type=sample", "--dartpad"]
14+
description: "Creates full application sample code documentation output from embedded documentation samples and displays it in an embedded DartPad."

‎dev/bots/analyze-sample-code.dart

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ class SampleCheckerException implements Exception {
107107
/// error output from the analyzer is parsed for details, and the problem
108108
/// locations are translated back to the source location.
109109
///
110-
/// For snippets, the snippets are generated using the snippets tool, and they
111-
/// are analyzed with the samples. If errors are found in snippets, then the
112-
/// line number of the start of the snippet is given instead of the actual error
113-
/// line, since snippets get reformatted when written, and the line numbers
110+
/// For samples, the samples are generated using the snippets tool, and they
111+
/// are analyzed with the snippets. If errors are found in samples, then the
112+
/// line number of the start of the sample is given instead of the actual error
113+
/// line, since samples get reformatted when written, and the line numbers
114114
/// don't necessarily match. It does, however, print the source of the
115115
/// problematic line.
116116
class SampleChecker {
@@ -209,7 +209,7 @@ class SampleChecker {
209209
Map<String, List<AnalysisError>> errors = <String, List<AnalysisError>>{};
210210
try {
211211
final Map<String, Section> sections = <String, Section>{};
212-
final Map<String, Snippet> snippets = <String, Snippet>{};
212+
final Map<String, Sample> snippets = <String, Sample>{};
213213
_extractSamples(sections, snippets);
214214
errors = _analyze(_tempDirectory, sections, snippets);
215215
} finally {
@@ -242,10 +242,10 @@ class SampleChecker {
242242
/// Creates a name for the snippets tool to use for the snippet ID from a
243243
/// filename and starting line number.
244244
String _createNameFromSource(String prefix, String filename, int start) {
245-
String snippetId = path.split(filename).join('.');
246-
snippetId = path.basenameWithoutExtension(snippetId);
247-
snippetId = '$prefix.$snippetId.$start';
248-
return snippetId;
245+
String sampleId = path.split(filename).join('.');
246+
sampleId = path.basenameWithoutExtension(sampleId);
247+
sampleId = '$prefix.$sampleId.$start';
248+
return sampleId;
249249
}
250250

251251
// Precompiles the snippets tool if _snippetsSnapshotPath isn't set yet, and
@@ -273,42 +273,42 @@ class SampleChecker {
273273
}
274274
}
275275

276-
/// Writes out the given [snippet] to an output file in the [_tempDirectory] and
276+
/// Writes out the given sample to an output file in the [_tempDirectory] and
277277
/// returns the output file.
278-
File _writeSnippet(Snippet snippet) {
278+
File _writeSample(Sample sample) {
279279
// Generate the snippet.
280-
final String snippetId = _createNameFromSource('snippet', snippet.start.filename, snippet.start.line);
281-
final String inputName = '$snippetId.input';
280+
final String sampleId = _createNameFromSource('sample', sample.start.filename, sample.start.line);
281+
final String inputName = '$sampleId.input';
282282
// Now we have a filename like 'lib.src.material.foo_widget.123.dart' for each snippet.
283283
final File inputFile = File(path.join(_tempDirectory.path, inputName))..createSync(recursive: true);
284-
inputFile.writeAsStringSync(snippet.input.join('\n'));
285-
final File outputFile = File(path.join(_tempDirectory.path, '$snippetId.dart'));
284+
inputFile.writeAsStringSync(sample.input.join('\n'));
285+
final File outputFile = File(path.join(_tempDirectory.path, '$sampleId.dart'));
286286
final List<String> args = <String>[
287287
'--output=${outputFile.absolute.path}',
288288
'--input=${inputFile.absolute.path}',
289-
...snippet.args,
289+
...sample.args,
290290
];
291291
if (verbose)
292-
print('Generating snippet for ${snippet.start?.filename}:${snippet.start?.line}');
292+
print('Generating sample for ${sample.start?.filename}:${sample.start?.line}');
293293
final ProcessResult process = _runSnippetsScript(args);
294294
if (verbose)
295295
stderr.write('${process.stderr}');
296296
if (process.exitCode != 0) {
297297
throw SampleCheckerException(
298-
'Unable to create snippet for ${snippet.start.filename}:${snippet.start.line} '
298+
'Unable to create sample for ${sample.start.filename}:${sample.start.line} '
299299
'(using input from ${inputFile.path}):\n${process.stdout}\n${process.stderr}',
300-
file: snippet.start.filename,
301-
line: snippet.start.line,
300+
file: sample.start.filename,
301+
line: sample.start.line,
302302
);
303303
}
304304
return outputFile;
305305
}
306306

307307
/// Extracts the samples from the Dart files in [_flutterPackage], writes them
308-
/// to disk, and adds them to the appropriate [sectionMap] or [snippetMap].
309-
void _extractSamples(Map<String, Section> sectionMap, Map<String, Snippet> snippetMap) {
308+
/// to disk, and adds them to the appropriate [sectionMap] or [sampleMap].
309+
void _extractSamples(Map<String, Section> sectionMap, Map<String, Sample> sampleMap) {
310310
final List<Section> sections = <Section>[];
311-
final List<Snippet> snippets = <Snippet>[];
311+
final List<Sample> samples = <Sample>[];
312312

313313
for (final File file in _listDartFiles(_flutterPackage, recursive: true)) {
314314
final String relativeFilePath = path.relative(file.path, from: _flutterPackage.path);
@@ -334,12 +334,12 @@ class SampleChecker {
334334
throw SampleCheckerException('Snippet section unterminated.', file: relativeFilePath, line: lineNumber);
335335
}
336336
if (_dartDocSampleEndRegex.hasMatch(trimmedLine)) {
337-
snippets.add(
338-
Snippet(
337+
samples.add(
338+
Sample(
339339
start: startLine,
340340
input: block,
341341
args: snippetArgs,
342-
serial: snippets.length,
342+
serial: samples.length,
343343
),
344344
);
345345
snippetArgs = <String>[];
@@ -407,7 +407,7 @@ class SampleChecker {
407407
startLine = Line('', filename: relativeFilePath, line: lineNumber + 1, indent: 3);
408408
inPreamble = true;
409409
} else if (sampleMatch != null) {
410-
inSnippet = sampleMatch != null && (sampleMatch[1] == 'snippet' || sampleMatch[1] == 'dartpad');
410+
inSnippet = sampleMatch != null && (sampleMatch[1] == 'sample' || sampleMatch[1] == 'dartpad');
411411
if (inSnippet) {
412412
startLine = Line(
413413
'',
@@ -425,7 +425,7 @@ class SampleChecker {
425425
inSampleSection = !inSnippet;
426426
} else if (RegExp(r'///\s*#+\s+[Ss]ample\s+[Cc]ode:?$').hasMatch(trimmedLine)) {
427427
throw SampleCheckerException(
428-
"Found deprecated '## Sample code' section: use {@tool sample}...{@end-tool} instead.",
428+
"Found deprecated '## Sample code' section: use {@tool snippet}...{@end-tool} instead.",
429429
file: relativeFilePath,
430430
line: lineNumber,
431431
);
@@ -437,10 +437,10 @@ class SampleChecker {
437437
for (final Section section in sections) {
438438
sectionMap[_writeSection(section).path] = section;
439439
}
440-
for (final Snippet snippet in snippets) {
441-
final File snippetFile = _writeSnippet(snippet);
442-
snippet.contents = snippetFile.readAsLinesSync();
443-
snippetMap[snippetFile.absolute.path] = snippet;
440+
for (final Sample sample in samples) {
441+
final File snippetFile = _writeSample(sample);
442+
sample.contents = snippetFile.readAsLinesSync();
443+
sampleMap[snippetFile.absolute.path] = sample;
444444
}
445445
}
446446

@@ -506,7 +506,7 @@ linter:
506506

507507
/// Writes out a sample section to the disk and returns the file.
508508
File _writeSection(Section section) {
509-
final String sectionId = _createNameFromSource('sample', section.start.filename, section.start.line);
509+
final String sectionId = _createNameFromSource('snippet', section.start.filename, section.start.line);
510510
final File outputFile = File(path.join(_tempDirectory.path, '$sectionId.dart'))..createSync(recursive: true);
511511
final List<Line> mainContents = <Line>[
512512
...headers,
@@ -520,7 +520,7 @@ linter:
520520

521521
/// Invokes the analyzer on the given [directory] and returns the stdout.
522522
List<String> _runAnalyzer(Directory directory) {
523-
print('Starting analysis of samples.');
523+
print('Starting analysis of code samples.');
524524
_createConfigurationFiles(directory);
525525
final ProcessResult result = Process.runSync(
526526
_flutter,
@@ -556,7 +556,7 @@ linter:
556556
Map<String, List<AnalysisError>> _analyze(
557557
Directory directory,
558558
Map<String, Section> sections,
559-
Map<String, Snippet> snippets,
559+
Map<String, Sample> samples,
560560
) {
561561
final List<String> errors = _runAnalyzer(directory);
562562
final Map<String, List<AnalysisError>> analysisErrors = <String, List<AnalysisError>>{};
@@ -587,7 +587,7 @@ linter:
587587
final String line = parts[4];
588588
final String column = parts[5];
589589
final String errorCode = parts[6];
590-
final int lineNumber = int.parse(line, radix: 10) - (isSample ? headerLength : 0);
590+
final int lineNumber = int.parse(line, radix: 10) - (isSnippet ? headerLength : 0);
591591
final int columnNumber = int.parse(column, radix: 10);
592592
if (lineNumber < 0 && errorCode == 'unused_import') {
593593
// We don't care about unused imports.
@@ -621,7 +621,7 @@ linter:
621621
// We don't really care if sample code isn't used!
622622
continue;
623623
}
624-
if (isSnippet) {
624+
if (isSample) {
625625
addAnalysisError(
626626
file,
627627
AnalysisError(
@@ -630,7 +630,7 @@ linter:
630630
message,
631631
errorCode,
632632
null,
633-
snippet: snippets[file.path],
633+
sample: samples[file.path],
634634
),
635635
);
636636
} else {
@@ -794,7 +794,7 @@ class Line {
794794
String toString() => '$filename:$line: $code';
795795
}
796796

797-
/// A class to represent a section of sample code, marked by "{@tool sample}...{@end-tool}".
797+
/// A class to represent a section of sample code, marked by "{@tool snippet}...{@end-tool}".
798798
class Section {
799799
const Section(this.code);
800800
factory Section.combine(List<Section> sections) {
@@ -841,12 +841,12 @@ class Section {
841841
final List<Line> code;
842842
}
843843

844-
/// A class to represent a snippet in the dartdoc comments, marked by
845-
/// "{@tool snippet ...}...{@end-tool}". Snippets are processed separately from
846-
/// regular samples, because they must be injected into templates in order to be
844+
/// A class to represent a sample in the dartdoc comments, marked by
845+
/// "{@tool sample ...}...{@end-tool}". Samples are processed separately from
846+
/// regular snippets, because they must be injected into templates in order to be
847847
/// analyzed.
848-
class Snippet {
849-
Snippet({this.start, List<String> input, List<String> args, this.serial}) {
848+
class Sample {
849+
Sample({this.start, List<String> input, List<String> args, this.serial}) {
850850
this.input = input.toList();
851851
this.args = args.toList();
852852
}
@@ -858,7 +858,7 @@ class Snippet {
858858

859859
@override
860860
String toString() {
861-
final StringBuffer buf = StringBuffer('snippet ${args.join(' ')}\n');
861+
final StringBuffer buf = StringBuffer('sample ${args.join(' ')}\n');
862862
int count = start.line;
863863
for (final String line in input) {
864864
buf.writeln(' ${count.toString().padLeft(4, ' ')}: $line');
@@ -878,23 +878,23 @@ class AnalysisError {
878878
this.message,
879879
this.errorCode,
880880
this.source, {
881-
this.snippet,
881+
this.sample,
882882
});
883883

884884
final int line;
885885
final int column;
886886
final String message;
887887
final String errorCode;
888888
final Line source;
889-
final Snippet snippet;
889+
final Sample sample;
890890

891891
@override
892892
String toString() {
893893
if (source != null) {
894894
return '${source.toStringWithColumn(column)}\n>>> $message ($errorCode)';
895-
} else if (snippet != null) {
896-
return 'In snippet starting at '
897-
'${snippet.start.filename}:${snippet.start.line}:${snippet.contents[line - 1]}\n'
895+
} else if (sample != null) {
896+
return 'In sample starting at '
897+
'${sample.start.filename}:${sample.start.line}:${sample.contents[line - 1]}\n'
898898
'>>> $message ($errorCode)';
899899
} else {
900900
return '<source unknown>:$line:$column\n>>> $message ($errorCode)';

0 commit comments

Comments
 (0)
Please sign in to comment.