Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/JExtractSwiftLib/CTypes/CFunction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ extension CFunction: CustomStringConvertible {

// Function parameters.
result += "("
result += parameters.map { $0.description }.joined(separator: ", ")
result += parameters.map { $0.description }.joined(separator: .comma)
CType.printFunctionParametersSuffix(
isVariadic: isVariadic,
hasZeroParameters: parameters.isEmpty,
Expand Down
2 changes: 1 addition & 1 deletion Sources/JExtractSwiftLib/CTypes/CType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ extension CType: CustomStringConvertible {
result += "("

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

CType.printFunctionParametersSuffix(
isVariadic: variadic,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ extension JavaType {
}
let genericClause: String =
if !typeParameters.isEmpty {
"<\(typeParameters.map(\.boxedName).joined(separator: ", "))>"
"<\(typeParameters.map(\.boxedName).joined(separator: .comma))>"
} else {
""
}
Expand Down
18 changes: 18 additions & 0 deletions Sources/JExtractSwiftLib/Convenience/String+Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2026 Apple Inc. and the Swift.org project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Swift.org project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

extension String {
/// Comma-space separator; Convenience to avoid having to escape the string when joining inside other strings.
public static let comma: String = ", "
}
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ extension LoweredFunctionSignature {
as apiKind: SwiftAPIKind,
) -> FunctionDeclSyntax {

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

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

case .getter:
Expand All @@ -1056,7 +1056,7 @@ extension LoweredFunctionSignature {
.map { (i, argument) -> String in
LabeledExprSyntax(label: original.parameters[i].argumentLabel, expression: argument).description
}
.joined(separator: ", ")
.joined(separator: .comma)
resultExpr = "\(callee)[\(raw: parameters)]"
case .subscriptSetter:
assert(paramExprs.count >= 1)
Expand All @@ -1068,7 +1068,7 @@ extension LoweredFunctionSignature {
.map { (i, argument) -> String in
LabeledExprSyntax(label: original.parameters[i].argumentLabel, expression: argument).description
}
.joined(separator: ", ")
.joined(separator: .comma)
resultExpr = "\(callee)[\(raw: parameters)] = \(newValueArgument)"
}

Expand Down
10 changes: 5 additions & 5 deletions Sources/JExtractSwiftLib/FFM/ConversionStep.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ enum ConversionStep: Equatable {

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

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

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

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

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

let methodApply: String =
if let methodName {
Expand Down Expand Up @@ -240,7 +240,7 @@ enum ConversionStep: Equatable {
}

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

// Raise the lowered result.
let result = resultStep.asExprSyntax(placeholder: loweredResult.description, bodyItems: &body)
Expand All @@ -249,7 +249,7 @@ enum ConversionStep: Equatable {
// Construct the closure expression.
var closure = ExprSyntax(
"""
{ (\(raw: params.joined(separator: ", "))) in
{ (\(raw: params.joined(separator: .comma))) in
}
"""
).cast(ClosureExprSyntax.self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ extension FFMSwift2JavaGenerator {
params.append("\(annotationsStr)\(param.type.javaType) \(name)")
args.append(name)
}
let paramsStr = params.joined(separator: ", ")
let argsStr = args.joined(separator: ", ")
let paramsStr = params.joined(separator: .comma)
let argsStr = args.joined(separator: .comma)

printer.print(
"""
Expand Down Expand Up @@ -236,7 +236,7 @@ extension FFMSwift2JavaGenerator {
"""
@FunctionalInterface
public interface Function {
\(cResultType.javaType) apply(\(paramDecls.joined(separator: ", ")));
\(cResultType.javaType) apply(\(paramDecls.joined(separator: .comma)));
}
"""
)
Expand All @@ -246,7 +246,7 @@ extension FFMSwift2JavaGenerator {
"""
public final static class Function$Impl implements Function {
\(impl.members.joinedJavaStatements(indent: 2))
public \(cResultType.javaType) apply(\(paramDecls.joined(separator: ", "))) {
public \(cResultType.javaType) apply(\(paramDecls.joined(separator: .comma))) {
\(impl.body)
}
}
Expand Down Expand Up @@ -319,7 +319,7 @@ extension FFMSwift2JavaGenerator {
"""
@FunctionalInterface
public interface \(functionType.name) {
\(functionType.result.javaResultType) apply(\(apiParams.joined(separator: ", ")));
\(functionType.result.javaResultType) apply(\(apiParams.joined(separator: .comma)));
}
"""
)
Expand All @@ -333,7 +333,7 @@ extension FFMSwift2JavaGenerator {
) { printer in
printer.print(
"""
return \(cdeclDescriptor).toUpcallStub((\(cdeclParams.joined(separator: ", "))) -> {
return \(cdeclDescriptor).toUpcallStub((\(cdeclParams.joined(separator: .comma))) -> {
"""
)
printer.indent()
Expand All @@ -343,7 +343,7 @@ extension FFMSwift2JavaGenerator {
convertedArgs.append(arg)
}

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

TranslatedDocumentation.printDocumentation(
importedFunc: decl,
Expand All @@ -404,7 +404,7 @@ extension FFMSwift2JavaGenerator {
)
printer.printBraceBlock(
"""
\(annotationsStr)\(modifiers) \(returnTy) \(methodName)(\(paramDecls.joined(separator: ", ")))\(throwsClause)
\(annotationsStr)\(modifiers) \(returnTy) \(methodName)(\(paramDecls.joined(separator: .comma)))\(throwsClause)
"""
) { printer in
if case .instance = decl.functionSignature.selfParameter {
Expand Down Expand Up @@ -516,7 +516,7 @@ extension FFMSwift2JavaGenerator {
}

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

/// Helper to emit the error check after a downcall
func printErrorCheck(_ printer: inout JavaPrinter) {
Expand Down Expand Up @@ -813,7 +813,7 @@ extension FFMSwift2JavaGenerator.JavaConversionStep {
placeholderForDowncall: placeholderForDowncall,
)
}
return "\(tupleClassName)(\(args.joined(separator: ", ")))"
return "\(tupleClassName)(\(args.joined(separator: .comma)))"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ extension JNISwift2JavaGenerator {
if !self.interfaceProtocolWrappers.keys.contains(decl) && !extends.contains("JNISwiftInstance") {
extends.append("JNISwiftInstance")
}
let extendsString = extends.isEmpty ? "" : " extends \(extends.joined(separator: ", "))"
let extendsString = extends.isEmpty ? "" : " extends \(extends.joined(separator: .comma))"

printer.printBraceBlock("public interface \(decl.effectiveJavaSimpleName)\(extendsString)") { printer in
for initializer in decl.initializers {
Expand Down Expand Up @@ -270,7 +270,7 @@ extension JNISwift2JavaGenerator {
if isEffectivelyGeneric {
swiftPointerParams.append("selfTypePointer")
}
let swiftPointerArg = swiftPointerParams.map { "long \($0)" }.joined(separator: ", ")
let swiftPointerArg = swiftPointerParams.map { "long \($0)" }.joined(separator: .comma)
printer.printBraceBlock("private \(decl.effectiveJavaSimpleName)(\(swiftPointerArg), SwiftArena swiftArena)") { printer in
for param in swiftPointerParams {
printer.print(
Expand Down Expand Up @@ -304,11 +304,11 @@ extension JNISwift2JavaGenerator {
* </ul>
*/
public static\(genericClause) \(javaName)\(genericClause) wrapMemoryAddressUnsafe(\(swiftPointerArg), SwiftArena swiftArena) {
return new \(javaName)\(genericClause)(\(swiftPointerParams.joined(separator: ", ")), swiftArena);
return new \(javaName)\(genericClause)(\(swiftPointerParams.joined(separator: .comma)), swiftArena);
}

public static\(genericClause) \(javaName)\(genericClause) wrapMemoryAddressUnsafe(\(swiftPointerArg)) {
return new \(javaName)\(genericClause)(\(swiftPointerParams.joined(separator: ", ")), SwiftMemoryManagement.DEFAULT_SWIFT_JAVA_AUTO_ARENA);
return new \(javaName)\(genericClause)(\(swiftPointerParams.joined(separator: .comma)), SwiftMemoryManagement.DEFAULT_SWIFT_JAVA_AUTO_ARENA);
}
"""
)
Expand Down Expand Up @@ -458,7 +458,7 @@ extension JNISwift2JavaGenerator {
.compactMap(\.asNominalTypeDeclaration)
.filter { $0.kind == .protocol }
.map(\.name)
let implementsClause = implements.joined(separator: ", ")
let implementsClause = implements.joined(separator: .comma)
// Specialized types are concrete — no generic clause on the Java side
let genericClause = decl.javaGenericClause
printer.printBraceBlock(
Expand Down Expand Up @@ -510,7 +510,7 @@ extension JNISwift2JavaGenerator {
if decl.genericParameterNames.isEmpty {
""
} else {
"<\(decl.genericParameterNames.joined(separator: ", "))>"
"<\(decl.genericParameterNames.joined(separator: .comma))>"
}

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

// Print record
printer.print("record \(translatedCase.name)\(caseGenericClause)(\(members.joined(separator: ", "))) implements Case\(caseGenericClause) {}")
printer.print("record \(translatedCase.name)\(caseGenericClause)(\(members.joined(separator: .comma))) implements Case\(caseGenericClause) {}")
}
}
printer.println()
Expand Down Expand Up @@ -591,7 +591,7 @@ extension JNISwift2JavaGenerator {
} else {
(0..<enumCase.parameters.count).map { i in
"t.$\(i)"
}.joined(separator: ", ")
}.joined(separator: .comma)
}
let translatedResult = getAsCaseFunction.translatedFunctionSignature.result
getAsCaseFunction.translatedFunctionSignature.result.conversion = .method(
Expand Down Expand Up @@ -679,7 +679,7 @@ extension JNISwift2JavaGenerator {
"""
@FunctionalInterface
public interface \(functionType.name) {
\(functionType.result.javaType) apply(\(apiParams.joined(separator: ", ")));
\(functionType.result.javaType) apply(\(apiParams.joined(separator: .comma)));
}
"""
)
Expand Down Expand Up @@ -732,7 +732,7 @@ extension JNISwift2JavaGenerator {
generics.append((name, extends))
}
.map { "\($0) extends \($1.compactMap(\.className).joined(separator: " & "))" }
.joined(separator: ", ")
.joined(separator: .comma)

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

let parametersStr = parameters.joined(separator: ", ")
let parametersStr = parameters.joined(separator: .comma)

// Print default global arena variation
// If we have enabled javaCallbacks we must emit default
Expand Down Expand Up @@ -772,7 +772,7 @@ extension JNISwift2JavaGenerator {
) { printer in
let globalArenaName = "SwiftMemoryManagement.DEFAULT_SWIFT_JAVA_AUTO_ARENA"
let arguments = translatedDecl.translatedFunctionSignature.parameters.map(\.parameter.name) + [globalArenaName]
let call = "\(translatedDecl.name)(\(arguments.joined(separator: ", ")))"
let call = "\(translatedDecl.name)(\(arguments.joined(separator: .comma)))"
if translatedDecl.translatedFunctionSignature.result.javaType.isVoid {
printer.print("\(call);")
} else {
Expand All @@ -794,7 +794,7 @@ extension JNISwift2JavaGenerator {
)
}
let signature =
"\(annotationsStr)\(modifiers.joined(separator: " ")) \(resultType) \(translatedDecl.name)(\(parameters.joined(separator: ", ")))\(throwsClause)"
"\(annotationsStr)\(modifiers.joined(separator: " ")) \(resultType) \(translatedDecl.name)(\(parameters.joined(separator: .comma)))\(throwsClause)"
if skipMethodBody {
printer.print("\(signature);")
} else {
Expand All @@ -820,7 +820,7 @@ extension JNISwift2JavaGenerator {

let renderedParameters = parameters.map { javaParameter in
"\(javaParameter.type) \(javaParameter.name)"
}.joined(separator: ", ")
}.joined(separator: .comma)

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

//=== Part 4: Convert the return value.
if translatedFunctionSignature.result.javaType.isVoid {
Expand Down
Loading
Loading