Skip to content

Commit c85b7d7

Browse files
devoncarewjcollins-g
authored andcommitted
Generic function types (#1366)
* Basic support for typedefs with generic functions * Unit tests for feature * Better example. * Add returned type parameter from generic typedef to docs. * Basic support for typedefs with generic functions * Unit tests for feature * Better example. * Add returned type parameter from generic typedef to docs. * Prepare 0.9.14-dev for SDK * Basic support for typedefs with generic functions * Unit tests for feature * Better example. * Add returned type parameter from generic typedef to docs. * Update changelog and dartfmt * dartfmt * update test package docs post merge * Adjust pubspec.yaml to require the precise version where generic functions were introduced * rebuild package docs for generic types change + index.json sorting
1 parent aff322b commit c85b7d7

File tree

79 files changed

+593
-28
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+593
-28
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
* Enable support for generic function types. #1321
12
* Update analyzer to 0.30. #1403
3+
* Enhancements to css style to better match dartlang.org. #1372 (partial)
24

35
## 0.11.2
46
* Fix regression where warnings generated by the README could result in a fatal exception. #1409
@@ -111,6 +113,12 @@
111113
--category-order, lets you change what order categories appear in. (#1323)
112114
* fix broken masthead links in enums (#1225).
113115

116+
## 0.9.14-dev
117+
118+
This is a prerelease only, features listed as added here don't carry forward.
119+
120+
* Enable support for generic function types (#1321)
121+
114122
## 0.9.13
115123

116124
* fix grind check-links and check-sdk-links (#1360)

lib/src/model.dart

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2310,9 +2310,11 @@ abstract class ModelElement implements Comparable, Nameable, Documentable {
23102310
typeName = mt.linkedName;
23112311
}
23122312
if (typeName.isNotEmpty) {
2313-
buf.write('<span class="type-annotation">$typeName</span> ');
2313+
buf.write('<span class="type-annotation">$typeName</span>');
23142314
}
2315-
if (showNames) {
2315+
if (typeName.isNotEmpty && showNames && param.name.isNotEmpty)
2316+
buf.write(' ');
2317+
if (showNames && param.name.isNotEmpty) {
23162318
buf.write('<span class="parameter-name">${param.name}</span>');
23172319
}
23182320
}
@@ -3775,6 +3777,17 @@ class Typedef extends ModelElement
37753777
String get fileName => '$name.html';
37763778

37773779
@override
3780+
String get genericParameters {
3781+
if (element is GenericTypeAliasElement) {
3782+
List<TypeParameterElement> genericTypeParameters =
3783+
(element as GenericTypeAliasElement).function.typeParameters;
3784+
if (genericTypeParameters.isNotEmpty) {
3785+
return '&lt;${genericTypeParameters.map((t) => t.name).join(', ')}&gt;';
3786+
}
3787+
} // else, all types are resolved.
3788+
return '';
3789+
}
3790+
37783791
String get href {
37793792
if (canonicalLibrary == null) return null;
37803793
return '${canonicalLibrary.dirName}/$fileName';

pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,4 +350,4 @@ packages:
350350
source: hosted
351351
version: "2.1.12"
352352
sdks:
353-
dart: ">=1.22.0 <2.0.0"
353+
dart: ">=1.23.0-dev.11.5 <2.0.0"

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ author: Dart Team <[email protected]>
55
description: A documentation generator for Dart.
66
homepage: https://github.com/dart-lang/dartdoc
77
environment:
8-
sdk: '>=1.14.0 <2.0.0'
8+
sdk: '>=1.23.0-dev.11.5 <2.0.0'
99
dependencies:
1010
analyzer: ^0.30.0
1111
args: ^0.13.0

test/model_test.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,29 +1514,43 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
15141514

15151515
group('Typedef', () {
15161516
Typedef t;
1517+
Typedef generic;
15171518

15181519
setUp(() {
15191520
t = exLibrary.typedefs.firstWhere((t) => t.name == 'processMessage');
1521+
generic =
1522+
fakeLibrary.typedefs.firstWhere((t) => t.name == 'NewGenericTypedef');
15201523
});
15211524

15221525
test('has a fully qualified name', () {
15231526
expect(t.fullyQualifiedName, 'ex.processMessage');
1527+
expect(generic.fullyQualifiedName, 'fake.NewGenericTypedef');
15241528
});
15251529

15261530
test('has enclosing element', () {
15271531
expect(t.enclosingElement.name, equals(exLibrary.name));
1532+
expect(generic.enclosingElement.name, equals(fakeLibrary.name));
15281533
});
15291534

15301535
test('docs', () {
15311536
expect(t.documentation, equals(''));
1537+
expect(generic.documentation,
1538+
equals('A typedef with the new style generic function syntax.'));
15321539
});
15331540

15341541
test('linked return type', () {
15351542
expect(t.linkedReturnType, equals('String'));
1543+
expect(generic.linkedReturnType, equals('List&lt;S&gt;'));
15361544
});
15371545

15381546
test("name with generics", () {
15391547
expect(t.nameWithGenerics, equals('processMessage&lt;T&gt;'));
1548+
expect(generic.nameWithGenerics, equals('NewGenericTypedef&lt;T&gt;'));
1549+
});
1550+
1551+
test("generic parameters", () {
1552+
expect(t.genericParameters, equals(''));
1553+
expect(generic.genericParameters, equals('&lt;S&gt;'));
15401554
});
15411555
});
15421556

testing/test_package/lib/fake.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ typedef String FakeProcesses(String input);
134134
/// A typedef with a type parameter.
135135
typedef T GenericTypedef<T>(T input);
136136

137+
/// A typedef with the new style generic function syntax.
138+
typedef NewGenericTypedef<T> = List<S> Function<S>(T, int, bool);
139+
137140
/// Lots and lots of parameters.
138141
typedef int LotsAndLotsOfParameters(so, many, parameters, it, should, wrap,
139142
when, converted, to, html, documentation);
@@ -394,6 +397,11 @@ thisIsAsync() async => 42;
394397
/// Explicitly returns a Future and is marked async.
395398
Future thisIsAlsoAsync() async => 43;
396399

400+
/// A generic function with a type parameter.
401+
void myGenericFunction<S>(int a, bool b, S c) {
402+
return;
403+
}
404+
397405
/// This is a great thing.
398406
const greatAnnotation = 'great';
399407

testing/test_package_docs/css/css-library.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ <h2>Properties</h2>
7676
<dl class="properties">
7777
<dt id="theOnlyThingInTheLibrary" class="property">
7878
<span class="name"><a href="css/theOnlyThingInTheLibrary.html">theOnlyThingInTheLibrary</a></span><span class="signature">
79-
<span class="returntype parameter">&#8596; <span class="parameter" id="theOnlyThingInTheLibrary=-param-_theOnlyThingInTheLibrary"><span class="type-annotation">String</span> </span> </span>
79+
<span class="returntype parameter">&#8596; <span class="parameter" id="theOnlyThingInTheLibrary=-param-_theOnlyThingInTheLibrary"><span class="type-annotation">String</span></span> </span>
8080
</span>
8181
</dt>
8282
<dd>

testing/test_package_docs/ex/Apple-class.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ <h2>Properties</h2>
163163
</dd>
164164
<dt id="m" class="property">
165165
<span class="name"><a href="ex/Apple/m.html">m</a></span><span class="signature">
166-
<span class="returntype parameter">&#8596; <span class="parameter" id="m=-param-_m"><span class="type-annotation">int</span> </span> </span>
166+
<span class="returntype parameter">&#8596; <span class="parameter" id="m=-param-_m"><span class="type-annotation">int</span></span> </span>
167167
</span>
168168
</dt>
169169
<dd>
@@ -306,7 +306,7 @@ <h2>Static Properties</h2>
306306
<dl class="properties">
307307
<dt id="string" class="property">
308308
<span class="name"><a href="ex/Apple/string.html">string</a></span><span class="signature">
309-
<span class="returntype parameter">&#8596; <span class="parameter" id="string=-param-_string"><span class="type-annotation">String</span> </span> </span>
309+
<span class="returntype parameter">&#8596; <span class="parameter" id="string=-param-_string"><span class="type-annotation">String</span></span> </span>
310310
</span>
311311
</dt>
312312
<dd>

testing/test_package_docs/ex/B-class.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ <h2>Properties</h2>
154154
<dl class="properties">
155155
<dt id="autoCompress" class="property">
156156
<span class="name"><a href="ex/B/autoCompress.html">autoCompress</a></span><span class="signature">
157-
<span class="returntype parameter">&#8596; <span class="parameter" id="autoCompress=-param-_autoCompress"><span class="type-annotation">bool</span> </span> </span>
157+
<span class="returntype parameter">&#8596; <span class="parameter" id="autoCompress=-param-_autoCompress"><span class="type-annotation">bool</span></span> </span>
158158
</span>
159159
</dt>
160160
<dd>
@@ -172,7 +172,7 @@ <h2>Properties</h2>
172172
</dd>
173173
<dt id="list" class="property">
174174
<span class="name"><a href="ex/B/list.html">list</a></span><span class="signature">
175-
<span class="returntype parameter">&#8596; <span class="parameter" id="list=-param-_list"><span class="type-annotation">List&lt;String&gt;</span> </span> </span>
175+
<span class="returntype parameter">&#8596; <span class="parameter" id="list=-param-_list"><span class="type-annotation">List&lt;String&gt;</span></span> </span>
176176
</span>
177177
</dt>
178178
<dd>
@@ -205,7 +205,7 @@ <h2>Properties</h2>
205205
</dd>
206206
<dt id="m" class="property inherited">
207207
<span class="name"><a href="ex/Apple/m.html">m</a></span><span class="signature">
208-
<span class="returntype parameter">&#8596; <span class="parameter" id="m=-param-_m"><span class="type-annotation">int</span> </span> </span>
208+
<span class="returntype parameter">&#8596; <span class="parameter" id="m=-param-_m"><span class="type-annotation">int</span></span> </span>
209209
</span>
210210
</dt>
211211
<dd class="inherited">

testing/test_package_docs/ex/Dog-class.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ <h2>Properties</h2>
191191
</dd>
192192
<dt id="deprecatedField" class="property">
193193
<span class="name deprecated"><a class="deprecated" href="ex/Dog/deprecatedField.html">deprecatedField</a></span><span class="signature">
194-
<span class="returntype parameter">&#8596; <span class="parameter" id="deprecatedField=-param-_deprecatedField"><span class="type-annotation">int</span> </span> </span>
194+
<span class="returntype parameter">&#8596; <span class="parameter" id="deprecatedField=-param-_deprecatedField"><span class="type-annotation">int</span></span> </span>
195195
</span>
196196
</dt>
197197
<dd>
@@ -225,7 +225,7 @@ <h2>Properties</h2>
225225
</dd>
226226
<dt id="name" class="property">
227227
<span class="name"><a href="ex/Dog/name.html">name</a></span><span class="signature">
228-
<span class="returntype parameter">&#8596; <span class="parameter" id="name=-param-_name"><span class="type-annotation">String</span> </span> </span>
228+
<span class="returntype parameter">&#8596; <span class="parameter" id="name=-param-_name"><span class="type-annotation">String</span></span> </span>
229229
</span>
230230
</dt>
231231
<dd>

0 commit comments

Comments
 (0)