Skip to content

Commit 59ca6d2

Browse files
authored
Introduce String.comma constant for join separators (#812)
1 parent 9af890c commit 59ca6d2

12 files changed

Lines changed: 89 additions & 71 deletions

‎Sources/JExtractSwiftLib/CTypes/CFunction.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ extension CFunction: CustomStringConvertible {
5555

5656
// Function parameters.
5757
result += "("
58-
result += parameters.map { $0.description }.joined(separator: ", ")
58+
result += parameters.map { $0.description }.joined(separator: .comma)
5959
CType.printFunctionParametersSuffix(
6060
isVariadic: isVariadic,
6161
hasZeroParameters: parameters.isEmpty,

‎Sources/JExtractSwiftLib/CTypes/CType.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ extension CType: CustomStringConvertible {
216216
result += "("
217217

218218
// Render the parameter types.
219-
result += parameters.map { $0.description }.joined(separator: ", ")
219+
result += parameters.map { $0.description }.joined(separator: .comma)
220220

221221
CType.printFunctionParametersSuffix(
222222
isVariadic: variadic,

‎Sources/JExtractSwiftLib/Convenience/JavaType+Extensions.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ extension JavaType {
196196
}
197197
let genericClause: String =
198198
if !typeParameters.isEmpty {
199-
"<\(typeParameters.map(\.boxedName).joined(separator: ", "))>"
199+
"<\(typeParameters.map(\.boxedName).joined(separator: .comma))>"
200200
} else {
201201
""
202202
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2026 Apple Inc. and the Swift.org project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of Swift.org project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
extension String {
16+
/// Comma-space separator; Convenience to avoid having to escape the string when joining inside other strings.
17+
public static let comma: String = ", "
18+
}

‎Sources/JExtractSwiftLib/FFM/CDeclLowering/FFMSwift2JavaGenerator+FunctionLowering.swift‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ extension LoweredFunctionSignature {
976976
as apiKind: SwiftAPIKind,
977977
) -> FunctionDeclSyntax {
978978

979-
let cdeclParams = allLoweredParameters.map(\.description).joined(separator: ", ")
979+
let cdeclParams = allLoweredParameters.map(\.description).joined(separator: .comma)
980980
let cdeclReturnType = cdeclReturnTypeForThunk
981981
let returnClause = !cdeclReturnType.isVoid ? " -> \(cdeclReturnType.description)" : ""
982982

@@ -1036,7 +1036,7 @@ extension LoweredFunctionSignature {
10361036
let argExpr = original.parameters[i].convention == .inout ? "&\(argument)" : argument
10371037
return LabeledExprSyntax(label: original.parameters[i].argumentLabel, expression: argExpr).description
10381038
}
1039-
.joined(separator: ", ")
1039+
.joined(separator: .comma)
10401040
resultExpr = "\(callee)(\(raw: arguments))"
10411041

10421042
case .getter:
@@ -1056,7 +1056,7 @@ extension LoweredFunctionSignature {
10561056
.map { (i, argument) -> String in
10571057
LabeledExprSyntax(label: original.parameters[i].argumentLabel, expression: argument).description
10581058
}
1059-
.joined(separator: ", ")
1059+
.joined(separator: .comma)
10601060
resultExpr = "\(callee)[\(raw: parameters)]"
10611061
case .subscriptSetter:
10621062
assert(paramExprs.count >= 1)
@@ -1068,7 +1068,7 @@ extension LoweredFunctionSignature {
10681068
.map { (i, argument) -> String in
10691069
LabeledExprSyntax(label: original.parameters[i].argumentLabel, expression: argument).description
10701070
}
1071-
.joined(separator: ", ")
1071+
.joined(separator: .comma)
10721072
resultExpr = "\(callee)[\(raw: parameters)] = \(newValueArgument)"
10731073
}
10741074

‎Sources/JExtractSwiftLib/FFM/ConversionStep.swift‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ enum ConversionStep: Equatable {
135135

136136
// FIXME: Should be able to use structured initializers here instead
137137
// of splatting out text.
138-
let renderedArgumentList = renderedArguments.joined(separator: ", ")
138+
let renderedArgumentList = renderedArguments.joined(separator: .comma)
139139
return "\(raw: type.description)(\(raw: renderedArgumentList))"
140140

141141
case .tuplify(let elements):
@@ -145,7 +145,7 @@ enum ConversionStep: Equatable {
145145

146146
// FIXME: Should be able to use structured initializers here instead
147147
// of splatting out text.
148-
let renderedElementList = renderedElements.joined(separator: ", ")
148+
let renderedElementList = renderedElements.joined(separator: .comma)
149149
return "(\(raw: renderedElementList))"
150150

151151
case .populatePointer(name: let pointer, assumingType: let type, to: let step):
@@ -185,7 +185,7 @@ enum ConversionStep: Equatable {
185185
}
186186

187187
// FIXME: Should be able to use structured initializers here instead of splatting out text.
188-
let renderedArgumentList = renderedArguments.joined(separator: ", ")
188+
let renderedArgumentList = renderedArguments.joined(separator: .comma)
189189

190190
let methodApply: String =
191191
if let methodName {
@@ -240,7 +240,7 @@ enum ConversionStep: Equatable {
240240
}
241241

242242
// Call the lowered closure with lowered parameters.
243-
let loweredResult = "\(placeholder)(\(args.map(\.description).joined(separator: ", ")))"
243+
let loweredResult = "\(placeholder)(\(args.map(\.description).joined(separator: .comma)))"
244244

245245
// Raise the lowered result.
246246
let result = resultStep.asExprSyntax(placeholder: loweredResult.description, bodyItems: &body)
@@ -249,7 +249,7 @@ enum ConversionStep: Equatable {
249249
// Construct the closure expression.
250250
var closure = ExprSyntax(
251251
"""
252-
{ (\(raw: params.joined(separator: ", "))) in
252+
{ (\(raw: params.joined(separator: .comma))) in
253253
}
254254
"""
255255
).cast(ClosureExprSyntax.self)

‎Sources/JExtractSwiftLib/FFM/FFMSwift2JavaGenerator+JavaBindingsPrinting.swift‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ extension FFMSwift2JavaGenerator {
136136
params.append("\(annotationsStr)\(param.type.javaType) \(name)")
137137
args.append(name)
138138
}
139-
let paramsStr = params.joined(separator: ", ")
140-
let argsStr = args.joined(separator: ", ")
139+
let paramsStr = params.joined(separator: .comma)
140+
let argsStr = args.joined(separator: .comma)
141141

142142
printer.print(
143143
"""
@@ -236,7 +236,7 @@ extension FFMSwift2JavaGenerator {
236236
"""
237237
@FunctionalInterface
238238
public interface Function {
239-
\(cResultType.javaType) apply(\(paramDecls.joined(separator: ", ")));
239+
\(cResultType.javaType) apply(\(paramDecls.joined(separator: .comma)));
240240
}
241241
"""
242242
)
@@ -246,7 +246,7 @@ extension FFMSwift2JavaGenerator {
246246
"""
247247
public final static class Function$Impl implements Function {
248248
\(impl.members.joinedJavaStatements(indent: 2))
249-
public \(cResultType.javaType) apply(\(paramDecls.joined(separator: ", "))) {
249+
public \(cResultType.javaType) apply(\(paramDecls.joined(separator: .comma))) {
250250
\(impl.body)
251251
}
252252
}
@@ -319,7 +319,7 @@ extension FFMSwift2JavaGenerator {
319319
"""
320320
@FunctionalInterface
321321
public interface \(functionType.name) {
322-
\(functionType.result.javaResultType) apply(\(apiParams.joined(separator: ", ")));
322+
\(functionType.result.javaResultType) apply(\(apiParams.joined(separator: .comma)));
323323
}
324324
"""
325325
)
@@ -333,7 +333,7 @@ extension FFMSwift2JavaGenerator {
333333
) { printer in
334334
printer.print(
335335
"""
336-
return \(cdeclDescriptor).toUpcallStub((\(cdeclParams.joined(separator: ", "))) -> {
336+
return \(cdeclDescriptor).toUpcallStub((\(cdeclParams.joined(separator: .comma))) -> {
337337
"""
338338
)
339339
printer.indent()
@@ -343,7 +343,7 @@ extension FFMSwift2JavaGenerator {
343343
convertedArgs.append(arg)
344344
}
345345

346-
let call = "fi.apply(\(convertedArgs.joined(separator: ", ")))"
346+
let call = "fi.apply(\(convertedArgs.joined(separator: .comma)))"
347347
let result = functionType.result.conversion.render(&printer, call)
348348
if functionType.result.javaResultType == .void {
349349
printer.print("\(result);")
@@ -394,7 +394,7 @@ extension FFMSwift2JavaGenerator {
394394
if translatedSignature.canThrowSwiftIntegerOverflowException {
395395
throwsClauses.append(JavaType.swiftIntegerOverflowException.className!)
396396
}
397-
let throwsClause = throwsClauses.isEmpty ? "" : " throws \(throwsClauses.joined(separator: ", "))"
397+
let throwsClause = throwsClauses.isEmpty ? "" : " throws \(throwsClauses.joined(separator: .comma))"
398398

399399
TranslatedDocumentation.printDocumentation(
400400
importedFunc: decl,
@@ -404,7 +404,7 @@ extension FFMSwift2JavaGenerator {
404404
)
405405
printer.printBraceBlock(
406406
"""
407-
\(annotationsStr)\(modifiers) \(returnTy) \(methodName)(\(paramDecls.joined(separator: ", ")))\(throwsClause)
407+
\(annotationsStr)\(modifiers) \(returnTy) \(methodName)(\(paramDecls.joined(separator: .comma)))\(throwsClause)
408408
"""
409409
) { printer in
410410
if case .instance = decl.functionSignature.selfParameter {
@@ -516,7 +516,7 @@ extension FFMSwift2JavaGenerator {
516516
}
517517

518518
//=== Part 3: Downcall.
519-
let downCall = "\(thunkName).call(\(downCallArguments.joined(separator: ", ")))"
519+
let downCall = "\(thunkName).call(\(downCallArguments.joined(separator: .comma)))"
520520

521521
/// Helper to emit the error check after a downcall
522522
func printErrorCheck(_ printer: inout JavaPrinter) {
@@ -813,7 +813,7 @@ extension FFMSwift2JavaGenerator.JavaConversionStep {
813813
placeholderForDowncall: placeholderForDowncall,
814814
)
815815
}
816-
return "\(tupleClassName)(\(args.joined(separator: ", ")))"
816+
return "\(tupleClassName)(\(args.joined(separator: .comma)))"
817817
}
818818
}
819819
}

‎Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+JavaBindingsPrinting.swift‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ extension JNISwift2JavaGenerator {
180180
if !self.interfaceProtocolWrappers.keys.contains(decl) && !extends.contains("JNISwiftInstance") {
181181
extends.append("JNISwiftInstance")
182182
}
183-
let extendsString = extends.isEmpty ? "" : " extends \(extends.joined(separator: ", "))"
183+
let extendsString = extends.isEmpty ? "" : " extends \(extends.joined(separator: .comma))"
184184

185185
printer.printBraceBlock("public interface \(decl.effectiveJavaSimpleName)\(extendsString)") { printer in
186186
for initializer in decl.initializers {
@@ -270,7 +270,7 @@ extension JNISwift2JavaGenerator {
270270
if isEffectivelyGeneric {
271271
swiftPointerParams.append("selfTypePointer")
272272
}
273-
let swiftPointerArg = swiftPointerParams.map { "long \($0)" }.joined(separator: ", ")
273+
let swiftPointerArg = swiftPointerParams.map { "long \($0)" }.joined(separator: .comma)
274274
printer.printBraceBlock("private \(decl.effectiveJavaSimpleName)(\(swiftPointerArg), SwiftArena swiftArena)") { printer in
275275
for param in swiftPointerParams {
276276
printer.print(
@@ -304,11 +304,11 @@ extension JNISwift2JavaGenerator {
304304
* </ul>
305305
*/
306306
public static\(genericClause) \(javaName)\(genericClause) wrapMemoryAddressUnsafe(\(swiftPointerArg), SwiftArena swiftArena) {
307-
return new \(javaName)\(genericClause)(\(swiftPointerParams.joined(separator: ", ")), swiftArena);
307+
return new \(javaName)\(genericClause)(\(swiftPointerParams.joined(separator: .comma)), swiftArena);
308308
}
309309
310310
public static\(genericClause) \(javaName)\(genericClause) wrapMemoryAddressUnsafe(\(swiftPointerArg)) {
311-
return new \(javaName)\(genericClause)(\(swiftPointerParams.joined(separator: ", ")), SwiftMemoryManagement.DEFAULT_SWIFT_JAVA_AUTO_ARENA);
311+
return new \(javaName)\(genericClause)(\(swiftPointerParams.joined(separator: .comma)), SwiftMemoryManagement.DEFAULT_SWIFT_JAVA_AUTO_ARENA);
312312
}
313313
"""
314314
)
@@ -458,7 +458,7 @@ extension JNISwift2JavaGenerator {
458458
.compactMap(\.asNominalTypeDeclaration)
459459
.filter { $0.kind == .protocol }
460460
.map(\.name)
461-
let implementsClause = implements.joined(separator: ", ")
461+
let implementsClause = implements.joined(separator: .comma)
462462
// Specialized types are concrete — no generic clause on the Java side
463463
let genericClause = decl.javaGenericClause
464464
printer.printBraceBlock(
@@ -510,7 +510,7 @@ extension JNISwift2JavaGenerator {
510510
if decl.genericParameterNames.isEmpty {
511511
""
512512
} else {
513-
"<\(decl.genericParameterNames.joined(separator: ", "))>"
513+
"<\(decl.genericParameterNames.joined(separator: .comma))>"
514514
}
515515

516516
printer.printBraceBlock("public sealed interface Case\(caseGenericClause)") { printer in
@@ -524,7 +524,7 @@ extension JNISwift2JavaGenerator {
524524
}
525525

526526
// Print record
527-
printer.print("record \(translatedCase.name)\(caseGenericClause)(\(members.joined(separator: ", "))) implements Case\(caseGenericClause) {}")
527+
printer.print("record \(translatedCase.name)\(caseGenericClause)(\(members.joined(separator: .comma))) implements Case\(caseGenericClause) {}")
528528
}
529529
}
530530
printer.println()
@@ -591,7 +591,7 @@ extension JNISwift2JavaGenerator {
591591
} else {
592592
(0..<enumCase.parameters.count).map { i in
593593
"t.$\(i)"
594-
}.joined(separator: ", ")
594+
}.joined(separator: .comma)
595595
}
596596
let translatedResult = getAsCaseFunction.translatedFunctionSignature.result
597597
getAsCaseFunction.translatedFunctionSignature.result.conversion = .method(
@@ -679,7 +679,7 @@ extension JNISwift2JavaGenerator {
679679
"""
680680
@FunctionalInterface
681681
public interface \(functionType.name) {
682-
\(functionType.result.javaType) apply(\(apiParams.joined(separator: ", ")));
682+
\(functionType.result.javaType) apply(\(apiParams.joined(separator: .comma)));
683683
}
684684
"""
685685
)
@@ -732,7 +732,7 @@ extension JNISwift2JavaGenerator {
732732
generics.append((name, extends))
733733
}
734734
.map { "\($0) extends \($1.compactMap(\.className).joined(separator: " & "))" }
735-
.joined(separator: ", ")
735+
.joined(separator: .comma)
736736

737737
if !generics.isEmpty {
738738
modifiers.append("<" + generics + ">")
@@ -741,7 +741,7 @@ extension JNISwift2JavaGenerator {
741741
var annotationsStr = translatedSignature.annotations.map({ $0.render() }).joined(separator: "\n")
742742
if !annotationsStr.isEmpty { annotationsStr += "\n" }
743743

744-
let parametersStr = parameters.joined(separator: ", ")
744+
let parametersStr = parameters.joined(separator: .comma)
745745

746746
// Print default global arena variation
747747
// If we have enabled javaCallbacks we must emit default
@@ -772,7 +772,7 @@ extension JNISwift2JavaGenerator {
772772
) { printer in
773773
let globalArenaName = "SwiftMemoryManagement.DEFAULT_SWIFT_JAVA_AUTO_ARENA"
774774
let arguments = translatedDecl.translatedFunctionSignature.parameters.map(\.parameter.name) + [globalArenaName]
775-
let call = "\(translatedDecl.name)(\(arguments.joined(separator: ", ")))"
775+
let call = "\(translatedDecl.name)(\(arguments.joined(separator: .comma)))"
776776
if translatedDecl.translatedFunctionSignature.result.javaType.isVoid {
777777
printer.print("\(call);")
778778
} else {
@@ -794,7 +794,7 @@ extension JNISwift2JavaGenerator {
794794
)
795795
}
796796
let signature =
797-
"\(annotationsStr)\(modifiers.joined(separator: " ")) \(resultType) \(translatedDecl.name)(\(parameters.joined(separator: ", ")))\(throwsClause)"
797+
"\(annotationsStr)\(modifiers.joined(separator: " ")) \(resultType) \(translatedDecl.name)(\(parameters.joined(separator: .comma)))\(throwsClause)"
798798
if skipMethodBody {
799799
printer.print("\(signature);")
800800
} else {
@@ -820,7 +820,7 @@ extension JNISwift2JavaGenerator {
820820

821821
let renderedParameters = parameters.map { javaParameter in
822822
"\(javaParameter.type) \(javaParameter.name)"
823-
}.joined(separator: ", ")
823+
}.joined(separator: .comma)
824824

825825
printer.print("private static native \(resultType) \(translatedDecl.nativeFunctionName)(\(renderedParameters));")
826826
}
@@ -862,7 +862,7 @@ extension JNISwift2JavaGenerator {
862862
// TODO: If we always generate a native method and a "public" method, we can actually choose our own thunk names
863863
// using the registry?
864864
let downcall =
865-
"\(translatedDecl.parentName).\(translatedDecl.nativeFunctionName)(\(arguments.joined(separator: ", ")))"
865+
"\(translatedDecl.parentName).\(translatedDecl.nativeFunctionName)(\(arguments.joined(separator: .comma)))"
866866

867867
//=== Part 4: Convert the return value.
868868
if translatedFunctionSignature.result.javaType.isVoid {

0 commit comments

Comments
 (0)