Skip to content

Commit 056995d

Browse files
authored
Migrate package_meta, io_utils, and utils. (#2760)
* flatten * Review comments
1 parent bcc0043 commit 056995d

File tree

5 files changed

+114
-128
lines changed

5 files changed

+114
-128
lines changed

lib/src/dartdoc_options.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,12 +1388,12 @@ Future<List<DartdocOption>> createDartdocOptions(
13881388
negatable: true),
13891389
// This could be a ArgOnly, but trying to not provide too many ways
13901390
// to set the flutter root.
1391-
DartdocOptionSyntheticOnly<String>(
1392-
'flutterRoot',
1393-
(DartdocSyntheticOption<String> option, Folder dir) => resourceProvider
1394-
.pathContext
1395-
.resolveTildePath(Platform.environment['FLUTTER_ROOT']),
1396-
resourceProvider,
1391+
DartdocOptionSyntheticOnly<String?>('flutterRoot',
1392+
(DartdocSyntheticOption<String?> option, Folder dir) {
1393+
var envFlutterRoot = Platform.environment['FLUTTER_ROOT'];
1394+
if (envFlutterRoot == null) return null;
1395+
return resourceProvider.pathContext.resolveTildePath(envFlutterRoot);
1396+
}, resourceProvider,
13971397
optionIs: OptionKind.dir,
13981398
help: 'Root of the Flutter SDK, specified from environment.',
13991399
mustExist: true),

lib/src/io_utils.dart

Lines changed: 11 additions & 12 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
/// This is a helper library to make working with io easier.
86
library dartdoc.io_utils;
97

@@ -37,16 +35,16 @@ extension PathExtensions on path.Context {
3735
/// Return a resolved path including the home directory in place of tilde
3836
/// references.
3937
String resolveTildePath(String originalPath) {
40-
if (originalPath == null || !originalPath.startsWith('~/')) {
38+
if (!originalPath.startsWith('~/')) {
4139
return originalPath;
4240
}
4341

4442
String homeDir;
4543

4644
if (io.Platform.isWindows) {
47-
homeDir = absolute(io.Platform.environment['USERPROFILE']);
45+
homeDir = absolute(io.Platform.environment['USERPROFILE'] ?? '\'');
4846
} else {
49-
homeDir = absolute(io.Platform.environment['HOME']);
47+
homeDir = absolute(io.Platform.environment['HOME'] ?? '/');
5048
}
5149

5250
return join(homeDir, originalPath.substring(2));
@@ -67,8 +65,7 @@ extension ResourceProviderExtensions on ResourceProvider {
6765
if (this is PhysicalResourceProvider) {
6866
return io.Platform.resolvedExecutable;
6967
} else {
70-
// TODO(srawlins): Return what is needed for tests.
71-
return null;
68+
throw UnimplementedError('resolvedExecutable not implemented');
7269
}
7370
}
7471

@@ -77,8 +74,7 @@ extension ResourceProviderExtensions on ResourceProvider {
7774
var mode = io.File(file.path).statSync().mode;
7875
return (0x1 & ((mode >> 6) | (mode >> 3) | mode)) != 0;
7976
} else {
80-
// TODO(srawlins)
81-
return false;
77+
throw UnimplementedError('isExecutable not implemented');
8278
}
8379
}
8480

@@ -124,8 +120,11 @@ final RegExp newLinePartOfRegexp = RegExp('\npart of ');
124120

125121
typedef TaskQueueClosure<T> = Future<T> Function();
126122

123+
void _defaultOnComplete() {}
124+
127125
class _TaskQueueItem<T> {
128-
_TaskQueueItem(this._closure, this._completer, {this.onComplete});
126+
_TaskQueueItem(this._closure, this._completer,
127+
{this.onComplete = _defaultOnComplete});
129128

130129
final TaskQueueClosure<T> _closure;
131130
final Completer<T> _completer;
@@ -137,7 +136,7 @@ class _TaskQueueItem<T> {
137136
} catch (e) {
138137
_completer.completeError(e);
139138
} finally {
140-
onComplete?.call();
139+
onComplete.call();
141140
}
142141
}
143142
}
@@ -150,7 +149,7 @@ class TaskQueue<T> {
150149
/// Creates a task queue with a maximum number of simultaneous jobs.
151150
/// The [maxJobs] parameter defaults to the number of CPU cores on the
152151
/// system.
153-
TaskQueue({int maxJobs})
152+
TaskQueue({int? maxJobs})
154153
: maxJobs = maxJobs ?? io.Platform.numberOfProcessors;
155154

156155
/// The maximum number of jobs that this queue will run simultaneously.

lib/src/model/accessor.dart

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class Accessor extends ModelElement implements EnclosedElement {
7676

7777
@override
7878
String computeDocumentationComment() {
79+
String docComment;
7980
if (isSynthetic) {
8081
// If we're a setter, only display something if we have something different than the getter.
8182
// TODO(jcollins-g): modify analyzer to do this itself?
@@ -85,12 +86,17 @@ class Accessor extends ModelElement implements EnclosedElement {
8586
definingCombo.hasGetter &&
8687
definingCombo.getter.documentationComment !=
8788
definingCombo.documentationComment)) {
88-
return stripComments(definingCombo.documentationComment);
89+
docComment = definingCombo.documentationComment;
8990
} else {
90-
return '';
91+
docComment = '';
9192
}
93+
} else {
94+
docComment = super.computeDocumentationComment();
95+
}
96+
if (docComment != null) {
97+
return stripComments(docComment);
9298
}
93-
return stripComments(super.computeDocumentationComment());
99+
return null;
94100
}
95101

96102
@override

0 commit comments

Comments
 (0)