swiftlang / swiftlang/swift-java
Java2Swift: static native methods
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 1.2k
- Forks
- 123
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 16
Description
Are static native methods supported?
I have (yes, related to #168) this:
public class SwiftHeapObjectHolder implements AutoCloseable {
...
public static native void _releaseSwiftObject(long swiftObject);
}
but I don't see anything in the generated Swift file. If I just naively attempt to implement as an extension on JavaClass<SwiftHeapObjectHolder>, I get a load time error – weirdly it's looking for Java_com_padl_FlutterAndroid_SwiftHeapObjectHolder__1releaseSwiftObject. No idea where the 1 prefix came from. If I put that in the Swift method name, it at least loads OK:
@JavaImplementation("com.padl.FlutterAndroid.SwiftHeapObjectHolder")
extension JavaClass<SwiftHeapObjectHolder> {
@JavaMethod
public static func _1releaseSwiftObject(swiftObject: Int64, environment: JNIEnvironment? = nil) {
guard swiftObject != 0 else { return }
let swiftObjectIntPtr = Int(swiftObject)
unsafeBitCast(Int(swiftObjectIntPtr), to: Unmanaged<AnyObject>.self).release()
}
}
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
Start with the Java declaration and compare it with the generated Swift file, then inspect how native methods are represented for JavaClass extensions. Verify that static native methods are generated and that the resulting Swift implementation loads with the expected native name.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, swift
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100