Skip to content

Keep default category out of Categorization.categoryNames #2153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions lib/src/model/categorization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,14 @@ abstract class Categorization implements ModelElement {
return '';
});

if (_categorySet.isEmpty) {
// All objects are in the default category if not specified.
_categorySet.add(null);
}
if (_subCategorySet.isEmpty) {
// All objects are in the default subcategory if not specified.
_subCategorySet.add(null);
}
_categoryNames = _categorySet.toList()..sort();
_subCategoryNames = _subCategorySet.toList()..sort();
_image ??= '';
_samples ??= '';
return rawDocs;
}

bool get hasSubCategoryNames =>
subCategoryNames.length > 1 || subCategoryNames.first != null;
bool get hasSubCategoryNames => subCategoryNames.isNotEmpty;
List<String> _subCategoryNames;

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

@override
bool get hasCategoryNames =>
categoryNames.length > 1 || categoryNames.first != null;
bool get hasCategoryNames => categoryNames.isNotEmpty;
List<String> _categoryNames;

/// Either a set of strings containing all declared categories for this symbol,
Expand Down
9 changes: 7 additions & 2 deletions lib/src/model/package.dart
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,13 @@ class Package extends LibraryContainer
_nameToCategory[null] = Category(null, this, config);
for (Categorization c in libraries.expand(
(l) => l.allCanonicalModelElements.whereType<Categorization>())) {
for (String category in c.categoryNames) {
categoryFor(category).addItem(c);
if (c.hasCategoryNames) {
for (String category in c.categoryNames) {
categoryFor(category).addItem(c);
}
} else {
// Add to the default category.
categoryFor(null).addItem(c);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions test/dartdoc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ void main() {
});

test('includeExternal and showUndocumentedCategories', () async {
Class Something = p.allCanonicalModelElements
Class withUndocumentedCategory = p.allCanonicalModelElements
.whereType<Class>()
.firstWhere((ModelElement c) => c.name == 'Something');
expect(Something.isPublic, isTrue);
expect(Something.displayedCategories, isNotEmpty);
.firstWhere((ModelElement c) => c.name == 'UseAnExampleHere');
expect(withUndocumentedCategory.isPublic, isTrue);
expect(withUndocumentedCategory.displayedCategories, isNotEmpty);
});
});

Expand Down