Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8599a30

Browse files
committedMay 4, 2020
Dev: fix SwiftBlock with primitives
1 parent 241d6ea commit 8599a30

38 files changed

+497
-46
lines changed
 

‎compiler/src/main/java/com/readdle/codegen/JavaSwiftProcessor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ static String replaceLast(String text, char replace, char replacement) {
382382
}
383383

384384
public SwiftEnvironment.Type parseJavaType(String javaType) {
385-
if (moduleDescriptor.customTypeMappings.containsKey(javaType)) {
385+
if (moduleDescriptor.customTypeMappings != null && moduleDescriptor.customTypeMappings.containsKey(javaType)) {
386386
return new SwiftEnvironment.Type(moduleDescriptor.customTypeMappings.get(javaType), javaType);
387387
}
388388
switch (javaType) {

‎compiler/src/main/java/com/readdle/codegen/SwiftBlockDescriptor.java

+25-14
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ File generateCode() throws IOException {
203203

204204
String jniMethodTemplate;
205205
if (returnSwiftType != null) {
206-
jniMethodTemplate = "let optionalResult = JNI.CallObjectMethod(self.jniObject, %s.javaMethod%s";
206+
String methodCallMethod = returnSwiftType.returnTypeFunc(isReturnTypeOptional);
207+
jniMethodTemplate = "let optionalResult = JNI." + methodCallMethod + "(self.jniObject, %s.javaMethod%s";
207208
}
208209
else {
209210
jniMethodTemplate = "JNI.CallVoidMethod(self.jniObject, %s.javaMethod%s";
@@ -231,19 +232,29 @@ File generateCode() throws IOException {
231232
swiftWriter.emitStatement("}");
232233

233234
if (returnSwiftType != null) {
234-
swiftWriter.emitStatement("guard let result = optionalResult else {");
235-
swiftWriter.emitStatement(isReturnTypeOptional ? "return nil" : "fatalError(\"Don't support nil here!\")");
236-
swiftWriter.emitStatement("}");
237-
swiftWriter.emitStatement("defer {");
238-
swiftWriter.emitStatement("JNI.DeleteLocalRef(result)");
239-
swiftWriter.emitStatement("}");
240-
swiftWriter.emitStatement("do {");
241-
swiftWriter.emitStatement(String.format("return try %s.from(javaObject: result)", returnSwiftType.swiftConstructorType));
242-
swiftWriter.emitStatement("}");
243-
swiftWriter.emitStatement("catch {");
244-
swiftWriter.emitStatement("let errorString = String(reflecting: type(of: error)) + String(describing: error)");
245-
swiftWriter.emitStatement("fatalError(errorString)");
246-
swiftWriter.emitStatement("}");
235+
if (!isReturnTypeOptional && returnSwiftType.isPrimitiveType()) {
236+
swiftWriter.emitStatement("return " + returnSwiftType.swiftType + "(fromJavaPrimitive: optionalResult)");
237+
}
238+
else {
239+
swiftWriter.emitStatement("guard let result = optionalResult else {");
240+
if (isReturnTypeOptional) {
241+
swiftWriter.emitStatement("return nil");
242+
} else {
243+
swiftWriter.emitStatement("fatalError(\"Don't support nil here!\")");
244+
}
245+
swiftWriter.emitStatement("}");
246+
247+
swiftWriter.emitStatement("defer {");
248+
swiftWriter.emitStatement("JNI.DeleteLocalRef(result)");
249+
swiftWriter.emitStatement("}");
250+
swiftWriter.emitStatement("do {");
251+
swiftWriter.emitStatement(String.format("return try %s.from(javaObject: result)", returnSwiftType.swiftConstructorType));
252+
swiftWriter.emitStatement("}");
253+
swiftWriter.emitStatement("catch {");
254+
swiftWriter.emitStatement("let errorString = String(reflecting: type(of: error)) + String(describing: error)");
255+
swiftWriter.emitStatement("fatalError(errorString)");
256+
swiftWriter.emitStatement("}");
257+
}
247258
}
248259

249260
swiftWriter.emitStatement("}");

‎sample/build.gradle

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ apply plugin: 'kotlin-android'
55
apply plugin: 'kotlin-android-extensions'
66
apply plugin: 'kotlin-kapt'
77

8-
apply plugin: 'kotlin-kapt'
9-
108
swift {
119
useKapt true
1210
cleanEnabled true

‎sample/src/androidTest/java/com/readdle/swiftjava/sample/BoolTests.java

+10
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,14 @@ public void testDecode() {
9191
Assert.assertFalse(BoolTest.testDecode(badParam));
9292
}
9393

94+
@Test
95+
public void testBlock() {
96+
Assert.assertTrue(BoolTest.testBlock(value -> value));
97+
}
98+
99+
@Test
100+
public void testOptionalBlock() {
101+
Assert.assertTrue(BoolTest.testOptionalBlock(value -> value));
102+
}
103+
94104
}

‎sample/src/androidTest/java/com/readdle/swiftjava/sample/DoubleTests.java

+10
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,14 @@ public void testDecode() {
9898
Assert.assertFalse(DoubleTest.testDecode(badParam));
9999
}
100100

101+
@Test
102+
public void testBlock() {
103+
Assert.assertTrue(DoubleTest.testBlock(value -> value));
104+
}
105+
106+
@Test
107+
public void testOptionalBoolBlock() {
108+
Assert.assertTrue(DoubleTest.testOptionalBlock(value -> value));
109+
}
110+
101111
}

‎sample/src/androidTest/java/com/readdle/swiftjava/sample/FloatTests.java

+10
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,14 @@ public void testDecode() {
9898
Assert.assertFalse(FloatTest.testDecode(badParam));
9999
}
100100

101+
@Test
102+
public void testBlock() {
103+
Assert.assertTrue(FloatTest.testBlock(value -> value));
104+
}
105+
106+
@Test
107+
public void testOptionalBlock() {
108+
Assert.assertTrue(FloatTest.testOptionalBlock(value -> value));
109+
}
110+
101111
}

‎sample/src/androidTest/java/com/readdle/swiftjava/sample/Int16Tests.java

+10
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,14 @@ public void testOptionSetDecode() {
124124
Assert.assertEquals(Int16OptionsSet.getThree().getRawValue(), Int16Test.testOptionSetDecode(Int16OptionsSet.getThree()));
125125
}
126126

127+
@Test
128+
public void testBlock() {
129+
Assert.assertTrue(Int16Test.testBlock(value -> value));
130+
}
131+
132+
@Test
133+
public void testOptionalBlock() {
134+
Assert.assertTrue(Int16Test.testOptionalBlock(value -> value));
135+
}
136+
127137
}

‎sample/src/androidTest/java/com/readdle/swiftjava/sample/Int64Tests.java

+10
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,14 @@ public void testOptionSetDecode() {
124124
Assert.assertEquals(Int64OptionsSet.getThree().getRawValue(), Int64Test.testOptionSetDecode(Int64OptionsSet.getThree()));
125125
}
126126

127+
@Test
128+
public void testBlock() {
129+
Assert.assertTrue(Int64Test.testBlock(value -> value));
130+
}
131+
132+
@Test
133+
public void testOptionalBlock() {
134+
Assert.assertTrue(Int64Test.testOptionalBlock(value -> value));
135+
}
136+
127137
}

‎sample/src/androidTest/java/com/readdle/swiftjava/sample/Int8Tests.java

+10
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,14 @@ public void testOptionSetDecode() {
124124
Assert.assertEquals(Int8OptionsSet.getThree().getRawValue(), Int8Test.testOptionSetDecode(Int8OptionsSet.getThree()));
125125
}
126126

127+
@Test
128+
public void testBlock() {
129+
Assert.assertTrue(Int8Test.testBlock(value -> value));
130+
}
131+
132+
@Test
133+
public void testOptionalBlock() {
134+
Assert.assertTrue(Int8Test.testOptionalBlock(value -> value));
135+
}
136+
127137
}

‎sample/src/androidTest/java/com/readdle/swiftjava/sample/IntTests.java

+10
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,14 @@ public void testOptionSetDecode() {
144144
Assert.assertEquals(IntOptionsSet.getThree().getRawValue(), IntTest.testOptionSetDecode(IntOptionsSet.getThree()));
145145
}
146146

147+
@Test
148+
public void testBlock() {
149+
Assert.assertTrue(IntTest.testBlock(value -> value));
150+
}
151+
152+
@Test
153+
public void testOptionalBlock() {
154+
Assert.assertTrue(IntTest.testOptionalBlock(value -> value));
155+
}
156+
147157
}

