Skip to content

Commit 0599437

Browse files
authored
Cleanup categorization to simplify template generation migration (#2875)
1 parent c573859 commit 0599437

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

lib/src/model/categorization.dart

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
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+
import 'package:collection/collection.dart';
56
import 'package:dartdoc/src/model/model.dart';
67

78
final RegExp _categoryRegExp = RegExp(
@@ -49,23 +50,23 @@ abstract class Categorization implements ModelElement {
4950
return rawDocs;
5051
}
5152

52-
bool get hasSubCategoryNames => subCategoryNames!.isNotEmpty;
53+
bool get hasSubCategoryNames => subCategoryNames?.isNotEmpty ?? false;
5354
List<String>? _subCategoryNames;
5455

5556
/// 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.
5758
List<String>? get subCategoryNames {
5859
// TODO(jcollins-g): avoid side-effect dependency
5960
if (_subCategoryNames == null) documentationLocal;
6061
return _subCategoryNames;
6162
}
6263

6364
@override
64-
bool get hasCategoryNames => categoryNames!.isNotEmpty;
65+
bool get hasCategoryNames => categoryNames?.isNotEmpty ?? false;
6566
List<String>? _categoryNames;
6667

6768
/// 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.
6970
List<String>? get categoryNames {
7071
// TODO(jcollins-g): avoid side-effect dependency
7172
if (_categoryNames == null) documentationLocal;
@@ -75,40 +76,42 @@ abstract class Categorization implements ModelElement {
7576
bool get hasImage => image!.isNotEmpty;
7677
String? _image;
7778

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.
8081
String? get image {
8182
// TODO(jcollins-g): avoid side-effect dependency
8283
if (_image == null) documentationLocal;
8384
return _image;
8485
}
8586

86-
bool get hasSamples => samples!.isNotEmpty;
87+
bool get hasSamples => samples?.isNotEmpty ?? false;
8788
String? _samples;
8889

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.
9192
String? get samples {
9293
// TODO(jcollins-g): avoid side-effect dependency
9394
if (_samples == null) documentationLocal;
9495
return _samples;
9596
}
9697

97-
Iterable<Category?>? _categories;
98+
late final Iterable<Category> categories = () {
99+
var categoryNames = this.categoryNames;
100+
if (categoryNames == null) {
101+
return <Category>[];
102+
}
98103

99-
Iterable<Category?> get categories {
100-
_categories ??= categoryNames!
104+
return categoryNames
101105
.map((n) => package?.nameToCategory[n])
102-
.where((c) => c != null)
106+
.whereNotNull()
103107
.toList()
104108
..sort();
105-
return _categories!;
106-
}
109+
}();
107110

108111
@override
109-
Iterable<Category?> get displayedCategories {
112+
Iterable<Category> get displayedCategories {
110113
if (config.showUndocumentedCategories) return categories;
111-
return categories.where((c) => c!.isDocumented);
114+
return categories.where((c) => c.isDocumented);
112115
}
113116

114117
bool? _hasCategorization;
@@ -117,6 +120,6 @@ abstract class Categorization implements ModelElement {
117120
/// declared.
118121
late final bool hasCategorization = () {
119122
if (_hasCategorization == null) documentationLocal;
120-
return _hasCategorization!;
123+
return _hasCategorization ?? false;
121124
}();
122125
}

0 commit comments

Comments
 (0)