@@ -102,7 +102,7 @@ extension Swift2JavaTranslator {
102102 printModuleClass ( & printer) { printer in
103103 // TODO: print all "static" methods
104104 for decl in importedGlobalFuncs {
105- printDowncallMethods ( & printer, decl)
105+ printFunctionDowncallMethods ( & printer, decl)
106106 }
107107 }
108108 }
@@ -133,7 +133,7 @@ extension Swift2JavaTranslator {
133133
134134 // Methods
135135 for funcDecl in decl. methods {
136- printDowncallMethods ( & printer, funcDecl)
136+ printFunctionDowncallMethods ( & printer, funcDecl)
137137 }
138138 }
139139 }
@@ -456,7 +456,7 @@ extension Swift2JavaTranslator {
456456 )
457457 }
458458
459- public func printDowncallMethods ( _ printer: inout CodePrinter , _ decl: ImportedFunc ) {
459+ public func printFunctionDowncallMethods ( _ printer: inout CodePrinter , _ decl: ImportedFunc ) {
460460 printer. printSeparator ( decl. identifier)
461461
462462 printer. printTypeDecl ( " private static class \( decl. baseIdentifier) " ) { printer in
@@ -551,6 +551,7 @@ extension Swift2JavaTranslator {
551551 }
552552 }
553553
554+ // First print all the supporting infra
554555 for accessorKind in decl. supportedAccessorKinds {
555556 guard let accessor = decl. accessorFunc ( kind: accessorKind) else {
556557 log. warning ( " Skip print for \( accessorKind) of \( decl. identifier) ! " )
@@ -561,12 +562,20 @@ extension Swift2JavaTranslator {
561562 printFunctionAddressMethod ( & printer, decl: accessor, accessorKind: accessorKind)
562563 }
563564
564- // Render the basic "make the downcall" function
565- if decl. hasParent {
566- // printFuncDowncallMethod(&printer, decl: decl, selfVariant: .memorySegment)
567- // printFuncDowncallMethod(&printer, decl: decl, selfVariant: .wrapper)
568- } else {
569- // printFuncDowncallMethod(&printer, decl: decl, selfVariant: nil)
565+ // Then print the actual downcall methods
566+ for accessorKind in decl. supportedAccessorKinds {
567+ guard let accessor = decl. accessorFunc ( kind: accessorKind) else {
568+ log. warning ( " Skip print for \( accessorKind) of \( decl. identifier) ! " )
569+ continue
570+ }
571+
572+ // Render the basic "make the downcall" function
573+ if decl. hasParent {
574+ printFuncDowncallMethod ( & printer, decl: accessor, selfVariant: . memorySegment, accessorKind: accessorKind)
575+ printFuncDowncallMethod ( & printer, decl: accessor, selfVariant: . wrapper, accessorKind: accessorKind)
576+ } else {
577+ printFuncDowncallMethod ( & printer, decl: accessor, selfVariant: nil , accessorKind: accessorKind)
578+ }
570579 }
571580 }
572581
@@ -594,7 +603,8 @@ extension Swift2JavaTranslator {
594603 public func printFuncDowncallMethod(
595604 _ printer: inout CodePrinter ,
596605 decl: ImportedFunc ,
597- selfVariant: SelfParameterVariant ?
606+ selfVariant: SelfParameterVariant ? ,
607+ accessorKind: VariableAccessorKind ? = nil
598608 ) {
599609 let returnTy = decl. returnType. javaType
600610
@@ -605,32 +615,37 @@ extension Swift2JavaTranslator {
605615 maybeReturnCast = " return ( \( returnTy) ) "
606616 }
607617
618+ // TODO: we could copy the Swift method's documentation over here, that'd be great UX
619+ let javaDocComment : String =
620+ """
621+ /**
622+ * Downcall to Swift:
623+ \(decl.renderCommentSnippet ?? "* ")
624+ */
625+ """
626+
627+ // An identifier may be "getX", "setX" or just the plain method name
628+ let identifier = accessorKind. renderMethodName ( decl)
629+
608630 if selfVariant == SelfParameterVariant . wrapper {
609631 // delegate to the MemorySegment "self" accepting overload
610632 printer. print (
611633 """
612- /**
613- * {@snippet lang=swift :
614- * \(/*TODO: make a printSnippet func*/decl.syntax ?? "")
615- * }
616- */
617- public \( returnTy) \( decl. baseIdentifier) ( \( renderJavaParamDecls ( decl, selfVariant: . wrapper) ) ) {
618- \( maybeReturnCast) \( decl. baseIdentifier) ( \( renderForwardParams ( decl, selfVariant: . wrapper) ) );
634+ \( javaDocComment)
635+ public \( returnTy) \( identifier) ( \( renderJavaParamDecls ( decl, selfVariant: . wrapper) ) ) {
636+ \( maybeReturnCast) \( identifier) ( \( renderForwardParams ( decl, selfVariant: . wrapper) ) );
619637 }
620638 """
621639 )
622640 return
623641 }
624642
643+ let handleName = accessorKind. renderHandleFieldName
625644 printer. print (
626645 """
627- /**
628- * {@snippet lang=swift :
629- * \(/*TODO: make a printSnippet func*/decl.syntax ?? "")
630- * }
631- */
632- public static \( returnTy) \( decl. baseIdentifier) ( \( renderJavaParamDecls ( decl, selfVariant: selfVariant) ) ) {
633- var mh$ = \( decl. baseIdentifier) .HANDLE;
646+ \( javaDocComment)
647+ public static \( returnTy) \( identifier) ( \( renderJavaParamDecls ( decl, selfVariant: selfVariant) ) ) {
648+ var mh$ = \( decl. baseIdentifier) . \( handleName) ;
634649 try {
635650 if (TRACE_DOWNCALLS) {
636651 traceDowncall( \( renderForwardParams ( decl, selfVariant: . memorySegment) ) );
0 commit comments