javakit-macros: Support wrapping generic arguments#601
Open
sidepelican wants to merge 7 commits intoswiftlang:mainfrom
Open
javakit-macros: Support wrapping generic arguments#601sidepelican wants to merge 7 commits intoswiftlang:mainfrom
sidepelican wants to merge 7 commits intoswiftlang:mainfrom
Conversation
sidepelican
commented
Mar 10, 2026
| let javaList = try XCTUnwrap(ArrayList<JavaInteger>(environment: environment).as(List<JavaInteger>.self)) | ||
| _ = javaList.add(JavaInteger(0, environment: environment)) | ||
| _ = javaList.add(JavaInteger(1, environment: environment)) | ||
| _ = javaList.add(JavaInteger(2, environment: environment)) |
Contributor
Author
There was a problem hiding this comment.
Currently, this add function uses a generic implementation.
ktoso
reviewed
Mar 10, 2026
| if let decl = contextNode.asProtocol(WithGenericParametersSyntax.self) { | ||
| if decl.genericParameterClause?.parameters.contains(where: { | ||
| $0.name.text == typeName | ||
| }) == true { |
Collaborator
There was a problem hiding this comment.
no need to == true
Suggested change
| }) == true { | |
| }) { |
Contributor
Author
There was a problem hiding this comment.
genericParameterClause? produces optional bool here.
ktoso
reviewed
Mar 10, 2026
|
|
||
| /// Determines whether an argument is generic. | ||
| /// Since Optional does not appear in JNI signatures, it is removed before checking. | ||
| private static func isJNIGenericParameter( |
Collaborator
There was a problem hiding this comment.
Let's document that this is a heuristic please, since it may get things wrong. It's good to mark this as source of potential mixups
Contributor
Author
There was a problem hiding this comment.
Upon further review, I noticed that typeErasedResult references JavaClass information, which I believe is more preferable. I've added a comment regarding this point.
ktoso
reviewed
Mar 10, 2026
Collaborator
|
Minor requests here and there, looks good, thank you! |
ktoso
approved these changes
Mar 10, 2026
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.
This PR is part of the improvements for #599.
Previously, generic method arguments (such as
T) had to be manually replaced withJavaObject.I have updated the
@JavaMethodmacro to handle this automatically.The macro now uses a heuristic search to determine if a type is generic and inserts the necessary conversion to
JavaObject.Additionally, I have updated the implementation of
JavaOptional.swiftand (partially)List.swiftusingwrap-java.