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