Skip to content

Commit ea6cfaa

Browse files
committed
Java2Swift: Include protected methods in generated classes
Swift doesn't have the notion of "protected", so treat these as "open" (or "public") as approriate.
1 parent 9f5fbbf commit ea6cfaa

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

Sources/Java2SwiftLib/JavaClassTranslator.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ struct JavaClassTranslator {
181181
for method in methods {
182182
guard let method else { continue }
183183

184-
// Only look at public methods here.
185-
guard method.isPublic else { continue }
184+
// Only look at public and protected methods here.
185+
guard method.isPublic || method.isProtected else { continue }
186186

187187
// Skip any methods that are expected to be implemented in Swift. We will
188188
// visit them in the second pass, over the *declared* methods, because

Sources/JavaKitReflection/Method+Utilities.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ extension Method {
1818
return (getModifiers() & 1) != 0
1919
}
2020

21+
/// Whether this is a 'protected' method.
22+
public var isProtected: Bool {
23+
return (getModifiers() & 4) != 0
24+
}
25+
2126
/// Whether this is a 'static' method.
2227
public var isStatic: Bool {
2328
return (getModifiers() & 0x08) != 0

Tests/Java2SwiftTests/Java2SwiftTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,11 @@ class Java2SwiftTests: XCTestCase {
289289
"""
290290
@JavaMethod
291291
open func wait() throws
292+
""",
292293
"""
294+
@JavaMethod
295+
open func clone() throws -> JavaObject!
296+
""",
293297
]
294298
)
295299
}

0 commit comments

Comments
 (0)