Skip to content

Commit f96ef94

Browse files
authored
Merge pull request #1209 from dart-lang/fix_1137
Fix signatures for functions with typedef params (#1137).
2 parents 0553641 + afc5b4f commit f96ef94

Some content is hidden

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

61 files changed

+1030
-9
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/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/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>

testing/test_package_docs/fake/AnotherInterface-class.html

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

9090
<li class="section-title"><a href="fake/fake-library.html#typedefs">Typedefs</a></li>
91+
<li><a href="fake/Callback2.html">Callback2</a></li>
9192
<li><a class="deprecated" href="fake/FakeProcesses.html">FakeProcesses</a></li>
9293
<li><a href="fake/GenericTypedef.html">GenericTypedef</a></li>
9394
<li><a href="fake/LotsAndLotsOfParameters.html">LotsAndLotsOfParameters</a></li>
95+
<li><a href="fake/VoidCallback.html">VoidCallback</a></li>
9496

9597
<li class="section-title"><a href="fake/fake-library.html#properties">Properties</a></li>
9698
<li><a href="fake/dynamicGetter.html">dynamicGetter</a></li>
@@ -102,6 +104,8 @@ <h5><a href="fake/fake-library.html">fake</a></h5>
102104
<li><a href="fake/simpleProperty.html">simpleProperty</a></li>
103105

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

testing/test_package_docs/fake/BaseForDocComments-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>

testing/test_package_docs/fake/CUSTOM_CLASS-constant.html

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

8585
<li class="section-title"><a href="fake/fake-library.html#typedefs">Typedefs</a></li>
86+
<li><a href="fake/Callback2.html">Callback2</a></li>
8687
<li><a class="deprecated" href="fake/FakeProcesses.html">FakeProcesses</a></li>
8788
<li><a href="fake/GenericTypedef.html">GenericTypedef</a></li>
8889
<li><a href="fake/LotsAndLotsOfParameters.html">LotsAndLotsOfParameters</a></li>
90+
<li><a href="fake/VoidCallback.html">VoidCallback</a></li>
8991

9092
<li class="section-title"><a href="fake/fake-library.html#properties">Properties</a></li>
9193
<li><a href="fake/dynamicGetter.html">dynamicGetter</a></li>
@@ -97,6 +99,8 @@ <h5><a href="fake/fake-library.html">fake</a></h5>
9799
<li><a href="fake/simpleProperty.html">simpleProperty</a></li>
98100

99101
<li class="section-title"><a href="fake/fake-library.html#functions">Functions</a></li>
102+
<li><a href="fake/addCallback.html">addCallback</a></li>
103+
<li><a href="fake/addCallback2.html">addCallback2</a></li>
100104
<li><a href="fake/functionWithFunctionParameters.html">functionWithFunctionParameters</a></li>
101105
<li><a href="fake/onlyPositionalWithNoDefaultNoType.html">onlyPositionalWithNoDefaultNoType</a></li>
102106
<li><a href="fake/paramFromAnotherLib.html">paramFromAnotherLib</a></li>

0 commit comments

Comments
 (0)