Repository navigation
JNI: align protocol parameter wrapper names - #16
Merged
Merged
Conversation
Use the same wrapper name in generated declarations and JNI conversions when Java method names differ from Swift names. Preserve shared adapters for initializer overloads, and cover protocol property setters and Java callbacks.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
With Java callbacks enabled, JNI bindings for a public protocol-typed property can generate a Swift setter that references a wrapper class under a different name from its declaration. The generated Swift code then fails to compile.
For example, the JNI sample contains this API:
Before this change, the wrapper declaration used the Swift property name, while the setter's argument conversion used the Java setter name:
After this change, both the declaration and the setter conversion use
_ProtocolPropertyService_setCallback_newValue_Wrapper. A Java implementation can therefore be assigned through the generated setter and called from Swift:The same mismatch can occur when Java method names differ from Swift names for label-disambiguated overloads or Java keywords.
Changes
initname so overloads can share an identical adapter even when their Java names are disambiguated.Validation
Tested on macOS 27.0.1 with Apple Swift 6.4.2 and JetBrains Runtime 25.0.2.
swift test --disable-experimental-prebuilts --disable-sandbox(full Swift suite)../gradlew :Samples:SwiftJavaExtractJNISampleApp:test --no-daemon(generated Swift and Java bindings compiled; all 297 Java tests passed, including the setter callback and existing initializer overload tests).swift-format lint --stricton changed Swift files andgit diff --check.The callback was exercised with Java on macOS; an Android or Kotlin runtime was not tested.