File tree Expand file tree Collapse file tree 3 files changed +33
-7
lines changed
Tests/SwiftJavaToolLibTests Expand file tree Collapse file tree 3 files changed +33
-7
lines changed Original file line number Diff line number Diff line change @@ -356,10 +356,10 @@ extension JavaClassTranslator {
356356 // Compute the "extends" clause for the superclass (of the struct
357357 // formulation) or the inheritance clause (for the class
358358 // formulation).
359- let extends : String
359+ let extendsClause : String
360360 let inheritanceClause : String
361361 if translateAsClass {
362- extends = " "
362+ extendsClause = " "
363363 inheritanceClause =
364364 if let swiftSuperclass, swiftSuperclass. typeArguments. isEmpty {
365365 " : \( swiftSuperclass. name) "
@@ -369,7 +369,12 @@ extension JavaClassTranslator {
369369 " "
370370 }
371371 } else {
372- extends = swiftSuperclass. map { " , extends: \( $0) .self " } ?? " "
372+ extendsClause =
373+ if let swiftSuperclass {
374+ " , extends: \( swiftSuperclass. render ( ) ) .self "
375+ } else {
376+ " "
377+ }
373378 inheritanceClause = " "
374379 }
375380
@@ -394,7 +399,7 @@ extension JavaClassTranslator {
394399 let introducer = translateAsClass ? " open class " : " public struct "
395400 var classDecl : DeclSyntax =
396401 """
397- @ \( raw: classOrInterface) ( \( literal: javaClass. getName ( ) ) \( raw: extends ) \( raw: interfacesStr) )
402+ @ \( raw: classOrInterface) ( \( literal: javaClass. getName ( ) ) \( raw: extendsClause ) \( raw: interfacesStr) )
398403 \( raw: introducer) \( raw: swiftInnermostTypeName) \( raw: genericParameterClause) \( raw: inheritanceClause) {
399404 \( raw: members. map { $0. description } . joined ( separator: " \n \n " ) )
400405 }
Original file line number Diff line number Diff line change @@ -25,4 +25,14 @@ struct SwiftJavaParameterizedType {
2525 self . name = name
2626 self . typeArguments = typeArguments
2727 }
28+
29+ func render( ) -> String {
30+ if typeArguments. isEmpty {
31+ name
32+ } else {
33+ " \( name) < \( typeArguments. joined ( separator: " , " ) ) > "
34+ }
35+ }
36+
37+
2838}
Original file line number Diff line number Diff line change @@ -262,8 +262,8 @@ class Java2SwiftTests: XCTestCase {
262262 public struct MyJavaObjects {
263263 """ ,
264264 """
265- @JavaStaticMethod
266- public func requireNonNull(_ arg0: JavaObject?, _ arg1: MySupplier<JavaString>?) -> JavaObject!
265+ @JavaStaticMethod
266+ public func requireNonNull<T: AnyJavaObject> (_ arg0: JavaObject?, _ arg1: MySupplier<JavaString>?) -> T
267267 """ ,
268268 ]
269269 )
@@ -675,8 +675,19 @@ func assertTranslatedClass<JavaClassType: AnyJavaObject>(
675675 \( translatedDecls. map { $0. description } . joined ( separator: " \n " ) )
676676 """
677677
678+ // Helper function to normalize whitespace by trimming leading whitespace from each line
679+ func normalizeWhitespace( _ text: String ) -> String {
680+ return text. components ( separatedBy: . newlines)
681+ . map { $0. trimmingCharacters ( in: . whitespaces) }
682+ . joined ( separator: " \n " )
683+ }
684+
685+ let normalizedSwiftFileText = normalizeWhitespace ( swiftFileText)
686+
678687 for expectedChunk in expectedChunks {
679- if swiftFileText. contains ( expectedChunk) {
688+ let normalizedExpectedChunk = normalizeWhitespace ( expectedChunk)
689+
690+ if normalizedSwiftFileText. contains ( normalizedExpectedChunk) {
680691 continue
681692 }
682693
You can’t perform that action at this time.
0 commit comments