You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
JavaKit: Rework @ImplementsJava to be more like @implements language feature
The `@ImplementsJava` macro had an odd formulation where it was used similarly
to `@JavaMethod`, but was actually interpreted by the outer `@JavaClass` macro.
Completely rework the way `@ImplementsJava` is used to make it more like the
`@implements` feature introduced in SE-0436, and rename it to `@JavaImplements`
to more closely match the canonical spelling for `@implementation` with a
language and make use of the `@Java...` as a common prefix.
In this new design, one places `@JavaImplements` on an extension of the Swift
type and marks the implementing methods with `@JavaMethod`. For example:
@JavaImplements("org.swift.javakit.HelloSwift")
extension Hello {
@JavaMethod
func reportStatistics(_ meaning: String, _ numbers: [Double]) -> String {
let average = numbers.isEmpty ? 0.0 : numbers.reduce(0.0) { $0 + $1 } / Double(numbers.count)
return "Average of \(meaning) is \(average)"
}
}
This also means that we can generate most of the `@JavaClass` definition
for a given Java class, and leave the native methods to be implemented
by an `@JavaImplements` extension. Update the JavaKitSampleApp to use the
Java compilation plugin to compile the Java files in the target. Automatically
feed those into the Java2Swift plugin to generate the Swift
representations of the Java classes, skipping the native methods
(since they'll be implemented here).
The user guide / tutorial is a bit behind the implementation here as I
smooth out more corners.
0 commit comments