‎sample/src/androidTest/java/com/readdle/swiftjava/sample/UInt16Tests.java

+10
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,14 @@ public void testOptionSetDecode() {
127127
Assert.assertEquals(UInt16OptionsSet.getThree().getRawValue(),UInt16Test.testOptionSetDecode(UInt16OptionsSet.getThree()));
128128
}
129129

130+
@Test
131+
public void testBlock() {
132+
Assert.assertTrue(UInt16Test.testBlock(value -> value));
133+
}
134+
135+
@Test
136+
public void testOptionalBlock() {
137+
Assert.assertTrue(UInt16Test.testOptionalBlock(value -> value));
138+
}
139+
130140
}

‎sample/src/androidTest/java/com/readdle/swiftjava/sample/UInt64Tests.java

+10
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,14 @@ public void testOptionSetDecode() {
127127
Assert.assertEquals(UInt64OptionsSet.getThree().getRawValue(),UInt64Test.testOptionSetDecode(UInt64OptionsSet.getThree()));
128128
}
129129

130+
@Test
131+
public void testBlock() {
132+
Assert.assertTrue(UInt64Test.testBlock(value -> value));
133+
}
134+
135+
@Test
136+
public void testOptionalBlock() {
137+
Assert.assertTrue(UInt64Test.testOptionalBlock(value -> value));
138+
}
139+
130140
}

