jextract/jni: Support Foundation value types in protocol callbacks

Đang mở
#943 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
49/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
java, swift
Lĩnh vực
backend-api-design

Hướng nghiên cứu

Start by tracing how enableJavaCallbacks handles protocol callback arguments and return values, then compare that path with the existing Java-facing representations for Data, Date, URL, and UUID. The issue does not name files or tests, so locate the callback bridge and its coverage first. Done means Java callbacks can accept and return these Foundation value types, including the UUID example.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

feature:jextract

Problem

JNI protocol callbacks reject Foundation value types even though the Java-facing method signatures already support them. As a result, a Swift protocol accepting or returning Data, Date, URL, or UUID cannot be implemented as an ordinary Java callback.

Example

import Foundation

public protocol IdentityCallback {
  func transform(_ value: UUID) -> UUID
}

public func apply(_ callback: some IdentityCallback, _ value: UUID) -> UUID {
  callback.transform(value)
}

With enableJavaCallbacks enabled, Java should be able to implement the protocol using the existing java.util.UUID representation:

IdentityCallback callback = value ->
    java.util.UUID.fromString("87654321-4321-8765-cba9-876543210fed");

java.util.UUID input =
    java.util.UUID.fromString("12345678-1234-5678-9abc-def012345678");
java.util.UUID result = MySwiftLibrary.apply(callback, input);

The callback bridge would need to convert the Swift argument into a Java UUID and the Java result back into Swift. Data, Date, and URL could use their existing generated wrapper classes.

Reference workaround implementation: https://github.com/qoncept/swift-java/pull/5

Ngôn ngữ chính
Swift
Star
1.3k
Fork
127
Merge trung bình
2 ngày 14 giờ
Pull request đã merge (30 ngày)
5

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của swiftlang/swift-java

Tất cả issue của swiftlang/swift-java

Issue tương tự

Thêm issue về Swift

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.