Skip to content

Add support for failing build when multiple types are mapped to the same type #182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 23, 2024

Conversation

jrosen081
Copy link
Contributor

Closes #176

Adds validation to the configurations created to make sure that two types are not mapped to the same type in the same module. The output looks as following:

Error: The following Java classes were mapped to the same Swift type:
  Swift Type: Testing.ProcessBuilder, Java Types: java.lang.Math, java.lang.ProcessBuilder

The configuration used was:

{
  "classes": {
    "java.lang.ProcessBuilder": "ProcessBuilder",
    "java.lang.Math": "ProcessBuilder"
  }
}

"""
The following Java classes were mapped to the same Swift type:
\(swiftToJavaMapping.map { mapping in
"Swift Type: \(mapping.swiftType.swiftModule ?? "").\(mapping.swiftType.swiftType), Java Types: \(mapping.javaTypes.sorted().joined(separator: ", "))"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"Swift Type: \(mapping.swiftType.swiftModule ?? "").\(mapping.swiftType.swiftType), Java Types: \(mapping.javaTypes.sorted().joined(separator: ", "))"
"Swift Type: '\(mapping.swiftType.swiftModule ?? "")'.\(mapping.swiftType.swiftType), Java Types: \(mapping.javaTypes.sorted().map({ "'\($0)'" })joined(separator: ", "))"

I'd split out the creating of the names into separate lines, this is a bit busy inside the string interpolation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated and made a helper function to split it out even more

Copy link
Collaborator

@ktoso ktoso left a comment

Choose a reason for hiding this comment

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

Minor nit but looks good :-)

@DougGregor
Copy link
Member

Thank you!

@DougGregor DougGregor merged commit a26cb1a into swiftlang:main Nov 23, 2024
12 checks passed
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.

Java2Swift: Diagnose when two Java classes are mapped to the same Swift type
3 participants