Skip to content

jextract-jni: Add type parameters to generated java types#648

Merged
ktoso merged 9 commits intoswiftlang:mainfrom
sidepelican:java_typeparamete
Mar 26, 2026
Merged

jextract-jni: Add type parameters to generated java types#648
ktoso merged 9 commits intoswiftlang:mainfrom
sidepelican:java_typeparamete

Conversation

@sidepelican
Copy link
Copy Markdown
Contributor

The Java classes introduced in #572 were generated without their generic parameters.
This PR adds them.

To map Swift generic parameter values to their corresponding Java type names, I have added translateGenericTypeParameter to JNISwift2JavaGenerator.
(Adding this function ended up requiring an extra argument for many other functions 🥲)

@sidepelican sidepelican requested a review from ktoso as a code owner March 26, 2026 05:21
}

/// A container for receiving Swift generic instances.
static var _OutSwiftGenericInstance: JavaType {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was mistakenly ported to jni-core, so I'll remove the definition from that side later.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I had a feel we'll move one or two too many huh

printer.println()
let genericClause =
if decl.swiftNominal.isGeneric {
"<\(decl.swiftNominal.genericParameters.map(\.name).joined(separator: ", "))>"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


```java
public final class MyID implements JNISwiftInstance {
public final class MyID<T> implements JNISwiftInstance {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very exciting :)

@ktoso ktoso merged commit 6c9340b into swiftlang:main Mar 26, 2026
61 checks passed
@sidepelican sidepelican deleted the java_typeparamete branch March 26, 2026 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants