@@ -107,10 +107,10 @@ class SampleCheckerException implements Exception {
107
107
/// error output from the analyzer is parsed for details, and the problem
108
108
/// locations are translated back to the source location.
109
109
///
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
114
114
/// don't necessarily match. It does, however, print the source of the
115
115
/// problematic line.
116
116
class SampleChecker {
@@ -209,7 +209,7 @@ class SampleChecker {
209
209
Map <String , List <AnalysisError >> errors = < String , List <AnalysisError >> {};
210
210
try {
211
211
final Map <String , Section > sections = < String , Section > {};
212
- final Map <String , Snippet > snippets = < String , Snippet > {};
212
+ final Map <String , Sample > snippets = < String , Sample > {};
213
213
_extractSamples (sections, snippets);
214
214
errors = _analyze (_tempDirectory, sections, snippets);
215
215
} finally {
@@ -242,10 +242,10 @@ class SampleChecker {
242
242
/// Creates a name for the snippets tool to use for the snippet ID from a
243
243
/// filename and starting line number.
244
244
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 ;
249
249
}
250
250
251
251
// Precompiles the snippets tool if _snippetsSnapshotPath isn't set yet, and
@@ -273,42 +273,42 @@ class SampleChecker {
273
273
}
274
274
}
275
275
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
277
277
/// returns the output file.
278
- File _writeSnippet ( Snippet snippet ) {
278
+ File _writeSample ( Sample sample ) {
279
279
// 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' ;
282
282
// Now we have a filename like 'lib.src.material.foo_widget.123.dart' for each snippet.
283
283
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' ));
286
286
final List <String > args = < String > [
287
287
'--output=${outputFile .absolute .path }' ,
288
288
'--input=${inputFile .absolute .path }' ,
289
- ...snippet .args,
289
+ ...sample .args,
290
290
];
291
291
if (verbose)
292
- print ('Generating snippet for ${snippet .start ?.filename }:${snippet .start ?.line }' );
292
+ print ('Generating sample for ${sample .start ?.filename }:${sample .start ?.line }' );
293
293
final ProcessResult process = _runSnippetsScript (args);
294
294
if (verbose)
295
295
stderr.write ('${process .stderr }' );
296
296
if (process.exitCode != 0 ) {
297
297
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 } '
299
299
'(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,
302
302
);
303
303
}
304
304
return outputFile;
305
305
}
306
306
307
307
/// 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 ) {
310
310
final List <Section > sections = < Section > [];
311
- final List <Snippet > snippets = < Snippet > [];
311
+ final List <Sample > samples = < Sample > [];
312
312
313
313
for (final File file in _listDartFiles (_flutterPackage, recursive: true )) {
314
314
final String relativeFilePath = path.relative (file.path, from: _flutterPackage.path);
@@ -334,12 +334,12 @@ class SampleChecker {
334
334
throw SampleCheckerException ('Snippet section unterminated.' , file: relativeFilePath, line: lineNumber);
335
335
}
336
336
if (_dartDocSampleEndRegex.hasMatch (trimmedLine)) {
337
- snippets .add (
338
- Snippet (
337
+ samples .add (
338
+ Sample (
339
339
start: startLine,
340
340
input: block,
341
341
args: snippetArgs,
342
- serial: snippets .length,
342
+ serial: samples .length,
343
343
),
344
344
);
345
345
snippetArgs = < String > [];
@@ -407,7 +407,7 @@ class SampleChecker {
407
407
startLine = Line ('' , filename: relativeFilePath, line: lineNumber + 1 , indent: 3 );
408
408
inPreamble = true ;
409
409
} else if (sampleMatch != null ) {
410
- inSnippet = sampleMatch != null && (sampleMatch[1 ] == 'snippet ' || sampleMatch[1 ] == 'dartpad' );
410
+ inSnippet = sampleMatch != null && (sampleMatch[1 ] == 'sample ' || sampleMatch[1 ] == 'dartpad' );
411
411
if (inSnippet) {
412
412
startLine = Line (
413
413
'' ,
@@ -425,7 +425,7 @@ class SampleChecker {
425
425
inSampleSection = ! inSnippet;
426
426
} else if (RegExp (r'///\s*#+\s+[Ss]ample\s+[Cc]ode:?$' ).hasMatch (trimmedLine)) {
427
427
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." ,
429
429
file: relativeFilePath,
430
430
line: lineNumber,
431
431
);
@@ -437,10 +437,10 @@ class SampleChecker {
437
437
for (final Section section in sections) {
438
438
sectionMap[_writeSection (section).path] = section;
439
439
}
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 ;
444
444
}
445
445
}
446
446
@@ -506,7 +506,7 @@ linter:
506
506
507
507
/// Writes out a sample section to the disk and returns the file.
508
508
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);
510
510
final File outputFile = File (path.join (_tempDirectory.path, '$sectionId .dart' ))..createSync (recursive: true );
511
511
final List <Line > mainContents = < Line > [
512
512
...headers,
@@ -520,7 +520,7 @@ linter:
520
520
521
521
/// Invokes the analyzer on the given [directory] and returns the stdout.
522
522
List <String > _runAnalyzer (Directory directory) {
523
- print ('Starting analysis of samples.' );
523
+ print ('Starting analysis of code samples.' );
524
524
_createConfigurationFiles (directory);
525
525
final ProcessResult result = Process .runSync (
526
526
_flutter,
@@ -556,7 +556,7 @@ linter:
556
556
Map <String , List <AnalysisError >> _analyze (
557
557
Directory directory,
558
558
Map <String , Section > sections,
559
- Map <String , Snippet > snippets ,
559
+ Map <String , Sample > samples ,
560
560
) {
561
561
final List <String > errors = _runAnalyzer (directory);
562
562
final Map <String , List <AnalysisError >> analysisErrors = < String , List <AnalysisError >> {};
@@ -587,7 +587,7 @@ linter:
587
587
final String line = parts[4 ];
588
588
final String column = parts[5 ];
589
589
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 );
591
591
final int columnNumber = int .parse (column, radix: 10 );
592
592
if (lineNumber < 0 && errorCode == 'unused_import' ) {
593
593
// We don't care about unused imports.
@@ -621,7 +621,7 @@ linter:
621
621
// We don't really care if sample code isn't used!
622
622
continue ;
623
623
}
624
- if (isSnippet ) {
624
+ if (isSample ) {
625
625
addAnalysisError (
626
626
file,
627
627
AnalysisError (
@@ -630,7 +630,7 @@ linter:
630
630
message,
631
631
errorCode,
632
632
null ,
633
- snippet : snippets [file.path],
633
+ sample : samples [file.path],
634
634
),
635
635
);
636
636
} else {
@@ -794,7 +794,7 @@ class Line {
794
794
String toString () => '$filename :$line : $code ' ;
795
795
}
796
796
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}".
798
798
class Section {
799
799
const Section (this .code);
800
800
factory Section .combine (List <Section > sections) {
@@ -841,12 +841,12 @@ class Section {
841
841
final List <Line > code;
842
842
}
843
843
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
847
847
/// 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}) {
850
850
this .input = input.toList ();
851
851
this .args = args.toList ();
852
852
}
@@ -858,7 +858,7 @@ class Snippet {
858
858
859
859
@override
860
860
String toString () {
861
- final StringBuffer buf = StringBuffer ('snippet ${args .join (' ' )}\n ' );
861
+ final StringBuffer buf = StringBuffer ('sample ${args .join (' ' )}\n ' );
862
862
int count = start.line;
863
863
for (final String line in input) {
864
864
buf.writeln (' ${count .toString ().padLeft (4 , ' ' )}: $line ' );
@@ -878,23 +878,23 @@ class AnalysisError {
878
878
this .message,
879
879
this .errorCode,
880
880
this .source, {
881
- this .snippet ,
881
+ this .sample ,
882
882
});
883
883
884
884
final int line;
885
885
final int column;
886
886
final String message;
887
887
final String errorCode;
888
888
final Line source;
889
- final Snippet snippet ;
889
+ final Sample sample ;
890
890
891
891
@override
892
892
String toString () {
893
893
if (source != null ) {
894
894
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 '
898
898
'>>> $message ($errorCode )' ;
899
899
} else {
900
900
return '<source unknown>:$line :$column \n >>> $message ($errorCode )' ;
0 commit comments