@@ -25,7 +25,9 @@ extension FFMSwift2JavaGenerator {
2525
2626 let translated : TranslatedFunctionDecl ?
2727 do {
28- let translation = JavaTranslation ( config: self . config, knownTypes: SwiftKnownTypes ( symbolTable: lookupContext. symbolTable) )
28+ let translation = JavaTranslation (
29+ config: self . config,
30+ knownTypes: SwiftKnownTypes ( symbolTable: lookupContext. symbolTable) )
2931 translated = try translation. translate ( decl)
3032 } catch {
3133 self . log. info ( " Failed to translate: ' \( decl. swiftDecl. qualifiedNameForDebug) '; \( error) " )
@@ -101,20 +103,14 @@ extension FFMSwift2JavaGenerator {
101103 /// Function signature for a Java API.
102104 struct TranslatedFunctionSignature {
103105 var selfParameter : TranslatedParameter ?
104- var annotations : [ JavaAnnotation ] = [ ]
105106 var parameters : [ TranslatedParameter ]
106107 var result : TranslatedResult
107108
108- init ( selfParameter: TranslatedParameter ? ,
109- parameters: [ TranslatedParameter ] ,
110- result: TranslatedResult ) {
111- self . selfParameter = selfParameter
112- // if the result type implied any annotations,
113- // propagate them onto the function the result is returned from
114- self . annotations = result. annotations
115- self . parameters = parameters
116- self . result = result
117- }
109+ // if the result type implied any annotations,
110+ // propagate them onto the function the result is returned from
111+ var annotations : [ JavaAnnotation ] {
112+ self . result. annotations
113+ }
118114 }
119115
120116 /// Represent a Swift closure type in the user facing Java API.
@@ -142,9 +138,7 @@ extension FFMSwift2JavaGenerator {
142138 self . knownTypes = knownTypes
143139 }
144140
145- func translate(
146- _ decl: ImportedFunc
147- ) throws -> TranslatedFunctionDecl {
141+ func translate( _ decl: ImportedFunc ) throws -> TranslatedFunctionDecl {
148142 let lowering = CdeclLowering ( knownTypes: knownTypes)
149143 let loweredSignature = try lowering. lowerFunctionSignature ( decl. functionSignature)
150144
@@ -326,30 +320,29 @@ extension FFMSwift2JavaGenerator {
326320 genericParameters: [ SwiftGenericParameterDeclaration ] ,
327321 genericRequirements: [ SwiftGenericRequirement ]
328322 ) throws -> TranslatedParameter {
323+ // If the result type should cause any annotations on the method, include them here.
324+ let parameterAnnotations : [ JavaAnnotation ] = getTypeAnnotations ( swiftType: swiftType, config: config)
329325
330326 // If we need to handle unsigned integers do so here
331327 if config. effectiveUnsignedNumbersMode. needsConversion {
332- if let unsignedWrapperType = JavaType . unsignedWrapper ( for: swiftType) /* and we're in safe wrapper mode */ {
328+ if let unsignedWrapperType = JavaType . unsignedWrapper ( for: swiftType) {
333329 return TranslatedParameter (
334330 javaParameters: [
335- JavaParameter ( name: parameterName, type: unsignedWrapperType)
331+ JavaParameter ( name: parameterName, type: unsignedWrapperType, annotations : parameterAnnotations )
336332 ] , conversion: . call( . placeholder, function: " UnsignedNumbers.toPrimitive " , withArena: false ) )
337333 }
338334 }
339335
340- // If the result type should cause any annotations on the method, include them here.
341- let parameterAnnotations : [ JavaAnnotation ] = getTypeAnnotations ( swiftType: swiftType)
342-
343336 // If there is a 1:1 mapping between this Swift type and a C type, that can
344337 // be expressed as a Java primitive type.
345338 if let cType = try ? CType ( cdeclType: swiftType) {
346339 let javaType = cType. javaType
347340 return TranslatedParameter (
348341 javaParameters: [
349342 JavaParameter (
350- name: parameterName, type : javaType ,
351- annotations : parameterAnnotations
352- )
343+ name: parameterName,
344+ type : javaType ,
345+ annotations : parameterAnnotations )
353346 ] ,
354347 conversion: . placeholder
355348 )
@@ -564,46 +557,36 @@ extension FFMSwift2JavaGenerator {
564557 }
565558 }
566559
567- /// Determine if the given type needs any extra annotations that should be included
568- /// in Java sources when the corresponding Java type is rendered.
569- func getTypeAnnotations( swiftType: SwiftType ) -> [ JavaAnnotation ] {
570- if swiftType. isUnsignedInteger, config. effectiveUnsignedNumbersMode == . annotate {
571- return [ JavaAnnotation . unsigned]
572- }
573-
574- return [ ]
575- }
576-
577- func unsignedResultConversion( _ from: SwiftType , to javaType: JavaType ,
578- mode: JExtractUnsignedIntegerMode ) -> JavaConversionStep {
579- switch mode {
580- case . annotate:
581- return . placeholder // no conversions
560+ func unsignedResultConversion( _ from: SwiftType , to javaType: JavaType ,
561+ mode: JExtractUnsignedIntegerMode ) -> JavaConversionStep {
562+ switch mode {
563+ case . annotate:
564+ return . placeholder // no conversions
582565
583- case . wrapGuava:
584- guard let typeName = javaType. fullyQualifiedClassName else {
585- fatalError ( " Missing target class name for result conversion step from \( from) to \( javaType) " )
586- }
566+ case . wrapGuava:
567+ guard let typeName = javaType. fullyQualifiedClassName else {
568+ fatalError ( " Missing target class name for result conversion step from \( from) to \( javaType) " )
569+ }
587570
588- switch from {
589- case . nominal( let nominal) :
590- switch nominal. nominalTypeDecl. knownTypeKind {
591- case . uint8:
592- return . call( . placeholder, function: " \( typeName) .fromIntBits " , withArena: false )
593- case . uint16:
594- return . placeholder // no conversion, UInt16 can be returned as-is and will be seen as char by Java
595- case . uint32:
596- return . call( . placeholder, function: " \( typeName) .fromIntBits " , withArena: false )
597- case . uint64:
598- return . call( . placeholder, function: " \( typeName) .fromLongBits " , withArena: false )
599- default :
600- fatalError ( " unsignedResultConversion: Unsupported conversion from \( from) to \( javaType) " )
601- }
602- default :
603- fatalError ( " unsignedResultConversion: Unsupported conversion from \( from) to \( javaType) " )
571+ switch from {
572+ case . nominal( let nominal) :
573+ switch nominal. nominalTypeDecl. knownTypeKind {
574+ case . uint8:
575+ return . call( . placeholder, function: " \( typeName) .fromIntBits " , withArena: false )
576+ case . uint16:
577+ return . placeholder // no conversion, UInt16 can be returned as-is and will be seen as char by Java
578+ case . uint32:
579+ return . call( . placeholder, function: " \( typeName) .fromIntBits " , withArena: false )
580+ case . uint64:
581+ return . call( . placeholder, function: " \( typeName) .fromLongBits " , withArena: false )
582+ default :
583+ fatalError ( " unsignedResultConversion: Unsupported conversion from \( from) to \( javaType) " )
584+ }
585+ default :
586+ fatalError ( " unsignedResultConversion: Unsupported conversion from \( from) to \( javaType) " )
587+ }
604588 }
605589 }
606- }
607590
608591 /// Translate a Swift API result to the user-facing Java API result.
609592 func translate(
@@ -626,7 +609,7 @@ extension FFMSwift2JavaGenerator {
626609 }
627610
628611 // If the result type should cause any annotations on the method, include them here.
629- let resultAnnotations : [ JavaAnnotation ] = getTypeAnnotations ( swiftType: swiftType)
612+ let resultAnnotations : [ JavaAnnotation ] = getTypeAnnotations ( swiftType: swiftType, config : config )
630613
631614 // If there is a 1:1 mapping between this Swift type and a C type, that can
632615 // be expressed as a Java primitive type.
0 commit comments