Skip to content

Commit 1abe7fd

Browse files
authored
Merge pull request #2783 from jcollins-g/nnbd-more-migrations
Migrate a few more peripheral libraries to NNBD
2 parents e02a1cf + c33b4f7 commit 1abe7fd

File tree

5 files changed

+45
-62
lines changed

5 files changed

+45
-62
lines changed

lib/src/experiment_options.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
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-
75
///
86
/// Implementation of Dart language experiment option handling for dartdoc.
97
/// See https://github.com/dart-lang/sdk/blob/main/docs/process/experimental-flags.md.
@@ -30,7 +28,6 @@ Future<List<DartdocOption<Object>>> createExperimentOptions(
3028
'enable-experiment', ['non-nullable'], resourceProvider,
3129
help: 'Enable or disable listed experiments.\n' +
3230
ExperimentStatus.knownFeatures.values
33-
.where((e) => e.documentation != null)
3431
.map((e) =>
3532
' [no-]${e.enableString}: ${e.documentation} (default: ${e.isEnabledByDefault})')
3633
.join('\n')),

lib/src/generator/generator.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
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-
75
/// A library containing an abstract documentation generator.
86
library dartdoc.generator;
97

@@ -45,7 +43,7 @@ abstract class Generator {
4543
Future<void> generate(PackageGraph packageGraph, FileWriter writer);
4644
}
4745

