Skip to content

Commit 3f0b8ba

Browse files
authored
Typedef implements ModelFunctionTyped. (#2376)
Typedef implements ModelFunctionTyped. The relationship is different from ModelFunctionTypedef which _extends_ ModelFunctionTyped because the typedef is the alias _which contains_ a function-typed element. Nevertheless, Typedef was always implementing (approximately) the interface defined by ModelFunctionTyped because both types are sent to the _callable template. Additionally one change is made to the ModelFunctionTyped interface such that Typedef perfectly implements ModelFunctionTyped. * **Breaking change**: Remove the `typeParameters` setter. The field is now final.
1 parent 881d606 commit 3f0b8ba

File tree

3 files changed

+14
-19
lines changed

3 files changed

+14
-19
lines changed

lib/src/model/model_function.dart

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,13 @@ class ModelFunction extends ModelFunctionTyped with Categorization {
1313
: super(element, library, packageGraph);
1414

1515
@override
16-
bool get isStatic {
17-
return _func.isStatic;
18-
}
16+
bool get isStatic => element.isStatic;
1917

2018
@override
2119
String get name => element.name ?? '';
2220

2321
@override
24-
FunctionElement get _func => (element as FunctionElement);
22+
FunctionElement get element => super.element;
2523
}
2624

2725
/// A [ModelElement] for a [FunctionTypedElement] that is part of an
@@ -39,19 +37,15 @@ class ModelFunctionTyped extends ModelElement
3937
with TypeParameters
4038
implements EnclosedElement {
4139
@override
42-
List<TypeParameter> typeParameters = [];
40+
final List<TypeParameter> typeParameters;
4341

4442
ModelFunctionTyped(
4543
FunctionTypedElement element, Library library, PackageGraph packageGraph)
46-
: super(element, library, packageGraph, null) {
47-
_calcTypeParameters();
48-
}
49-
50-
void _calcTypeParameters() {
51-
typeParameters = _func.typeParameters.map((f) {
52-
return ModelElement.from(f, library, packageGraph) as TypeParameter;
53-
}).toList();
54-
}
44+
: typeParameters = <TypeParameter>[
45+
for (var p in element.typeParameters)
46+
ModelElement.from(p, library, packageGraph),
47+
],
48+
super(element, library, packageGraph, null);
5549

5650
@override
5751
ModelElement get enclosingElement => library;
@@ -79,6 +73,4 @@ class ModelFunctionTyped extends ModelElement
7973

8074
@override
8175
DefinedElementType get modelType => super.modelType;
82-
83-
FunctionTypedElement get _func => (element as FunctionTypedElement);
8476
}

lib/src/model/top_level_container.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,14 @@ abstract class TopLevelContainer implements Nameable {
6060
Iterable<Class> get publicExceptions =>
6161
model_utils.filterNonPublic(exceptions);
6262

63-
Iterable<ModelFunction> get publicFunctions =>
63+
Iterable<ModelFunctionTyped> get publicFunctions =>
6464
model_utils.filterNonPublic(functions);
6565

6666
Iterable<Mixin> get publicMixins => model_utils.filterNonPublic(mixins);
6767

6868
Iterable<TopLevelVariable> get publicProperties =>
6969
model_utils.filterNonPublic(properties);
7070

71-
Iterable<Typedef> get publicTypedefs => model_utils.filterNonPublic(typedefs);
71+
Iterable<ModelFunctionTyped> get publicTypedefs =>
72+
model_utils.filterNonPublic(typedefs);
7273
}

lib/src/model/typedef.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import 'package:dartdoc/src/render/typedef_renderer.dart';
99

1010
class Typedef extends ModelElement
1111
with TypeParameters, Categorization
12-
implements EnclosedElement {
12+
implements EnclosedElement, ModelFunctionTyped {
1313
Typedef(FunctionTypeAliasElement element, Library library,
1414
PackageGraph packageGraph)
1515
: super(element, library, packageGraph, null);
@@ -44,11 +44,13 @@ class Typedef extends ModelElement
4444
}
4545

4646
// Food for mustache.
47+
@override
4748
bool get isInherited => false;
4849

4950
@override
5051
String get kind => 'typedef';
5152

53+
@override
5254
String get linkedReturnType => modelType.createLinkedReturnTypeName();
5355

5456
@override

0 commit comments

Comments
 (0)