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
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,11 @@ extension JNISwift2JavaGenerator {
)
}

private func printJavaBindingWrapperMethod(_ printer: inout CodePrinter, _ decl: ImportedFunc, signaturesOnly: Bool) {
private func printJavaBindingWrapperMethod(
_ printer: inout CodePrinter,
_ decl: ImportedFunc,
signaturesOnly: Bool
) {
guard let translatedDecl = translatedDecl(for: decl) else {
fatalError("Decl was not translated, \(decl)")
}
Expand Down Expand Up @@ -470,6 +474,13 @@ extension JNISwift2JavaGenerator {
if let importedFunc {
printDeclDocumentation(&printer, importedFunc)
}
var modifiers = modifiers

// If we are a protocol, we emit this as default method
if importedFunc?.parentType?.asNominalTypeDeclaration?.kind == .protocol {
modifiers.insert("default", at: 1)
}

printer.printBraceBlock("\(annotationsStr)\(modifiers.joined(separator: " ")) \(resultType) \(translatedDecl.name)(\(parametersStr))\(throwsClause)") { printer in
let globalArenaName = "SwiftMemoryManagement.GLOBAL_SWIFT_JAVA_ARENA"
let arguments = translatedDecl.translatedFunctionSignature.parameters.map(\.parameter.name) + [globalArenaName]
Expand Down
30 changes: 30 additions & 0 deletions Tests/JExtractSwiftTests/MemoryManagementModeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,34 @@ struct MemoryManagementModeTests {
]
)
}

@Test
func allowGlobalAutomatic_protocol() throws {
var config = Configuration()
config.memoryManagementMode = .allowGlobalAutomatic

try assertOutput(
input:
"""
public class MyClass {}

public protocol MyProtocol {
public func f() -> MyClass
}
""",
config: config,
.jni, .java,
detectChunkByInitialLines: 1,
expectedChunks: [
"""
public default MyClass f() {
return f(SwiftMemoryManagement.GLOBAL_SWIFT_JAVA_ARENA);
}
""",
"""
public MyClass f(SwiftArena swiftArena$);
"""
]
)
}
}
Loading