Skip to content

Commit 5c577af

Browse files
committed
print methods and initializers
1 parent 4b753f0 commit 5c577af

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

Samples/SwiftJavaExtractJNISampleApp/src/test/java/com/example/swift/ProtocolTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,23 @@ void takeCombinedGenericProtocol() {
5353
assertEquals(15, MySwiftLibrary.takeCombinedGenericProtocol(proto1));
5454
}
5555
}
56+
57+
@Test
58+
void protocolVariables() {
59+
try (var arena = SwiftArena.ofConfined()) {
60+
ProtocolA proto1 = ConcreteProtocolAB.init(10, 5, arena);
61+
assertEquals(10, proto1.getConstantA());
62+
assertEquals(0, proto1.getMutable());
63+
proto1.setMutable(3);
64+
assertEquals(3, proto1.getMutable());
65+
}
66+
}
67+
68+
@Test
69+
void protocolMethod() {
70+
try (var arena = SwiftArena.ofConfined()) {
71+
ProtocolA proto1 = ConcreteProtocolAB.init(10, 5, arena);
72+
assertEquals("ConcreteProtocolAB", proto1.name());
73+
}
74+
}
5675
}

Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+JavaBindingsPrinting.swift

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,16 @@ extension JNISwift2JavaGenerator {
113113
private func printProtocol(_ printer: inout CodePrinter, _ decl: ImportedNominalType) {
114114
let extends = ["JNISwiftInstance"]
115115
printer.printBraceBlock("public interface \(decl.swiftNominal.name) extends \(extends.joined(separator: ", "))") { printer in
116+
for initializer in decl.initializers {
117+
printFunctionDowncallMethods(&printer, initializer, signaturesOnly: true)
118+
printer.println()
119+
}
120+
121+
for method in decl.methods {
122+
printFunctionDowncallMethods(&printer, method, signaturesOnly: true)
123+
printer.println()
124+
}
125+
116126
for variable in decl.variables {
117127
printFunctionDowncallMethods(&printer, variable, signaturesOnly: true)
118128
printer.println()
@@ -135,9 +145,6 @@ extension JNISwift2JavaGenerator {
135145
"""
136146
)
137147

138-
let p1: UnsafeMutableRawPointer!
139-
let ex = UnsafeMutablePointer<(any Equatable)>.allocate(capacity: 1)
140-
141148
printer.print(
142149
"""
143150
/**
@@ -429,8 +436,10 @@ extension JNISwift2JavaGenerator {
429436
}
430437
.map { "\($0) extends \($1.compactMap(\.className).joined(separator: " & "))" }
431438
.joined(separator: ", ")
432-
let genericsStr = generics.isEmpty ? "" : "<" + generics + ">"
433-
modifiers.append(genericsStr)
439+
440+
if !generics.isEmpty {
441+
modifiers.append("<" + generics + ">")
442+
}
434443

435444
var annotationsStr = translatedSignature.annotations.map({ $0.render() }).joined(separator: "\n")
436445
if !annotationsStr.isEmpty { annotationsStr += "\n" }

0 commit comments

Comments
 (0)