File tree Expand file tree Collapse file tree 2 files changed +49
-8
lines changed Expand file tree Collapse file tree 2 files changed +49
-8
lines changed Original file line number Diff line number Diff line change @@ -664,15 +664,30 @@ extension JavaClassTranslator {
664
664
/// Determine whether this method is an override of another Java
665
665
/// method.
666
666
func isOverride( _ method: Method ) -> Bool {
667
- guard let javaSuperclass = effectiveJavaSuperclass else {
668
- return false
669
- }
667
+ var currentSuperclass = effectiveJavaSuperclass
668
+ while let currentSuperclassNonOpt = currentSuperclass {
669
+ // Set the loop up for the next run.
670
+ defer {
671
+ currentSuperclass = currentSuperclassNonOpt. getSuperclass ( )
672
+ }
673
+
674
+ do {
675
+ // If this class didn't get translated into Swift, skip it.
676
+ if translator. translatedClasses [ currentSuperclassNonOpt. getName ( ) ] == nil {
677
+ continue
678
+ }
670
679
671
- do {
672
- let overriddenMethod = try javaSuperclass. getDeclaredMethod ( method. getName ( ) , method. getParameterTypes ( ) )
673
- return overriddenMethod != nil
674
- } catch {
675
- return false
680
+ // If this superclass declares a method with the same parameter types,
681
+ // we have an override.
682
+ let overriddenMethod = try currentSuperclassNonOpt
683
+ . getDeclaredMethod ( method. getName ( ) , method. getParameterTypes ( ) )
684
+ if overriddenMethod != nil {
685
+ return true
686
+ }
687
+ } catch {
688
+ }
676
689
}
690
+
691
+ return false
677
692
}
678
693
}
Original file line number Diff line number Diff line change @@ -422,6 +422,32 @@ class Java2SwiftTests: XCTestCase {
422
422
]
423
423
)
424
424
}
425
+
426
+ func testOverrideSkipImmediateSuperclass( ) throws {
427
+ // JavaByte overrides equals() from JavaObject, which it indirectly
428
+ // inherits through JavaNumber
429
+ try assertTranslatedClass (
430
+ JavaByte . self,
431
+ swiftTypeName: " JavaByte " ,
432
+ asClass: true ,
433
+ translatedClasses: [
434
+ " java.lang.Object " : ( " JavaObject " , " JavaKit " ) ,
435
+ " java.lang.Number " : ( " JavaNumber " , " JavaKit " ) ,
436
+ " java.lang.Byte " : ( " JavaByte " , " JavaKit " ) ,
437
+ ] ,
438
+ expectedChunks: [
439
+ " import JavaKit " ,
440
+ """
441
+ @JavaClass( " java.lang.Byte " )
442
+ open class JavaByte: JavaNumber {
443
+ """ ,
444
+ """
445
+ @JavaMethod
446
+ open override func equals(_ arg0: JavaObject?) -> Bool
447
+ """ ,
448
+ ]
449
+ )
450
+ }
425
451
}
426
452
427
453
@JavaClass ( " java.lang.ClassLoader " )
You can’t perform that action at this time.
0 commit comments