diff --git a/lib/src/model/inheriting_container.dart b/lib/src/model/inheriting_container.dart index d37303423c..39f97e9a20 100644 --- a/lib/src/model/inheriting_container.dart +++ b/lib/src/model/inheriting_container.dart @@ -104,10 +104,15 @@ abstract class InheritingContainer extends Container packageGraph.rendererFactory.languageFeatureRenderer) .toList(); - late final List _allModelElements = [ - ...super.allModelElements, - ...typeParameters, - ]; + late final List _allModelElements = () { + _inheritedElementsCache = _inheritedElements; + var result = [ + ...super.allModelElements, + ...typeParameters, + ]; + _inheritedElementsCache = null; + return result; + }(); Iterable get inheritedMethods { var methodNames = declaredMethods.map((m) => m.element.name).toSet(); @@ -144,7 +149,9 @@ abstract class InheritingContainer extends Container late final List publicSuperChain = model_utils.filterNonPublic(superChain).toList(growable: false); + List? _inheritedElementsCache; List get _inheritedElements { + if (_inheritedElementsCache != null) return _inheritedElementsCache!; if (element is ClassElement && (element as ClassElement).isDartCoreObject) { return const []; } @@ -193,7 +200,7 @@ abstract class InheritingContainer extends Container } /// All fields defined on this container, _including inherited fields_. - List get allFields { + late List allFields = () { var inheritedAccessorElements = { ..._inheritedElements.whereType() }; @@ -243,7 +250,7 @@ abstract class InheritingContainer extends Container }); return fields; - } + }(); @override late final List declaredMethods = element.methods diff --git a/lib/src/model/package.dart b/lib/src/model/package.dart index 3fdcdad883..45fafeb994 100644 --- a/lib/src/model/package.dart +++ b/lib/src/model/package.dart @@ -175,7 +175,7 @@ class Package extends LibraryContainer /// Returns the location of documentation for this package, for linkToRemote /// and canonicalization decision making. - DocumentLocation get documentedWhere { + late DocumentLocation documentedWhere = () { if (isLocal && isPublic) { return DocumentLocation.local; } @@ -186,7 +186,7 @@ class Package extends LibraryContainer return DocumentLocation.remote; } return DocumentLocation.missing; - } + }(); @override String get enclosingName => packageGraph.defaultPackageName;