swiftlang / swiftlang/swift-java
Generating SaticMethods protocol ignores 'static native' java methods
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 1.2k
- Forks
- 123
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 16
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with JNIExample.java and the Java2Swift-tool invocation shown, then inspect how the generated JNIExampleNativeMethods protocol is produced. Confirm that the static native computeStatic method is represented in the generated output, while preserving the existing instance methods.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, swift
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100