Skip to content

Commit 6c03624

Browse files
committed
PR feedback
1 parent a6d3887 commit 6c03624

File tree

5 files changed

+36
-32
lines changed

5 files changed

+36
-32
lines changed

Samples/JExtractJNISampleApp/Sources/MySwiftLibrary/MySwiftClass.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ public class MySwiftClass {
3535
}
3636
}
3737
public let warm: Bool = false
38+
public var getAsync: Int64 {
39+
get async {
40+
return 42
41+
}
42+
}
3843

3944
public static func method() {
4045
p("Hello from static method in a class!")

Sources/JExtractSwiftLib/ImportedDecls.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,6 @@ extension ImportedFunc {
169169
}
170170

171171
var javaSetterName: String {
172-
let firstParameterIsBoolean = self.functionSignature.parameters.first?.type.asNominalTypeDeclaration?.knownTypeKind == .bool
173-
174-
if !firstParameterIsBoolean || self.name.hasJavaBooleanNamingConvention {
175-
return "set\(self.name.toCamelCase)"
176-
} else {
177-
return "setIs\(self.name.toCamelCase)"
178-
}
172+
"set\(self.name.toCamelCase)"
179173
}
180174
}

Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+SwiftThunkPrinting.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,10 @@ extension JNISwift2JavaGenerator {
217217
result = "\(tryClause)\(calleeName).\(decl.name)"
218218

219219
case .setter:
220-
assert(decl.functionSignature.parameters.count == 1)
221-
let newValueParameter = decl.functionSignature.parameters[0]
220+
guard let newValueParameter = decl.functionSignature.parameters.first else {
221+
fatalError("Setter did not contain newValue parameter: \(decl)")
222+
}
223+
222224
result = "\(calleeName).\(decl.name) = \(renderJNIToSwiftConversion("newValue", type: newValueParameter.type))"
223225
}
224226

Sources/JExtractSwiftLib/SwiftTypes/SwiftFunctionSignature.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,11 @@ extension SwiftFunctionSignature {
211211
switch binding.accessorBlock?.accessors {
212212
case .getter(let getter):
213213
if let getter = getter.as(AccessorDeclSyntax.self) {
214-
effectSpecifiers = Self.effectSpecifiers(from: getter)
214+
effectSpecifiers = try Self.effectSpecifiers(from: getter)
215215
}
216216
case .accessors(let accessors):
217217
if let getter = accessors.first(where: { $0.accessorSpecifier.tokenKind == .keyword(.get) }) {
218-
effectSpecifiers = Self.effectSpecifiers(from: getter)
218+
effectSpecifiers = try Self.effectSpecifiers(from: getter)
219219
}
220220
default:
221221
break
@@ -232,11 +232,14 @@ extension SwiftFunctionSignature {
232232
}
233233
}
234234

235-
private static func effectSpecifiers(from decl: AccessorDeclSyntax) -> [SwiftEffectSpecifier] {
235+
private static func effectSpecifiers(from decl: AccessorDeclSyntax) throws -> [SwiftEffectSpecifier] {
236236
var effectSpecifiers = [SwiftEffectSpecifier]()
237237
if decl.effectSpecifiers?.throwsClause != nil {
238238
effectSpecifiers.append(.throws)
239239
}
240+
if let asyncSpecifier = decl.effectSpecifiers?.asyncSpecifier {
241+
throw SwiftFunctionTranslationError.async(asyncSpecifier)
242+
}
240243
return effectSpecifiers
241244
}
242245
}

Tests/JExtractSwiftTests/JNI/JNIVariablesTests.swift

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,25 @@ import Testing
1717

1818
@Suite
1919
struct JNIVariablesTests {
20-
let membersSource = """
20+
let membersSource =
21+
"""
2122
public class MyClass {
22-
public let constant: Int64
23-
public var mutable: Int64
24-
public var computed: Int64 {
25-
return 0
26-
}
27-
public var computedThrowing: Int64 {
28-
get throws { return 0 }
29-
}
30-
public var getterAndSetter: Int64 {
31-
get { return 0 }
32-
set { }
33-
}
23+
public let constant: Int64
24+
public var mutable: Int64
25+
public var computed: Int64 {
26+
return 0
27+
}
28+
public var computedThrowing: Int64 {
29+
get throws { return 0 }
30+
}
31+
public var getterAndSetter: Int64 {
32+
get { return 0 }
33+
set { }
34+
}
3435
public var someBoolean: Bool
3536
public let isBoolean: Bool
3637
}
37-
"""
38+
"""
3839

3940
@Test
4041
func constant_javaBindings() throws {
@@ -341,16 +342,16 @@ struct JNIVariablesTests {
341342
* public var someBoolean: Bool
342343
* }
343344
*/
344-
public void setIsSomeBoolean(boolean newValue) {
345+
public void setSomeBoolean(boolean newValue) {
345346
long selfPointer = this.pointer();
346-
MyClass.$setIsSomeBoolean(newValue, selfPointer);
347+
MyClass.$setSomeBoolean(newValue, selfPointer);
347348
}
348349
""",
349350
"""
350351
private static native boolean $isSomeBoolean(long selfPointer);
351352
""",
352353
"""
353-
private static native void $setIsSomeBoolean(boolean newValue, long selfPointer);
354+
private static native void $setSomeBoolean(boolean newValue, long selfPointer);
354355
"""
355356
]
356357
)
@@ -373,14 +374,13 @@ struct JNIVariablesTests {
373374
}
374375
""",
375376
"""
376-
@_cdecl("Java_com_example_swift_MyClass__00024setIsSomeBoolean__ZJ")
377-
func Java_com_example_swift_MyClass__00024setIsSomeBoolean__ZJ(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, newValue: jboolean, selfPointer: jlong) {
377+
@_cdecl("Java_com_example_swift_MyClass__00024setSomeBoolean__ZJ")
378+
func Java_com_example_swift_MyClass__00024setSomeBoolean__ZJ(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, newValue: jboolean, selfPointer: jlong) {
378379
let self$ = UnsafeMutablePointer<MyClass>(bitPattern: Int(Int64(fromJNI: selfPointer, in: environment!)))!
379380
self$.pointee.someBoolean = Bool(fromJNI: newValue, in: environment!)
380381
}
381382
"""
382383
]
383384
)
384385
}
385-
386386
}

0 commit comments

Comments
 (0)