diff --git a/lib/src/model/accessor.dart b/lib/src/model/accessor.dart index b821f80a40..8f0c4e3f15 100644 --- a/lib/src/model/accessor.dart +++ b/lib/src/model/accessor.dart @@ -16,7 +16,6 @@ import 'package:dartdoc/src/warnings.dart'; /// Getters and setters. class Accessor extends ModelElement { - @override final PropertyAccessorElement element; @@ -105,7 +104,7 @@ class Accessor extends ModelElement { void warn( PackageWarning kind, { String? message, - Iterable referredFrom = const [], + Iterable referredFrom = const [], Iterable extendedDebug = const [], }) { enclosingCombo.warn(kind, diff --git a/lib/src/model/canonicalization.dart b/lib/src/model/canonicalization.dart index d222c65d62..e963b43505 100644 --- a/lib/src/model/canonicalization.dart +++ b/lib/src/model/canonicalization.dart @@ -203,7 +203,7 @@ final class _Canonicalization { } } -/// A pattern that can split [Locatable.location] strings. +/// A pattern that can split [HasLocation.location] strings. final _locationSplitter = RegExp(r'(package:|[\\/;.])'); /// This class represents the score for a particular element; how likely diff --git a/lib/src/model/category.dart b/lib/src/model/category.dart index 3c4caf34f8..21045f1286 100644 --- a/lib/src/model/category.dart +++ b/lib/src/model/category.dart @@ -16,7 +16,6 @@ class Category Nameable, Warnable, CommentReferable, - Locatable, MarkdownFileDocumentation, LibraryContainer, TopLevelContainer @@ -96,7 +95,7 @@ class Category PackageGraph get packageGraph => package.packageGraph; @override - List get documentationFrom => [this]; + List get documentationFrom => [this]; @override DocumentLocation get documentedWhere => package.documentedWhere; diff --git a/lib/src/model/documentation_comment.dart b/lib/src/model/documentation_comment.dart index 2385e74c59..00941cd160 100644 --- a/lib/src/model/documentation_comment.dart +++ b/lib/src/model/documentation_comment.dart @@ -39,7 +39,7 @@ final _htmlInjectRegExp = RegExp(r'([a-f0-9]+)'); /// [_processCommentWithoutTools] and [processComment] are the primary /// entrypoints. mixin DocumentationComment - implements Documentable, Warnable, Locatable, SourceCode { + implements Documentable, Warnable, HasLocation, SourceCode { @override Element get element; diff --git a/lib/src/model/locatable.dart b/lib/src/model/locatable.dart index bc9b529d5d..fddda1db5e 100644 --- a/lib/src/model/locatable.dart +++ b/lib/src/model/locatable.dart @@ -5,7 +5,7 @@ import 'package:dartdoc/src/model/model.dart'; /// Something that can be located for warning purposes. -mixin Locatable { +abstract interface class HasLocation { /// The [Locatable](s) from which we will get documentation. /// /// Can be more than one if this is a [Field] composing documentation from @@ -13,11 +13,7 @@ mixin Locatable { /// /// This will walk up the inheritance hierarchy to find docs, if the current /// class doesn't have docs for this element. - List get documentationFrom; - - /// Whether [documentationFrom] contains only one item, `this`. - bool get documentationIsLocal => - documentationFrom.length == 1 && identical(documentationFrom.first, this); + List get documentationFrom; String get fullyQualifiedName; @@ -36,7 +32,7 @@ mixin Locatable { bool get isCanonical; } -extension NullableLocatable on Locatable? { +extension NullableHasLocation on HasLocation? { String get safeWarnableName => this?.fullyQualifiedName.replaceFirst(':', '-') ?? ''; } diff --git a/lib/src/model/model_element.dart b/lib/src/model/model_element.dart index a8bb8f8662..571ab587df 100644 --- a/lib/src/model/model_element.dart +++ b/lib/src/model/model_element.dart @@ -57,14 +57,8 @@ import 'package:path/path.dart' as p show Context; /// ModelElement will reference itself as part of the "wrong" [Library] from the /// public interface perspective. abstract class ModelElement - with - CommentReferable, - Warnable, - Locatable, - Nameable, - SourceCode, - DocumentationComment - implements Comparable, Documentable { + with CommentReferable, Warnable, Nameable, SourceCode, DocumentationComment + implements Comparable, Documentable, HasLocation { // TODO(jcollins-g): This really wants a "member that has a type" class. final Element? _originalMember; final Library _library; diff --git a/lib/src/model/package.dart b/lib/src/model/package.dart index f4dec4758e..8839675c23 100644 --- a/lib/src/model/package.dart +++ b/lib/src/model/package.dart @@ -30,7 +30,7 @@ const String htmlBasePlaceholder = r'%%__HTMLBASE_dartdoc_internal__%%'; /// A [LibraryContainer] that contains [Library] objects related to a particular /// package. class Package extends LibraryContainer - with Nameable, Locatable, Warnable, CommentReferable { + with Nameable, Warnable, CommentReferable { @override final String name; @@ -101,7 +101,7 @@ class Package extends LibraryContainer String? get belowSidebarPath => null; @override - List get documentationFrom => [this]; + List get documentationFrom => [this]; /// Return true if the code has defined non-default categories for libraries /// in this package. diff --git a/lib/src/model/package_graph.dart b/lib/src/model/package_graph.dart index c87e5d32d0..ac590ed21a 100644 --- a/lib/src/model/package_graph.dart +++ b/lib/src/model/package_graph.dart @@ -388,7 +388,7 @@ class PackageGraph with CommentReferable, Nameable { void warnOnElement(Warnable? warnable, PackageWarning kind, {String? message, - Iterable referredFrom = const [], + Iterable referredFrom = const [], Iterable extendedDebug = const []}) { var newEntry = (warnable?.element, kind, message); if (_warnAlreadySeen.contains(newEntry)) { @@ -406,7 +406,7 @@ class PackageGraph with CommentReferable, Nameable { void _warnOnElement(Warnable? warnable, PackageWarning kind, {required String message, - Iterable referredFrom = const [], + Iterable referredFrom = const [], Iterable extendedDebug = const []}) { if (warnable is ModelElement && kind == PackageWarning.ambiguousReexport) { // This sort of warning is only applicable to top level elements. diff --git a/lib/src/validator.dart b/lib/src/validator.dart index 8d87b9e5d7..a5469b8d65 100644 --- a/lib/src/validator.dart +++ b/lib/src/validator.dart @@ -236,7 +236,7 @@ class Validator { String origin, { String? referredFrom, }) { - final referredFromElements = {}; + final referredFromElements = {}; // Make all paths relative to origin. if (path.isWithin(origin, warnOn)) { diff --git a/lib/src/warnings.dart b/lib/src/warnings.dart index 662e1516d0..bcf9fdb354 100644 --- a/lib/src/warnings.dart +++ b/lib/src/warnings.dart @@ -94,13 +94,13 @@ List> createPackageWarningOptions( /// Something that package warnings can be reported on. Optionally associated /// with an analyzer [element]. -mixin Warnable implements CommentReferable, Documentable, Locatable { +mixin Warnable implements CommentReferable, Documentable, HasLocation { Element? get element; void warn( PackageWarning kind, { String? message, - Iterable referredFrom = const [], + Iterable referredFrom = const [], Iterable extendedDebug = const [], }) { packageGraph.warnOnElement(this, kind, @@ -108,6 +108,10 @@ mixin Warnable implements CommentReferable, Documentable, Locatable { referredFrom: referredFrom, extendedDebug: extendedDebug); } + + /// Whether [documentationFrom] contains only one item, `this`. + bool get documentationIsLocal => + documentationFrom.length == 1 && identical(documentationFrom.first, this); } /// The kinds of warnings that can be displayed when documenting a package. @@ -326,7 +330,7 @@ enum PackageWarning implements Comparable { String messageForWarnable(Warnable warnable) => '$_warnablePrefix ${warnable.safeWarnableName}: ${warnable.location}'; - String messageForReferral(Locatable referral) => + String messageForReferral(HasLocation referral) => '$_referredFromPrefix ${referral.safeWarnableName}: ${referral.location}'; }