@@ -398,10 +398,10 @@ abstract class DartdocOption<T> {
398
398
399
399
bool get _isDouble => _kDoubleVal is T ;
400
400
401
- DartdocOption < Object > _parent;
401
+ DartdocOption _parent;
402
402
403
403
/// The parent of this DartdocOption, or null if this is the root.
404
- DartdocOption < Object > get parent => _parent;
404
+ DartdocOption get parent => _parent;
405
405
406
406
final Map <String , _YamlFileData > __yamlAtCanonicalPathCache = {};
407
407
@@ -426,18 +426,18 @@ abstract class DartdocOption<T> {
426
426
/// Throw [DartdocFileMissing] with a detailed error message indicating where
427
427
/// the error came from when a file or directory option is missing.
428
428
void _onMissing (
429
- _OptionValueWithContext <Object > valueWithContext, String missingFilename);
429
+ _OptionValueWithContext <T > valueWithContext, String missingFilename);
430
430
431
431
/// Call [_onMissing] for every path that does not exist.
432
- void _validatePaths (_OptionValueWithContext <Object > valueWithContext) {
432
+ void _validatePaths (_OptionValueWithContext <T > valueWithContext) {
433
433
if (! mustExist) return ;
434
434
assert (isDir || isFile);
435
435
List <String > resolvedPaths;
436
436
var value = valueWithContext.value;
437
437
if (value is String ) {
438
- resolvedPaths = [valueWithContext.resolvedValue];
438
+ resolvedPaths = [valueWithContext.resolvedValue as String ];
439
439
} else if (value is List <String >) {
440
- resolvedPaths = valueWithContext.resolvedValue as List ;
440
+ resolvedPaths = valueWithContext.resolvedValue as List < String > ;
441
441
} else if (value is Map <String , String >) {
442
442
resolvedPaths = (valueWithContext.resolvedValue as Map ).values.toList ();
443
443
} else {
@@ -458,7 +458,7 @@ abstract class DartdocOption<T> {
458
458
459
459
/// For a [List<String>] or [String] value, if [isDir] or [isFile] is set,
460
460
/// resolve paths in value relative to canonicalPath.
461
- T _handlePathsInContext (_OptionValueWithContext <Object > valueWithContext) {
461
+ T _handlePathsInContext (_OptionValueWithContext <T > valueWithContext) {
462
462
if (valueWithContext? .value == null || ! (isDir || isFile || isGlob)) {
463
463
return valueWithContext? .value;
464
464
}
@@ -474,15 +474,15 @@ abstract class DartdocOption<T> {
474
474
ArgResults get _argResults => root.__argResults;
475
475
476
476
/// Set the parent of this [DartdocOption] . Do not call more than once.
477
- set parent (DartdocOption < Object > newParent) {
477
+ set parent (DartdocOption newParent) {
478
478
assert (_parent == null );
479
479
_parent = newParent;
480
480
}
481
481
482
482
/// The root [DartdocOption] containing this object, or [this] if the object
483
483
/// has no parent.
484
- DartdocOption < Object > get root {
485
- DartdocOption < Object > p = this ;
484
+ DartdocOption get root {
485
+ DartdocOption p = this ;
486
486
while (p.parent != null ) {
487
487
p = p.parent;
488
488
}
@@ -492,7 +492,7 @@ abstract class DartdocOption<T> {
492
492
/// All object names starting at the root.
493
493
Iterable <String > get keys {
494
494
var keyList = < String > [];
495
- DartdocOption < Object > option = this ;
495
+ DartdocOption option = this ;
496
496
while (option? .name != null ) {
497
497
keyList.add (option.name);
498
498
option = option.parent;
@@ -501,7 +501,7 @@ abstract class DartdocOption<T> {
501
501
}
502
502
503
503
/// Direct children of this node, mapped by name.
504
- final Map <String , DartdocOption < Object > > _children = {};
504
+ final Map <String , DartdocOption > _children = {};
505
505
506
506
/// Return the calculated value of this option, given the directory as
507
507
/// context.
@@ -533,7 +533,7 @@ abstract class DartdocOption<T> {
533
533
resourceProvider.pathContext.basename (element.source.fullName))));
534
534
535
535
/// Adds a DartdocOption to the children of this DartdocOption.
536
- void add (DartdocOption < Object > option) {
536
+ void add (DartdocOption option) {
537
537
if (_children.containsKey (option.name)) {
538
538
throw DartdocOptionError (
539
539
'Tried to add two children with the same name: ${option .name }' );
@@ -547,15 +547,15 @@ abstract class DartdocOption<T> {
547
547
void _onAdd () {}
548
548
549
549
/// Adds a list of dartdoc options to the children of this DartdocOption.
550
- void addAll (Iterable <DartdocOption < Object > > options) => options.forEach (add);
550
+ void addAll (Iterable <DartdocOption > options) => options.forEach (add);
551
551
552
552
/// Get the immediate child of this node named [name] .
553
553
DartdocOption <dynamic > operator [](String name) {
554
554
return _children[name];
555
555
}
556
556
557
557
/// Apply the function [visit] to [this] and all children.
558
- void traverse (void Function (DartdocOption < Object > option) visit) {
558
+ void traverse (void Function (DartdocOption option) visit) {
559
559
visit (this );
560
560
_children.values.forEach ((d) => d.traverse (visit));
561
561
}
@@ -592,7 +592,7 @@ class DartdocOptionFileSynth<T> extends DartdocOption<T>
592
592
593
593
@override
594
594
void _onMissing (
595
- _OptionValueWithContext <Object > valueWithContext, String missingPath) {
595
+ _OptionValueWithContext <T > valueWithContext, String missingPath) {
596
596
if (valueWithContext.definingFile != null ) {
597
597
_onMissingFromFiles (valueWithContext, missingPath);
598
598
} else {
@@ -634,7 +634,7 @@ class DartdocOptionArgSynth<T> extends DartdocOption<T>
634
634
635
635
@override
636
636
void _onMissing (
637
- _OptionValueWithContext <Object > valueWithContext, String missingPath) {
637
+ _OptionValueWithContext <T > valueWithContext, String missingPath) {
638
638
_onMissingFromArgs (valueWithContext, missingPath);
639
639
}
640
640
@@ -689,20 +689,20 @@ abstract class DartdocSyntheticOption<T> implements DartdocOption<T> {
689
689
}
690
690
691
691
@override
692
- void _onMissing (_OptionValueWithContext < Object > valueWithContext,
693
- String missingPath) =>
692
+ void _onMissing (
693
+ _OptionValueWithContext < T > valueWithContext, String missingPath) =>
694
694
_onMissingFromSynthetic (valueWithContext, missingPath);
695
695
696
696
void _onMissingFromSynthetic (
697
- _OptionValueWithContext <Object > valueWithContext, String missingPath) {
697
+ _OptionValueWithContext <T > valueWithContext, String missingPath) {
698
698
var description = 'Synthetic configuration option $name from <internal>' ;
699
699
throw DartdocFileMissing (
700
700
'$description , computed as ${valueWithContext .value }, resolves to '
701
701
'missing path: "$missingPath "' );
702
702
}
703
703
}
704
704
705
- typedef OptionGenerator = Future <List <DartdocOption < Object > >> Function (
705
+ typedef OptionGenerator = Future <List <DartdocOption >> Function (
706
706
PackageMetaProvider );
707
707
708
708
/// A [DartdocOption] that only contains other [DartdocOption] s and is not an
@@ -736,13 +736,13 @@ class DartdocOptionSet extends DartdocOption<void> {
736
736
737
737
/// Since we have no value, [_onMissing] does nothing.
738
738
@override
739
- void _onMissing (_OptionValueWithContext < Object > valueWithContext,
740
- String missingFilename) {}
739
+ void _onMissing (
740
+ _OptionValueWithContext < void > valueWithContext, String missingFilename) {}
741
741
742
742
/// Traverse skips this node, because it doesn't represent a real
743
743
/// configuration object.
744
744
@override
745
- void traverse (void Function (DartdocOption < Object > option) visitor) {
745
+ void traverse (void Function (DartdocOption option) visitor) {
746
746
_children.values.forEach ((d) => d.traverse (visitor));
747
747
}
748
748
}
@@ -817,7 +817,7 @@ class DartdocOptionArgFile<T> extends DartdocOption<T>
817
817
818
818
@override
819
819
void _onMissing (
820
- _OptionValueWithContext <Object > valueWithContext, String missingPath) {
820
+ _OptionValueWithContext <T > valueWithContext, String missingPath) {
821
821
if (valueWithContext.definingFile != null ) {
822
822
_onMissingFromFiles (valueWithContext, missingPath);
823
823
} else {
@@ -889,12 +889,12 @@ abstract class _DartdocFileOption<T> implements DartdocOption<T> {
889
889
String get fieldName => keys.join ('.' );
890
890
891
891
@override
892
- void _onMissing (_OptionValueWithContext < Object > valueWithContext,
893
- String missingPath) =>
892
+ void _onMissing (
893
+ _OptionValueWithContext < T > valueWithContext, String missingPath) =>
894
894
_onMissingFromFiles (valueWithContext, missingPath);
895
895
896
896
void _onMissingFromFiles (
897
- _OptionValueWithContext <Object > valueWithContext, String missingPath) {
897
+ _OptionValueWithContext <T > valueWithContext, String missingPath) {
898
898
var dartdocYaml = resourceProvider.pathContext.join (
899
899
valueWithContext.canonicalDirectoryPath, valueWithContext.definingFile);
900
900
throw DartdocFileMissing ('Field $fieldName from $dartdocYaml , set to '
@@ -916,7 +916,7 @@ abstract class _DartdocFileOption<T> implements DartdocOption<T> {
916
916
T _valueAtFromFiles (Folder dir) {
917
917
var key = resourceProvider.pathContext.canonicalize (dir.path);
918
918
if (! __valueAtFromFiles.containsKey (key)) {
919
- _OptionValueWithContext <Object > valueWithContext;
919
+ _OptionValueWithContext <T > valueWithContext;
920
920
if (parentDirOverridesChild) {
921
921
valueWithContext = _valueAtFromFilesLastFound (dir);
922
922
} else {
@@ -929,8 +929,8 @@ abstract class _DartdocFileOption<T> implements DartdocOption<T> {
929
929
930
930
/// Searches all dartdoc_options files through parent directories, starting at
931
931
/// [dir] , for the option and returns one once found.
932
- _OptionValueWithContext <Object > _valueAtFromFilesFirstFound (Folder folder) {
933
- _OptionValueWithContext <Object > value;
932
+ _OptionValueWithContext <T > _valueAtFromFilesFirstFound (Folder folder) {
933
+ _OptionValueWithContext <T > value;
934
934
for (var dir in folder.withAncestors) {
935
935
value = _valueAtFromFile (dir);
936
936
if (value != null ) break ;
@@ -941,8 +941,8 @@ abstract class _DartdocFileOption<T> implements DartdocOption<T> {
941
941
/// Searches all dartdoc_options files for the option, and returns the value
942
942
/// in the top-most parent directory `dartdoc_options.yaml` file it is
943
943
/// mentioned in.
944
- _OptionValueWithContext <Object > _valueAtFromFilesLastFound (Folder folder) {
945
- _OptionValueWithContext <Object > value;
944
+ _OptionValueWithContext <T > _valueAtFromFilesLastFound (Folder folder) {
945
+ _OptionValueWithContext <T > value;
946
946
for (var dir in folder.withAncestors) {
947
947
var tmpValue = _valueAtFromFile (dir);
948
948
if (tmpValue != null ) value = tmpValue;
@@ -952,7 +952,7 @@ abstract class _DartdocFileOption<T> implements DartdocOption<T> {
952
952
953
953
/// Returns null if not set in the YAML file in this directory (or its
954
954
/// parents).
955
- _OptionValueWithContext <Object > _valueAtFromFile (Folder dir) {
955
+ _OptionValueWithContext <T > _valueAtFromFile (Folder dir) {
956
956
var yamlFileData = _yamlAtDirectory (dir);
957
957
var contextPath = yamlFileData.canonicalDirectoryPath;
958
958
Object yamlData = yamlFileData.data ?? {};
@@ -1083,12 +1083,12 @@ abstract class _DartdocArgOption<T> implements DartdocOption<T> {
1083
1083
}
1084
1084
1085
1085
@override
1086
- void _onMissing (_OptionValueWithContext < Object > valueWithContext,
1087
- String missingPath) =>
1086
+ void _onMissing (
1087
+ _OptionValueWithContext < T > valueWithContext, String missingPath) =>
1088
1088
_onMissingFromArgs (valueWithContext, missingPath);
1089
1089
1090
1090
void _onMissingFromArgs (
1091
- _OptionValueWithContext <Object > valueWithContext, String missingPath) {
1091
+ _OptionValueWithContext <T > valueWithContext, String missingPath) {
1092
1092
throw DartdocFileMissing (
1093
1093
'Argument --$argName , set to ${valueWithContext .value }, resolves to '
1094
1094
'missing path: "$missingPath "' );
@@ -1098,7 +1098,7 @@ abstract class _DartdocArgOption<T> implements DartdocOption<T> {
1098
1098
/// the [argParser] and the working directory from [_directoryCurrent] .
1099
1099
///
1100
1100
/// Throws [UnsupportedError] if [T] is not a supported type.
1101
- _OptionValueWithContext <Object > _valueAtFromArgsWithContext () {
1101
+ _OptionValueWithContext <T > _valueAtFromArgsWithContext () {
1102
1102
if (! _argResults.wasParsed (argName)) return null ;
1103
1103
1104
1104
T retval;
@@ -1217,21 +1217,23 @@ class DartdocOptionContext extends DartdocOptionContextBase
1217
1217
// TODO(jcollins-g): Allow passing in structured data to initialize a
1218
1218
// [DartdocOptionContext]'s arguments instead of having to parse strings
1219
1219
// via optionSet.
1220
- /// If [entity] is null, assume this is the initialization case and use
1221
- /// the inputDir flag to determine the context.
1222
- DartdocOptionContext (
1223
- this .optionSet, Resource resource, ResourceProvider resourceProvider) {
1224
- if (resource == null ) {
1225
- var current = resourceProvider.pathContext.current;
1226
- String inputDir =
1227
- optionSet['inputDir' ].valueAt (resourceProvider.getFolder (current)) ??
1228
- current;
1229
- context = resourceProvider.getFolder (inputDir);
1230
- } else {
1231
- context = resourceProvider.getFolder (resourceProvider.pathContext
1232
- .canonicalize (
1233
- resource is File ? resource.parent2.path : resource.path));
1234
- }
1220
+ DartdocOptionContext (this .optionSet, Resource contextLocation,
1221
+ ResourceProvider resourceProvider) {
1222
+ assert (contextLocation != null );
1223
+ context = resourceProvider.getFolder (resourceProvider.pathContext
1224
+ .canonicalize (contextLocation is File
1225
+ ? contextLocation.parent2.path
1226
+ : contextLocation.path));
1227
+ }
1228
+
1229
+ /// Build a DartdocOptionContext via the 'inputDir' command line option.
1230
+ DartdocOptionContext .fromDefaultContextLocation (
1231
+ this .optionSet, ResourceProvider resourceProvider) {
1232
+ var current = resourceProvider.pathContext.current;
1233
+ String inputDir =
1234
+ optionSet['inputDir' ].valueAt (resourceProvider.getFolder (current)) ??
1235
+ current;
1236
+ context = resourceProvider.getFolder (inputDir);
1235
1237
}
1236
1238
1237
1239
/// Build a DartdocOptionContext from an analyzer element (using its source
@@ -1368,7 +1370,7 @@ class DartdocOptionContext extends DartdocOptionContextBase
1368
1370
1369
1371
/// Instantiate dartdoc's configuration file and options parser with the
1370
1372
/// given command line arguments.
1371
- Future <List <DartdocOption < Object > >> createDartdocOptions (
1373
+ Future <List <DartdocOption >> createDartdocOptions (
1372
1374
PackageMetaProvider packageMetaProvider,
1373
1375
) async {
1374
1376
var resourceProvider = packageMetaProvider.resourceProvider;
0 commit comments