swiftlang / swiftlang/swift-java

`AnyJavaObject` doesn't have any conformance to `JavaValue`

Open
#13 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature:wrap-java
Dominant language
Swift
Stars
1.2k
Forks
123
Avg merge
1d 7h
Merged PRs (30d)
16

Description

As per https://github.com/swiftlang/swift-java/blob/80b68a595ca533ffb4d63d04ee53785a8549f8af/Sources/JavaKit/JavaValue.swift#L23C69-L26C70 , AnyJavaObject protocol should inherit the JavaValue protocol. And this would allow us to utilise the java types such as java.lang.String and java.lang.Array by code gen using Java2Swift.

For some unknown reasons, the code documentation seems to be outdated and the implementation of all the primitive types including types such as the above mentioned ones have been updated to conform to JavaValue directly as we can see in the JavaKit/BridgedValues folder.

This now puts us in an interesting situation where non-primitive java classes, java.lang.Class, java.lang.Object all conform to AnyJavaObject which doesn't conform to JavaValue while the primitive types, java.lang.String, java.lang.Array all conform to JavaValue but does not conform to AnyJavaObject. Thus, creating completely disjoint sets of types.

This also becomes a problem when we mark a method with @JavaMethod to let Swift access the Java methods, because this macro internally needs to make a dynamicJavaMethodCall whose parameters and return type are all JavaValue, therefore we can't have function signatures that involves java.lang.Class, java.lang.Object, or anyother non-primitive java type since the Macro Expansion would fail due to type mismatch.

Its possible that I might have overlooked some details and maybe there's a way to convert AnyJavaObject to JavaValue and vice versa. Please feel free to let me know if I missed something. And also update the code documentation if time permits.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with Sources/JavaKit/JavaValue.swift at the cited protocol definitions, then inspect the JavaKit/BridgedValues implementations and the Java2Swift handling of @JavaMethod and dynamicJavaMethodCall. Determine how AnyJavaObject and JavaValue should relate so signatures involving java.lang.Class and java.lang.Object type-check, and update the relevant documentation if it is confirmed to be outdated.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, swift
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.