@@ -26,7 +26,7 @@ extension Trivia {
26
26
27
27
/// Produce trivia from the last newline to the end, dropping anything
28
28
/// prior to that.
29
- func onlyLastLine( ) -> Trivia {
29
+ var onlyLastLine : Trivia {
30
30
guard let lastNewline = pieces. lastIndex ( where: { $0. isNewline } ) else {
31
31
return self
32
32
}
@@ -122,15 +122,13 @@ extension LabeledExprListSyntax {
122
122
/// context.
123
123
func insertingArgument(
124
124
at position: SyntaxChildrenIndex ,
125
- generator: ( Trivia , TokenSyntax ? ) -> LabeledExprSyntax
125
+ generator: ( _ leadingTrivia : Trivia , _ trailingComma : TokenSyntax ? ) -> LabeledExprSyntax
126
126
) -> LabeledExprListSyntax {
127
127
// Turn the arguments into an array so we can manipulate them.
128
128
var arguments = Array ( self )
129
129
130
130
let positionIdx = distance ( from: startIndex, to: position)
131
131
132
- let commaToken = TokenSyntax . commaToken ( )
133
-
134
132
// Figure out leading trivia and adjust the prior argument (if there is
135
133
// one) by adding a comma, if necessary.
136
134
let leadingTrivia : Trivia
@@ -143,7 +141,7 @@ extension LabeledExprListSyntax {
143
141
144
142
// If the prior argument is missing a trailing comma, add one.
145
143
if priorArgument. trailingComma == nil {
146
- arguments [ positionIdx - 1 ] . trailingComma = commaToken
144
+ arguments [ positionIdx - 1 ] . trailingComma = . commaToken( )
147
145
}
148
146
} else if positionIdx + 1 < count {
149
147
leadingTrivia = arguments [ positionIdx + 1 ] . leadingTrivia
@@ -154,7 +152,7 @@ extension LabeledExprListSyntax {
154
152
// Determine whether we need a trailing comma on this argument.
155
153
let trailingComma : TokenSyntax ?
156
154
if position < endIndex {
157
- trailingComma = commaToken
155
+ trailingComma = . commaToken( )
158
156
} else {
159
157
trailingComma = nil
160
158
}
@@ -194,9 +192,7 @@ extension FunctionCallExprSyntax {
194
192
return false
195
193
}
196
194
197
- guard let stringLiteral = nameArgument. expression. as ( StringLiteralExprSyntax . self) ,
198
- let literalValue = stringLiteral. representedLiteralValue
199
- else {
195
+ guard let literalValue = nameArgument. expression. as ( StringLiteralExprSyntax . self) ? . representedLiteralValue else {
200
196
return false
201
197
}
202
198
@@ -220,24 +216,21 @@ extension ArrayExprSyntax {
220
216
) -> ArrayExprSyntax {
221
217
var elements = self . elements
222
218
223
- let commaToken = TokenSyntax . commaToken ( )
224
-
225
219
// If there are already elements, tack it on.
226
220
let leadingTrivia : Trivia
227
221
let trailingTrivia : Trivia
228
222
let leftSquareTrailingTrivia : Trivia
229
223
if let last = elements. last {
230
224
// The leading trivia of the new element should match that of the
231
225
// last element.
232
- leadingTrivia = last. leadingTrivia. onlyLastLine ( )
226
+ leadingTrivia = last. leadingTrivia. onlyLastLine
233
227
234
228
// Add a trailing comma to the last element if it isn't already
235
229
// there.
236
230
if last. trailingComma == nil {
237
231
var newElements = Array ( elements)
238
- newElements [ newElements. count - 1 ] . trailingComma = commaToken
239
- newElements [ newElements. count - 1 ] . expression. trailingTrivia =
240
- Trivia ( )
232
+ newElements [ newElements. count - 1 ] . trailingComma = . commaToken( )
233
+ newElements [ newElements. count - 1 ] . expression. trailingTrivia = Trivia ( )
241
234
newElements [ newElements. count - 1 ] . trailingTrivia = last. trailingTrivia
242
235
elements = ArrayElementListSyntax ( newElements)
243
236
}
@@ -257,7 +250,7 @@ extension ArrayExprSyntax {
257
250
elements. append (
258
251
ArrayElementSyntax (
259
252
expression: element. with ( \. leadingTrivia, leadingTrivia) ,
260
- trailingComma: commaToken. with ( \. trailingTrivia, trailingTrivia)
253
+ trailingComma: . commaToken( ) . with ( \. trailingTrivia, trailingTrivia)
261
254
)
262
255
)
263
256
@@ -358,10 +351,10 @@ extension Array<LabeledExprSyntax> {
358
351
359
352
/// Append an array literal containing elements that can be rendered
360
353
/// into expression syntax nodes.
361
- mutating func append< T> (
354
+ mutating func append< T: ManifestSyntaxRepresentable > (
362
355
label: String ? ,
363
356
arrayLiteral: [ T ]
364
- ) where T: ManifestSyntaxRepresentable , T . PreferredSyntax == ExprSyntax {
357
+ ) where T. PreferredSyntax == ExprSyntax {
365
358
var elements : [ ArrayElementSyntax ] = [ ]
366
359
for element in arrayLiteral {
367
360
elements. append ( expression: element. asSyntax ( ) )
@@ -402,20 +395,20 @@ extension Array<LabeledExprSyntax> {
402
395
403
396
/// Append an array literal containing elements that can be rendered
404
397
/// into expression syntax nodes.
405
- mutating func appendIf< T> (
398
+ mutating func appendIf< T: ManifestSyntaxRepresentable > (
406
399
label: String ? ,
407
400
arrayLiteral: [ T ] ?
408
- ) where T: ManifestSyntaxRepresentable , T . PreferredSyntax == ExprSyntax {
401
+ ) where T. PreferredSyntax == ExprSyntax {
409
402
guard let arrayLiteral else { return }
410
403
append ( label: label, arrayLiteral: arrayLiteral)
411
404
}
412
405
413
406
/// Append an array literal containing elements that can be rendered
414
407
/// into expression syntax nodes, but only if it's not empty.
415
- mutating func appendIfNonEmpty< T> (
408
+ mutating func appendIfNonEmpty< T: ManifestSyntaxRepresentable > (
416
409
label: String ? ,
417
410
arrayLiteral: [ T ]
418
- ) where T: ManifestSyntaxRepresentable , T . PreferredSyntax == ExprSyntax {
411
+ ) where T. PreferredSyntax == ExprSyntax {
419
412
if arrayLiteral. isEmpty { return }
420
413
421
414
append ( label: label, arrayLiteral: arrayLiteral)
@@ -468,7 +461,7 @@ extension FunctionCallExprSyntax {
468
461
/// - Returns: the function call after making this change.
469
462
func appendingToArrayArgument(
470
463
label: String ,
471
- trailingLabels : Set < String > ,
464
+ labelsAfter : Set < String > ,
472
465
newElement: ExprSyntax
473
466
) throws -> FunctionCallExprSyntax {
474
467
// If there is already an argument with this name, append to the array
@@ -483,7 +476,7 @@ extension FunctionCallExprSyntax {
483
476
484
477
// Format the element appropriately for the context.
485
478
let indentation = Trivia (
486
- pieces: arg. leadingTrivia. filter { $0 . isSpaceOrTab }
479
+ pieces: arg. leadingTrivia. filter ( \ . isSpaceOrTab)
487
480
)
488
481
let format = BasicFormat (
489
482
indentationWidth: [ defaultIndent] ,
@@ -504,13 +497,13 @@ extension FunctionCallExprSyntax {
504
497
505
498
// Insert the new argument at the appropriate place in the call.
506
499
let insertionPos = arguments. findArgumentInsertionPosition (
507
- labelsAfter: trailingLabels
500
+ labelsAfter: labelsAfter
508
501
)
509
502
let newArguments = arguments. insertingArgument (
510
503
at: insertionPos
511
504
) { ( leadingTrivia, trailingComma) in
512
505
// Format the element appropriately for the context.
513
- let indentation = Trivia ( pieces: leadingTrivia. filter { $0 . isSpaceOrTab } )
506
+ let indentation = Trivia ( pieces: leadingTrivia. filter ( \ . isSpaceOrTab) )
514
507
let format = BasicFormat (
515
508
indentationWidth: [ defaultIndent] ,
516
509
initialIndentation: indentation. appending ( defaultIndent)
@@ -521,9 +514,7 @@ extension FunctionCallExprSyntax {
521
514
// Form the array.
522
515
let newArgument = ArrayExprSyntax (
523
516
leadingTrivia: . space,
524
- leftSquare: . leftSquareToken(
525
- trailingTrivia: . newline
526
- ) ,
517
+ leftSquare: . leftSquareToken( trailingTrivia: . newline) ,
527
518
elements: ArrayElementListSyntax (
528
519
[
529
520
ArrayElementSyntax (
@@ -532,9 +523,7 @@ extension FunctionCallExprSyntax {
532
523
)
533
524
]
534
525
) ,
535
- rightSquare: . rightSquareToken(
536
- leadingTrivia: leadingTrivia
537
- )
526
+ rightSquare: . rightSquareToken( leadingTrivia: leadingTrivia)
538
527
)
539
528
540
529
// Create the labeled argument for the array.
0 commit comments