22// for details. All rights reserved. Use of this source code is governed by a
33// BSD-style license that can be found in the LICENSE file.
44
5- // @dart=2.9
6-
75import 'dart:async' ;
86
97import 'package:analyzer/file_system/file_system.dart' ;
108import 'package:dartdoc/src/dartdoc_options.dart' ;
119import 'package:dartdoc/src/io_utils.dart' ;
1210import 'package:dartdoc/src/tool_runner.dart' ;
13- import 'package:meta/meta.dart' ;
1411import 'package:path/path.dart' as p show extension;
1512
1613/// Defines the attributes of a tool in the options file, corresponding to
@@ -19,15 +16,15 @@ import 'package:path/path.dart' as p show extension;
1916class ToolDefinition {
2017 /// A list containing the command and options to be run for this tool. The
2118 /// first argument in the command is the tool executable, and will have its
22- /// path evaluated relative to the `dartdoc_options.yaml` location. Must not
23- /// be an empty list, or be null .
19+ /// path evaluated relative to the `dartdoc_options.yaml` location. Must
20+ /// not be empty .
2421 final List <String > command;
2522
2623 /// A list containing the command and options to setup phase for this tool.
2724 /// The first argument in the command is the tool executable, and will have
2825 /// its path evaluated relative to the `dartdoc_options.yaml` location. May
2926 /// be null or empty, in which case it will be ignored at setup time.
30- final List <String > setupCommand;
27+ final List <String >? setupCommand;
3128
3229 /// A description of the defined tool. Must not be null.
3330 final String description;
@@ -46,13 +43,11 @@ class ToolDefinition {
4643 /// given.
4744 factory ToolDefinition .fromCommand (
4845 List <String > command,
49- List <String > setupCommand,
46+ List <String >? setupCommand,
5047 String description,
5148 ResourceProvider resourceProvider,
52- {List <String > compileArgs}) {
53- assert (command != null );
49+ {List <String >? compileArgs}) {
5450 assert (command.isNotEmpty);
55- assert (description != null );
5651 if (isDartExecutable (command[0 ])) {
5752 return DartToolDefinition (
5853 command, setupCommand, description, resourceProvider,
@@ -69,12 +64,11 @@ class ToolDefinition {
6964 }
7065
7166 ToolDefinition (this .command, this .setupCommand, this .description)
72- : assert (command != null ),
73- assert (command.isNotEmpty),
74- assert (description != null );
67+ : assert (command.isNotEmpty);
7568
7669 @override
7770 String toString () {
71+ var setupCommand = this .setupCommand;
7872 final commandString =
7973 '${this is DartToolDefinition ? '(Dart) ' : '' }"${command .join (' ' )}"' ;
8074 if (setupCommand == null ) {
@@ -86,7 +80,7 @@ class ToolDefinition {
8680 }
8781
8882 Future <ToolStateForArgs > toolStateForArgs (String toolName, List <String > args,
89- {@ required ToolErrorCallback toolErrorCallback}) async {
83+ {required ToolErrorCallback toolErrorCallback}) async {
9084 var commandPath = args.removeAt (0 );
9185 return ToolStateForArgs (commandPath, args, null );
9286 }
@@ -107,7 +101,7 @@ class DartToolDefinition extends ToolDefinition {
107101 /// built.
108102 @override
109103 Future <ToolStateForArgs > toolStateForArgs (String toolName, List <String > args,
110- {@ required ToolErrorCallback toolErrorCallback}) async {
104+ {required ToolErrorCallback toolErrorCallback}) async {
111105 assert (args[0 ] == command.first);
112106 // Set up flags to create a new snapshot, if needed, and use the first run
113107 // as the training run.
@@ -135,11 +129,9 @@ class DartToolDefinition extends ToolDefinition {
135129 } else {
136130 await snapshot._snapshotValid ();
137131 if (! snapshotFile.exists) {
138- if (toolErrorCallback != null ) {
139- toolErrorCallback (
140- 'Snapshot creation failed for $toolName tool. $snapshotPath does '
141- 'not exist. Will execute tool without snapshot.' );
142- }
132+ toolErrorCallback (
133+ 'Snapshot creation failed for $toolName tool. $snapshotPath does '
134+ 'not exist. Will execute tool without snapshot.' );
143135 } else {
144136 // replace the first argument with the path to the snapshot.
145137 args[0 ] = snapshotPath;
@@ -148,11 +140,10 @@ class DartToolDefinition extends ToolDefinition {
148140 }
149141 }
150142
151- DartToolDefinition (List <String > command, List <String > setupCommand,
143+ DartToolDefinition (List <String > command, List <String >? setupCommand,
152144 String description, this ._resourceProvider,
153145 {this .compileArgs = const []})
154- : assert (compileArgs != null ),
155- super (command, setupCommand, description);
146+ : super (command, setupCommand, description);
156147}
157148
158149/// Manages the creation of a single snapshot file in a context where multiple
@@ -238,17 +229,17 @@ class SnapshotCache {
238229
239230 _Snapshot getSnapshot (String toolPath) {
240231 if (snapshots.containsKey (toolPath)) {
241- return snapshots[toolPath];
232+ return snapshots[toolPath]! ;
242233 }
243234 snapshots[toolPath] =
244235 _Snapshot (snapshotCache, toolPath, _serial, _resourceProvider);
245236 _serial++ ;
246- return snapshots[toolPath];
237+ return snapshots[toolPath]! ;
247238 }
248239
249240 void dispose () {
250241 _instances.remove (_resourceProvider);
251- if (snapshotCache != null && snapshotCache .exists) {
242+ if (snapshotCache.exists) {
252243 return snapshotCache.delete ();
253244 }
254245 return null ;
@@ -258,7 +249,7 @@ class SnapshotCache {
258249class ToolStateForArgs {
259250 final String commandPath;
260251 final List <String > args;
261- final void Function () onProcessComplete;
252+ final void Function ()? onProcessComplete;
262253
263254 ToolStateForArgs (this .commandPath, this .args, this .onProcessComplete);
264255}
0 commit comments