Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ extension JNISwift2JavaGenerator {
printer.printBraceBlock(
"""
@_cdecl("\(cName)")
func \(cName)(\(thunkParameters.joined(separator: ", ")))\(thunkReturnType)
public func \(cName)(\(thunkParameters.joined(separator: ", ")))\(thunkReturnType)
"""
) { printer in
body(&printer)
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftJava/JNI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ package final class JNI {
}

@_cdecl("JNI_OnLoad")
func SwiftJava_JNI_OnLoad(javaVM: JavaVMPointer, reserved: UnsafeMutableRawPointer) -> jint {
public func SwiftJava_JNI_OnLoad(javaVM: JavaVMPointer, reserved: UnsafeMutableRawPointer) -> jint {
JNI.shared = JNI(fromVM: JavaVirtualMachine(adoptingJVM: javaVM))
return JNI_VERSION_1_6
}
18 changes: 9 additions & 9 deletions Tests/JExtractSwiftTests/JNI/JNIArrayTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct JNIArrayTest {
detectChunkByInitialLines: 1,
expectedChunks: [
"""
public static byte[] f(@Unsigned byte[] array) {
public static byte[] f(@Unsigned byte[] array) {
return SwiftModule.$f(Objects.requireNonNull(array, "array must not be null"));
}
""",
Expand All @@ -46,7 +46,7 @@ struct JNIArrayTest {
expectedChunks: [
"""
@_cdecl("Java_com_example_swift_SwiftModule__00024f___3B")
func Java_com_example_swift_SwiftModule__00024f___3B(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, array: jbyteArray?) -> jbyteArray? {
public func Java_com_example_swift_SwiftModule__00024f___3B(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, array: jbyteArray?) -> jbyteArray? {
return SwiftModule.f(array: [UInt8](fromJNI: array, in: environment)).getJNIValue(in: environment)
}
"""
Expand All @@ -62,7 +62,7 @@ struct JNIArrayTest {
detectChunkByInitialLines: 1,
expectedChunks: [
"""
public static byte[] f(@Unsigned byte[] array) {
public static byte[] f(@Unsigned byte[] array) {
return SwiftModule.$f(Objects.requireNonNull(array, "array must not be null"));
}
""",
Expand All @@ -82,7 +82,7 @@ struct JNIArrayTest {
expectedChunks: [
"""
@_cdecl("Java_com_example_swift_SwiftModule__00024f___3B")
func Java_com_example_swift_SwiftModule__00024f___3B(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, array: jbyteArray?) -> jbyteArray? {
public func Java_com_example_swift_SwiftModule__00024f___3B(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, array: jbyteArray?) -> jbyteArray? {
return SwiftModule.f(array: [UInt8](fromJNI: array, in: environment)).getJNIValue(in: environment)
}
"""
Expand All @@ -98,7 +98,7 @@ struct JNIArrayTest {
detectChunkByInitialLines: 1,
expectedChunks: [
"""
public static long[] f(long[] array) {
public static long[] f(long[] array) {
return SwiftModule.$f(Objects.requireNonNull(array, "array must not be null"));
}
""",
Expand All @@ -118,7 +118,7 @@ struct JNIArrayTest {
expectedChunks: [
"""
@_cdecl("Java_com_example_swift_SwiftModule__00024f___3J")
func Java_com_example_swift_SwiftModule__00024f___3J(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, array: jlongArray?) -> jlongArray? {
public func Java_com_example_swift_SwiftModule__00024f___3J(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, array: jlongArray?) -> jlongArray? {
return SwiftModule.f(array: [Int64](fromJNI: array, in: environment)).getJNIValue(in: environment)
}
"""
Expand All @@ -137,8 +137,8 @@ struct JNIArrayTest {
detectChunkByInitialLines: 1,
expectedChunks: [
"""
public static MySwiftClass[] f(MySwiftClass[] array, SwiftArena swiftArena$) {
return Arrays.stream(SwiftModule.$f(Arrays.stream(Objects.requireNonNull(array, "array must not be null")).mapToLong(MySwiftClass::$memoryAddress).toArray())).mapToObj((pointer) -> {
public static MySwiftClass[] f(MySwiftClass[] array, SwiftArena swiftArena$) {
return Arrays.stream(SwiftModule.$f(Arrays.stream(Objects.requireNonNull(array, "array must not be null")).mapToLong(MySwiftClass::$memoryAddress).toArray())).mapToObj((pointer) -> {
return MySwiftClass.wrapMemoryAddressUnsafe(pointer, swiftArena$);
}
).toArray(MySwiftClass[]::new);
Expand All @@ -163,7 +163,7 @@ struct JNIArrayTest {
expectedChunks: [
"""
@_cdecl("Java_com_example_swift_SwiftModule__00024f___3J")
func Java_com_example_swift_SwiftModule__00024f___3J(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, array: jlongArray?) -> jlongArray? {
public func Java_com_example_swift_SwiftModule__00024f___3J(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, array: jlongArray?) -> jlongArray? {
return SwiftModule.f(array: [Int64](fromJNI: array, in: environment).map( { (pointer$) in
assert(pointer$ != 0, "pointer$ memory address was null")
let pointer$Bits$ = Int(pointer$)
Expand Down
28 changes: 14 additions & 14 deletions Tests/JExtractSwiftTests/JNI/JNIAsyncTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct JNIAsyncTests {
expectedChunks: [
"""
@_cdecl("Java_com_example_swift_SwiftModule__00024asyncVoid__Ljava_util_concurrent_CompletableFuture_2")
func Java_com_example_swift_SwiftModule__00024asyncVoid__Ljava_util_concurrent_CompletableFuture_2(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, result_future: jobject?) {
public func Java_com_example_swift_SwiftModule__00024asyncVoid__Ljava_util_concurrent_CompletableFuture_2(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, result_future: jobject?) {
let globalFuture = environment.interface.NewGlobalRef(environment, result_future)
var task: Task<Void, Never>? = nil
#if swift(>=6.2)
Expand Down Expand Up @@ -132,7 +132,7 @@ struct JNIAsyncTests {
expectedChunks: [
"""
@_cdecl("Java_com_example_swift_SwiftModule__00024async__Ljava_util_concurrent_CompletableFuture_2")
func Java_com_example_swift_SwiftModule__00024async__Ljava_util_concurrent_CompletableFuture_2(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, result_future: jobject?) {
public func Java_com_example_swift_SwiftModule__00024async__Ljava_util_concurrent_CompletableFuture_2(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, result_future: jobject?) {
let globalFuture = environment.interface.NewGlobalRef(environment, result_future)
var task: Task<Void, Never>? = nil
#if swift(>=6.2)
Expand Down Expand Up @@ -220,7 +220,7 @@ struct JNIAsyncTests {
expectedChunks: [
"""
@_cdecl("Java_com_example_swift_SwiftModule__00024async__JLjava_util_concurrent_CompletableFuture_2")
func Java_com_example_swift_SwiftModule__00024async__JLjava_util_concurrent_CompletableFuture_2(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, i: jlong, result_future: jobject?) {
public func Java_com_example_swift_SwiftModule__00024async__JLjava_util_concurrent_CompletableFuture_2(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, i: jlong, result_future: jobject?) {
let globalFuture = environment.interface.NewGlobalRef(environment, result_future)
var task: Task<Void, Never>? = nil
#if swift(>=6.2)
Expand Down Expand Up @@ -251,7 +251,7 @@ struct JNIAsyncTests {
_ = environment.interface.CallBooleanMethodA(environment, globalFuture, _JNIMethodIDCache.CompletableFuture.complete, [jvalue(l: boxedResult$)])
}
}
return
return
}
"""
]
Expand All @@ -263,7 +263,7 @@ struct JNIAsyncTests {
try assertOutput(
input: """
class MyClass { }

public func async(c: MyClass) async -> MyClass
""",
.jni, .java,
Expand Down Expand Up @@ -297,15 +297,15 @@ struct JNIAsyncTests {
try assertOutput(
input: """
class MyClass { }

public func async(c: MyClass) async -> MyClass
""",
.jni, .swift,
detectChunkByInitialLines: 1,
expectedChunks: [
"""
@_cdecl("Java_com_example_swift_SwiftModule__00024async__JLjava_util_concurrent_CompletableFuture_2")
func Java_com_example_swift_SwiftModule__00024async__JLjava_util_concurrent_CompletableFuture_2(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, c: jlong, result_future: jobject?) {
public func Java_com_example_swift_SwiftModule__00024async__JLjava_util_concurrent_CompletableFuture_2(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, c: jlong, result_future: jobject?) {
assert(c != 0, "c memory address was null")
let cBits$ = Int(Int64(fromJNI: c, in: environment))
let c$ = UnsafeMutablePointer<MyClass>(bitPattern: cBits$)
Expand Down Expand Up @@ -348,7 +348,7 @@ struct JNIAsyncTests {
_ = environment.interface.CallBooleanMethodA(environment, globalFuture, _JNIMethodIDCache.CompletableFuture.complete, [jvalue(l: boxedResult$)])
}
}
return
return
}
"""
]
Expand Down Expand Up @@ -392,7 +392,7 @@ struct JNIAsyncTests {
expectedChunks: [
"""
@_cdecl("Java_com_example_swift_SwiftModule__00024async__Ljava_lang_String_2Ljava_util_concurrent_CompletableFuture_2")
func Java_com_example_swift_SwiftModule__00024async__Ljava_lang_String_2Ljava_util_concurrent_CompletableFuture_2(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, s: jstring?, result_future: jobject?) {
public func Java_com_example_swift_SwiftModule__00024async__Ljava_lang_String_2Ljava_util_concurrent_CompletableFuture_2(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, s: jstring?, result_future: jobject?) {
let s = environment.interface.NewGlobalRef(environment, s)
let globalFuture = environment.interface.NewGlobalRef(environment, result_future)
...
Expand All @@ -418,7 +418,7 @@ struct JNIAsyncTests {
try assertOutput(
input: """
class MyClass { }

public func async(c: MyClass) async -> MyClass
""",
config: config,
Expand Down Expand Up @@ -450,7 +450,7 @@ struct JNIAsyncTests {
try assertOutput(
input: """
class MyClass { }

public func async(c: MyClass) async -> MyClass
""",
config: config,
Expand All @@ -459,15 +459,15 @@ struct JNIAsyncTests {
expectedChunks: [
"""
@_cdecl("Java_com_example_swift_SwiftModule__00024async__JLorg_swift_swiftkit_core_SimpleCompletableFuture_2")
func Java_com_example_swift_SwiftModule__00024async__JLorg_swift_swiftkit_core_SimpleCompletableFuture_2(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, c: jlong, result_future: jobject?) {
public func Java_com_example_swift_SwiftModule__00024async__JLorg_swift_swiftkit_core_SimpleCompletableFuture_2(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, c: jlong, result_future: jobject?) {
...
var task: Task<Void, Never>? = nil
...
_ = environment.interface.CallBooleanMethodA(environment, globalFuture, _JNIMethodIDCache.SimpleCompletableFuture.complete, [jvalue(l: boxedResult$)])
...
...
}
"""
]
)
}
}
}
20 changes: 10 additions & 10 deletions Tests/JExtractSwiftTests/JNI/JNIClassTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ struct JNIClassTests {
private MyClass(long selfPointer, SwiftArena swiftArena) {
SwiftObjects.requireNonZero(selfPointer, "selfPointer");
this.selfPointer = selfPointer;

// Only register once we have fully initialized the object since this will need the object pointer.
swiftArena.register(this);
}
Expand Down Expand Up @@ -163,7 +163,7 @@ struct JNIClassTests {
expectedChunks: [
"""
@_cdecl("Java_com_example_swift_MyClass__00024method__")
func Java_com_example_swift_MyClass__00024method__(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass) {
public func Java_com_example_swift_MyClass__00024method__(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass) {
MyClass.method()
}
"""
Expand Down Expand Up @@ -220,7 +220,7 @@ struct JNIClassTests {
expectedChunks: [
"""
@_cdecl("Java_com_example_swift_MyClass__00024init__JJ")
func Java_com_example_swift_MyClass__00024init__JJ(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, x: jlong, y: jlong) -> jlong {
public func Java_com_example_swift_MyClass__00024init__JJ(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, x: jlong, y: jlong) -> jlong {
let result$ = UnsafeMutablePointer<MyClass>.allocate(capacity: 1)
result$.initialize(to: MyClass.init(x: Int64(fromJNI: x, in: environment), y: Int64(fromJNI: y, in: environment)))
let resultBits$ = Int64(Int(bitPattern: result$))
Expand All @@ -229,7 +229,7 @@ struct JNIClassTests {
""",
"""
@_cdecl("Java_com_example_swift_MyClass__00024init__")
func Java_com_example_swift_MyClass__00024init__(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass) -> jlong {
public func Java_com_example_swift_MyClass__00024init__(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass) -> jlong {
let result$ = UnsafeMutablePointer<MyClass>.allocate(capacity: 1)
result$.initialize(to: MyClass.init())
let resultBits$ = Int64(Int(bitPattern: result$))
Expand All @@ -250,7 +250,7 @@ struct JNIClassTests {
expectedChunks: [
"""
@_cdecl("Java_com_example_swift_MyClass__00024destroy__J")
func Java_com_example_swift_MyClass__00024destroy__J(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, selfPointer: jlong) {
public func Java_com_example_swift_MyClass__00024destroy__J(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, selfPointer: jlong) {
guard let env$ = environment else {
fatalError("Missing JNIEnv in downcall to \\(#function)")
}
Expand Down Expand Up @@ -302,7 +302,7 @@ struct JNIClassTests {
expectedChunks: [
"""
@_cdecl("Java_com_example_swift_MyClass__00024doSomething__JJ")
func Java_com_example_swift_MyClass__00024doSomething__JJ(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, x: jlong, self: jlong) {
public func Java_com_example_swift_MyClass__00024doSomething__JJ(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, x: jlong, self: jlong) {
assert(self != 0, "self memory address was null")
let selfBits$ = Int(Int64(fromJNI: self, in: environment))
let self$ = UnsafeMutablePointer<MyClass>(bitPattern: selfBits$)
Expand Down Expand Up @@ -351,7 +351,7 @@ struct JNIClassTests {
expectedChunks: [
"""
@_cdecl("Java_com_example_swift_MyClass__00024copy__J")
func Java_com_example_swift_MyClass__00024copy__J(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, self: jlong) -> jlong {
public func Java_com_example_swift_MyClass__00024copy__J(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, self: jlong) -> jlong {
assert(self != 0, "self memory address was null")
let selfBits$ = Int(Int64(fromJNI: self, in: environment))
let self$ = UnsafeMutablePointer<MyClass>(bitPattern: selfBits$)
Expand Down Expand Up @@ -383,7 +383,7 @@ struct JNIClassTests {
* }
*/
public boolean isEqual(MyClass other) {
return MyClass.$isEqual(other.$memoryAddress(), this.$memoryAddress());
return MyClass.$isEqual(other.$memoryAddress(), this.$memoryAddress());
}
""",
"""
Expand All @@ -403,10 +403,10 @@ struct JNIClassTests {
expectedChunks: [
"""
@_cdecl("Java_com_example_swift_MyClass__00024isEqual__JJ")
func Java_com_example_swift_MyClass__00024isEqual__JJ(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, other: jlong, self: jlong) -> jboolean {
public func Java_com_example_swift_MyClass__00024isEqual__JJ(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, other: jlong, self: jlong) -> jboolean {
assert(other != 0, "other memory address was null")
let otherBits$ = Int(Int64(fromJNI: other, in: environment))
let other$ = UnsafeMutablePointer<MyClass>(bitPattern: otherBits$)
let other$ = UnsafeMutablePointer<MyClass>(bitPattern: otherBits$)
guard let other$ else {
fatalError("other memory address was null in call to \\(#function)!")
}
Expand Down
6 changes: 3 additions & 3 deletions Tests/JExtractSwiftTests/JNI/JNIClosureTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ struct JNIClosureTests {
expectedChunks: [
"""
@_cdecl("Java_com_example_swift_SwiftModule__00024emptyClosure__Lcom_example_swift_SwiftModule_00024emptyClosure_00024closure_2")
func Java_com_example_swift_SwiftModule__00024emptyClosure__Lcom_example_swift_SwiftModule_00024emptyClosure_00024closure_2(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, closure: jobject?) {
SwiftModule.emptyClosure(closure: {
public func Java_com_example_swift_SwiftModule__00024emptyClosure__Lcom_example_swift_SwiftModule_00024emptyClosure_00024closure_2(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, closure: jobject?) {
SwiftModule.emptyClosure(closure: {
let class$ = environment.interface.GetObjectClass(environment, closure)
let methodID$ = environment.interface.GetMethodID(environment, class$, "apply", "()V")!
let arguments$: [jvalue] = []
Expand Down Expand Up @@ -113,7 +113,7 @@ struct JNIClosureTests {
expectedChunks: [
"""
@_cdecl("Java_com_example_swift_SwiftModule__00024closureWithArgumentsAndReturn__Lcom_example_swift_SwiftModule_00024closureWithArgumentsAndReturn_00024closure_2")
func Java_com_example_swift_SwiftModule__00024closureWithArgumentsAndReturn__Lcom_example_swift_SwiftModule_00024closureWithArgumentsAndReturn_00024closure_2(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, closure: jobject?) {
public func Java_com_example_swift_SwiftModule__00024closureWithArgumentsAndReturn__Lcom_example_swift_SwiftModule_00024closureWithArgumentsAndReturn_00024closure_2(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, closure: jobject?) {
SwiftModule.closureWithArgumentsAndReturn(closure: { _0, _1 in
let class$ = environment.interface.GetObjectClass(environment, closure)
let methodID$ = environment.interface.GetMethodID(environment, class$, "apply", "(JZ)J")!
Expand Down
Loading
Loading