blob: 496d62b4ae8c2d6ad3a3397303417f38c60e1465 [file] [log] [blame]
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:dartdoc/src/dartdoc_options.dart';
import 'package:dartdoc/src/model/comment_referable.dart';
import 'package:dartdoc/src/model/model.dart';
import 'package:dartdoc/src/model/model_object_builder.dart';
import 'package:dartdoc/src/render/category_renderer.dart';
import 'package:dartdoc/src/warnings.dart';
/// A subcategory of a package, containing elements tagged with `{@category}`.
class Category extends Nameable
implements Documentable {
/// All libraries in [libraries] must come from [_package].
final Package _package;
Package get package => _package;
final String? _name;
final DartdocOptionContext _config;
DartdocOptionContext get config => _config;
final List<Class> _classes = [];
final List<Extension> _extensions = [];
final List<Enum> _enums = [];
final List<Mixin> _mixins = [];
final List<Class> _exceptions = [];
final List<TopLevelVariable> _constants = [];
final List<TopLevelVariable> _properties = [];
final List<ModelFunction> _functions = [];
final List<Typedef> _typedefs = [];
Category(this._name, this._package, this._config);
void addClass(Class class_) {
if (class_.isErrorOrException) {
} else {
Element? get element => null;
String get name => categoryDefinition.displayName;
String get sortKey => _name ?? '<default>';
List<String> get containerOrder => config.categoryOrder;
String get enclosingName =>;
PackageGraph get packageGraph => package.packageGraph;
Library get canonicalLibrary =>
throw UnimplementedError('Categories can not have associated libraries.');
List<Locatable> get documentationFrom => [this];
DocumentLocation get documentedWhere => package.documentedWhere;
late final bool isDocumented =
documentedWhere != DocumentLocation.missing && documentationFile != null;
String get fullyQualifiedName => name;
String get filePath => 'topics/${fileStructure.fileName}';
String? get href => isCanonical ? '${package.baseHref}$filePath' : null;
String get categoryLabel => _categoryRenderer.renderCategoryLabel(this);
String get linkedName => _categoryRenderer.renderLinkedName(this);
/// The position in the container order for this category.
late final int categoryIndex = package.categories.indexOf(this);
late final CategoryDefinition categoryDefinition =
config.categories.categoryDefinitions[sortKey] ??
CategoryDefinition(_name, null, null);
bool get isCanonical =>
Kind get kind => Kind.topic;
late final File? documentationFile = () {
var documentationMarkdown = categoryDefinition.documentationMarkdown;
if (documentationMarkdown != null) {
return _config.resourceProvider.getFile(documentationMarkdown);
return null;
Iterable<Class> get classes => _classes;
List<TopLevelVariable> get constants => _constants;
List<Enum> get enums => _enums;
Iterable<Class> get exceptions => _exceptions;
List<Extension> get extensions => _extensions;
List<ModelFunction> get functions => _functions;
List<Mixin> get mixins => _mixins;
List<TopLevelVariable> get properties => _properties;
List<Typedef> get typedefs => _typedefs;
CategoryRenderer get _categoryRenderer =>
Map<String, CommentReferable> get referenceChildren => const {};
Iterable<CommentReferable> get referenceParents => const [];