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
+ import 'package:collection/collection.dart' ;
5
6
import 'package:dartdoc/src/model/model.dart' ;
6
7
7
8
final RegExp _categoryRegExp = RegExp (
@@ -49,23 +50,23 @@ abstract class Categorization implements ModelElement {
49
50
return rawDocs;
50
51
}
51
52
52
- bool get hasSubCategoryNames => subCategoryNames! .isNotEmpty;
53
+ bool get hasSubCategoryNames => subCategoryNames? .isNotEmpty ?? false ;
53
54
List <String >? _subCategoryNames;
54
55
55
56
/// Either a set of strings containing all declared subcategories for this symbol,
56
- /// or a set containing Null if none were declared.
57
+ /// or 'null' if none were declared.
57
58
List <String >? get subCategoryNames {
58
59
// TODO(jcollins-g): avoid side-effect dependency
59
60
if (_subCategoryNames == null ) documentationLocal;
60
61
return _subCategoryNames;
61
62
}
62
63
63
64
@override
64
- bool get hasCategoryNames => categoryNames! .isNotEmpty;
65
+ bool get hasCategoryNames => categoryNames? .isNotEmpty ?? false ;
65
66
List <String >? _categoryNames;
66
67
67
68
/// Either a set of strings containing all declared categories for this symbol,
68
- /// or a set containing Null if none were declared.
69
+ /// or 'null' if none were declared.
69
70
List <String >? get categoryNames {
70
71
// TODO(jcollins-g): avoid side-effect dependency
71
72
if (_categoryNames == null ) documentationLocal;
@@ -75,40 +76,42 @@ abstract class Categorization implements ModelElement {
75
76
bool get hasImage => image! .isNotEmpty;
76
77
String ? _image;
77
78
78
- /// Either a URI to a defined image, or the empty string if none
79
- /// was declared.
79
+ /// Either a URI to a defined image,
80
+ /// or 'null' if one was not declared.
80
81
String ? get image {
81
82
// TODO(jcollins-g): avoid side-effect dependency
82
83
if (_image == null ) documentationLocal;
83
84
return _image;
84
85
}
85
86
86
- bool get hasSamples => samples! .isNotEmpty;
87
+ bool get hasSamples => samples? .isNotEmpty ?? false ;
87
88
String ? _samples;
88
89
89
- /// Either a URI to documentation with samples, or the empty string if none
90
- /// was declared.
90
+ /// Either a URI to documentation with samples,
91
+ /// or 'null' if one was not declared.
91
92
String ? get samples {
92
93
// TODO(jcollins-g): avoid side-effect dependency
93
94
if (_samples == null ) documentationLocal;
94
95
return _samples;
95
96
}
96
97
97
- Iterable <Category ?>? _categories;
98
+ late final Iterable <Category > categories = () {
99
+ var categoryNames = this .categoryNames;
100
+ if (categoryNames == null ) {
101
+ return < Category > [];
102
+ }
98
103
99
- Iterable <Category ?> get categories {
100
- _categories ?? = categoryNames!
104
+ return categoryNames
101
105
.map ((n) => package? .nameToCategory[n])
102
- .where ((c) => c != null )
106
+ .whereNotNull ( )
103
107
.toList ()
104
108
..sort ();
105
- return _categories! ;
106
- }
109
+ }();
107
110
108
111
@override
109
- Iterable <Category ? > get displayedCategories {
112
+ Iterable <Category > get displayedCategories {
110
113
if (config.showUndocumentedCategories) return categories;
111
- return categories.where ((c) => c! .isDocumented);
114
+ return categories.where ((c) => c.isDocumented);
112
115
}
113
116
114
117
bool ? _hasCategorization;
@@ -117,6 +120,6 @@ abstract class Categorization implements ModelElement {
117
120
/// declared.
118
121
late final bool hasCategorization = () {
119
122
if (_hasCategorization == null ) documentationLocal;
120
- return _hasCategorization! ;
123
+ return _hasCategorization ?? false ;
121
124
}();
122
125
}
0 commit comments