Skip to content

Commit 17c5e5a

Browse files
authored
Tighten types and visibilities (#3559)
1 parent b947413 commit 17c5e5a

File tree

4 files changed

+29
-67
lines changed

4 files changed

+29
-67
lines changed

lib/src/generator/templates.runtime_renderers.dart

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7589,13 +7589,6 @@ class _Renderer_InheritingContainer extends RendererBase<InheritingContainer> {
75897589
self.renderSimpleVariable(c, remainingNames, 'bool'),
75907590
getBool: (CT_ c) => c.hasModifiers == true,
75917591
),
7592-
'hasPublicInheritedMethods': Property(
7593-
getValue: (CT_ c) => c.hasPublicInheritedMethods,
7594-
renderVariable: (CT_ c, Property<CT_> self,
7595-
List<String> remainingNames) =>
7596-
self.renderSimpleVariable(c, remainingNames, 'bool'),
7597-
getBool: (CT_ c) => c.hasPublicInheritedMethods == true,
7598-
),
75997592
'hasPublicSuperChainReversed': Property(
76007593
getValue: (CT_ c) => c.hasPublicSuperChainReversed,
76017594
renderVariable: (CT_ c, Property<CT_> self,
@@ -7616,18 +7609,6 @@ class _Renderer_InheritingContainer extends RendererBase<InheritingContainer> {
76167609
parent: r));
76177610
},
76187611
),
7619-
'inheritedFields': Property(
7620-
getValue: (CT_ c) => c.inheritedFields,
7621-
renderVariable: (CT_ c, Property<CT_> self,
7622-
List<String> remainingNames) =>
7623-
self.renderSimpleVariable(
7624-
c, remainingNames, 'Iterable<Field>'),
7625-
renderIterable: (CT_ c, RendererBase<CT_> r,
7626-
List<MustachioNode> ast, StringSink sink) {
7627-
return c.inheritedFields.map((e) =>
7628-
_render_Field(e, ast, r.template, sink, parent: r));
7629-
},
7630-
),
76317612
'inheritedMethods': Property(
76327613
getValue: (CT_ c) => c.inheritedMethods,
76337614
renderVariable: (CT_ c, Property<CT_> self,
@@ -7761,18 +7742,6 @@ class _Renderer_InheritingContainer extends RendererBase<InheritingContainer> {
77617742
parent: r);
77627743
},
77637744
),
7764-
'publicInheritedFields': Property(
7765-
getValue: (CT_ c) => c.publicInheritedFields,
7766-
renderVariable: (CT_ c, Property<CT_> self,
7767-
List<String> remainingNames) =>
7768-
self.renderSimpleVariable(
7769-
c, remainingNames, 'Iterable<Field>'),
7770-
renderIterable: (CT_ c, RendererBase<CT_> r,
7771-
List<MustachioNode> ast, StringSink sink) {
7772-
return c.publicInheritedFields.map((e) =>
7773-
_render_Field(e, ast, r.template, sink, parent: r));
7774-
},
7775-
),
77767745
'publicInheritedInstanceFields': Property(
77777746
getValue: (CT_ c) => c.publicInheritedInstanceFields,
77787747
renderVariable: (CT_ c, Property<CT_> self,
@@ -7795,18 +7764,6 @@ class _Renderer_InheritingContainer extends RendererBase<InheritingContainer> {
77957764
getBool: (CT_ c) =>
77967765
c.publicInheritedInstanceOperators == true,
77977766
),
7798-
'publicInheritedMethods': Property(
7799-
getValue: (CT_ c) => c.publicInheritedMethods,
7800-
renderVariable: (CT_ c, Property<CT_> self,
7801-
List<String> remainingNames) =>
7802-
self.renderSimpleVariable(
7803-
c, remainingNames, 'Iterable<Method>'),
7804-
renderIterable: (CT_ c, RendererBase<CT_> r,
7805-
List<MustachioNode> ast, StringSink sink) {
7806-
return c.publicInheritedMethods.map((e) =>
7807-
_render_Method(e, ast, r.template, sink, parent: r));
7808-
},
7809-
),
78107767
'publicInterfaces': Property(
78117768
getValue: (CT_ c) => c.publicInterfaces,
78127769
renderVariable: (CT_ c, Property<CT_> self,

lib/src/model/inheriting_container.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ abstract class InheritingContainer extends Container
287287
hasPublicSuperChainReversed ||
288288
hasPotentiallyApplicableExtensions;
289289

290+
@visibleForTesting
290291
bool get hasPublicInheritedMethods => publicInheritedMethods.isNotEmpty;
291292

292293
bool get hasPublicSuperChainReversed => publicSuperChainReversed.isNotEmpty;
@@ -299,6 +300,7 @@ abstract class InheritingContainer extends Container
299300
/// purposes in abstract classes.
300301
List<InheritingContainer> get inheritanceChain;
301302

303+
@visibleForTesting
302304
Iterable<Field> get inheritedFields => allFields.where((f) => f.isInherited);
303305

304306
@override
@@ -328,6 +330,7 @@ abstract class InheritingContainer extends Container
328330

329331
bool get isSealed;
330332

333+
@visibleForTesting
331334
Iterable<Field> get publicInheritedFields =>
332335
model_utils.filterNonPublic(inheritedFields);
333336

@@ -343,6 +346,7 @@ abstract class InheritingContainer extends Container
343346
bool get publicInheritedInstanceOperators =>
344347
publicInstanceOperators.every((f) => f.isInherited);
345348

349+
@visibleForTesting
346350
Iterable<Method> get publicInheritedMethods =>
347351
model_utils.filterNonPublic(inheritedMethods);
348352

lib/src/model/model_element.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ abstract class ModelElement extends Canonicalization
287287
/// Caches a newly-created [ModelElement] from [ModelElement._from] or
288288
/// [ModelElement._fromPropertyInducingElement].
289289
static void _cacheNewModelElement(
290-
Element e, ModelElement? newModelElement, Library library,
290+
Element e, ModelElement newModelElement, Library library,
291291
{Container? enclosingContainer}) {
292292
// TODO(jcollins-g): Reenable Parameter caching when dart-lang/sdk#30146
293293
// is fixed?
@@ -355,8 +355,8 @@ abstract class ModelElement extends Canonicalization
355355
PropertyAccessorElement e,
356356
Library library,
357357
PackageGraph packageGraph, {
358-
Container? enclosingContainer,
359-
Member? originalMember,
358+
required Container? enclosingContainer,
359+
required Member? originalMember,
360360
}) {
361361
// Accessors can be part of a [Container], or a part of a [Library].
362362
if (e.enclosingElement is ExtensionElement ||

lib/src/model/package_graph.dart

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,8 @@ class PackageGraph with CommentReferable, Nameable, ModelBuilder {
285285

286286
/// All [ModelElement]s constructed for this package; a superset of
287287
/// [_allModelElements].
288-
final Map<(Element element, Library? library, Container? enclosingElement),
289-
ModelElement?> allConstructedModelElements = {};
288+
final Map<(Element element, Library library, Container? enclosingElement),
289+
ModelElement> allConstructedModelElements = {};
290290

291291
/// Anything that might be inheritable, place here for later lookup.
292292
final Map<(Element, Library), Set<ModelElement>> allInheritableElements = {};
@@ -538,7 +538,6 @@ class PackageGraph with CommentReferable, Nameable, ModelBuilder {
538538
if (modelElement is Dynamic) continue;
539539
// TODO: see [Accessor.enclosingCombo]
540540
if (modelElement is Accessor) continue;
541-
if (modelElement == null) continue;
542541
final href = modelElement.href;
543542
if (href == null) continue;
544543

@@ -680,7 +679,7 @@ class PackageGraph with CommentReferable, Nameable, ModelBuilder {
680679
return buffer.toString();
681680
}
682681

683-
final Map<Element?, Library?> _canonicalLibraryFor = {};
682+
final Map<Element, Library?> _canonicalLibraryFor = {};
684683

685684
/// Tries to find a top level library that references this element.
686685
Library? _findCanonicalLibraryFor(Element e) {
@@ -733,8 +732,8 @@ class PackageGraph with CommentReferable, Nameable, ModelBuilder {
733732
lib ??= modelBuilder.fromElement(enclosingElement.library) as Library?;
734733
// TODO(keertip): Find a better way to exclude members of extensions
735734
// when libraries are specified using the "--include" flag.
736-
if (lib?.isDocumented == true) {
737-
return modelBuilder.from(e, lib!);
735+
if (lib != null && lib.isDocumented) {
736+
return modelBuilder.from(e, lib);
738737
}
739738
}
740739
// TODO(jcollins-g): The data structures should be changed to eliminate
@@ -773,20 +772,22 @@ class PackageGraph with CommentReferable, Nameable, ModelBuilder {
773772

774773
ModelElement? _findCanonicalModelElementForAmbiguous(Element e, Library? lib,
775774
{InheritingContainer? preferredClass}) {
776-
var candidates = <ModelElement?>{};
777-
var constructedWithKey = allConstructedModelElements[(e, lib, null)];
778-
if (constructedWithKey != null) {
779-
candidates.add(constructedWithKey);
780-
}
781-
var constructedWithKeyWithClass =
782-
allConstructedModelElements[(e, lib, preferredClass)];
783-
if (constructedWithKeyWithClass != null) {
784-
candidates.add(constructedWithKeyWithClass);
785-
}
786-
if (candidates.isEmpty) {
787-
candidates = {
788-
...?allInheritableElements[(e, lib)]?.where((me) => me.isCanonical),
789-
};
775+
var candidates = <ModelElement>{};
776+
if (lib != null) {
777+
var constructedWithKey = allConstructedModelElements[(e, lib, null)];
778+
if (constructedWithKey != null) {
779+
candidates.add(constructedWithKey);
780+
}
781+
var constructedWithKeyWithClass =
782+
allConstructedModelElements[(e, lib, preferredClass)];
783+
if (constructedWithKeyWithClass != null) {
784+
candidates.add(constructedWithKeyWithClass);
785+
}
786+
if (candidates.isEmpty) {
787+
candidates = {
788+
...?allInheritableElements[(e, lib)]?.where((me) => me.isCanonical),
789+
};
790+
}
790791
}
791792

792793
var canonicalClass = findCanonicalModelElementFor(e.enclosingElement);
@@ -795,7 +796,7 @@ class PackageGraph with CommentReferable, Nameable, ModelBuilder {
795796
.where((m) => m.element == e));
796797
}
797798

798-
var matches = {...candidates.whereNotNull().where((me) => me.isCanonical)};
799+
var matches = {...candidates.where((me) => me.isCanonical)};
799800

800801
// It's possible to find [Accessor]s but no combos. Be sure that if we
801802
// have accessors, we find their combos too.

0 commit comments

Comments
 (0)