Skip to content

Commit 87a0e4f

Browse files
committed
PR feedback
1 parent 3fdb127 commit 87a0e4f

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

Samples/SwiftKitSampleApp/Sources/MySwiftLibrary/MySwiftClass.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
public class MySwiftClass {
1616

17+
public let byte: UInt8 = 0
1718
public var len: Int
1819
public var cap: Int
1920

Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+JavaBindingsPrinting.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ extension JNISwift2JavaGenerator {
176176
}
177177

178178
private func printFunctionBinding(_ printer: inout CodePrinter, _ decl: ImportedFunc) {
179-
guard let translatedDecl = translatedDecl(for: decl) else {
179+
guard let _ = translatedDecl(for: decl) else {
180180
// Failed to translate. Skip.
181181
return
182182
}
@@ -201,7 +201,7 @@ extension JNISwift2JavaGenerator {
201201
/// and passes it down to another native function along with the arguments
202202
/// to call the Swift implementation.
203203
private func printMemberMethodBindings(_ printer: inout CodePrinter, _ decl: ImportedFunc) {
204-
let translatedDecl = translatedDecl(for: decl)!
204+
let translatedDecl = translatedDecl(for: decl)! // We will only call this method if we can translate the decl.
205205

206206
printDeclDocumentation(&printer, decl)
207207
printer.printBraceBlock("public \(renderFunctionSignature(decl))") { printer in
@@ -283,7 +283,9 @@ extension JNISwift2JavaGenerator {
283283
/// `func method(x: Int, y: Int) -> Int` becomes
284284
/// `long method(long x, long y)`
285285
private func renderFunctionSignature(_ decl: ImportedFunc) -> String {
286-
let translatedDecl = translatedDecl(for: decl)!
286+
guard let translatedDecl = translatedDecl(for: decl) else {
287+
fatalError("Unable to render function signature for a function that cannot be translated: \(decl)")
288+
}
287289
let resultType = translatedDecl.translatedFunctionSignature.resultType
288290
var parameters = translatedDecl.translatedFunctionSignature.parameters.map(\.asParameter)
289291

Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+JavaTranslation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ extension JNISwift2JavaGenerator {
2727
let translation = JavaTranslation(swiftModuleName: swiftModuleName)
2828
translated = try translation.translate(decl)
2929
} catch {
30-
self.logger.info("Failed to translate: '\(decl.swiftDecl.qualifiedNameForDebug)'; \(error)")
30+
self.logger.debug("Failed to translate: '\(decl.swiftDecl.qualifiedNameForDebug)'; \(error)")
3131
translated = nil
3232
}
3333

Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+SwiftThunkPrinting.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ extension JNISwift2JavaGenerator {
164164
}
165165

166166
private func printSwiftStaticFunctionThunk(_ printer: inout CodePrinter, _ decl: ImportedFunc) {
167-
let translatedDecl = self.translatedDecl(for: decl)!
167+
let translatedDecl = self.translatedDecl(for: decl)! // We will only call this method if we can translate the decl.
168168

169169
printCDecl(
170170
&printer,
@@ -181,7 +181,7 @@ extension JNISwift2JavaGenerator {
181181
}
182182

183183
private func printSwiftMemberFunctionThunk(_ printer: inout CodePrinter, _ decl: ImportedFunc) {
184-
let translatedDecl = self.translatedDecl(for: decl)!
184+
let translatedDecl = self.translatedDecl(for: decl)! // We will only call this method if can translate the decl.
185185
let swiftParentName = decl.parentType!.asNominalTypeDeclaration!.qualifiedName
186186

187187
printCDecl(
@@ -208,7 +208,9 @@ extension JNISwift2JavaGenerator {
208208
_ decl: ImportedFunc,
209209
calleeName: String
210210
) {
211-
let translatedDecl = self.translatedDecl(for: decl)!
211+
guard let translatedDecl = self.translatedDecl(for: decl) else {
212+
fatalError("Cannot print function downcall for a function that can't be translated: \(decl)")
213+
}
212214
let swiftReturnType = decl.functionSignature.result.type
213215

214216
let tryClause: String = decl.isThrowing ? "try " : ""

0 commit comments

Comments
 (0)