Skip to content

Commit 8683902

Browse files
committed
add docs
1 parent f1b7442 commit 8683902

File tree

1 file changed

+43
-3
lines changed

1 file changed

+43
-3
lines changed

Sources/SwiftJavaDocumentation/Documentation.docc/SupportedFeatures.md

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,15 @@ SwiftJava's `swift-java jextract` tool automates generating Java bindings from S
6060
| Async functions `func async` and properties: `var { get async {} }` |||
6161
| Arrays: `[UInt8]`, `[T]` |||
6262
| Dictionaries: `[String: Int]`, `[K:V]` |||
63-
| Generic functions |||
63+
| Generic parameters in functions: `func f<T: A & B>(x: T)` |||
64+
| Generic return values in functions: `func f<T: A & B>() -> T` |||
6465
| `Foundation.Data`, `any Foundation.DataProtocol` |||
6566
| Tuples: `(Int, String)`, `(A, B, C)` |||
66-
| Protocols: `protocol`, existential parameters `any Collection` |||
67+
| Protocols: `protocol` |||
68+
| Existential parameters `f(x: any (A & B)) ` |||
69+
| Existential return types `f() -> any Collection ` |||
70+
| Opaque parameters: `func take(worker: some Builder) -> some Builder` |||
71+
| Opaque return types: `func get() -> some Builder` |||
6772
| Optional parameters: `func f(i: Int?, class: MyClass?)` |||
6873
| Optional return types: `func f() -> Int?`, `func g() -> MyClass?` |||
6974
| Primitive types: `Bool`, `Int`, `Int8`, `Int16`, `Int32`, `Int64`, `Float`, `Double` |||
@@ -90,7 +95,6 @@ SwiftJava's `swift-java jextract` tool automates generating Java bindings from S
9095
| Result builders |||
9196
| Automatic Reference Counting of class types / lifetime safety |||
9297
| Value semantic types (e.g. struct copying) |||
93-
| Opaque types: `func get() -> some Builder`, func take(worker: some Worker) |||
9498
| Swift concurrency: `func async`, `actor`, `distribued actor` |||
9599
| | | |
96100
| | | |
@@ -266,5 +270,41 @@ try (var arena = SwiftArena.ofConfined()) {
266270
}
267271
```
268272

273+
### Protocols
269274

275+
> Note: Protocols are currently only supported in JNI mode.
270276
277+
Protocols are imported as Java `interface`s. For now, we require that all
278+
concrete types of an interface wrap a Swift instance. In the future, we will add support
279+
for providing Java-based implementations of interfaces, that you can pass to Java functions.
280+
281+
Consider the following Swift protocol:
282+
```swift
283+
protocol Named {
284+
var name: String { get }
285+
286+
func describe() -> String
287+
}
288+
```
289+
will be exported as
290+
```java
291+
interface Named extends JNISwiftInstance {
292+
public String getName();
293+
294+
public String describe();
295+
}
296+
```
297+
298+
#### Parameters
299+
Any opaque, existential or generic parameters are imported as Java generics.
300+
This means that the following function:
301+
```swift
302+
func f<S: A & B>(x: S, y: any C, z: some D)
303+
```
304+
will be exported as
305+
```java
306+
<S extends A & B, T1 extends C, T2 extends D> void f(S x, T1 y, T2 z)
307+
```
308+
309+
#### Return types
310+
Protocols are not yet supported as return types.

0 commit comments

Comments
 (0)