swiftlang / swiftlang/swift-java
[Java2Swift] Generating invalid code for methods with generic parameters
Open
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 1.2k
- Forks
- 123
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 16
Description
The code generation for java.net.ContentHandler produces invalid code due when a method signature references a generic type, like JavaClass.
// Auto-generated by Java-to-Swift wrapper generator.
import JavaKit
import JavaRuntime
@JavaClass("java.net.ContentHandler")
open class ContentHandler: JavaObject {
@JavaMethod
@_nonoverride public convenience init(environment: JNIEnvironment? = nil)
@JavaMethod
open func getContent(_ arg0: URLConnection?) throws -> JavaObject!
@JavaMethod
open func getContent(_ arg0: URLConnection?, _ arg1: [JavaClass?]) throws -> JavaObject!
}
/Users/coleman/Developer/Android/Sources/AndroidJavaNet/ContentHandler.swift:14:57: error: reference to generic type 'JavaClass' requires arguments in <...>
12 |
13 | @JavaMethod
14 | open func getContent(_ arg0: URLConnection?, _ arg1: [JavaClass?]) throws -> JavaObject!
| `- error: reference to generic type 'JavaClass' requires arguments in <...>
15 | }
16 |
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Java2Swift generation for java.net.ContentHandler and reproduce the compiler error shown for AndroidJavaNet/ContentHandler.swift. Trace how the generic parameter in the getContent signature is emitted; done means the generated Swift uses a valid generic JavaClass type and compiles.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, swift
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 42/100