Skip to content

Commit 7ab3444

Browse files
authored
Format function references. (#1349)
1 parent f5153b2 commit 7ab3444

File tree

2 files changed

+67
-2
lines changed

2 files changed

+67
-2
lines changed

lib/src/front_end/ast_node_visitor.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,10 @@ class AstNodeVisitor extends ThrowingAstVisitor<Piece> with PieceFactory {
874874

875875
@override
876876
Piece visitFunctionReference(FunctionReference node) {
877-
throw UnimplementedError();
877+
return buildPiece((b) {
878+
b.visit(node.function);
879+
b.visit(node.typeArguments);
880+
});
878881
}
879882

880883
@override

test/type/function.stmt

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,4 +217,66 @@ longMethod({required int reallyLongParameterNameWow}) {}
217217
longMethod({
218218
required int
219219
reallyLongParameterNameWow,
220-
}) {}
220+
}) {}
221+
>>> Unsplit generic method instantiation.
222+
void main() => id < int > ;
223+
<<<
224+
void main() => id<int>;
225+
>>> Unsplit generic function reference, multiple type arguments.
226+
void main() => id < int , String , bool > ;
227+
<<<
228+
void main() => id<int, String, bool>;
229+
>>> Unsplit generic constructor tear-off.
230+
var x = Class < int >;
231+
<<<
232+
var x = Class<int>;
233+
>>> Split generic function reference between arguments.
234+
LongClassName<First, Second, Third, Fourth>;
235+
<<<
236+
LongClassName<
237+
First,
238+
Second,
239+
Third,
240+
Fourth
241+
>;
242+
>>> Split generic function references, one type argument per line.
243+
LongClassName<First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth>;
244+
<<<
245+
LongClassName<
246+
First,
247+
Second,
248+
Third,
249+
Fourth,
250+
Fifth,
251+
Sixth,
252+
Seventh,
253+
Eighth
254+
>;
255+
>>> Split generic function reference with nested type arguments.
256+
LongClassName<First, Inner<Second, Third, Fourth, Fifth, Sixth, Seventh>, Eighth>;
257+
<<<
258+
LongClassName<
259+
First,
260+
Inner<
261+
Second,
262+
Third,
263+
Fourth,
264+
Fifth,
265+
Sixth,
266+
Seventh
267+
>,
268+
Eighth
269+
>;
270+
>>> Split generic function reference nested inside expression.
271+
veryLongFunction(argument, ConstructorTearOff<First, Second, Third, Fourth>, argument);
272+
<<<
273+
veryLongFunction(
274+
argument,
275+
ConstructorTearOff<
276+
First,
277+
Second,
278+
Third,
279+
Fourth
280+
>,
281+
argument,
282+
);

0 commit comments

Comments
 (0)