Skip to content
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

Clean up some sorting, naming, and doc nits #3876

Merged
merged 1 commit into from
Sep 10, 2024
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
22 changes: 11 additions & 11 deletions lib/src/model/accessor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Accessor extends ModelElement {
/// constructor.
// TODO(srawlins): This might be super fragile. This field should somehow be
// initialized by code inside this library.
late GetterSetterCombo enclosingCombo;
late final GetterSetterCombo enclosingCombo;

Accessor(this.element, super.library, super.packageGraph,
{ExecutableMember? super.originalMember});
Expand Down Expand Up @@ -167,12 +167,22 @@ class Accessor extends ModelElement {

/// A getter or setter that is a member of a [Container].
class ContainerAccessor extends Accessor with ContainerMember, Inheritable {
late final Container _enclosingElement;

@override
final bool isInherited;

ContainerAccessor(super.element, super.library, super.packageGraph,
[Container? enclosingElement])
: isInherited = false {
_enclosingElement = enclosingElement ?? super.enclosingElement as Container;
}

ContainerAccessor.inherited(
super.element, super.library, super.packageGraph, this._enclosingElement,
{super.originalMember})
: isInherited = true;

/// The index and values fields are never declared, and must be special cased.
bool get _isEnumSynthetic =>
enclosingCombo is EnumField && (name == 'index' || name == 'values');
Expand All @@ -186,19 +196,9 @@ class ContainerAccessor extends Accessor with ContainerMember, Inheritable {
return super.characterLocation;
}

late final Container _enclosingElement;

@override
final bool isInherited;

@override
bool get isCovariant => isSetter && parameters.first.isCovariant;

ContainerAccessor.inherited(
super.element, super.library, super.packageGraph, this._enclosingElement,
{super.originalMember})
: isInherited = true;

@override
Container get enclosingElement => _enclosingElement;

Expand Down
5 changes: 2 additions & 3 deletions lib/src/model/inheritable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ import 'package:dartdoc/src/special_elements.dart';
/// place in the documentation, and we pick a canonical class because that's
/// the one in the public namespace that will be documented.
mixin Inheritable on ContainerMember {
/// True if this [Inheritable] is inherited from a different class.
/// Whether this is inherited from a different class or mixin.
bool get isInherited;

/// True if this [Inheritable] has a parameter whose type is overridden
/// by a subtype.
/// Whether this has a parameter whose type is overridden by a subtype.
bool get isCovariant;

@override
Expand Down
27 changes: 14 additions & 13 deletions lib/src/model/package_graph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -771,20 +771,21 @@ class PackageGraph with CommentReferable, Nameable {
findCanonicalModelElementFor(preferredClass) as Container?;
if (canonicalClass != null) preferredClass = canonicalClass;
}
var lib = modelElement.canonicalLibrary;
if (modelElement is Library) return lib;
var library = modelElement.canonicalLibrary;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I like full names :-)

if (modelElement is Library) return library;

if (lib == null && preferredClass != null) {
lib = preferredClass.canonicalLibrary;
if (library == null && preferredClass != null) {
library = preferredClass.canonicalLibrary;
}
// For elements defined in extensions, they are canonical.
var enclosingElement = element.enclosingElement3;
if (enclosingElement is ExtensionElement) {
lib ??= getModelForElement(enclosingElement.library) as Library?;
library ??= getModelForElement(enclosingElement.library) as Library?;
// TODO(keertip): Find a better way to exclude members of extensions
// when libraries are specified using the "--include" flag.
if (lib != null && lib.isDocumented) {
return getModelFor(element, lib, enclosingContainer: preferredClass);
if (library != null && library.isDocumented) {
return getModelFor(element, library,
enclosingContainer: preferredClass);
}
}
// TODO(jcollins-g): The data structures should be changed to eliminate
Expand All @@ -796,20 +797,20 @@ class PackageGraph with CommentReferable, Nameable {
modelElement = getModelForElement(declaration);
element = modelElement.element;
canonicalModelElement = _findCanonicalModelElementForAmbiguous(
modelElement, lib,
modelElement, library,
preferredClass: preferredClass as InheritingContainer?);
} else {
if (lib != null) {
if (library != null) {
if (element case PropertyInducingElement(:var getter, :var setter)) {
var getterElement =
getter == null ? null : getModelFor(getter, lib) as Accessor;
getter == null ? null : getModelFor(getter, library) as Accessor;
var setterElement =
setter == null ? null : getModelFor(setter, lib) as Accessor;
setter == null ? null : getModelFor(setter, library) as Accessor;
canonicalModelElement = getModelForPropertyInducingElement(
element, lib,
element, library,
getter: getterElement, setter: setterElement);
} else {
canonicalModelElement = getModelFor(element, lib);
canonicalModelElement = getModelFor(element, library);
}
}
assert(canonicalModelElement is! Inheritable);
Expand Down