48-
Future<List<DartdocOption<Object>>> createGeneratorOptions(
46+
Future<List<DartdocOption>> createGeneratorOptions(
4947
PackageMetaProvider packageMetaProvider) async {
5048
var resourceProvider = packageMetaProvider.resourceProvider;
5149
return [
@@ -73,16 +71,16 @@ Future<List<DartdocOption<Object>>> createGeneratorOptions(
7371
'Generates `index.json` with indentation and newlines. The file is '
7472
'larger, but it\'s also easier to diff.',
7573
negatable: false),
76-
DartdocOptionArgFile<String>('favicon', null, resourceProvider,
74+
DartdocOptionArgFile<String?>('favicon', null, resourceProvider,
7775
optionIs: OptionKind.file,
7876
help: 'A path to a favicon for the generated docs.',
7977
mustExist: true),
80-
DartdocOptionArgOnly<String>('relCanonicalPrefix', null, resourceProvider,
78+
DartdocOptionArgOnly<String?>('relCanonicalPrefix', null, resourceProvider,
8179
help:
8280
'If provided, add a rel="canonical" prefixed with provided value. '
8381
'Consider using if building many versions of the docs for public '
8482
'SEO; learn more at https://goo.gl/gktN6F.'),
85-
DartdocOptionArgOnly<String>('templatesDir', null, resourceProvider,
83+
DartdocOptionArgOnly<String?>('templatesDir', null, resourceProvider,
8684
optionIs: OptionKind.dir,
8785
mustExist: true,
8886
hide: true,

lib/src/source_linker.dart

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,31 @@
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-
75
/// A library for getting external source code links for Dartdoc.
86
library dartdoc.source_linker;
97

108
import 'package:analyzer/file_system/file_system.dart';
119
import 'package:dartdoc/src/dartdoc_options.dart';
1210
import 'package:dartdoc/src/model/model.dart';
13-
import 'package:meta/meta.dart';
1411
import 'package:path/path.dart' as path;
1512

1613
final _uriTemplateRegExp = RegExp(r'(%[frl]%)');
17-
@Deprecated('Public variable intended to be private; will be removed as early '
18-
'as Dartdoc 1.0.0')
19-
RegExp get uriTemplateRegexp => _uriTemplateRegExp;
2014

2115
abstract class SourceLinkerOptionContext implements DartdocOptionContextBase {
2216
List<String> get linkToSourceExcludes =>
2317
optionSet['linkToSource']['excludes'].valueAt(context);
2418

25-
String get linkToSourceRevision =>
19+
String? get linkToSourceRevision =>
2620
optionSet['linkToSource']['revision'].valueAt(context);
2721

28-
String get linkToSourceRoot =>
22+
String? get linkToSourceRoot =>
2923
optionSet['linkToSource']['root'].valueAt(context);
3024

31-
String get linkToSourceUriTemplate =>
25+
String? get linkToSourceUriTemplate =>
3226
optionSet['linkToSource']['uriTemplate'].valueAt(context);
3327
}
3428

35-
Future<List<DartdocOption<Object>>> createSourceLinkerOptions(
29+
Future<List<DartdocOption<Object?>>> createSourceLinkerOptions(
3630
ResourceProvider resourceProvider) async {
3731
return [
3832
DartdocOptionSet('linkToSource', resourceProvider)
@@ -42,13 +36,13 @@ Future<List<DartdocOption<Object>>> createSourceLinkerOptions(
4236
help:
4337
'A list of directories to exclude from linking to a source code repository.'),
4438
// TODO(jcollins-g): Use [DartdocOptionArgSynth], possibly in combination with a repository type and the root directory, and get revision number automatically
45-
DartdocOptionArgOnly<String>('revision', null, resourceProvider,
39+
DartdocOptionArgOnly<String?>('revision', null, resourceProvider,
4640
help: 'Revision number to insert into the URI.'),
47-
DartdocOptionArgFile<String>('root', null, resourceProvider,
41+
DartdocOptionArgFile<String?>('root', null, resourceProvider,
4842
optionIs: OptionKind.dir,
4943
help:
5044
'Path to a local directory that is the root of the repository we link to. All source code files under this directory will be linked.'),
51-
DartdocOptionArgFile<String>('uriTemplate', null, resourceProvider,
45+
DartdocOptionArgFile<String?>('uriTemplate', null, resourceProvider,
5246
help:
5347
'''Substitute into this template to generate a uri for an element's source code.
5448
Dartdoc dynamically substitutes the following fields into the template:
@@ -63,16 +57,16 @@ class SourceLinker {
6357
final List<String> excludes;
6458
final int lineNumber;
6559
final String sourceFileName;
66-
final String revision;
67-
final String root;
68-
final String uriTemplate;
60+
final String? revision;
61+
final String? root;
62+
final String? uriTemplate;
6963

7064
/// Most users of this class should use the [SourceLinker.fromElement] factory
7165
/// instead. This constructor is public for testing.
7266
SourceLinker(
73-
{@required this.excludes,
74-
this.lineNumber,
75-
this.sourceFileName,
67+
{required this.excludes,
68+
required this.lineNumber,
69+
required this.sourceFileName,
7670
this.revision,
7771
this.root,
7872
this.uriTemplate}) {
@@ -81,7 +75,10 @@ class SourceLinker {
8175
throw DartdocOptionError(
8276
'linkToSource root and uriTemplate must both be specified to generate repository links');
8377
}
84-
if (uriTemplate.contains('%r%') && revision == null) {
78+
var uriTemplateValue = uriTemplate;
79+
if (uriTemplateValue != null &&
80+
uriTemplateValue.contains('%r%') &&
81+
revision == null) {
8582
throw DartdocOptionError(
8683
r'%r% specified in uriTemplate, but no revision available');
8784
}
@@ -104,7 +101,9 @@ class SourceLinker {
104101
}
105102

106103
String href() {
107-
if (sourceFileName == null || root == null || uriTemplate == null) {
104+
var root = this.root;
105+
var uriTemplate = this.uriTemplate;
106+
if (root == null || uriTemplate == null) {
108107
return '';
109108
}
110109
if (!path.isWithin(root, sourceFileName) ||
@@ -118,15 +117,12 @@ class SourceLinker {
118117
var urlContext = path.Context(style: path.Style.url);
119118
return urlContext
120119
.joinAll(path.split(path.relative(sourceFileName, from: root)));
121-
break;
122120
case '%r%':
123-
return revision;
124-
break;
121+
return revision!;
125122
case '%l%':
126123
return lineNumber.toString();
127-
break;
128124
default:
129-
return null;
125+
return '';
130126
}
131127
});
132128
}

lib/src/tool_definition.dart

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
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-
75
import 'dart:async';
86

97
import 'package:analyzer/file_system/file_system.dart';
108
import 'package:dartdoc/src/dartdoc_options.dart';
119
import 'package:dartdoc/src/io_utils.dart';
1210
import 'package:dartdoc/src/tool_runner.dart';
13-
import 'package:meta/meta.dart';
1411
import '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;
1916
class 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 {
258249
class 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
}

test/source_linker_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ void main() {
5353
excludes: [],
5454
lineNumber: 20,
5555
revision: '12345',
56+
sourceFileName: 'path/to/file.dart',
5657
).href();
5758
expect(sourceLinkerHref, throwsA(TypeMatcher<DartdocOptionError>()));
5859
});

0 commit comments

Comments
 (0)