Skip to content

Commit 392e2aa

Browse files
authored
Simplify some Container fields only used for sidebar logic. (#3834)
* Rename `isInterface` to `isImplementableInterface`, as that is more accurate. * Rename `isClassOrEnum` to `isInterface`, as _that_ is more accurate. * Remove `isInterfaceOrExtension` as all Containers are either interfaces or extensions; unnecessary. * Remove `isClassOrExtensionType`; this functionality is covered by the existing property, `hasPublicConstructors`.
1 parent 31e110d commit 392e2aa

9 files changed

+105
-137
lines changed

lib/src/generator/templates.aot_renderers_for_html.dart

+52-56
Original file line numberDiff line numberDiff line change
@@ -1694,27 +1694,25 @@ String renderSidebarForContainer<T extends Documentable>(
16941694
buffer.write('''<ol>''');
16951695
var context1 = context0.container;
16961696
buffer.writeln();
1697-
if (context1.isClassOrExtensionType) {
1698-
if (context1.hasPublicConstructors) {
1697+
if (context1.hasPublicConstructors) {
1698+
buffer.writeln();
1699+
buffer.write('''
1700+
<li class="section-title"><a href="''');
1701+
buffer.write(context1.href);
1702+
buffer.write('''#constructors">Constructors</a></li>''');
1703+
var context2 = context1.publicConstructorsSorted;
1704+
for (var context3 in context2) {
16991705
buffer.writeln();
17001706
buffer.write('''
1701-
<li class="section-title"><a href="''');
1702-
buffer.write(context1.href);
1703-
buffer.write('''#constructors">Constructors</a></li>''');
1704-
var context2 = context1.publicConstructorsSorted;
1705-
for (var context3 in context2) {
1706-
buffer.writeln();
1707-
buffer.write('''
1708-
<li><a''');
1709-
if (context3.isDeprecated) {
1710-
buffer.write(''' class="deprecated"''');
1711-
}
1712-
buffer.write(''' href="''');
1713-
buffer.write(context3.href);
1714-
buffer.write('''">''');
1715-
buffer.writeEscaped(context3.shortName);
1716-
buffer.write('''</a></li>''');
1707+
<li><a''');
1708+
if (context3.isDeprecated) {
1709+
buffer.write(''' class="deprecated"''');
17171710
}
1711+
buffer.write(''' href="''');
1712+
buffer.write(context3.href);
1713+
buffer.write('''">''');
1714+
buffer.writeEscaped(context3.shortName);
1715+
buffer.write('''</a></li>''');
17181716
}
17191717
}
17201718
buffer.writeln();
@@ -1736,7 +1734,7 @@ String renderSidebarForContainer<T extends Documentable>(
17361734
}
17371735
}
17381736
buffer.write('\n\n ');
1739-
if (context1.isClassOrEnum) {
1737+
if (context1.isInterface) {
17401738
if (context1.hasPublicInstanceFields) {
17411739
buffer.writeln();
17421740
buffer.write('''
@@ -1862,53 +1860,51 @@ String renderSidebarForContainer<T extends Documentable>(
18621860
}
18631861
}
18641862
buffer.write('\n\n ');
1865-
if (context1.isInterfaceOrExtension) {
1866-
if (context1.hasPublicVariableStaticFields) {
1863+
if (context1.hasPublicVariableStaticFields) {
1864+
buffer.writeln();
1865+
buffer.write('''
1866+
<li class="section-title"><a href="''');
1867+
buffer.write(context1.href);
1868+
buffer.write('''#static-properties">Static properties</a></li>''');
1869+
var context18 = context1.publicVariableStaticFieldsSorted;
1870+
for (var context19 in context18) {
18671871
buffer.writeln();
18681872
buffer.write('''
1869-
<li class="section-title"><a href="''');
1870-
buffer.write(context1.href);
1871-
buffer.write('''#static-properties">Static properties</a></li>''');
1872-
var context18 = context1.publicVariableStaticFieldsSorted;
1873-
for (var context19 in context18) {
1874-
buffer.writeln();
1875-
buffer.write('''
1876-
<li>''');
1877-
buffer.write(context19.linkedName);
1878-
buffer.write('''</li>''');
1879-
}
1873+
<li>''');
1874+
buffer.write(context19.linkedName);
1875+
buffer.write('''</li>''');
18801876
}
1877+
}
1878+
buffer.writeln();
1879+
if (context1.hasPublicStaticMethods) {
18811880
buffer.writeln();
1882-
if (context1.hasPublicStaticMethods) {
1881+
buffer.write('''
1882+
<li class="section-title"><a href="''');
1883+
buffer.write(context1.href);
1884+
buffer.write('''#static-methods">Static methods</a></li>''');
1885+
var context20 = context1.publicStaticMethodsSorted;
1886+
for (var context21 in context20) {
18831887
buffer.writeln();
18841888
buffer.write('''
1885-
<li class="section-title"><a href="''');
1886-
buffer.write(context1.href);
1887-
buffer.write('''#static-methods">Static methods</a></li>''');
1888-
var context20 = context1.publicStaticMethodsSorted;
1889-
for (var context21 in context20) {
1890-
buffer.writeln();
1891-
buffer.write('''
1892-
<li>''');
1893-
buffer.write(context21.linkedName);
1894-
buffer.write('''</li>''');
1895-
}
1889+
<li>''');
1890+
buffer.write(context21.linkedName);
1891+
buffer.write('''</li>''');
18961892
}
1893+
}
1894+
buffer.writeln();
1895+
if (context1.hasPublicConstantFields) {
18971896
buffer.writeln();
1898-
if (context1.hasPublicConstantFields) {
1897+
buffer.write('''
1898+
<li class="section-title"><a href="''');
1899+
buffer.write(context1.href);
1900+
buffer.write('''#constants">Constants</a></li>''');
1901+
var context22 = context1.publicConstantFieldsSorted;
1902+
for (var context23 in context22) {
18991903
buffer.writeln();
19001904
buffer.write('''
1901-
<li class="section-title"><a href="''');
1902-
buffer.write(context1.href);
1903-
buffer.write('''#constants">Constants</a></li>''');
1904-
var context22 = context1.publicConstantFieldsSorted;
1905-
for (var context23 in context22) {
1906-
buffer.writeln();
1907-
buffer.write('''
1908-
<li>''');
1909-
buffer.write(context23.linkedName);
1910-
buffer.write('''</li>''');
1911-
}
1905+
<li>''');
1906+
buffer.write(context23.linkedName);
1907+
buffer.write('''</li>''');
19121908
}
19131909
}
19141910
buffer.writeln();

lib/src/generator/templates.runtime_renderers.dart

+18-32
Original file line numberDiff line numberDiff line change
@@ -1655,12 +1655,12 @@ class _Renderer_Class extends RendererBase<Class> {
16551655
self.renderSimpleVariable(c, remainingNames, 'bool'),
16561656
getBool: (CT_ c) => c.isFinal,
16571657
),
1658-
'isInterface': Property(
1659-
getValue: (CT_ c) => c.isInterface,
1658+
'isImplementableInterface': Property(
1659+
getValue: (CT_ c) => c.isImplementableInterface,
16601660
renderVariable: (CT_ c, Property<CT_> self,
16611661
List<String> remainingNames) =>
16621662
self.renderSimpleVariable(c, remainingNames, 'bool'),
1663-
getBool: (CT_ c) => c.isInterface,
1663+
getBool: (CT_ c) => c.isImplementableInterface,
16641664
),
16651665
'isMixinClass': Property(
16661666
getValue: (CT_ c) => c.isMixinClass,
@@ -2929,20 +2929,6 @@ class _Renderer_Container extends RendererBase<Container> {
29292929
_render_Operator(e, ast, r.template, sink, parent: r));
29302930
},
29312931
),
2932-
'isClassOrEnum': Property(
2933-
getValue: (CT_ c) => c.isClassOrEnum,
2934-
renderVariable: (CT_ c, Property<CT_> self,
2935-
List<String> remainingNames) =>
2936-
self.renderSimpleVariable(c, remainingNames, 'bool'),
2937-
getBool: (CT_ c) => c.isClassOrEnum,
2938-
),
2939-
'isClassOrExtensionType': Property(
2940-
getValue: (CT_ c) => c.isClassOrExtensionType,
2941-
renderVariable: (CT_ c, Property<CT_> self,
2942-
List<String> remainingNames) =>
2943-
self.renderSimpleVariable(c, remainingNames, 'bool'),
2944-
getBool: (CT_ c) => c.isClassOrExtensionType,
2945-
),
29462932
'isEnum': Property(
29472933
getValue: (CT_ c) => c.isEnum,
29482934
renderVariable: (CT_ c, Property<CT_> self,
@@ -2957,12 +2943,12 @@ class _Renderer_Container extends RendererBase<Container> {
29572943
self.renderSimpleVariable(c, remainingNames, 'bool'),
29582944
getBool: (CT_ c) => c.isExtension,
29592945
),
2960-
'isInterfaceOrExtension': Property(
2961-
getValue: (CT_ c) => c.isInterfaceOrExtension,
2946+
'isInterface': Property(
2947+
getValue: (CT_ c) => c.isInterface,
29622948
renderVariable: (CT_ c, Property<CT_> self,
29632949
List<String> remainingNames) =>
29642950
self.renderSimpleVariable(c, remainingNames, 'bool'),
2965-
getBool: (CT_ c) => c.isInterfaceOrExtension,
2951+
getBool: (CT_ c) => c.isInterface,
29662952
),
29672953
'isMixin': Property(
29682954
getValue: (CT_ c) => c.isMixin,
@@ -4392,12 +4378,12 @@ class _Renderer_Enum extends RendererBase<Enum> {
43924378
self.renderSimpleVariable(c, remainingNames, 'bool'),
43934379
getBool: (CT_ c) => c.isBase,
43944380
),
4395-
'isInterface': Property(
4396-
getValue: (CT_ c) => c.isInterface,
4381+
'isImplementableInterface': Property(
4382+
getValue: (CT_ c) => c.isImplementableInterface,
43974383
renderVariable: (CT_ c, Property<CT_> self,
43984384
List<String> remainingNames) =>
43994385
self.renderSimpleVariable(c, remainingNames, 'bool'),
4400-
getBool: (CT_ c) => c.isInterface,
4386+
getBool: (CT_ c) => c.isImplementableInterface,
44014387
),
44024388
'isMixinClass': Property(
44034389
getValue: (CT_ c) => c.isMixinClass,
@@ -5146,12 +5132,12 @@ class _Renderer_ExtensionType extends RendererBase<ExtensionType> {
51465132
self.renderSimpleVariable(c, remainingNames, 'bool'),
51475133
getBool: (CT_ c) => c.isBase,
51485134
),
5149-
'isInterface': Property(
5150-
getValue: (CT_ c) => c.isInterface,
5135+
'isImplementableInterface': Property(
5136+
getValue: (CT_ c) => c.isImplementableInterface,
51515137
renderVariable: (CT_ c, Property<CT_> self,
51525138
List<String> remainingNames) =>
51535139
self.renderSimpleVariable(c, remainingNames, 'bool'),
5154-
getBool: (CT_ c) => c.isInterface,
5140+
getBool: (CT_ c) => c.isImplementableInterface,
51555141
),
51565142
'isMixinClass': Property(
51575143
getValue: (CT_ c) => c.isMixinClass,
@@ -7440,12 +7426,12 @@ class _Renderer_InheritingContainer extends RendererBase<InheritingContainer> {
74407426
self.renderSimpleVariable(c, remainingNames, 'bool'),
74417427
getBool: (CT_ c) => c.isFinal,
74427428
),
7443-
'isInterface': Property(
7444-
getValue: (CT_ c) => c.isInterface,
7429+
'isImplementableInterface': Property(
7430+
getValue: (CT_ c) => c.isImplementableInterface,
74457431
renderVariable: (CT_ c, Property<CT_> self,
74467432
List<String> remainingNames) =>
74477433
self.renderSimpleVariable(c, remainingNames, 'bool'),
7448-
getBool: (CT_ c) => c.isInterface,
7434+
getBool: (CT_ c) => c.isImplementableInterface,
74497435
),
74507436
'isMixinClass': Property(
74517437
getValue: (CT_ c) => c.isMixinClass,
@@ -9811,12 +9797,12 @@ class _Renderer_Mixin extends RendererBase<Mixin> {
98119797
self.renderSimpleVariable(c, remainingNames, 'bool'),
98129798
getBool: (CT_ c) => c.isFinal,
98139799
),
9814-
'isInterface': Property(
9815-
getValue: (CT_ c) => c.isInterface,
9800+
'isImplementableInterface': Property(
9801+
getValue: (CT_ c) => c.isImplementableInterface,
98169802
renderVariable: (CT_ c, Property<CT_> self,
98179803
List<String> remainingNames) =>
98189804
self.renderSimpleVariable(c, remainingNames, 'bool'),
9819-
getBool: (CT_ c) => c.isInterface,
9805+
getBool: (CT_ c) => c.isImplementableInterface,
98209806
),
98219807
'isMixinClass': Property(
98229808
getValue: (CT_ c) => c.isMixinClass,

lib/src/model/class.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class Class extends InheritingContainer with Constructable, MixedInTypes {
6969
bool get isFinal => element.isFinal && !element.isSealed;
7070

7171
@override
72-
bool get isInterface => element.isInterface && !element.isSealed;
72+
bool get isImplementableInterface => element.isInterface && !element.isSealed;
7373

7474
@override
7575
bool get isMixinClass => element.isMixinClass;

lib/src/model/container.dart

+2-13
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,11 @@ abstract class Container extends ModelElement
4040

4141
bool get isExtension => element is ExtensionElement;
4242

43-
/// Whether this is an interface type (class, enum, mixin, extension type) or
44-
/// an extension.
45-
///
46-
/// For templates, interfaces and extensions have much in common despite
47-
/// differing underlying implementations in the analyzer.
48-
bool get isInterfaceOrExtension => element is InterfaceElement || isExtension;
49-
5043
/// Whether this is an enum.
5144
bool get isEnum => element is EnumElement;
5245

53-
/// Whether this is a class or an enum.
54-
bool get isClassOrEnum => element is InterfaceElement;
55-
56-
/// Whether this is a class or an extension type.
57-
bool get isClassOrExtensionType =>
58-
element is ClassElement || element is ExtensionTypeElement;
46+
/// Whether this is an interface (e.g. class, enum, mixin, or extension type).
47+
bool get isInterface => element is InterfaceElement;
5948

6049
/// Whether this is a mixin.
6150
bool get isMixin => element is MixinElement;

lib/src/model/enum.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class Enum extends InheritingContainer with Constructable, MixedInTypes {
5858
bool get isBase => false;
5959

6060
@override
61-
bool get isInterface => false;
61+
bool get isImplementableInterface => false;
6262

6363
@override
6464
bool get isMixinClass => false;

lib/src/model/extension_type.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ExtensionType extends InheritingContainer with Constructable {
3030
bool get isBase => false;
3131

3232
@override
33-
bool get isInterface => false;
33+
bool get isImplementableInterface => false;
3434

3535
@override
3636
bool get isMixinClass => false;

lib/src/model/inheriting_container.dart

+3-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ abstract class InheritingContainer extends Container {
8585
if (isAbstract) ContainerModifier.abstract,
8686
if (isSealed) ContainerModifier.sealed,
8787
if (isBase) ContainerModifier.base,
88-
if (isInterface) ContainerModifier.interface,
88+
if (isImplementableInterface) ContainerModifier.interface,
8989
if (isFinal) ContainerModifier.finalModifier,
9090
if (isMixinClass) ContainerModifier.mixin,
9191
]..sort();
@@ -350,7 +350,8 @@ abstract class InheritingContainer extends Container {
350350
@override
351351
bool get isFinal;
352352

353-
bool get isInterface;
353+
/// Whether this element is a publicly implementable interface.
354+
bool get isImplementableInterface;
354355

355356
bool get isMixinClass;
356357

lib/src/model/mixin.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class Mixin extends InheritingContainer {
6464
bool get isFinal => false;
6565

6666
@override
67-
bool get isInterface => false;
67+
bool get isImplementableInterface => false;
6868

6969
@override
7070

0 commit comments

Comments
 (0)