Skip to content

Commit 08756dc

Browse files
authored
Keep default category out of Categorization.categoryNames (#2153)
1 parent 3163f52 commit 08756dc

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

lib/src/model/categorization.dart

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,14 @@ abstract class Categorization implements ModelElement {
4242
return '';
4343
});
4444

45-
if (_categorySet.isEmpty) {
46-
// All objects are in the default category if not specified.
47-
_categorySet.add(null);
48-
}
49-
if (_subCategorySet.isEmpty) {
50-
// All objects are in the default subcategory if not specified.
51-
_subCategorySet.add(null);
52-
}
5345
_categoryNames = _categorySet.toList()..sort();
5446
_subCategoryNames = _subCategorySet.toList()..sort();
5547
_image ??= '';
5648
_samples ??= '';
5749
return rawDocs;
5850
}
5951

60-
bool get hasSubCategoryNames =>
61-
subCategoryNames.length > 1 || subCategoryNames.first != null;
52+
bool get hasSubCategoryNames => subCategoryNames.isNotEmpty;
6253
List<String> _subCategoryNames;
6354

6455
/// Either a set of strings containing all declared subcategories for this symbol,
@@ -70,8 +61,7 @@ abstract class Categorization implements ModelElement {
7061
}
7162

7263
@override
73-
bool get hasCategoryNames =>
74-
categoryNames.length > 1 || categoryNames.first != null;
64+
bool get hasCategoryNames => categoryNames.isNotEmpty;
7565
List<String> _categoryNames;
7666

7767
/// Either a set of strings containing all declared categories for this symbol,

lib/src/model/package.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,13 @@ class Package extends LibraryContainer
270270
_nameToCategory[null] = Category(null, this, config);
271271
for (Categorization c in libraries.expand(
272272
(l) => l.allCanonicalModelElements.whereType<Categorization>())) {
273-
for (String category in c.categoryNames) {
274-
categoryFor(category).addItem(c);
273+
if (c.hasCategoryNames) {
274+
for (String category in c.categoryNames) {
275+
categoryFor(category).addItem(c);
276+
}
277+
} else {
278+
// Add to the default category.
279+
categoryFor(null).addItem(c);
275280
}
276281
}
277282
}

test/dartdoc_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ void main() {
8989
});
9090

9191
test('includeExternal and showUndocumentedCategories', () async {
92-
Class Something = p.allCanonicalModelElements
92+
Class withUndocumentedCategory = p.allCanonicalModelElements
9393
.whereType<Class>()
94-
.firstWhere((ModelElement c) => c.name == 'Something');
95-
expect(Something.isPublic, isTrue);
96-
expect(Something.displayedCategories, isNotEmpty);
94+
.firstWhere((ModelElement c) => c.name == 'UseAnExampleHere');
95+
expect(withUndocumentedCategory.isPublic, isTrue);
96+
expect(withUndocumentedCategory.displayedCategories, isNotEmpty);
9797
});
9898
});
9999

0 commit comments

Comments
 (0)