From 5e2996c8bbe8921d0f47ba31a567aa25c71e4bd9 Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Tue, 13 Aug 2024 10:38:37 -0700 Subject: [PATCH] Simplify some Container fields only used for sidebar logic. * 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`. --- .../templates.aot_renderers_for_html.dart | 108 +++++++++--------- .../templates.runtime_renderers.dart | 50 +++----- lib/src/model/class.dart | 2 +- lib/src/model/container.dart | 15 +-- lib/src/model/enum.dart | 2 +- lib/src/model/extension_type.dart | 2 +- lib/src/model/inheriting_container.dart | 5 +- lib/src/model/mixin.dart | 2 +- lib/templates/_sidebar_for_container.html | 56 +++++---- 9 files changed, 105 insertions(+), 137 deletions(-) diff --git a/lib/src/generator/templates.aot_renderers_for_html.dart b/lib/src/generator/templates.aot_renderers_for_html.dart index 2663dd84d2..a3983e40c7 100644 --- a/lib/src/generator/templates.aot_renderers_for_html.dart +++ b/lib/src/generator/templates.aot_renderers_for_html.dart @@ -1694,27 +1694,25 @@ String renderSidebarForContainer( buffer.write('''
    '''); var context1 = context0.container; buffer.writeln(); - if (context1.isClassOrExtensionType) { - if (context1.hasPublicConstructors) { + if (context1.hasPublicConstructors) { + buffer.writeln(); + buffer.write(''' +
  1. Constructors
  2. '''); + var context2 = context1.publicConstructorsSorted; + for (var context3 in context2) { buffer.writeln(); buffer.write(''' -
  3. Constructors
  4. '''); - var context2 = context1.publicConstructorsSorted; - for (var context3 in context2) { - buffer.writeln(); - buffer.write(''' -
  5. '''); - buffer.writeEscaped(context3.shortName); - buffer.write('''
  6. '''); +
  7. '''); + buffer.writeEscaped(context3.shortName); + buffer.write('''
  8. '''); } } buffer.writeln(); @@ -1736,7 +1734,7 @@ String renderSidebarForContainer( } } buffer.write('\n\n '); - if (context1.isClassOrEnum) { + if (context1.isInterface) { if (context1.hasPublicInstanceFields) { buffer.writeln(); buffer.write(''' @@ -1862,53 +1860,51 @@ String renderSidebarForContainer( } } buffer.write('\n\n '); - if (context1.isInterfaceOrExtension) { - if (context1.hasPublicVariableStaticFields) { + if (context1.hasPublicVariableStaticFields) { + buffer.writeln(); + buffer.write(''' +
  9. Static properties
  10. '''); + var context18 = context1.publicVariableStaticFieldsSorted; + for (var context19 in context18) { buffer.writeln(); buffer.write(''' -
  11. Static properties
  12. '''); - var context18 = context1.publicVariableStaticFieldsSorted; - for (var context19 in context18) { - buffer.writeln(); - buffer.write(''' -
  13. '''); - buffer.write(context19.linkedName); - buffer.write('''
  14. '''); - } +
  15. '''); + buffer.write(context19.linkedName); + buffer.write('''
  16. '''); } + } + buffer.writeln(); + if (context1.hasPublicStaticMethods) { buffer.writeln(); - if (context1.hasPublicStaticMethods) { + buffer.write(''' +
  17. Static methods
  18. '''); + var context20 = context1.publicStaticMethodsSorted; + for (var context21 in context20) { buffer.writeln(); buffer.write(''' -
  19. Static methods
  20. '''); - var context20 = context1.publicStaticMethodsSorted; - for (var context21 in context20) { - buffer.writeln(); - buffer.write(''' -
  21. '''); - buffer.write(context21.linkedName); - buffer.write('''
  22. '''); - } +
  23. '''); + buffer.write(context21.linkedName); + buffer.write('''
  24. '''); } + } + buffer.writeln(); + if (context1.hasPublicConstantFields) { buffer.writeln(); - if (context1.hasPublicConstantFields) { + buffer.write(''' +
  25. Constants
  26. '''); + var context22 = context1.publicConstantFieldsSorted; + for (var context23 in context22) { buffer.writeln(); buffer.write(''' -
  27. Constants
  28. '''); - var context22 = context1.publicConstantFieldsSorted; - for (var context23 in context22) { - buffer.writeln(); - buffer.write(''' -
  29. '''); - buffer.write(context23.linkedName); - buffer.write('''
  30. '''); - } +
  31. '''); + buffer.write(context23.linkedName); + buffer.write('''
  32. '''); } } buffer.writeln(); diff --git a/lib/src/generator/templates.runtime_renderers.dart b/lib/src/generator/templates.runtime_renderers.dart index 98372fb8e0..28dca9890b 100644 --- a/lib/src/generator/templates.runtime_renderers.dart +++ b/lib/src/generator/templates.runtime_renderers.dart @@ -1655,12 +1655,12 @@ class _Renderer_Class extends RendererBase { self.renderSimpleVariable(c, remainingNames, 'bool'), getBool: (CT_ c) => c.isFinal, ), - 'isInterface': Property( - getValue: (CT_ c) => c.isInterface, + 'isImplementableInterface': Property( + getValue: (CT_ c) => c.isImplementableInterface, renderVariable: (CT_ c, Property self, List remainingNames) => self.renderSimpleVariable(c, remainingNames, 'bool'), - getBool: (CT_ c) => c.isInterface, + getBool: (CT_ c) => c.isImplementableInterface, ), 'isMixinClass': Property( getValue: (CT_ c) => c.isMixinClass, @@ -2929,20 +2929,6 @@ class _Renderer_Container extends RendererBase { _render_Operator(e, ast, r.template, sink, parent: r)); }, ), - 'isClassOrEnum': Property( - getValue: (CT_ c) => c.isClassOrEnum, - renderVariable: (CT_ c, Property self, - List remainingNames) => - self.renderSimpleVariable(c, remainingNames, 'bool'), - getBool: (CT_ c) => c.isClassOrEnum, - ), - 'isClassOrExtensionType': Property( - getValue: (CT_ c) => c.isClassOrExtensionType, - renderVariable: (CT_ c, Property self, - List remainingNames) => - self.renderSimpleVariable(c, remainingNames, 'bool'), - getBool: (CT_ c) => c.isClassOrExtensionType, - ), 'isEnum': Property( getValue: (CT_ c) => c.isEnum, renderVariable: (CT_ c, Property self, @@ -2957,12 +2943,12 @@ class _Renderer_Container extends RendererBase { self.renderSimpleVariable(c, remainingNames, 'bool'), getBool: (CT_ c) => c.isExtension, ), - 'isInterfaceOrExtension': Property( - getValue: (CT_ c) => c.isInterfaceOrExtension, + 'isInterface': Property( + getValue: (CT_ c) => c.isInterface, renderVariable: (CT_ c, Property self, List remainingNames) => self.renderSimpleVariable(c, remainingNames, 'bool'), - getBool: (CT_ c) => c.isInterfaceOrExtension, + getBool: (CT_ c) => c.isInterface, ), 'isMixin': Property( getValue: (CT_ c) => c.isMixin, @@ -4392,12 +4378,12 @@ class _Renderer_Enum extends RendererBase { self.renderSimpleVariable(c, remainingNames, 'bool'), getBool: (CT_ c) => c.isBase, ), - 'isInterface': Property( - getValue: (CT_ c) => c.isInterface, + 'isImplementableInterface': Property( + getValue: (CT_ c) => c.isImplementableInterface, renderVariable: (CT_ c, Property self, List remainingNames) => self.renderSimpleVariable(c, remainingNames, 'bool'), - getBool: (CT_ c) => c.isInterface, + getBool: (CT_ c) => c.isImplementableInterface, ), 'isMixinClass': Property( getValue: (CT_ c) => c.isMixinClass, @@ -5146,12 +5132,12 @@ class _Renderer_ExtensionType extends RendererBase { self.renderSimpleVariable(c, remainingNames, 'bool'), getBool: (CT_ c) => c.isBase, ), - 'isInterface': Property( - getValue: (CT_ c) => c.isInterface, + 'isImplementableInterface': Property( + getValue: (CT_ c) => c.isImplementableInterface, renderVariable: (CT_ c, Property self, List remainingNames) => self.renderSimpleVariable(c, remainingNames, 'bool'), - getBool: (CT_ c) => c.isInterface, + getBool: (CT_ c) => c.isImplementableInterface, ), 'isMixinClass': Property( getValue: (CT_ c) => c.isMixinClass, @@ -7440,12 +7426,12 @@ class _Renderer_InheritingContainer extends RendererBase { self.renderSimpleVariable(c, remainingNames, 'bool'), getBool: (CT_ c) => c.isFinal, ), - 'isInterface': Property( - getValue: (CT_ c) => c.isInterface, + 'isImplementableInterface': Property( + getValue: (CT_ c) => c.isImplementableInterface, renderVariable: (CT_ c, Property self, List remainingNames) => self.renderSimpleVariable(c, remainingNames, 'bool'), - getBool: (CT_ c) => c.isInterface, + getBool: (CT_ c) => c.isImplementableInterface, ), 'isMixinClass': Property( getValue: (CT_ c) => c.isMixinClass, @@ -9811,12 +9797,12 @@ class _Renderer_Mixin extends RendererBase { self.renderSimpleVariable(c, remainingNames, 'bool'), getBool: (CT_ c) => c.isFinal, ), - 'isInterface': Property( - getValue: (CT_ c) => c.isInterface, + 'isImplementableInterface': Property( + getValue: (CT_ c) => c.isImplementableInterface, renderVariable: (CT_ c, Property self, List remainingNames) => self.renderSimpleVariable(c, remainingNames, 'bool'), - getBool: (CT_ c) => c.isInterface, + getBool: (CT_ c) => c.isImplementableInterface, ), 'isMixinClass': Property( getValue: (CT_ c) => c.isMixinClass, diff --git a/lib/src/model/class.dart b/lib/src/model/class.dart index abc9b75da9..23df4ee4cf 100644 --- a/lib/src/model/class.dart +++ b/lib/src/model/class.dart @@ -69,7 +69,7 @@ class Class extends InheritingContainer with Constructable, MixedInTypes { bool get isFinal => element.isFinal && !element.isSealed; @override - bool get isInterface => element.isInterface && !element.isSealed; + bool get isImplementableInterface => element.isInterface && !element.isSealed; @override bool get isMixinClass => element.isMixinClass; diff --git a/lib/src/model/container.dart b/lib/src/model/container.dart index e8ee420160..644381b5ea 100644 --- a/lib/src/model/container.dart +++ b/lib/src/model/container.dart @@ -40,22 +40,11 @@ abstract class Container extends ModelElement bool get isExtension => element is ExtensionElement; - /// Whether this is an interface type (class, enum, mixin, extension type) or - /// an extension. - /// - /// For templates, interfaces and extensions have much in common despite - /// differing underlying implementations in the analyzer. - bool get isInterfaceOrExtension => element is InterfaceElement || isExtension; - /// Whether this is an enum. bool get isEnum => element is EnumElement; - /// Whether this is a class or an enum. - bool get isClassOrEnum => element is InterfaceElement; - - /// Whether this is a class or an extension type. - bool get isClassOrExtensionType => - element is ClassElement || element is ExtensionTypeElement; + /// Whether this is an interface (e.g. class, enum, mixin, or extension type). + bool get isInterface => element is InterfaceElement; /// Whether this is a mixin. bool get isMixin => element is MixinElement; diff --git a/lib/src/model/enum.dart b/lib/src/model/enum.dart index 3a7c0e48b2..84e2701f92 100644 --- a/lib/src/model/enum.dart +++ b/lib/src/model/enum.dart @@ -58,7 +58,7 @@ class Enum extends InheritingContainer with Constructable, MixedInTypes { bool get isBase => false; @override - bool get isInterface => false; + bool get isImplementableInterface => false; @override bool get isMixinClass => false; diff --git a/lib/src/model/extension_type.dart b/lib/src/model/extension_type.dart index ca5650b9c0..f463efe3b7 100644 --- a/lib/src/model/extension_type.dart +++ b/lib/src/model/extension_type.dart @@ -30,7 +30,7 @@ class ExtensionType extends InheritingContainer with Constructable { bool get isBase => false; @override - bool get isInterface => false; + bool get isImplementableInterface => false; @override bool get isMixinClass => false; diff --git a/lib/src/model/inheriting_container.dart b/lib/src/model/inheriting_container.dart index de8131eec0..018273459f 100644 --- a/lib/src/model/inheriting_container.dart +++ b/lib/src/model/inheriting_container.dart @@ -85,7 +85,7 @@ abstract class InheritingContainer extends Container { if (isAbstract) ContainerModifier.abstract, if (isSealed) ContainerModifier.sealed, if (isBase) ContainerModifier.base, - if (isInterface) ContainerModifier.interface, + if (isImplementableInterface) ContainerModifier.interface, if (isFinal) ContainerModifier.finalModifier, if (isMixinClass) ContainerModifier.mixin, ]..sort(); @@ -350,7 +350,8 @@ abstract class InheritingContainer extends Container { @override bool get isFinal; - bool get isInterface; + /// Whether this element is a publicly implementable interface. + bool get isImplementableInterface; bool get isMixinClass; diff --git a/lib/src/model/mixin.dart b/lib/src/model/mixin.dart index 4788c04362..d6d3fa9263 100644 --- a/lib/src/model/mixin.dart +++ b/lib/src/model/mixin.dart @@ -64,7 +64,7 @@ class Mixin extends InheritingContainer { bool get isFinal => false; @override - bool get isInterface => false; + bool get isImplementableInterface => false; @override diff --git a/lib/templates/_sidebar_for_container.html b/lib/templates/_sidebar_for_container.html index 35c7263526..701a87c16b 100644 --- a/lib/templates/_sidebar_for_container.html +++ b/lib/templates/_sidebar_for_container.html @@ -1,14 +1,12 @@
      {{ #container }} - {{ #isClassOrExtensionType }} - {{ #hasPublicConstructors }} -
    1. Constructors
    2. - {{ #publicConstructorsSorted }} -
    3. {{ shortName }}
    4. - {{ /publicConstructorsSorted }} - {{ /hasPublicConstructors }} - {{ /isClassOrExtensionType }} + {{ #hasPublicConstructors }} +
    5. Constructors
    6. + {{ #publicConstructorsSorted }} +
    7. {{ shortName }}
    8. + {{ /publicConstructorsSorted }} + {{ /hasPublicConstructors }} {{ #isEnum }} {{ #hasPublicEnumValues }} @@ -20,7 +18,7 @@ {{ /isEnum }} {{!-- Instance members which may or may not be inherited. --}} - {{ #isClassOrEnum }} + {{ #isInterface }} {{ #hasPublicInstanceFields }}
    9. Properties @@ -43,7 +41,7 @@ {{{ linkedName }}}
    10. {{ /publicInstanceOperatorsSorted }} {{ /hasPublicInstanceOperators }} - {{ /isClassOrEnum }} + {{ /isInterface }} {{!-- Instance members with no inheritance concept. --}} {{ #isExtension }} @@ -70,27 +68,25 @@ {{ /isExtension }} {{!-- Static members. --}} - {{ #isInterfaceOrExtension }} - {{ #hasPublicVariableStaticFields }} -
    11. Static properties
    12. - {{ #publicVariableStaticFieldsSorted }} -
    13. {{{ linkedName }}}
    14. - {{ /publicVariableStaticFieldsSorted }} - {{ /hasPublicVariableStaticFields }} + {{ #hasPublicVariableStaticFields }} +
    15. Static properties
    16. + {{ #publicVariableStaticFieldsSorted }} +
    17. {{{ linkedName }}}
    18. + {{ /publicVariableStaticFieldsSorted }} + {{ /hasPublicVariableStaticFields }} - {{ #hasPublicStaticMethods }} -
    19. Static methods
    20. - {{ #publicStaticMethodsSorted }} -
    21. {{{ linkedName }}}
    22. - {{ /publicStaticMethodsSorted }} - {{ /hasPublicStaticMethods }} + {{ #hasPublicStaticMethods }} +
    23. Static methods
    24. + {{ #publicStaticMethodsSorted }} +
    25. {{{ linkedName }}}
    26. + {{ /publicStaticMethodsSorted }} + {{ /hasPublicStaticMethods }} - {{ #hasPublicConstantFields }} -
    27. Constants
    28. - {{ #publicConstantFieldsSorted }} -
    29. {{{ linkedName }}}
    30. - {{ /publicConstantFieldsSorted }} - {{ /hasPublicConstantFields }} - {{ /isInterfaceOrExtension }} + {{ #hasPublicConstantFields }} +
    31. Constants
    32. + {{ #publicConstantFieldsSorted }} +
    33. {{{ linkedName }}}
    34. + {{ /publicConstantFieldsSorted }} + {{ /hasPublicConstantFields }} {{ /container }}