Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ package class FFMSwift2JavaGenerator: Swift2JavaGenerator {

// If we are forced to write empty files, construct the expected outputs.
// It is sufficient to use file names only, since SwiftPM requires names to be unique within a module anyway.
if translator.config.writeEmptyFiles ?? false {
if translator.config.effectiveWriteEmptyFiles {
self.expectedOutputSwiftFileNames = Set(
translator.inputs.compactMap { (input) -> String? in
guard let fileName = input.path.split(separator: PATH_SEPARATOR).last else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,6 @@ extension JNISwift2JavaGenerator {
genericParameters: [SwiftGenericParameterDeclaration],
genericRequirements: [SwiftGenericRequirement],
) throws -> TranslatedResult {
let arity = elements.count
var outParameters: [OutParameter] = []
var elementOutParamNames: [String] = []
var elementConversions: [JavaNativeConversionStep] = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ package class JNISwift2JavaGenerator: Swift2JavaGenerator {

// If we are forced to write empty files, construct the expected outputs.
// It is sufficient to use file names only, since SwiftPM requires names to be unique within a module anyway.
if translator.config.writeEmptyFiles ?? false {
if translator.config.effectiveWriteEmptyFiles {
self.expectedOutputSwiftFileNames = Set(
translator.inputs.compactMap { (input) -> String? in
guard let fileName = input.path.split(separator: PATH_SEPARATOR).last else {
Expand Down
5 changes: 4 additions & 1 deletion Sources/SwiftJavaConfigurationShared/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ public struct Configuration: Codable {
mode ?? .default
}

public var writeEmptyFiles: Bool? // FIXME: default it to false, but that plays not nice with Codable
public var writeEmptyFiles: Bool?
public var effectiveWriteEmptyFiles: Bool {
writeEmptyFiles ?? false
}

public var minimumInputAccessLevelMode: JExtractMinimumAccessLevelMode?
public var effectiveMinimumInputAccessLevelMode: JExtractMinimumAccessLevelMode {
Expand Down
8 changes: 2 additions & 6 deletions Tests/JExtractSwiftTests/FFMNestedTypesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,14 @@ final class FFMNestedTypesTests {

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

let generator = FFMSwift2JavaGenerator(
let _ = FFMSwift2JavaGenerator(
config: config,
translator: st,
javaPackage: "com.example.swift",
swiftOutputDirectory: "/fake",
javaOutputDirectory: "/fake"
)

guard let ty = st.importedTypes["MyNamespace.MyNestedStruct"] else {
fatalError("Didn't import nested type!")
}

#expect(st.importedTypes["MyNamespace.MyNestedStruct"] != nil, "Didn't import nested type!")
}

}
66 changes: 41 additions & 25 deletions Tests/JExtractSwiftTests/MethodImportTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ final class MethodImportTests {
javaOutputDirectory: "/fake"
)

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

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

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

let funcDecl = st.importedGlobalFuncs.first {
$0.name == "globalTakeInt"
}!
let funcDecl = try #require(
st.importedGlobalFuncs.first {
$0.name == "globalTakeInt"
}
)

let generator = FFMSwift2JavaGenerator(
config: config,
Expand Down Expand Up @@ -164,9 +166,11 @@ final class MethodImportTests {

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

let funcDecl = st.importedGlobalFuncs.first {
$0.name == "globalTakeIntLongString"
}!
let funcDecl = try #require(
st.importedGlobalFuncs.first {
$0.name == "globalTakeIntLongString"
}
)

let generator = FFMSwift2JavaGenerator(
config: config,
Expand Down Expand Up @@ -208,9 +212,11 @@ final class MethodImportTests {

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

let funcDecl = st.importedGlobalFuncs.first {
$0.name == "globalReturnClass"
}!
let funcDecl = try #require(
st.importedGlobalFuncs.first {
$0.name == "globalReturnClass"
}
)

let generator = FFMSwift2JavaGenerator(
config: config,
Expand Down Expand Up @@ -252,9 +258,11 @@ final class MethodImportTests {

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

let funcDecl = st.importedGlobalFuncs.first {
$0.name == "swapRawBufferPointer"
}!
let funcDecl = try #require(
st.importedGlobalFuncs.first {
$0.name == "swapRawBufferPointer"
}
)

let generator = FFMSwift2JavaGenerator(
config: config,
Expand Down Expand Up @@ -299,9 +307,11 @@ final class MethodImportTests {

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

let funcDecl: ImportedFunc = st.importedTypes["MySwiftClass"]!.methods.first {
$0.name == "helloMemberFunction"
}!
let funcDecl: ImportedFunc = try #require(
st.importedTypes["MySwiftClass"]!.methods.first {
$0.name == "helloMemberFunction"
}
)

let generator = FFMSwift2JavaGenerator(
config: config,
Expand Down Expand Up @@ -342,9 +352,11 @@ final class MethodImportTests {

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

let funcDecl: ImportedFunc = st.importedTypes["MySwiftClass"]!.methods.first {
$0.name == "makeInt"
}!
let funcDecl: ImportedFunc = try #require(
st.importedTypes["MySwiftClass"]!.methods.first {
$0.name == "makeInt"
}
)

let generator = FFMSwift2JavaGenerator(
config: config,
Expand Down Expand Up @@ -391,9 +403,11 @@ final class MethodImportTests {

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

let initDecl: ImportedFunc = st.importedTypes["MySwiftClass"]!.initializers.first {
$0.name == "init"
}!
let initDecl: ImportedFunc = try #require(
st.importedTypes["MySwiftClass"]!.initializers.first {
$0.name == "init"
}
)

let generator = FFMSwift2JavaGenerator(
config: config,
Expand Down Expand Up @@ -444,9 +458,11 @@ final class MethodImportTests {

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

let initDecl: ImportedFunc = st.importedTypes["MySwiftStruct"]!.initializers.first {
$0.name == "init"
}!
let initDecl: ImportedFunc = try #require(
st.importedTypes["MySwiftStruct"]!.initializers.first {
$0.name == "init"
}
)

let generator = FFMSwift2JavaGenerator(
config: config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct SwiftJavaConfigurationTests {

@Test
func parseJSONWithComments() throws {
let config = try readConfiguration(
let _ = try readConfiguration(
string:
"""
// some comments
Expand Down
Loading