Skip to content

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

Open
@DougGregor

Description

@DougGregor

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);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions