Skip to content

Commit 398a7b4

Browse files
committed
Fix signatures for functions with typedef params (#1137).
Fixes #1137
1 parent 0553641 commit 398a7b4

File tree

65 files changed

+1040
-19
lines changed

Some content is hidden

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

65 files changed

+1040
-19
lines changed

lib/src/model.dart

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,7 +1542,8 @@ abstract class ModelElement implements Comparable, Nameable, Documentable {
15421542
}
15431543
if (p.modelType.isFunctionType) {
15441544
var returnTypeName;
1545-
if (p.modelType.element is Typedef) {
1545+
bool isTypedef = p.modelType.element is Typedef;
1546+
if (isTypedef) {
15461547
returnTypeName = p.modelType.linkedName;
15471548
} else {
15481549
returnTypeName = p.modelType.createLinkedReturnTypeName();
@@ -1551,10 +1552,12 @@ abstract class ModelElement implements Comparable, Nameable, Documentable {
15511552
if (showNames) {
15521553
buf.write(' <span class="parameter-name">${p.name}</span>');
15531554
}
1554-
buf.write('(');
1555-
buf.write(p.modelType.element
1556-
.linkedParams(showNames: showNames, showMetadata: showMetadata));
1557-
buf.write(')');
1555+
if (!isTypedef) {
1556+
buf.write('(');
1557+
buf.write(p.modelType.element
1558+
.linkedParams(showNames: showNames, showMetadata: showMetadata));
1559+
buf.write(')');
1560+
}
15581561
} else if (p.modelType != null && p.modelType.element != null) {
15591562
var mt = p.modelType;
15601563
String typeName = "";

test/model_test.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,30 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
819819
return null;
820820
}'''));
821821
});
822+
823+
test('typedef params have proper signature', () {
824+
// typedef void VoidCallback();
825+
// void addCallback(VoidCallback callback) { }
826+
ModelFunction function =
827+
fakeLibrary.functions.firstWhere((f) => f.name == 'addCallback');
828+
String params = function.linkedParams();
829+
expect(
830+
params,
831+
'<span class="parameter" id="addCallback-param-callback">'
832+
'<span class="type-annotation"><a href="fake/VoidCallback.html">VoidCallback</a></span> '
833+
'<span class="parameter-name">callback</span></span>');
834+
835+
// typedef int Callback2(String);
836+
// void addCallback2(Callback2 callback) { }
837+
function =
838+
fakeLibrary.functions.firstWhere((f) => f.name == 'addCallback2');
839+
params = function.linkedParams();
840+
expect(
841+
params,
842+
'<span class="parameter" id="addCallback2-param-callback">'
843+
'<span class="type-annotation"><a href="fake/Callback2.html">Callback2</a></span> '
844+
'<span class="parameter-name">callback</span></span>');
845+
});
822846
});
823847

824848
group('Method', () {

testing/test_package/lib/fake.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,3 +430,13 @@ class SubForDocComments extends BaseForDocComments {
430430
/// Reference to [foo] and [bar]
431431
void localMethod(String foo, bar) {}
432432
}
433+
434+
typedef void VoidCallback();
435+
436+
/// Adds a callback.
437+
void addCallback(VoidCallback callback) { }
438+
439+
typedef int Callback2(String);
440+
441+
/// Adds another callback.
442+
void addCallback2(Callback2 callback) { }

testing/test_package_docs/code_in_comments/code_in_comments-library.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ <h5><a href="index.html">test_package</a></h5>
8383
<div class="col-xs-12 col-sm-9 col-md-8 main-content">
8484

8585
<section class="desc markdown">
86-
<pre class="prettyprint language-dart"><code class="language-dart">void main() {
86+
<pre class="dart prettyprint"><code>void main() {
8787
// in Dart!
8888
}
8989
</code></pre>
90-
<pre class="prettyprint language-dart"><code class="language-yaml">and_yaml:
90+
<pre class="yaml prettyprint"><code>and_yaml:
9191
- value
9292
- "value"
9393
- 3.14

testing/test_package_docs/ex/Apple-class.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ <h2>Methods</h2>
299299
<p>This is a method.</p>
300300
</dd>
301301
<dt id="methodWithTypedefParam" class="callable">
302-
<span class="name"><a href="ex/Apple/methodWithTypedefParam.html">methodWithTypedefParam</a></span><span class="signature">(<wbr><span class="parameter" id="methodWithTypedefParam-param-p"><span class="type-annotation"><a href="ex/processMessage.html">processMessage</a></span> <span class="parameter-name">p</span>(<span class="parameter" id="processMessage-param-msg"><span class="type-annotation">String</span> <span class="parameter-name">msg</span></span>)</span>)
302+
<span class="name"><a href="ex/Apple/methodWithTypedefParam.html">methodWithTypedefParam</a></span><span class="signature">(<wbr><span class="parameter" id="methodWithTypedefParam-param-p"><span class="type-annotation"><a href="ex/processMessage.html">processMessage</a></span> <span class="parameter-name">p</span></span>)
303303
<span class="returntype parameter">&#8594; void</span>
304304
</span>
305305
</dt>

testing/test_package_docs/ex/Apple/methodWithTypedefParam.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ <h5><a href="ex/Apple-class.html">Apple</a></h5>
111111
<div class="col-xs-12 col-sm-9 col-md-8 main-content">
112112
<section class="multi-line-signature">
113113
<span class="returntype">void</span>
114-
<span class="name ">methodWithTypedefParam</span>(<wbr><span class="parameter" id="methodWithTypedefParam-param-p"><span class="type-annotation"><a href="ex/processMessage.html">processMessage</a></span> <span class="parameter-name">p</span>(<span class="parameter" id="processMessage-param-msg"><span class="type-annotation">String</span> <span class="parameter-name">msg</span></span>)</span>)
114+
<span class="name ">methodWithTypedefParam</span>(<wbr><span class="parameter" id="methodWithTypedefParam-param-p"><span class="type-annotation"><a href="ex/processMessage.html">processMessage</a></span> <span class="parameter-name">p</span></span>)
115115
</section>
116116

117117

testing/test_package_docs/ex/B-class.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ <h2>Methods</h2>
314314
<p>This is a method.</p>
315315
</dd>
316316
<dt id="methodWithTypedefParam" class="callable inherited">
317-
<span class="name"><a href="ex/Apple/methodWithTypedefParam.html">methodWithTypedefParam</a></span><span class="signature">(<wbr><span class="parameter" id="methodWithTypedefParam-param-p"><span class="type-annotation"><a href="ex/processMessage.html">processMessage</a></span> <span class="parameter-name">p</span>(<span class="parameter" id="processMessage-param-msg"><span class="type-annotation">String</span> <span class="parameter-name">msg</span></span>)</span>)
317+
<span class="name"><a href="ex/Apple/methodWithTypedefParam.html">methodWithTypedefParam</a></span><span class="signature">(<wbr><span class="parameter" id="methodWithTypedefParam-param-p"><span class="type-annotation"><a href="ex/processMessage.html">processMessage</a></span> <span class="parameter-name">p</span></span>)
318318
<span class="returntype parameter">&#8594; void</span>
319319
</span>
320320
</dt>

testing/test_package_docs/ex/ShapeType-class.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ <h5><a href="ex/ex-library.html">ex</a></h5>
133133

134134
<section class="desc markdown">
135135
<p><code>Object</code> foo bar</p><ol><li>
136-
<p>All references should be hyperlinks. <code>Object</code> <code>MyError</code> <a href="ex/ShapeType-class.html">ShapeType</a>
137-
<code>MyError</code> <code>MyException</code>
138-
<code>MyError</code> <code>MyException</code> <code>Object</code>
136+
<p>All references should be hyperlinks. [Object] [MyError] <a href="ex/ShapeType-class.html">ShapeType</a>
137+
[MyError] [MyException]
138+
[MyError] [MyException] <code>Object</code>
139139
<a href="ex/ShapeType-class.html">ShapeType</a> foo bar</p></li></ol>
140140
</section>
141141

testing/test_package_docs/ex/ex-library.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ <h5><a href="index.html">test_package</a></h5>
9292
<div class="col-xs-12 col-sm-9 col-md-8 main-content">
9393

9494
<section class="desc markdown">
95-
<p>a library. testing string escaping: <code>var s = 'a string'</code> <cool></cool></p>
95+
<p>a library. testing string escaping: <code>var s = 'a string'</code> &lt;cool&gt;</p>
9696
</section>
9797

9898
<section class="summary offset-anchor" id="constants">

testing/test_package_docs/fake/Annotation-class.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,11 @@ <h5><a href="fake/fake-library.html">fake</a></h5>
8989
<li><a href="fake/ZERO-constant.html">ZERO</a></li>
9090

9191
<li class="section-title"><a href="fake/fake-library.html#typedefs">Typedefs</a></li>
92+
<li><a href="fake/Callback2.html">Callback2</a></li>
9293
<li><a class="deprecated" href="fake/FakeProcesses.html">FakeProcesses</a></li>
9394
<li><a href="fake/GenericTypedef.html">GenericTypedef</a></li>
9495
<li><a href="fake/LotsAndLotsOfParameters.html">LotsAndLotsOfParameters</a></li>
96+
<li><a href="fake/VoidCallback.html">VoidCallback</a></li>
9597

9698
<li class="section-title"><a href="fake/fake-library.html#properties">Properties</a></li>
9799
<li><a href="fake/dynamicGetter.html">dynamicGetter</a></li>
@@ -103,6 +105,8 @@ <h5><a href="fake/fake-library.html">fake</a></h5>
103105
<li><a href="fake/simpleProperty.html">simpleProperty</a></li>
104106

105107
<li class="section-title"><a href="fake/fake-library.html#functions">Functions</a></li>
108+
<li><a href="fake/addCallback.html">addCallback</a></li>
109+
<li><a href="fake/addCallback2.html">addCallback2</a></li>
106110
<li><a href="fake/functionWithFunctionParameters.html">functionWithFunctionParameters</a></li>
107111
<li><a href="fake/onlyPositionalWithNoDefaultNoType.html">onlyPositionalWithNoDefaultNoType</a></li>
108112
<li><a href="fake/paramFromAnotherLib.html">paramFromAnotherLib</a></li>

0 commit comments

Comments
 (0)