Open
Description
// JNIExample.java
package com.example;
public class JNIExample {
static {
System.loadLibrary("my-swift-lib");
}
public native int compute(int a, int b);
public native int compute(int a, Integer b);
public static native int computeStatic(int a, int b);
public static void main(String[] args) {
int result = new JNIExample().compute(5, 7);
System.out.println("Result from native code: " + result);
}
}
will generate the sayHello
and compute
but will ignore the computeStatic
:
/Users/ktoso/code/swift-java/Samples/JavaKitSampleApp/.build/arm64-apple-macosx/debug/Java2Swift-tool --module-name SwiftJNIExample --depends-on JavaKit=/Users/ktoso/code/swift-java/Sources/JavaKit/swift-java.config --swift-native-implementation com.example.JNIExample $(pwd)/swift-java.config
// Auto-generated by Java-to-Swift wrapper generator.
import JavaKit
import JavaRuntime
@JavaClass("com.example.JNIExample")
open class JNIExample: JavaObject {
@JavaMethod
@_nonoverride public convenience init(environment: JNIEnvironment? = nil)
}
extension JavaClass<JNIExample> {
@JavaStaticMethod
public func main(_ arg0: [String])
}
/// Describes the Java `native` methods for ``JNIExample``.
///
/// To implement all of the `native` methods for JNIExample in Swift,
/// extend JNIExample to conform to this protocol and mark
/// each implementation of the protocol requirement with
/// `@JavaMethod`.
protocol JNIExampleNativeMethods {
func compute(_ arg0: Int32, _ arg1: JavaInteger?) -> Int32
func compute(_ arg0: Int32, _ arg1: Int32) -> Int32
}
We need to be able to handle static native methods as well.