@@ -117,9 +117,16 @@ public struct ${node.name}: SyntaxCollection, SyntaxHashable {
117
117
self . _syntaxNode = Syntax ( data)
118
118
}
119
119
120
- public init( _ children: [ Element] ) {
120
+ public init( _ children: [ Element] ) { self . init ( children, arena: SyntaxArena ( ) ) }
121
+
122
+ % # NOTE: Don't make 'arena' defaulted because:
123
+ % # * Some clients use 'XXXListSyntax . init ' as a '( [ Element] ) - > XXXListSyntax '
124
+ % # func tion
125
+ % # * SyntaxBuilder has e . g . 'init( _: [ ExprSyntaxProtocol] ) ' method that makes
126
+ % # 'XXXListSyntax ( [ ExprSyntax ( node) !] ) ' ambiguous
127
+ public init( _ children: [ Element] , arena: SyntaxArena) {
121
128
let raw = RawSyntax . makeLayout ( kind: SyntaxKind . ${ node. swift_syntax_kind} ,
122
- from: children. map { $0. raw } , arena: . default )
129
+ from: children. map { $0. raw } , arena: arena )
123
130
let data = SyntaxData . forRoot ( raw)
124
131
self . init ( data)
125
132
}
@@ -134,9 +141,10 @@ public struct ${node.name}: SyntaxCollection, SyntaxHashable {
134
141
/// collection.
135
142
/// - Returns: A new `${node.name}` with the new layout underlying it.
136
143
internal func replacingLayout(
137
- _ layout: [ RawSyntax? ] ) - > ${ node. name} {
138
- let newRaw = layoutView. replacingLayout ( with: layout, arena: . default)
139
- let newData = data. replacingSelf ( newRaw)
144
+ _ layout: [ RawSyntax? ] ,
145
+ arena: SyntaxArena) - > ${ node. name} {
146
+ let newRaw = layoutView. replacingLayout ( with: layout, arena: arena)
147
+ let newData = data. replacingSelf ( newRaw, arena: arena)
140
148
return ${ node. name} ( newData)
141
149
}
142
150
@@ -145,10 +153,10 @@ public struct ${node.name}: SyntaxCollection, SyntaxHashable {
145
153
///
146
154
/// - Parameter syntax: The element to append.
147
155
/// - Returns: A new `${node.name}` with that element appended to the end.
148
- public func appending( _ syntax: Element) - > ${ node. name} {
156
+ public func appending( _ syntax: Element, arena : SyntaxArena = SyntaxArena ( ) ) - > ${ node. name} {
149
157
var newLayout = layoutView. formLayoutArray ( )
150
158
newLayout. append ( syntax. raw)
151
- return replacingLayout ( newLayout)
159
+ return replacingLayout ( newLayout, arena : arena )
152
160
}
153
161
154
162
/// Creates a new `${node.name}` by prepending the provided syntax element
@@ -157,8 +165,8 @@ public struct ${node.name}: SyntaxCollection, SyntaxHashable {
157
165
/// - Parameter syntax: The element to prepend.
158
166
/// - Returns: A new `${node.name}` with that element prepended to the
159
167
/// beginning.
160
- public func prepending( _ syntax: Element) - > ${ node. name} {
161
- return inserting ( syntax, at: 0 )
168
+ public func prepending( _ syntax: Element, arena : SyntaxArena = SyntaxArena ( ) ) - > ${ node. name} {
169
+ return inserting ( syntax, at: 0 , arena : arena )
162
170
}
163
171
164
172
/// Creates a new `${node.name}` by inserting the provided syntax element
@@ -169,13 +177,13 @@ public struct ${node.name}: SyntaxCollection, SyntaxHashable {
169
177
/// - index: The index at which to insert the element in the collection.
170
178
///
171
179
/// - Returns: A new `${node.name}` with that element appended to the end.
172
- public func inserting( _ syntax: Element, at index: Int) - > ${ node. name} {
180
+ public func inserting( _ syntax: Element, at index: Int, arena : SyntaxArena = SyntaxArena ( ) ) - > ${ node. name} {
173
181
var newLayout = layoutView. formLayoutArray ( )
174
182
/// Make sure the index is a valid insertion index (0 to 1 past the end)
175
183
precondition ( ( newLayout. startIndex... newLayout. endIndex) . contains ( index) ,
176
184
" inserting node at invalid index \( index) " )
177
185
newLayout. insert ( syntax. raw, at: index)
178
- return replacingLayout ( newLayout)
186
+ return replacingLayout ( newLayout, arena : arena )
179
187
}
180
188
181
189
/// Creates a new `${node.name}` by replacing the syntax element
@@ -186,13 +194,13 @@ public struct ${node.name}: SyntaxCollection, SyntaxHashable {
186
194
/// - syntax: The element to replace with.
187
195
///
188
196
/// - Returns: A new `${node.name}` with the new element at the provided index.
189
- public func replacing( childAt index: Int, with syntax: Element) - > ${ node. name} {
197
+ public func replacing( childAt index: Int, with syntax: Element, arena : SyntaxArena = SyntaxArena ( ) ) - > ${ node. name} {
190
198
var newLayout = layoutView. formLayoutArray ( )
191
199
/// Make sure the index is a valid index for replacing
192
200
precondition ( ( newLayout. startIndex..< newLayout. endIndex) . contains ( index) ,
193
201
" replacing node at invalid index \( index) " )
194
202
newLayout [ index] = syntax. raw
195
- return replacingLayout ( newLayout)
203
+ return replacingLayout ( newLayout, arena : arena )
196
204
}
197
205
198
206
/// Creates a new `${node.name}` by removing the syntax element at the
@@ -201,55 +209,55 @@ public struct ${node.name}: SyntaxCollection, SyntaxHashable {
201
209
/// - Parameter index: The index of the element to remove from the collection.
202
210
/// - Returns: A new `${node.name}` with the element at the provided index
203
211
/// removed.
204
- public func removing( childAt index: Int) - > ${ node. name} {
212
+ public func removing( childAt index: Int, arena : SyntaxArena = SyntaxArena ( ) ) - > ${ node. name} {
205
213
var newLayout = layoutView. formLayoutArray ( )
206
214
newLayout. remove ( at: index)
207
- return replacingLayout ( newLayout)
215
+ return replacingLayout ( newLayout, arena : arena )
208
216
}
209
217
210
218
/// Creates a new `${node.name}` by removing the first element.
211
219
///
212
220
/// - Returns: A new `${node.name}` with the first element removed.
213
- public func removingFirst( ) - > ${ node. name} {
221
+ public func removingFirst( arena : SyntaxArena = SyntaxArena ( ) ) - > ${ node. name} {
214
222
var newLayout = layoutView. formLayoutArray ( )
215
223
newLayout. removeFirst ( )
216
- return replacingLayout ( newLayout)
224
+ return replacingLayout ( newLayout, arena : arena )
217
225
}
218
226
219
227
/// Creates a new `${node.name}` by removing the last element.
220
228
///
221
229
/// - Returns: A new `${node.name}` with the last element removed.
222
- public func removingLast( ) - > ${ node. name} {
230
+ public func removingLast( arena : SyntaxArena = SyntaxArena ( ) ) - > ${ node. name} {
223
231
var newLayout = layoutView. formLayoutArray ( )
224
232
newLayout. removeLast ( )
225
- return replacingLayout ( newLayout)
233
+ return replacingLayout ( newLayout, arena : arena )
226
234
}
227
235
228
236
/// Returns a new `${node.name}` with its leading trivia replaced
229
237
/// by the provided trivia.
230
- public func withLeadingTrivia( _ leadingTrivia: Trivia) - > ${ node. name} {
231
- return ${ node. name} ( data. withLeadingTrivia ( leadingTrivia) )
238
+ public func withLeadingTrivia( _ leadingTrivia: Trivia, arena : SyntaxArena = SyntaxArena ( ) ) - > ${ node. name} {
239
+ return ${ node. name} ( data. withLeadingTrivia ( leadingTrivia, arena : arena ) )
232
240
}
233
241
234
242
/// Returns a new `${node.name}` with its trailing trivia replaced
235
243
/// by the provided trivia.
236
- public func withTrailingTrivia( _ trailingTrivia: Trivia) - > ${ node. name} {
237
- return ${ node. name} ( data. withTrailingTrivia ( trailingTrivia) )
244
+ public func withTrailingTrivia( _ trailingTrivia: Trivia, arena : SyntaxArena = SyntaxArena ( ) ) - > ${ node. name} {
245
+ return ${ node. name} ( data. withTrailingTrivia ( trailingTrivia, arena : arena ) )
238
246
}
239
247
240
248
/// Returns a new `${node.name}` with its leading trivia removed.
241
- public func withoutLeadingTrivia( ) - > ${ node. name} {
242
- return withLeadingTrivia ( [ ] )
249
+ public func withoutLeadingTrivia( arena : SyntaxArena = SyntaxArena ( ) ) - > ${ node. name} {
250
+ return withLeadingTrivia ( [ ] , arena : arena )
243
251
}
244
252
245
253
/// Returns a new `${node.name}` with its trailing trivia removed.
246
- public func withoutTrailingTrivia( ) - > ${ node. name} {
247
- return withTrailingTrivia ( [ ] )
254
+ public func withoutTrailingTrivia( arena : SyntaxArena = SyntaxArena ( ) ) - > ${ node. name} {
255
+ return withTrailingTrivia ( [ ] , arena : arena )
248
256
}
249
257
250
258
/// Returns a new `${node.name}` with all trivia removed.
251
- public func withoutTrivia( ) - > ${ node. name} {
252
- return withoutLeadingTrivia ( ) . withoutTrailingTrivia ( )
259
+ public func withoutTrivia( arena : SyntaxArena = SyntaxArena ( ) ) - > ${ node. name} {
260
+ return withoutLeadingTrivia ( arena : arena ) . withoutTrailingTrivia ( arena : arena )
253
261
}
254
262
255
263
/// The leading trivia (spaces, newlines, etc.) associated with this `${node.name}`.
0 commit comments