swiftlang / swiftlang/swift-java

Java2Swift: Improve diagnostics when we suppress import due to a missing Java class import

Open
#112 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

When we run Java2Swift, we generally get a large number of warnings like this:

warning: Unable to translate 'java.util.Collection' method 'removeIf': Java class 'java.util.function.Predicate' has not been translated into Swift
warning: Unable to translate 'java.util.Collection' method 'parallelStream': Java class 'java.util.stream.Stream' has not been translated into Swift
warning: Unable to translate 'java.util.Collection' method 'forEach': Java class 'java.util.function.Consumer' has not been translated into Swift

The user experience isn't great for several reasons:

  1. There are often a large number of warnings.
  2. It's not obvious how to address those warnings.
  3. It's not clear after-the-fact which APIs were dropped.

We should re-work how we report these kinds of issues. Specifically, I think we should report just one warning per target, and have that warning also produce the contents of a Java2Swift.config file that contains suggested mappings for those types, e.g.,

{
  "classes" : {
    "java.util.function.Consumer" : "Consumer",
    "java.util.function.Predicate" : "Predicate",
    "java.util.stream.Stream" : "Stream"
  }
}

Additionally, we could emit comments into the generated Swift sources indicating which APIs weren't mapped into Swift, and why, e.g.,

// Java API not available in Swift because java.util.Predicate has not been translated into Swift:
//   boolean removeIf(Predicate<? super E> filter);

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 by locating the Java2Swift diagnostics that report missing Java class imports, then inspect how Java2Swift.config mappings and generated Swift sources are handled. Done means consolidating warnings per target, emitting suggested mappings, and optionally adding comments for omitted APIs as described in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, swift
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.