‎sample/src/androidTest/java/com/readdle/swiftjava/sample/UInt8Tests.java

+10
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,14 @@ public void testOptionSetDecode() {
127127
Assert.assertEquals(UInt8OptionsSet.getThree().getRawValue(),UInt8Test.testOptionSetDecode(UInt8OptionsSet.getThree()));
128128
}
129129

130+
@Test
131+
public void testBlock() {
132+
Assert.assertTrue(UInt8Test.testBlock(value -> value));
133+
}
134+
135+
@Test
136+
public void testOptionalBlock() {
137+
Assert.assertTrue(UInt8Test.testOptionalBlock(value -> value));
138+
}
139+
130140
}

‎sample/src/androidTest/java/com/readdle/swiftjava/sample/UIntTests.java

+10
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,14 @@ public void testOptionSetDecode() {
140140
Assert.assertEquals(UIntOptionsSet.getThree().getRawValue(),UIntTest.testOptionSetDecode(UIntOptionsSet.getThree()));
141141
}
142142

143+
@Test
144+
public void testBlock() {
145+
Assert.assertTrue(UIntTest.testBlock(value -> value));
146+
}
147+
148+
@Test
149+
public void testOptionalBlock() {
150+
Assert.assertTrue(UIntTest.testOptionalBlock(value -> value));
151+
}
152+
143153
}

‎sample/src/main/java/com/readdle/swiftjava/sample/BoolTest.kt

+18-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package com.readdle.swiftjava.sample
22

3-
import com.readdle.codegen.anotation.SwiftCallbackFunc
4-
import com.readdle.codegen.anotation.SwiftDelegate
5-
import com.readdle.codegen.anotation.SwiftReference
6-
import com.readdle.codegen.anotation.SwiftValue
3+
import com.readdle.codegen.anotation.*
74
import java.lang.annotation.Native
85

96
@SwiftValue
@@ -39,6 +36,16 @@ class BoolTest private constructor() {
3936
fun testOptionalReturnType(): Boolean?
4037
}
4138

