Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Privatize some of the interface of Class #2292

Merged
merged 1 commit into from
Aug 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/src/model/category.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
77 changes: 49 additions & 28 deletions lib/src/model/class.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand All @@ -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);

Expand Down Expand Up @@ -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);

Expand All @@ -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;
Expand Down Expand Up @@ -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>[];
Expand All @@ -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 = [];
Expand Down Expand Up @@ -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';

Expand Down Expand Up @@ -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;
Expand Down