Skip to content

Commit

Permalink
Rewrite Library.allOriginalModelElementNames.
Browse files Browse the repository at this point in the history
* This method was public, but only used privately. :(
* This method returned a List, but only one method is ever called on the List:
  `contains`. So, change to a Set.
* This method used `allModelElements`, but that collection contains way too
  many things; it contains things like methods of classes, but in this case we
  are only concerned with direct library members.
  • Loading branch information
srawlins committed Mar 6, 2024
1 parent e8f3633 commit effc8df
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 42 deletions.
12 changes: 0 additions & 12 deletions lib/src/generator/templates.runtime_renderers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8241,18 +8241,6 @@ class _Renderer_Library extends RendererBase<Library> {
parent: r));
},
),
'allOriginalModelElementNames': Property(
getValue: (CT_ c) => c.allOriginalModelElementNames,
renderVariable: (CT_ c, Property<CT_> self,
List<String> remainingNames) =>
self.renderSimpleVariable(
c, remainingNames, 'List<String>'),
renderIterable: (CT_ c, RendererBase<CT_> r,
List<MustachioNode> ast, StringSink sink) {
return c.allOriginalModelElementNames.map((e) =>
_render_String(e, ast, r.template, sink, parent: r));
},
),
'belowSidebarPath': Property(
getValue: (CT_ c) => c.belowSidebarPath,
renderVariable:
Expand Down
73 changes: 43 additions & 30 deletions lib/src/model/library.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,35 +96,6 @@ class Library extends ModelElement

bool get isInSdk => element.isInSdk;

/// [allModelElements] resolved to their original names.
///
/// A collection of [ModelElement.fullyQualifiedName]s for [ModelElement]s
/// documented with this library, but these ModelElements and names correspond
/// to the defining library where each originally came from with respect
/// to inheritance and reexporting. Most useful for error reporting.
late final List<String> allOriginalModelElementNames =
allModelElements.map((e) {
if (e is GetterSetterCombo) {
Accessor? getter;
Accessor? setter;
var elementGetter = e.getter;
if (elementGetter != null) {
getter = getModelForElement(elementGetter.element) as Accessor;
}
var elementSetter = e.setter;
if (elementSetter != null) {
setter = getModelForElement(elementSetter.element) as Accessor;
}
return getModelForPropertyInducingElement(
e.element as PropertyInducingElement,
getModelForElement(e.element.library!) as Library,
getter: getter,
setter: setter)
.fullyQualifiedName;
}
return getModelForElement(e.element).fullyQualifiedName;
}).toList(growable: false);

@override
CharacterLocation? get characterLocation {
if (element.nameOffset == -1) {
Expand Down Expand Up @@ -455,8 +426,9 @@ class Library extends ModelElement
String buildDocumentationAddition(String rawDocs) {
rawDocs = super.buildDocumentationAddition(rawDocs);
var notFoundInAllModelElements = <String>{};
var elementNames = _allOriginalModelElementNames;
for (var elementName in canonicalFor) {
if (!allOriginalModelElementNames.contains(elementName)) {
if (!elementNames.contains(elementName)) {
notFoundInAllModelElements.add(elementName);
}
}
Expand All @@ -467,4 +439,45 @@ class Library extends ModelElement
// canonicalFor?
return rawDocs;
}

/// [allModelElements] resolved to their original names.
///
/// A collection of [ModelElement.fullyQualifiedName]s for [ModelElement]s
/// documented with this library, but these ModelElements and names correspond
/// to the defining library where each originally came from with respect
/// to inheritance and re-exporting. Used for error reporting.
late final Set<String> _allOriginalModelElementNames = () {
// Instead of using `allModelElements`, which includes deeper elements like
// methods on classes, gather up only the library's immediate members.
var libraryMembers = [
...library.extensions,
...library.extensionTypes,
...library.allClasses,
...library.enums,
...library.mixins,
...library.constants,
...library.functions,
...library.properties,
...library.typedefs,
];
return libraryMembers.map((member) {
if (member is! GetterSetterCombo) {
return getModelForElement(member.element).fullyQualifiedName;
}
var getter = switch (member.getter) {
Accessor accessor => getModelForElement(accessor.element) as Accessor,
_ => null,
};
var setter = switch (member.setter) {
Accessor accessor => getModelForElement(accessor.element) as Accessor,
_ => null,
};
return getModelForPropertyInducingElement(
member.element as PropertyInducingElement,
getModelForElement(member.element.library!) as Library,
getter: getter,
setter: setter,
).fullyQualifiedName;
}).toSet();
}();
}

0 comments on commit effc8df

Please sign in to comment.