Skip to content

Commit dd38340

Browse files
authored
Small refactorings and cleanups (#692)
1 parent 9fe337a commit dd38340

7 files changed

Lines changed: 50 additions & 36 deletions

File tree

Sources/JExtractSwiftLib/FFM/FFMSwift2JavaGenerator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ package class FFMSwift2JavaGenerator: Swift2JavaGenerator {
8585

8686
// If we are forced to write empty files, construct the expected outputs.
8787
// It is sufficient to use file names only, since SwiftPM requires names to be unique within a module anyway.
88-
if translator.config.writeEmptyFiles ?? false {
88+
if translator.config.effectiveWriteEmptyFiles {
8989
self.expectedOutputSwiftFileNames = Set(
9090
translator.inputs.compactMap { (input) -> String? in
9191
guard let fileName = input.path.split(separator: PATH_SEPARATOR).last else {

Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+JavaTranslation.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1162,7 +1162,6 @@ extension JNISwift2JavaGenerator {
11621162
genericParameters: [SwiftGenericParameterDeclaration],
11631163
genericRequirements: [SwiftGenericRequirement],
11641164
) throws -> TranslatedResult {
1165-
let arity = elements.count
11661165
var outParameters: [OutParameter] = []
11671166
var elementOutParamNames: [String] = []
11681167
var elementConversions: [JavaNativeConversionStep] = []

Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ package class JNISwift2JavaGenerator: Swift2JavaGenerator {
8888

8989
// If we are forced to write empty files, construct the expected outputs.
9090
// It is sufficient to use file names only, since SwiftPM requires names to be unique within a module anyway.
91-
if translator.config.writeEmptyFiles ?? false {
91+
if translator.config.effectiveWriteEmptyFiles {
9292
self.expectedOutputSwiftFileNames = Set(
9393
translator.inputs.compactMap { (input) -> String? in
9494
guard let fileName = input.path.split(separator: PATH_SEPARATOR).last else {

Sources/SwiftJavaConfigurationShared/Configuration.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ public struct Configuration: Codable {
4949
mode ?? .default
5050
}
5151

52-
public var writeEmptyFiles: Bool? // FIXME: default it to false, but that plays not nice with Codable
52+
public var writeEmptyFiles: Bool?
53+
public var effectiveWriteEmptyFiles: Bool {
54+
writeEmptyFiles ?? false
55+
}
5356

5457
public var minimumInputAccessLevelMode: JExtractMinimumAccessLevelMode?
5558
public var effectiveMinimumInputAccessLevelMode: JExtractMinimumAccessLevelMode {

Tests/JExtractSwiftTests/FFMNestedTypesTests.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,14 @@ final class FFMNestedTypesTests {
3737

3838
try st.analyze(path: "Fake.swift", text: class_interfaceFile)
3939

40-
let generator = FFMSwift2JavaGenerator(
40+
let _ = FFMSwift2JavaGenerator(
4141
config: config,
4242
translator: st,
4343
javaPackage: "com.example.swift",
4444
swiftOutputDirectory: "/fake",
4545
javaOutputDirectory: "/fake"
4646
)
4747

48-
guard let ty = st.importedTypes["MyNamespace.MyNestedStruct"] else {
49-
fatalError("Didn't import nested type!")
50-
}
51-
48+
#expect(st.importedTypes["MyNamespace.MyNestedStruct"] != nil, "Didn't import nested type!")
5249
}
53-
5450
}

Tests/JExtractSwiftTests/MethodImportTests.swift

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ final class MethodImportTests {
8383
javaOutputDirectory: "/fake"
8484
)
8585

86-
let funcDecl = st.importedGlobalFuncs.first { $0.name == "helloWorld" }!
86+
let funcDecl = try #require(st.importedGlobalFuncs.first { $0.name == "helloWorld" })
8787

8888
let output = CodePrinter.toString { printer in
8989
generator.printJavaBindingWrapperMethod(&printer, funcDecl)
@@ -117,9 +117,11 @@ final class MethodImportTests {
117117

118118
try st.analyze(path: "Fake.swift", text: class_interfaceFile)
119119

120-
let funcDecl = st.importedGlobalFuncs.first {
121-
$0.name == "globalTakeInt"
122-
}!
120+
let funcDecl = try #require(
121+
st.importedGlobalFuncs.first {
122+
$0.name == "globalTakeInt"
123+
}
124+
)
123125

124126
let generator = FFMSwift2JavaGenerator(
125127
config: config,
@@ -164,9 +166,11 @@ final class MethodImportTests {
164166

165167
try st.analyze(path: "Fake.swift", text: class_interfaceFile)
166168

167-
let funcDecl = st.importedGlobalFuncs.first {
168-
$0.name == "globalTakeIntLongString"
169-
}!
169+
let funcDecl = try #require(
170+
st.importedGlobalFuncs.first {
171+
$0.name == "globalTakeIntLongString"
172+
}
173+
)
170174

171175
let generator = FFMSwift2JavaGenerator(
172176
config: config,
@@ -208,9 +212,11 @@ final class MethodImportTests {
208212

209213
try st.analyze(path: "Fake.swift", text: class_interfaceFile)
210214

211-
let funcDecl = st.importedGlobalFuncs.first {
212-
$0.name == "globalReturnClass"
213-
}!
215+
let funcDecl = try #require(
216+
st.importedGlobalFuncs.first {
217+
$0.name == "globalReturnClass"
218+
}
219+
)
214220

215221
let generator = FFMSwift2JavaGenerator(
216222
config: config,
@@ -252,9 +258,11 @@ final class MethodImportTests {
252258

253259
try st.analyze(path: "Fake.swift", text: class_interfaceFile)
254260

255-
let funcDecl = st.importedGlobalFuncs.first {
256-
$0.name == "swapRawBufferPointer"
257-
}!
261+
let funcDecl = try #require(
262+
st.importedGlobalFuncs.first {
263+
$0.name == "swapRawBufferPointer"
264+
}
265+
)
258266

259267
let generator = FFMSwift2JavaGenerator(
260268
config: config,
@@ -299,9 +307,11 @@ final class MethodImportTests {
299307

300308
try st.analyze(path: "Fake.swift", text: class_interfaceFile)
301309

302-
let funcDecl: ImportedFunc = st.importedTypes["MySwiftClass"]!.methods.first {
303-
$0.name == "helloMemberFunction"
304-
}!
310+
let funcDecl: ImportedFunc = try #require(
311+
st.importedTypes["MySwiftClass"]!.methods.first {
312+
$0.name == "helloMemberFunction"
313+
}
314+
)
305315

306316
let generator = FFMSwift2JavaGenerator(
307317
config: config,
@@ -342,9 +352,11 @@ final class MethodImportTests {
342352

343353
try st.analyze(path: "Fake.swift", text: class_interfaceFile)
344354

345-
let funcDecl: ImportedFunc = st.importedTypes["MySwiftClass"]!.methods.first {
346-
$0.name == "makeInt"
347-
}!
355+
let funcDecl: ImportedFunc = try #require(
356+
st.importedTypes["MySwiftClass"]!.methods.first {
357+
$0.name == "makeInt"
358+
}
359+
)
348360

349361
let generator = FFMSwift2JavaGenerator(
350362
config: config,
@@ -391,9 +403,11 @@ final class MethodImportTests {
391403

392404
try st.analyze(path: "Fake.swift", text: class_interfaceFile)
393405

394-
let initDecl: ImportedFunc = st.importedTypes["MySwiftClass"]!.initializers.first {
395-
$0.name == "init"
396-
}!
406+
let initDecl: ImportedFunc = try #require(
407+
st.importedTypes["MySwiftClass"]!.initializers.first {
408+
$0.name == "init"
409+
}
410+
)
397411

398412
let generator = FFMSwift2JavaGenerator(
399413
config: config,
@@ -444,9 +458,11 @@ final class MethodImportTests {
444458

445459
try st.analyze(path: "Fake.swift", text: class_interfaceFile)
446460

447-
let initDecl: ImportedFunc = st.importedTypes["MySwiftStruct"]!.initializers.first {
448-
$0.name == "init"
449-
}!
461+
let initDecl: ImportedFunc = try #require(
462+
st.importedTypes["MySwiftStruct"]!.initializers.first {
463+
$0.name == "init"
464+
}
465+
)
450466

451467
let generator = FFMSwift2JavaGenerator(
452468
config: config,

Tests/SwiftJavaConfigurationSharedTests/SwiftJavaConfigurationTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct SwiftJavaConfigurationTests {
2020

2121
@Test
2222
func parseJSONWithComments() throws {
23-
let config = try readConfiguration(
23+
let _ = try readConfiguration(
2424
string:
2525
"""
2626
// some comments

0 commit comments

Comments
 (0)