Skip to content

Commit b769451

Browse files
authored
Merge pull request swiftlang#119 from nkcsgexi/addX-rename
Use child names in API instead of using child syntax type
2 parents 2af864a + f3dd051 commit b769451

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

Sources/SwiftSyntax/SyntaxBuilders.swift.gyb

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ public struct ${Builder} {
3939
% if child_node and child_node.is_syntax_collection():
4040
% child_elt = child_node.collection_element_name
4141
% child_elt_type = child_node.collection_element_type
42+
% child_elt_name = child.name + 'Member'
4243

43-
public mutating func add${child_elt}(_ elt: ${child_elt_type}) {
44+
public mutating func add${child_elt_name}(_ elt: ${child_elt_type}) {
4445
let idx = ${node.name}.Cursor.${child.swift_name}.rawValue
4546
if let list = layout[idx] {
4647
layout[idx] = list.appending(elt.raw)

Sources/SwiftSyntax/SyntaxNodes.swift.gyb

+2-1
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,15 @@ public struct ${node.name}: ${base_type}, _SyntaxBase, Hashable {
129129
% if child_node and child_node.is_syntax_collection():
130130
% child_elt = child_node.collection_element_name
131131
% child_elt_type = child_node.collection_element_type
132+
% child_elt_name = child.name + 'Member'
132133

133134
/// Adds the provided `${child_elt}` to the node's `${child.swift_name}`
134135
/// collection.
135136
/// - param element: The new `${child_elt}` to add to the node's
136137
/// `${child.swift_name}` collection.
137138
/// - returns: A copy of the receiver with the provided `${child_elt}`
138139
/// appended to its `${child.swift_name}` collection.
139-
public func add${child_elt}(_ element: ${child_elt_type}) -> ${node.name} {
140+
public func add${child_elt_name}(_ element: ${child_elt_type}) -> ${node.name} {
140141
var collection: RawSyntax
141142
if let col = raw[Cursor.${child.swift_name}] {
142143
collection = col.appending(element.raw)

Tests/SwiftSyntaxTest/ModifierTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fileprivate func cannedVarDecl() -> VariableDeclSyntax {
1111
initializer: nil, accessor: nil, trailingComma: nil)
1212
return VariableDeclSyntax {
1313
$0.useLetOrVarKeyword(SyntaxFactory.makeLetKeyword())
14-
$0.addPatternBinding(Pattern)
14+
$0.addBindingsMember(Pattern)
1515
}
1616
}
1717

Tests/SwiftSyntaxTest/SyntaxFactory.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public class SyntaxFactoryAPITestCase: XCTestCase {
102102
let call = FunctionCallExprSyntax {
103103
$0.useCalledExpression(printID)
104104
$0.useLeftParen(SyntaxFactory.makeLeftParenToken())
105-
$0.addFunctionCallArgument(arg)
105+
$0.addArgumentListMember(arg)
106106
$0.useRightParen(SyntaxFactory.makeRightParenToken())
107107
}
108108
XCTAssertEqual("\(call)", "print(\"Hello, world!\")")
@@ -133,7 +133,7 @@ public class SyntaxFactoryAPITestCase: XCTestCase {
133133
let call1 = FunctionCallExprSyntax {
134134
$0.useCalledExpression(printID)
135135
$0.useLeftParen(SyntaxFactory.makeLeftParenToken())
136-
$0.addFunctionCallArgument(arg)
136+
$0.addArgumentListMember(arg)
137137
$0.useRightParen(SyntaxFactory.makeRightParenToken())
138138
}
139139
XCTAssertNotNil(call1.leftParen)
@@ -145,7 +145,7 @@ public class SyntaxFactoryAPITestCase: XCTestCase {
145145

146146
let call3 = FunctionCallExprSyntax {
147147
$0.useCalledExpression(printID)
148-
$0.addFunctionCallArgument(arg)
148+
$0.addArgumentListMember(arg)
149149
}
150150
XCTAssertNil(call3.leftParen)
151151
XCTAssertNil(call3.rightParen)

0 commit comments

Comments
 (0)