diff --git a/lib/src/model/category.dart b/lib/src/model/category.dart index 6227ef9e69..7df4c952c4 100644 --- a/lib/src/model/category.dart +++ b/lib/src/model/category.dart @@ -24,6 +24,8 @@ class Category extends Nameable Indexable implements Documentable { /// All libraries in [libraries] must come from [package]. + // TODO(srawlins): To make final, remove public getter, setter, rename to be + // public, and add `final` modifier. Package _package; @override @@ -35,6 +37,8 @@ class Category extends Nameable final String _name; + // TODO(srawlins): To make final, remove public getter, setter, rename to be + // public, and add `final` modifier. DartdocOptionContext _config; @override diff --git a/lib/src/model/class.dart b/lib/src/model/class.dart index b76a216518..7f8823d086 100644 --- a/lib/src/model/class.dart +++ b/lib/src/model/class.dart @@ -8,6 +8,7 @@ import 'package:dartdoc/src/element_type.dart'; import 'package:dartdoc/src/model/extension_target.dart'; import 'package:dartdoc/src/model/model.dart'; import 'package:dartdoc/src/model_utils.dart' as model_utils; +import 'package:meta/meta.dart'; import 'package:quiver/iterables.dart' as quiver; /// A [Container] defined with a `class` declaration in Dart. @@ -20,32 +21,43 @@ import 'package:quiver/iterables.dart' as quiver; class Class extends Container with TypeParameters, Categorization, ExtensionTarget implements EnclosedElement { - List<DefinedElementType> mixins; - DefinedElementType supertype; - List<DefinedElementType> _interfaces; - List<Operator> _inheritedOperators; - List<Method> _inheritedMethods; + // TODO(srawlins): To make final, remove public getter, setter, rename to be + // public, and add `final` modifier. + List<DefinedElementType> _mixins; + + List<DefinedElementType> get mixins => _mixins; + + @Deprecated('Field intended to be final; setter will be removed as early as ' + 'Dartdoc 1.0.0') + set mixins(List<DefinedElementType> value) => _mixins = value; + + // TODO(srawlins): To make final, remove public getter, setter, rename to be + // public, and add `final` modifier. + DefinedElementType _supertype; + + DefinedElementType get supertype => _supertype; + + @Deprecated('Field intended to be final; setter will be removed as early as ' + 'Dartdoc 1.0.0') + set supertype(DefinedElementType value) => _supertype = value; + + final List<DefinedElementType> _interfaces; Class(ClassElement element, Library library, PackageGraph packageGraph) - : super(element, library, packageGraph) { + : _mixins = element.mixins + .map<DefinedElementType>( + (f) => ElementType.from(f, library, packageGraph)) + .where((mixin) => mixin != null) + .toList(growable: false), + _supertype = element.supertype?.element?.supertype == null + ? null + : ElementType.from(element.supertype, library, packageGraph), + _interfaces = element.interfaces + .map<DefinedElementType>( + (f) => ElementType.from(f, library, packageGraph)) + .toList(growable: false), + super(element, library, packageGraph) { packageGraph.specialClasses.addSpecial(this); - mixins = element.mixins - .map((f) { - DefinedElementType t = ElementType.from(f, library, packageGraph); - return t; - }) - .where((mixin) => mixin != null) - .toList(growable: false); - - if (element.supertype != null && - element.supertype.element.supertype != null) { - supertype = ElementType.from(element.supertype, library, packageGraph); - } - - _interfaces = element.interfaces - .map((f) => - ElementType.from(f, library, packageGraph) as DefinedElementType) - .toList(growable: false); } Constructor _defaultConstructor; @@ -60,6 +72,7 @@ class Class extends Container Iterable<Method> get instanceMethods => quiver.concat([super.instanceMethods, inheritedMethods]); + // Whether all instance methods are inherited, used in mustache templates. bool get publicInheritedInstanceMethods => instanceMethods.every((f) => f.isInherited); @@ -87,10 +100,10 @@ class Class extends Container allModelElements.where((e) => e.isCanonical).toList()); } - Iterable<Constructor> get constructors => element.constructors.map((e) { - return ModelElement.from(e, library, packageGraph) as Constructor; - }); + Iterable<Constructor> get constructors => element.constructors + .map((e) => ModelElement.from(e, library, packageGraph) as Constructor); + @visibleForTesting Iterable<Constructor> get publicConstructors => model_utils.filterNonPublic(constructors); @@ -112,6 +125,7 @@ class Class extends Container return kind; } + // Whether any constructors are public, used in mustache templates. bool get hasPublicConstructors => publicConstructorsSorted.isNotEmpty; List<Constructor> _publicConstructorsSorted; @@ -151,6 +165,7 @@ class Class extends Container model_utils.findCanonicalFor(packageGraph.implementors[href] ?? [])); } + /*lazy final*/ List<Method> _inheritedMethods; Iterable<Method> get inheritedMethods { if (_inheritedMethods == null) { _inheritedMethods = <Method>[]; @@ -177,6 +192,7 @@ class Class extends Container bool get hasPublicInheritedMethods => publicInheritedMethods.isNotEmpty; + /*lazy final*/ List<Operator> _inheritedOperators; Iterable<Operator> get inheritedOperators { if (_inheritedOperators == null) { _inheritedOperators = []; @@ -227,9 +243,14 @@ class Class extends Container } /// Returns true if [other] is a parent class for this class. - bool isInheritingFrom(covariant Class other) => + bool _isInheritingFrom(Class other) => superChain.map((et) => (et.element as Class)).contains(other); + @Deprecated( + 'Public method intended to be private; will be removed as early as ' + 'Dartdoc 1.0.0') + bool isInheritingFrom(Class other) => _isInheritingFrom(other); + @override String get kind => 'class'; @@ -417,7 +438,7 @@ class Class extends Container // to this class on the inheritance chain. if (setter.enclosingElement is Class && (setter.enclosingElement as Class) - .isInheritingFrom(getter.enclosingElement)) { + ._isInheritingFrom(getter.enclosingElement)) { f = setterElement.variable; } else { f = getterElement.variable;