39+
@SwiftBlock("(Bool) -> Bool")
40+
interface BoolBlock {
41+
fun call(value: Boolean): Boolean
42+
}
43+
44+
@SwiftBlock("(Bool?) -> Bool?")
45+
interface OptionalBoolBlock {
46+
fun call(value: Boolean?): Boolean?
47+
}
48+
4249
companion object {
4350
@JvmStatic
4451
external fun testYes(): Boolean
@@ -71,10 +78,16 @@ class BoolTest private constructor() {
7178
external fun testProtocolOptionalReturnType(callback: BoolOptionalReturnTypeProtocol): Boolean?
7279

7380
@JvmStatic
74-
external fun testEncode(): BoolTestStruct
81+
external fun testEncode(): BoolTestStruct
7582

7683
@JvmStatic
7784
external fun testDecode(value: BoolTestStruct): Boolean
85+
86+
@JvmStatic
87+
external fun testBlock(@SwiftBlock block: BoolBlock): Boolean
88+
89+
@JvmStatic
90+
external fun testOptionalBlock(@SwiftBlock block: OptionalBoolBlock): Boolean
7891
}
7992

8093
@Native

‎sample/src/main/java/com/readdle/swiftjava/sample/DoubleTest.kt

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package com.readdle.swiftjava.sample
22

3-
import com.readdle.codegen.anotation.SwiftCallbackFunc
4-
import com.readdle.codegen.anotation.SwiftDelegate
5-
import com.readdle.codegen.anotation.SwiftReference
6-
import com.readdle.codegen.anotation.SwiftValue
3+
import com.readdle.codegen.anotation.*
74
import java.lang.annotation.Native
85

96
@SwiftValue
@@ -40,6 +37,16 @@ class DoubleTest private constructor() {
4037
fun testOptionalReturnType(): Double?
4138
}
4239

40+
@SwiftBlock("(Double) -> Double")
41+
interface DoubleBlock {
42+
fun call(value: Double): Double
43+
}
44+
45+
@SwiftBlock("(Double?) -> Double?")
46+
interface OptionalDoubleBlock {
47+
fun call(value: Double?): Double?
48+
}
49+
4350
companion object {
4451
@JvmStatic
4552
external fun testZero(): Double
@@ -79,6 +86,12 @@ class DoubleTest private constructor() {
7986

8087
@JvmStatic
8188
external fun testDecode(value: DoubleTestStruct): Boolean
89+
90+
@JvmStatic
91+
external fun testBlock(@SwiftBlock block: DoubleBlock): Boolean
92+
93+
@JvmStatic
94+
external fun testOptionalBlock(@SwiftBlock block: OptionalDoubleBlock): Boolean
8295
}
8396

8497
@Native

‎sample/src/main/java/com/readdle/swiftjava/sample/FloatTest.kt

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package com.readdle.swiftjava.sample
22

3-
import com.readdle.codegen.anotation.SwiftCallbackFunc
4-
import com.readdle.codegen.anotation.SwiftDelegate
5-
import com.readdle.codegen.anotation.SwiftReference
6-
import com.readdle.codegen.anotation.SwiftValue
3+
import com.readdle.codegen.anotation.*
74
import java.lang.annotation.Native
85

96
@SwiftValue
@@ -40,6 +37,16 @@ class FloatTest private constructor() {
4037
fun testOptionalReturnType(): Float?
4138
}
4239

40+
@SwiftBlock("(Float) -> Float")
41+
interface FloatBlock {
42+
fun call(value: Float): Float
43+
}
44+
45+
@SwiftBlock("(Float?) -> Float?")
46+
interface OptionalFloatBlock {
47+
fun call(value: Float?): Float?
48+
}
49+
4350
companion object {
4451
@JvmStatic
4552
external fun testZero(): Float
@@ -79,6 +86,12 @@ class FloatTest private constructor() {
7986

8087
@JvmStatic
8188
external fun testDecode(value: FloatTestStruct): Boolean
89+
90+
@JvmStatic
91+
external fun testBlock(@SwiftBlock block: FloatBlock): Boolean
92+
93+
@JvmStatic
94+
external fun testOptionalBlock(@SwiftBlock block: OptionalFloatBlock): Boolean
8295
}
8396

8497
@Native

‎sample/src/main/java/com/readdle/swiftjava/sample/Int16Test.kt

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package com.readdle.swiftjava.sample
22

3-
import com.readdle.codegen.anotation.SwiftCallbackFunc
4-
import com.readdle.codegen.anotation.SwiftDelegate
5-
import com.readdle.codegen.anotation.SwiftReference
6-
import com.readdle.codegen.anotation.SwiftValue
3+
import com.readdle.codegen.anotation.*
74
import java.lang.annotation.Native
85

96
@SwiftValue
@@ -75,6 +72,16 @@ class Int16Test private constructor() {
7572
fun testOptionalReturnType(): Short?
7673
}
7774

75+
@SwiftBlock("(Int16) -> Int16")
76+
interface Int16Block {
77+
fun call(value: Short): Short
78+
}
79+
80+
@SwiftBlock("(Int16?) -> Int16?")
81+
interface OptionalInt16Block {
82+
fun call(value: Short?): Short?
83+
}
84+
7885
companion object {
7986
@JvmStatic
8087
external fun testZero(): Short
@@ -126,6 +133,12 @@ class Int16Test private constructor() {
126133

127134
@JvmStatic
128135
external fun testOptionSetDecode(enum: Int16OptionsSet) : Short
136+
137+
@JvmStatic
138+
external fun testBlock(@SwiftBlock block: Int16Block): Boolean
139+
140+
@JvmStatic
141+
external fun testOptionalBlock(@SwiftBlock block: OptionalInt16Block): Boolean
129142
}
130143

131144
@Native

‎sample/src/main/java/com/readdle/swiftjava/sample/Int64Test.kt

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package com.readdle.swiftjava.sample
22

3-
import com.readdle.codegen.anotation.SwiftCallbackFunc
4-
import com.readdle.codegen.anotation.SwiftDelegate
5-
import com.readdle.codegen.anotation.SwiftReference
6-
import com.readdle.codegen.anotation.SwiftValue
3+
import com.readdle.codegen.anotation.*
74
import java.lang.annotation.Native
85

96
@SwiftValue
@@ -75,6 +72,16 @@ class Int64Test private constructor() {
7572
fun testOptionalReturnType(): Long?
7673
}
7774

75+
@SwiftBlock("(Int64) -> Int64")
76+
interface Int64Block {
77+
fun call(value: Long): Long
78+
}
79+
80+
@SwiftBlock("(Int64?) -> Int64?")
81+
interface OptionalInt64Block {
82+
fun call(value: Long?): Long?
83+
}
84+
7885
companion object {
7986
@JvmStatic
8087
external fun testZero(): Long
@@ -126,6 +133,12 @@ class Int64Test private constructor() {
126133

127134
@JvmStatic
128135
external fun testOptionSetDecode(enum: Int64OptionsSet) : Long
136+
137+
@JvmStatic
138+
external fun testBlock(@SwiftBlock block: Int64Block): Boolean
139+
140+
@JvmStatic
141+
external fun testOptionalBlock(@SwiftBlock block: OptionalInt64Block): Boolean
129142
}
130143

131144
@Native

‎sample/src/main/java/com/readdle/swiftjava/sample/Int8Test.kt

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package com.readdle.swiftjava.sample
22

3-
import com.readdle.codegen.anotation.SwiftCallbackFunc
4-
import com.readdle.codegen.anotation.SwiftDelegate
5-
import com.readdle.codegen.anotation.SwiftReference
6-
import com.readdle.codegen.anotation.SwiftValue
3+
import com.readdle.codegen.anotation.*
74
import java.lang.annotation.Native
85

96
@SwiftValue
@@ -75,6 +72,16 @@ class Int8Test private constructor() {
7572
fun testOptionalReturnType(): Byte?
7673
}
7774

75+
@SwiftBlock("(Int8) -> Int8")
76+
interface Int8Block {
77+
fun call(value: Byte): Byte
78+
}
79+
80+
@SwiftBlock("(Int8?) -> Int8?")
81+
interface OptionalInt8Block {
82+
fun call(value: Byte?): Byte?
83+
}
84+
7885
companion object {
7986
@JvmStatic
8087
external fun testZero(): Byte
@@ -126,6 +133,12 @@ class Int8Test private constructor() {
126133

127134
@JvmStatic
128135
external fun testOptionSetDecode(enum: Int8OptionsSet) : Byte
136+
137+
@JvmStatic
138+
external fun testBlock(@SwiftBlock block: Int8Block): Boolean
139+
140+
@JvmStatic
141+
external fun testOptionalBlock(@SwiftBlock block: OptionalInt8Block): Boolean
129142
}
130143

131144
@Native

‎sample/src/main/java/com/readdle/swiftjava/sample/IntTest.kt

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package com.readdle.swiftjava.sample
22

3-
import com.readdle.codegen.anotation.SwiftCallbackFunc
4-
import com.readdle.codegen.anotation.SwiftDelegate
5-
import com.readdle.codegen.anotation.SwiftReference
6-
import com.readdle.codegen.anotation.SwiftValue
3+
import com.readdle.codegen.anotation.*
74
import java.lang.annotation.Native
85

96
@SwiftValue
@@ -75,6 +72,16 @@ class IntTest private constructor() {
7572
fun testOptionalReturnType(): Int?
7673
}
7774

75+
@SwiftBlock("(Int) -> Int")
76+
interface IntBlock {
77+
fun call(value: Int): Int
78+
}
79+
80+
@SwiftBlock("(Int?) -> Int?")
81+
interface OptionalIntBlock {
82+
fun call(value: Int?): Int?
83+
}
84+
7885
companion object {
7986
@JvmStatic
8087
external fun testZero(): Int
@@ -126,6 +133,12 @@ class IntTest private constructor() {
126133

127134
@JvmStatic
128135
external fun testOptionSetDecode(enum: IntOptionsSet) : Int
136+
137+
@JvmStatic
138+
external fun testBlock(@SwiftBlock block: IntBlock): Boolean
139+
140+
@JvmStatic
141+
external fun testOptionalBlock(@SwiftBlock block: OptionalIntBlock): Boolean
129142
}
130143

131144
@Native

‎sample/src/main/java/com/readdle/swiftjava/sample/UInt16Test.kt

+18
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ class UInt16Test private constructor() {
7575
fun testOptionalReturnType(): Short?
7676
}
7777

78+
@SwiftBlock("(UInt16) -> UInt16")
79+
interface UInt16Block {
80+
@Unsigned
81+
fun call(@Unsigned value: Short): Short
82+
}
83+
84+
@SwiftBlock("(UInt16?) -> UInt16?")
85+
interface OptionalUInt16Block {
86+
@Unsigned
87+
fun call(@Unsigned value: Short?): Short?
88+
}
89+
7890
companion object {
7991
@JvmStatic @Unsigned
8092
external fun testZero(): Short
@@ -126,6 +138,12 @@ class UInt16Test private constructor() {
126138

127139
@JvmStatic @Unsigned
128140
external fun testOptionSetDecode(enum: UInt16OptionsSet) : Short
141+
142+
@JvmStatic
143+
external fun testBlock(@SwiftBlock block: UInt16Block): Boolean
144+
145+
@JvmStatic
146+
external fun testOptionalBlock(@SwiftBlock block: OptionalUInt16Block): Boolean
129147
}
130148

131149
@Native

‎sample/src/main/java/com/readdle/swiftjava/sample/UInt64Test.kt

+18
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ class UInt64Test private constructor() {
7575
fun testOptionalReturnType(): Long?
7676
}
7777

78+
@SwiftBlock("(UInt64) -> UInt64")
79+
interface UInt64Block {
80+
@Unsigned
81+
fun call(@Unsigned value: Long): Long
82+
}
83+
84+
@SwiftBlock("(UInt64?) -> UInt64?")
85+
interface OptionalUInt64Block {
86+
@Unsigned
87+
fun call(@Unsigned value: Long?): Long?
88+
}
89+
7890
companion object {
7991
@JvmStatic @Unsigned
8092
external fun testZero(): Long
@@ -126,6 +138,12 @@ class UInt64Test private constructor() {
126138

127139
@JvmStatic @Unsigned
128140
external fun testOptionSetDecode(enum: UInt64OptionsSet) : Long
141+
142+
@JvmStatic
143+
external fun testBlock(@SwiftBlock block: UInt64Block): Boolean
144+
145+
@JvmStatic
146+
external fun testOptionalBlock(@SwiftBlock block: OptionalUInt64Block): Boolean
129147
}
130148

131149
@Native

‎sample/src/main/java/com/readdle/swiftjava/sample/UInt8Test.kt

+18
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@ class UInt8Test private constructor() {
8484
fun testOptionalReturnType(): Byte?
8585
}
8686

87+
@SwiftBlock("(UInt8) -> UInt8")
88+
interface UInt8Block {
89+
@Unsigned
90+
fun call(@Unsigned value: Byte): Byte
91+
}
92+
93+
@SwiftBlock("(UInt8?) -> UInt8?")
94+
interface OptionalUInt8Block {
95+
@Unsigned
96+
fun call(@Unsigned value: Byte?): Byte?
97+
}
98+
8799
companion object {
88100
@JvmStatic @Unsigned
89101
external fun testZero(): Byte
@@ -135,6 +147,12 @@ class UInt8Test private constructor() {
135147

136148
@JvmStatic @Unsigned
137149
external fun testOptionSetDecode(enum: UInt8OptionsSet) : Byte
150+
151+
@JvmStatic
152+
external fun testBlock(@SwiftBlock block: UInt8Block): Boolean
153+
154+
@JvmStatic
155+
external fun testOptionalBlock(@SwiftBlock block: OptionalUInt8Block): Boolean
138156
}
139157

140158
@Native

‎sample/src/main/java/com/readdle/swiftjava/sample/UIntTest.kt

+18
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ class UIntTest private constructor() {
7676
fun testOptionalReturnType(): Int?
7777
}
7878

79+
@SwiftBlock("(UInt) -> UInt")
80+
interface UIntBlock {
81+
@Unsigned
82+
fun call(@Unsigned value: Int): Int
83+
}
84+
85+
@SwiftBlock("(UInt?) -> UInt?")
86+
interface OptionalUIntBlock {
87+
@Unsigned
88+
fun call(@Unsigned value: Int?): Int?
89+
}
90+
7991
companion object {
8092
@JvmStatic @Unsigned
8193
external fun testZero(): Int
@@ -127,6 +139,12 @@ class UIntTest private constructor() {
127139

128140
@JvmStatic @Unsigned
129141
external fun testOptionSetDecode(enum: UIntOptionsSet) : Int
142+
143+
@JvmStatic
144+
external fun testBlock(@SwiftBlock block: UIntBlock): Boolean
145+
146+
@JvmStatic
147+
external fun testOptionalBlock(@SwiftBlock block: OptionalUIntBlock): Boolean
130148
}
131149

132150
@Native

‎sample/src/main/swift/Sources/SampleAppCore/BoolTest.swift

+13
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ public protocol BoolTestOptionalReturnTypeProtocol {
2727
func testOptionalReturnType() -> Bool?
2828
}
2929

30+
public typealias BoolBlock = (_ boolValue: Bool) -> Bool
31+
public typealias OptionalBoolBlock = (_ boolValue: Bool?) -> Bool?
32+
3033
public class BoolTest {
3134

3235
public static func testYes() -> Bool {
@@ -77,4 +80,14 @@ public class BoolTest {
7780
return value == BoolTestStruct()
7881
}
7982

83+
public static func testBlock(_ block: BoolBlock) -> Bool {
84+
let value = block(true)
85+
return value == true
86+
}
87+
88+
public static func testOptionalBlock(_ block: OptionalBoolBlock) -> Bool {
89+
let value = block(nil)
90+
return value == nil
91+
}
92+
8093
}

‎sample/src/main/swift/Sources/SampleAppCore/DoubleTest.swift

+13
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ public protocol DoubleTestOptionalReturnTypeProtocol {
2828
func testOptionalReturnType() -> Double?
2929
}
3030

31+
public typealias DoubleBlock = (_ value: Double) -> Double
32+
public typealias OptionalDoubleBlock = (_ value: Double?) -> Double?
33+
3134
public class DoubleTest {
3235

3336
public static func testZero() -> Double {
@@ -82,4 +85,14 @@ public class DoubleTest {
8285
return value == DoubleTestStruct()
8386
}
8487

88+
public static func testBlock(_ block: DoubleBlock) -> Bool {
89+
let value = block(0)
90+
return value == 0
91+
}
92+
93+
public static func testOptionalBlock(_ block: OptionalDoubleBlock) -> Bool {
94+
let value = block(nil)
95+
return value == nil
96+
}
97+
8598
}

‎sample/src/main/swift/Sources/SampleAppCore/FloatTest.swift

+13
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ public protocol FloatTestOptionalReturnTypeProtocol {
2828
func testOptionalReturnType() -> Float?
2929
}
3030

31+
public typealias FloatBlock = (_ value: Float) -> Float
32+
public typealias OptionalFloatBlock = (_ value: Float?) -> Float?
33+
3134
public class FloatTest {
3235

3336
public static func testZero() -> Float {
@@ -82,4 +85,14 @@ public class FloatTest {
8285
return value == FloatTestStruct()
8386
}
8487

88+
public static func testBlock(_ block: FloatBlock) -> Bool {
89+
let value = block(0)
90+
return value == 0
91+
}
92+
93+
public static func testOptionalBlock(_ block: OptionalFloatBlock) -> Bool {
94+
let value = block(nil)
95+
return value == nil
96+
}
97+
8598
}

‎sample/src/main/swift/Sources/SampleAppCore/Int16Test.swift

+13
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ public protocol Int16TestOptionalReturnTypeProtocol {
4747
func testOptionalReturnType() -> Int16?
4848
}
4949

50+
public typealias Int16Block = (_ value: Int16) -> Int16
51+
public typealias OptionalInt16Block = (_ value: Int16?) -> Int16?
52+
5053
public class Int16Test {
5154

5255
public static func testZero() -> Int16 {
@@ -122,4 +125,14 @@ public class Int16Test {
122125
return optionSet.rawValue
123126
}
124127

128+
public static func testBlock(_ block: Int16Block) -> Bool {
129+
let value = block(0)
130+
return value == 0
131+
}
132+
133+
public static func testOptionalBlock(_ block: OptionalInt16Block) -> Bool {
134+
let value = block(nil)
135+
return value == nil
136+
}
137+
125138
}

‎sample/src/main/swift/Sources/SampleAppCore/Int32Test.swift

+13
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ public protocol Int32TestOptionalReturnTypeProtocol {
4747
func testOptionalReturnType() -> Int32?
4848
}
4949

50+
public typealias Int32Block = (_ value: Int32) -> Int32
51+
public typealias OptionalInt32Block = (_ value: Int32?) -> Int32?
52+
5053
public class Int32Test {
5154

5255
public static func testZero() -> Int32 {
@@ -122,4 +125,14 @@ public class Int32Test {
122125
return Int(optionSet.rawValue)
123126
}
124127

128+
public static func testBlock(_ block: Int32Block) -> Bool {
129+
let value = block(0)
130+
return value == 0
131+
}
132+
133+
public static func testOptionalBlock(_ block: OptionalInt32Block) -> Bool {
134+
let value = block(nil)
135+
return value == nil
136+
}
137+
125138
}

‎sample/src/main/swift/Sources/SampleAppCore/Int64Test.swift

+13
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ public protocol Int64TestOptionalReturnTypeProtocol {
4747
func testOptionalReturnType() -> Int64?
4848
}
4949

50+
public typealias Int64Block = (_ value: Int64) -> Int64
51+
public typealias OptionalInt64Block = (_ value: Int64?) -> Int64?
52+
5053
public class Int64Test {
5154

5255
public static func testZero() -> Int64 {
@@ -122,4 +125,14 @@ public class Int64Test {
122125
return optionSet.rawValue
123126
}
124127

128+
public static func testBlock(_ block: Int64Block) -> Bool {
129+
let value = block(0)
130+
return value == 0
131+
}
132+
133+
public static func testOptionalBlock(_ block: OptionalInt64Block) -> Bool {
134+
let value = block(nil)
135+
return value == nil
136+
}
137+
125138
}

‎sample/src/main/swift/Sources/SampleAppCore/Int8Test.swift

+13
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ public protocol Int8TestOptionalReturnTypeProtocol {
4747
func testOptionalReturnType() -> Int8?
4848
}
4949

50+
public typealias Int8Block = (_ value: Int8) -> Int8
51+
public typealias OptionalInt8Block = (_ value: Int8?) -> Int8?
52+
5053
public class Int8Test {
5154

5255
public static func testZero() -> Int8 {
@@ -122,4 +125,14 @@ public class Int8Test {
122125
return optionSet.rawValue
123126
}
124127

128+
public static func testBlock(_ block: Int8Block) -> Bool {
129+
let value = block(0)
130+
return value == 0
131+
}
132+
133+
public static func testOptionalBlock(_ block: OptionalInt8Block) -> Bool {
134+
let value = block(nil)
135+
return value == nil
136+
}
137+
125138
}

‎sample/src/main/swift/Sources/SampleAppCore/IntTest.swift

+13
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ public protocol IntTestOptionalReturnTypeProtocol {
4747
func testOptionalReturnType() -> Int?
4848
}
4949

50+
public typealias IntBlock = (_ value: Int) -> Int
51+
public typealias OptionalIntBlock = (_ value: Int?) -> Int?
52+
5053
public class IntTest {
5154

5255
public static func testZero() -> Int {
@@ -134,4 +137,14 @@ public class IntTest {
134137
return optionSet.rawValue
135138
}
136139

140+
public static func testBlock(_ block: IntBlock) -> Bool {
141+
let value = block(0)
142+
return value == 0
143+
}
144+
145+
public static func testOptionalBlock(_ block: OptionalIntBlock) -> Bool {
146+
let value = block(nil)
147+
return value == nil
148+
}
149+
137150
}

‎sample/src/main/swift/Sources/SampleAppCore/UInt16Test.swift

+13
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ public protocol UInt16TestOptionalReturnTypeProtocol {
4747
func testOptionalReturnType() -> UInt16?
4848
}
4949

50+
public typealias UInt16Block = (_ value: UInt16) -> UInt16
51+
public typealias OptionalUInt16Block = (_ value: UInt16?) -> UInt16?
52+
5053
public class UInt16Test {
5154

5255
public static func testZero() -> UInt16 {
@@ -122,4 +125,14 @@ public class UInt16Test {
122125
return optionSet.rawValue
123126
}
124127

128+
public static func testBlock(_ block: UInt16Block) -> Bool {
129+
let value = block(0)
130+
return value == 0
131+
}
132+
133+
public static func testOptionalBlock(_ block: OptionalUInt16Block) -> Bool {
134+
let value = block(nil)
135+
return value == nil
136+
}
137+
125138
}

‎sample/src/main/swift/Sources/SampleAppCore/UInt32Test.swift

+13
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ public protocol UInt32TestOptionalReturnTypeProtocol {
4747
func testOptionalReturnType() -> UInt32?
4848
}
4949

50+
public typealias UInt32Block = (_ value: UInt32) -> UInt32
51+
public typealias OptionalUInt32Block = (_ value: UInt32?) -> UInt32?
52+
5053
public class UInt32Test {
5154

5255
public static func testZero() -> UInt32 {
@@ -122,4 +125,14 @@ public class UInt32Test {
122125
return UInt(optionSet.rawValue)
123126
}
124127

128+
public static func testBlock(_ block: UInt32Block) -> Bool {
129+
let value = block(0)
130+
return value == 0
131+
}
132+
133+
public static func testOptionalBlock(_ block: OptionalUInt32Block) -> Bool {
134+
let value = block(nil)
135+
return value == nil
136+
}
137+
125138
}

‎sample/src/main/swift/Sources/SampleAppCore/UInt64Test.swift

+13
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ public protocol UInt64TestOptionalReturnTypeProtocol {
4747
func testOptionalReturnType() -> UInt64?
4848
}
4949

50+
public typealias UInt64Block = (_ value: UInt64) -> UInt64
51+
public typealias OptionalUInt64Block = (_ value: UInt64?) -> UInt64?
52+
5053
public class UInt64Test {
5154

5255
public static func testZero() -> UInt64 {
@@ -122,4 +125,14 @@ public class UInt64Test {
122125
return optionSet.rawValue
123126
}
124127

128+
public static func testBlock(_ block: UInt64Block) -> Bool {
129+
let value = block(0)
130+
return value == 0
131+
}
132+
133+
public static func testOptionalBlock(_ block: OptionalUInt64Block) -> Bool {
134+
let value = block(nil)
135+
return value == nil
136+
}
137+
125138
}

‎sample/src/main/swift/Sources/SampleAppCore/UInt8Test.swift

+13
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ public protocol UInt8TestOptionalReturnTypeProtocol {
4747
func testOptionalReturnType() -> UInt8?
4848
}
4949

50+
public typealias UInt8Block = (_ value: UInt8) -> UInt8
51+
public typealias OptionalUInt8Block = (_ value: UInt8?) -> UInt8?
52+
5053
public class UInt8Test {
5154

5255
public static func testZero() -> UInt8 {
@@ -122,4 +125,14 @@ public class UInt8Test {
122125
return optionSet.rawValue
123126
}
124127

128+
public static func testBlock(_ block: UInt8Block) -> Bool {
129+
let value = block(0)
130+
return value == 0
131+
}
132+
133+
public static func testOptionalBlock(_ block: OptionalUInt8Block) -> Bool {
134+
let value = block(nil)
135+
return value == nil
136+
}
137+
125138
}

‎sample/src/main/swift/Sources/SampleAppCore/UIntTest.swift

+13
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ public protocol UIntTestOptionalReturnTypeProtocol {
4747
func testOptionalReturnType() -> UInt?
4848
}
4949

50+
public typealias UIntBlock = (_ value: UInt) -> UInt
51+
public typealias OptionalUIntBlock = (_ value: UInt?) -> UInt?
52+
5053
public class UIntTest {
5154

5255
public static func testZero() -> UInt {
@@ -134,4 +137,14 @@ public class UIntTest {
134137
return optionSet.rawValue
135138
}
136139

140+
public static func testBlock(_ block: UIntBlock) -> Bool {
141+
let value = block(0)
142+
return value == 0
143+
}
144+
145+
public static func testOptionalBlock(_ block: OptionalUIntBlock) -> Bool {
146+
let value = block(nil)
147+
return value == nil
148+
}
149+
137150
}

0 commit comments

Comments
 (0)
Please sign in to comment.