@@ -144,17 +144,17 @@ extension JNISwift2JavaGenerator {
144144
145145 printer . printBraceBlock ( " public interface \( decl . swiftNominal . name ) \( extendsString ) " ) { printer in
146146 for initializer in decl . initializers {
147- printFunctionDowncallMethods ( & printer , initializer , skipMethodBody : true , skipArenas : true )
147+ printFunctionDowncallMethods ( & printer , initializer , skipMethodBody : true )
148148 printer . println ( )
149149 }
150150
151151 for method in decl . methods {
152- printFunctionDowncallMethods ( & printer , method , skipMethodBody : true , skipArenas : true )
152+ printFunctionDowncallMethods ( & printer , method , skipMethodBody : true )
153153 printer . println ( )
154154 }
155155
156156 for variable in decl . variables {
157- printFunctionDowncallMethods ( & printer , variable , skipMethodBody : true , skipArenas : true )
157+ printFunctionDowncallMethods ( & printer , variable , skipMethodBody : true )
158158 printer . println ( )
159159 }
160160 }
@@ -420,16 +420,15 @@ extension JNISwift2JavaGenerator {
420420 printer . print ( " record _NativeParameters( \( nativeParameters . joined ( separator : " , " ) ) ) {} " )
421421 }
422422
423- self . printJavaBindingWrapperMethod ( & printer , translatedCase . getAsCaseFunction , skipMethodBody : false , skipArenas : false )
423+ self . printJavaBindingWrapperMethod ( & printer , translatedCase . getAsCaseFunction , skipMethodBody : false )
424424 printer . println ( )
425425 }
426426 }
427427
428428 private func printFunctionDowncallMethods (
429429 _ printer : inout CodePrinter ,
430430 _ decl : ImportedFunc ,
431- skipMethodBody : Bool = false ,
432- skipArenas : Bool = false
431+ skipMethodBody : Bool = false
433432 ) {
434433 guard translatedDecl ( for : decl ) != nil else {
435434 // Failed to translate. Skip.
@@ -440,7 +439,7 @@ extension JNISwift2JavaGenerator {
440439
441440 printJavaBindingWrapperHelperClass ( & printer , decl )
442441
443- printJavaBindingWrapperMethod ( & printer , decl , skipMethodBody : skipMethodBody , skipArenas : skipArenas )
442+ printJavaBindingWrapperMethod ( & printer , decl , skipMethodBody : skipMethodBody )
444443 }
445444
446445 /// Print the helper type container for a user-facing Java API.
@@ -486,21 +485,19 @@ extension JNISwift2JavaGenerator {
486485 private func printJavaBindingWrapperMethod (
487486 _ printer : inout CodePrinter ,
488487 _ decl : ImportedFunc ,
489- skipMethodBody : Bool ,
490- skipArenas : Bool
488+ skipMethodBody : Bool
491489 ) {
492490 guard let translatedDecl = translatedDecl ( for : decl ) else {
493491 fatalError ( " Decl was not translated, \( decl ) " )
494492 }
495- printJavaBindingWrapperMethod ( & printer , translatedDecl , importedFunc : decl , skipMethodBody : skipMethodBody , skipArenas : skipArenas )
493+ printJavaBindingWrapperMethod ( & printer , translatedDecl , importedFunc : decl , skipMethodBody : skipMethodBody )
496494 }
497495
498496 private func printJavaBindingWrapperMethod (
499497 _ printer : inout CodePrinter ,
500498 _ translatedDecl : TranslatedFunctionDecl ,
501499 importedFunc : ImportedFunc ? = nil ,
502- skipMethodBody : Bool ,
503- skipArenas : Bool
500+ skipMethodBody : Bool
504501 ) {
505502 var modifiers = [ " public " ]
506503 if translatedDecl . isStatic {
@@ -531,14 +528,28 @@ extension JNISwift2JavaGenerator {
531528 let parametersStr = parameters . joined ( separator : " , " )
532529
533530 // Print default global arena variation
531+ // If we have enabled javaCallbacks we must emit default
532+ // arena methods for protocols, as this is what
533+ // Swift will call into, when you call a interface from Swift.
534+ let shouldGenerateGlobalArenaVariation : Bool
535+ let isParentProtocol = importedFunc ? . parentType ? . asNominalType ? . isProtocol ?? false
536+
534537 if config . effectiveMemoryManagementMode . requiresGlobalArena && translatedSignature . requiresSwiftArena {
538+ shouldGenerateGlobalArenaVariation = true
539+ } else if isParentProtocol , translatedSignature . requiresSwiftArena , config . effectiveEnableJavaCallbacks {
540+ shouldGenerateGlobalArenaVariation = true
541+ } else {
542+ shouldGenerateGlobalArenaVariation = false
543+ }
544+
545+ if shouldGenerateGlobalArenaVariation {
535546 if let importedFunc {
536547 printDeclDocumentation ( & printer , importedFunc )
537548 }
538549 var modifiers = modifiers
539550
540551 // If we are a protocol, we emit this as default method
541- if importedFunc ? . parentType ? . asNominalTypeDeclaration ? . kind == . protocol {
552+ if isParentProtocol {
542553 modifiers . insert ( " default " , at : 1 )
543554 }
544555
@@ -555,7 +566,7 @@ extension JNISwift2JavaGenerator {
555566 printer . println ( )
556567 }
557568
558- if translatedSignature . requiresSwiftArena , ! skipArenas {
569+ if translatedSignature . requiresSwiftArena {
559570 parameters . append ( " SwiftArena swiftArena$ " )
560571 }
561572 if let importedFunc {
0 commit comments