2
2
// for details. All rights reserved. Use of this source code is governed by a
3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
- // @dart=2.9
6
-
7
5
import 'dart:async' ;
8
6
9
7
import 'package:analyzer/file_system/file_system.dart' ;
10
8
import 'package:dartdoc/src/dartdoc_options.dart' ;
11
9
import 'package:dartdoc/src/io_utils.dart' ;
12
10
import 'package:dartdoc/src/tool_runner.dart' ;
13
- import 'package:meta/meta.dart' ;
14
11
import 'package:path/path.dart' as p show extension;
15
12
16
13
/// 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;
19
16
class ToolDefinition {
20
17
/// A list containing the command and options to be run for this tool. The
21
18
/// 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 .
24
21
final List <String > command;
25
22
26
23
/// A list containing the command and options to setup phase for this tool.
27
24
/// The first argument in the command is the tool executable, and will have
28
25
/// its path evaluated relative to the `dartdoc_options.yaml` location. May
29
26
/// be null or empty, in which case it will be ignored at setup time.
30
- final List <String > setupCommand;
27
+ final List <String >? setupCommand;
31
28
32
29
/// A description of the defined tool. Must not be null.
33
30
final String description;
@@ -46,13 +43,11 @@ class ToolDefinition {
46
43
/// given.
47
44
factory ToolDefinition .fromCommand (
48
45
List <String > command,
49
- List <String > setupCommand,
46
+ List <String >? setupCommand,
50
47
String description,
51
48
ResourceProvider resourceProvider,
52
- {List <String > compileArgs}) {
53
- assert (command != null );
49
+ {List <String >? compileArgs}) {
54
50
assert (command.isNotEmpty);
55
- assert (description != null );
56
51
if (isDartExecutable (command[0 ])) {
57
52
return DartToolDefinition (
58
53
command, setupCommand, description, resourceProvider,
@@ -69,12 +64,11 @@ class ToolDefinition {
69
64
}
70
65
71
66
ToolDefinition (this .command, this .setupCommand, this .description)
72
- : assert (command != null ),
73
- assert (command.isNotEmpty),
74
- assert (description != null );
67
+ : assert (command.isNotEmpty);
75
68
76
69
@override
77
70
String toString () {
71
+ var setupCommand = this .setupCommand;
78
72
final commandString =
79
73
'${this is DartToolDefinition ? '(Dart) ' : '' }"${command .join (' ' )}"' ;
80
74
if (setupCommand == null ) {
@@ -86,7 +80,7 @@ class ToolDefinition {
86
80
}
87
81
88
82
Future <ToolStateForArgs > toolStateForArgs (String toolName, List <String > args,
89
- {@ required ToolErrorCallback toolErrorCallback}) async {
83
+ {required ToolErrorCallback toolErrorCallback}) async {
90
84
var commandPath = args.removeAt (0 );
91
85
return ToolStateForArgs (commandPath, args, null );
92
86
}
@@ -107,7 +101,7 @@ class DartToolDefinition extends ToolDefinition {
107
101
/// built.
108
102
@override
109
103
Future <ToolStateForArgs > toolStateForArgs (String toolName, List <String > args,
110
- {@ required ToolErrorCallback toolErrorCallback}) async {
104
+ {required ToolErrorCallback toolErrorCallback}) async {
111
105
assert (args[0 ] == command.first);
112
106
// Set up flags to create a new snapshot, if needed, and use the first run
113
107
// as the training run.
@@ -135,11 +129,9 @@ class DartToolDefinition extends ToolDefinition {
135
129
} else {
136
130
await snapshot._snapshotValid ();
137
131
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.' );
143
135
} else {
144
136
// replace the first argument with the path to the snapshot.
145
137
args[0 ] = snapshotPath;
@@ -148,11 +140,10 @@ class DartToolDefinition extends ToolDefinition {
148
140
}
149
141
}
150
142
151
- DartToolDefinition (List <String > command, List <String > setupCommand,
143
+ DartToolDefinition (List <String > command, List <String >? setupCommand,
152
144
String description, this ._resourceProvider,
153
145
{this .compileArgs = const []})
154
- : assert (compileArgs != null ),
155
- super (command, setupCommand, description);
146
+ : super (command, setupCommand, description);
156
147
}
157
148
158
149
/// Manages the creation of a single snapshot file in a context where multiple
@@ -238,17 +229,17 @@ class SnapshotCache {
238
229
239
230
_Snapshot getSnapshot (String toolPath) {
240
231
if (snapshots.containsKey (toolPath)) {
241
- return snapshots[toolPath];
232
+ return snapshots[toolPath]! ;
242
233
}
243
234
snapshots[toolPath] =
244
235
_Snapshot (snapshotCache, toolPath, _serial, _resourceProvider);
245
236
_serial++ ;
246
- return snapshots[toolPath];
237
+ return snapshots[toolPath]! ;
247
238
}
248
239
249
240
void dispose () {
250
241
_instances.remove (_resourceProvider);
251
- if (snapshotCache != null && snapshotCache .exists) {
242
+ if (snapshotCache.exists) {
252
243
return snapshotCache.delete ();
253
244
}
254
245
return null ;
@@ -258,7 +249,7 @@ class SnapshotCache {
258
249
class ToolStateForArgs {
259
250
final String commandPath;
260
251
final List <String > args;
261
- final void Function () onProcessComplete;
252
+ final void Function ()? onProcessComplete;
262
253
263
254
ToolStateForArgs (this .commandPath, this .args, this .onProcessComplete);
264
255
}
0 commit comments