Skip to content

Commit d59aea8

Browse files
authored
Merge pull request #330 from kimdv/kimdv/add-convenience-initializers-function-call-expr
Add convenience initializers function call expr
2 parents 3ea358d + c1b3007 commit d59aea8

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
14+
import Foundation
15+
16+
extension FunctionCallExpr {
17+
public init(
18+
_ calledExpression: IdentifierExpr,
19+
leftParen: ExpressibleAsTokenSyntax? = nil,
20+
rightParen: ExpressibleAsTokenSyntax? = nil,
21+
trailingClosure: ExpressibleAsClosureExpr? = nil,
22+
@TupleExprElementListBuilder argumentListBuilder: () -> TupleExprElementList = { .empty },
23+
@MultipleTrailingClosureElementListBuilder additionalTrailingClosuresBuilder: () -> MultipleTrailingClosureElementList? = { nil }
24+
) {
25+
self.init(
26+
calledExpression: calledExpression,
27+
leftParen: leftParen,
28+
argumentList: argumentListBuilder(),
29+
rightParen: rightParen,
30+
trailingClosure: trailingClosure,
31+
additionalTrailingClosures: additionalTrailingClosuresBuilder()
32+
)
33+
}
34+
}

Tests/SwiftSyntaxBuilderTest/FunctionTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ final class FunctionTests: XCTestCase {
2727
]), body: ifCodeBlock)
2828

2929
ReturnStmt(expression: SequenceExpr(elementsBuilder: {
30-
FunctionCallExpr(calledExpression: IdentifierExpr(identifier: TokenSyntax.identifier("fibonacci")), leftParen: TokenSyntax.leftParen, rightParen: TokenSyntax.rightParen, argumentListBuilder: {
30+
FunctionCallExpr(calledExpression: IdentifierExpr("fibonacci"), leftParen: TokenSyntax.leftParen, rightParen: TokenSyntax.rightParen, argumentListBuilder: {
3131
TupleExprElement(expression: SequenceExpr(elementsBuilder: {
3232
IntegerLiteralExpr(digits: "n")
3333

@@ -39,7 +39,7 @@ final class FunctionTests: XCTestCase {
3939

4040
BinaryOperatorExpr(operatorToken: TokenSyntax.spacedBinaryOperator("+"))
4141

42-
FunctionCallExpr(calledExpression: IdentifierExpr(identifier: TokenSyntax.identifier("fibonacci")), leftParen: TokenSyntax.leftParen, rightParen: TokenSyntax.rightParen, argumentListBuilder: {
42+
FunctionCallExpr("fibonacci", leftParen: TokenSyntax.leftParen, rightParen: TokenSyntax.rightParen, argumentListBuilder: {
4343
TupleExprElement(expression: SequenceExpr(elementsBuilder: {
4444
IntegerLiteralExpr(digits: "n")
4545

0 commit comments

Comments
 (0)