From d8e371824bc62319c359f3b1b1ed2932e19d9ca8 Mon Sep 17 00:00:00 2001 From: Mads Odgaard Date: Fri, 27 Mar 2026 22:04:55 +0100 Subject: [PATCH 1/6] dynamic list --- .../JExtractSwiftPlugin.swift | 10 ++++++ ...ift2JavaGenerator+SwiftThunkPrinting.swift | 35 +++++++++++++++++++ .../JNI/JNISwift2JavaGenerator.swift | 6 ++++ .../Configuration.swift | 8 +++++ .../Commands/JExtractCommand.swift | 11 ++++++ 5 files changed, 70 insertions(+) diff --git a/Plugins/JExtractSwiftPlugin/JExtractSwiftPlugin.swift b/Plugins/JExtractSwiftPlugin/JExtractSwiftPlugin.swift index 1ca1f505..b9ff53df 100644 --- a/Plugins/JExtractSwiftPlugin/JExtractSwiftPlugin.swift +++ b/Plugins/JExtractSwiftPlugin/JExtractSwiftPlugin.swift @@ -117,6 +117,16 @@ struct JExtractSwiftBuildToolPlugin: SwiftJavaPluginProtocol, BuildToolPlugin { let jextractOutputFiles = outputSwiftFiles + // In JNI mode, emit a linker export list so the linker can DCE unused Swift code. + // NOTE: intentionally NOT added to jextractOutputFiles — SPM would otherwise treat + // the .ld file as a resource and force-link Foundation as a side effect. + if configuration?.effectiveMode == .jni { + let linkerExportListFile = outputSwiftDirectory.appending(path: "swift-java-jni-exports.ld") + arguments += [ + "--linker-export-list-output", linkerExportListFile.path(percentEncoded: false), + ] + } + // If the developer has enabled java callbacks in the configuration (default is false) // and we are running in JNI mode, we will run additional phases in this build plugin // to generate Swift wrappers using wrap-java that can be used to callback to Java. diff --git a/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+SwiftThunkPrinting.swift b/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+SwiftThunkPrinting.swift index e8531787..9b48537d 100644 --- a/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+SwiftThunkPrinting.swift +++ b/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+SwiftThunkPrinting.swift @@ -119,6 +119,39 @@ extension JNISwift2JavaGenerator { } } + /// Writes a linker export list in lld ``--dynamic-list`` format to the path + /// specified by ``Configuration/linkerExportListOutput``, listing every JNI + /// ``@_cdecl`` symbol generated during this run. + /// + /// Pass the resulting file to the linker with: + /// ``` + /// -Xlinker --dynamic-list= -Xlinker --gc-sections + /// ``` + /// This lets lld treat only the JNI entry points as roots during link-time + /// dead-code elimination, removing unreachable Swift code from SPM + /// dependencies and the Swift standard library. + func writeLinkerExportList() throws { + guard let outputPath = config.linkerExportListOutput else { + return + } + guard !generatedCDeclSymbolNames.isEmpty else { + return + } + + let symbolLines = generatedCDeclSymbolNames + .sorted() + .map { " \($0);" } + .joined(separator: "\n") + let contents = "{\n\(symbolLines)\n};\n" + + try contents.write( + toFile: outputPath, + atomically: true, + encoding: .utf8 + ) + logger.info("[swift-java] Generated linker export list (\(generatedCDeclSymbolNames.count) symbols): \(outputPath)") + } + private func printJNICache(_ printer: inout CodePrinter, _ type: ImportedNominalType) { printer.printBraceBlock("enum \(JNICaching.cacheName(for: type))") { printer in for enumCase in type.cases { @@ -722,6 +755,8 @@ extension JNISwift2JavaGenerator { + "__" + jniSignature.escapedJNIIdentifier + self.generatedCDeclSymbolNames.append(cName) + let translatedParameters = parameters.map { "\($0.name): \($0.type.jniTypeName)" } diff --git a/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator.swift b/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator.swift index a6917227..8d6b538d 100644 --- a/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator.swift +++ b/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator.swift @@ -39,6 +39,11 @@ package class JNISwift2JavaGenerator: Swift2JavaGenerator { var thunkNameRegistry = ThunkNameRegistry() + /// Accumulates every ``@_cdecl`` symbol name emitted during thunk printing. + /// Written to a linker export list after generation when + /// ``Configuration/linkerExportListOutput`` is set. + var generatedCDeclSymbolNames: [String] = [] + /// Cached Java translation result. 'nil' indicates failed translation. var translatedDecls: [ImportedFunc: TranslatedFunctionDecl] = [:] var translatedEnumCases: [ImportedEnumCase: TranslatedEnumCase] = [:] @@ -103,6 +108,7 @@ package class JNISwift2JavaGenerator: Swift2JavaGenerator { func generate() throws { try writeSwiftThunkSources() try writeExportedJavaSources() + try writeLinkerExportList() let pendingFileCount = self.expectedOutputSwiftFileNames.count if pendingFileCount > 0 { diff --git a/Sources/SwiftJavaConfigurationShared/Configuration.swift b/Sources/SwiftJavaConfigurationShared/Configuration.swift index ae2e53cf..4c6ea233 100644 --- a/Sources/SwiftJavaConfigurationShared/Configuration.swift +++ b/Sources/SwiftJavaConfigurationShared/Configuration.swift @@ -67,6 +67,14 @@ public struct Configuration: Codable { public var generatedJavaSourcesListFileOutput: String? + /// If set, JExtract (JNI mode) will write a linker export list in lld + /// ``--dynamic-list`` format to this path, containing all generated JNI + /// ``@_cdecl`` entry-point symbols. Pass this file to the linker via + /// ``-Xlinker --dynamic-list=`` together with + /// ``-Xlinker --gc-sections`` to enable precise dead-code elimination of + /// unused Swift code in the final shared library. + public var linkerExportListOutput: String? + // ==== wrap-java --------------------------------------------------------- /// The Java class path that should be passed along to the swift-java tool. diff --git a/Sources/SwiftJavaTool/Commands/JExtractCommand.swift b/Sources/SwiftJavaTool/Commands/JExtractCommand.swift index 1afd2cc2..7ea3a31e 100644 --- a/Sources/SwiftJavaTool/Commands/JExtractCommand.swift +++ b/Sources/SwiftJavaTool/Commands/JExtractCommand.swift @@ -98,6 +98,16 @@ extension SwiftJava { @Option(help: "If specified, JExtract will output to this file a list of paths to all generated Java source files") var generatedJavaSourcesListFileOutput: String? + + @Option( + help: """ + If specified, JExtract (JNI mode) will write a linker export list in lld --dynamic-list + format to this path. The file contains every generated JNI @_cdecl entry-point symbol + and can be passed to the linker to enable dead-code elimination of unreachable Swift code: + -Xlinker --dynamic-list= -Xlinker --gc-sections + """ + ) + var linkerExportListOutput: String? } } @@ -116,6 +126,7 @@ extension SwiftJava.JExtractCommand { configure(&config.memoryManagementMode, overrideWith: self.memoryManagementMode) configure(&config.asyncFuncMode, overrideWith: self.asyncFuncMode) configure(&config.generatedJavaSourcesListFileOutput, overrideWith: self.generatedJavaSourcesListFileOutput) + configure(&config.linkerExportListOutput, overrideWith: self.linkerExportListOutput) try checkModeCompatibility(config: config) From 19e65c696655b1b6444a03c0d159eb5cc0512dbb Mon Sep 17 00:00:00 2001 From: Mads Odgaard Date: Sat, 28 Mar 2026 13:36:33 +0100 Subject: [PATCH 2/6] updates --- .../JExtractSwiftPlugin.swift | 7 +- ...ift2JavaGenerator+SwiftThunkPrinting.swift | 17 ++-- .../JNI/JNISwift2JavaGenerator.swift | 2 +- Sources/SwiftJava/JNI.swift | 3 + .../Configuration.swift | 12 +-- .../Documentation.docc/Android.md | 78 ++++++++++++++++++- .../SwiftJavaMacros/ImplementsJavaMacro.swift | 5 +- .../Commands/JExtractCommand.swift | 9 ++- .../JExtractSwiftTests/DataImportTests.swift | 8 +- Tests/JExtractSwiftTests/DateTests.swift | 12 +++ .../JExtractSwiftTests/JNI/JNIArrayTest.swift | 20 ++++- .../JNI/JNIAsyncTests.swift | 42 +++++++--- .../JNI/JNIClassTests.swift | 28 +++++-- .../JNI/JNIClosureTests.swift | 10 ++- .../JNI/JNIDictionaryTest.swift | 30 +++++-- .../JExtractSwiftTests/JNI/JNIEnumTests.swift | 19 ++++- .../JNI/JNIGenericTypeTests.swift | 25 ++++-- .../JNI/JNIIntConversionChecksTests.swift | 24 ++++++ .../JNI/JNIJavaKitTests.swift | 5 +- .../JNI/JNIModuleTests.swift | 27 ++++++- .../JNI/JNINestedTypesTests.swift | 14 +++- .../JNI/JNIOptionalTests.swift | 20 ++++- .../JNI/JNIProtocolTests.swift | 13 +++- Tests/JExtractSwiftTests/JNI/JNISetTest.swift | 25 ++++-- .../JNI/JNIStructTests.swift | 10 ++- .../JNI/JNISubscriptsTests.swift | 12 +++ .../JNI/JNIVariablesTests.swift | 47 +++++++++-- Tests/JExtractSwiftTests/UUIDTests.swift | 6 ++ .../JavaImplementationMacroTests.swift | 40 ++++++++-- 29 files changed, 478 insertions(+), 92 deletions(-) diff --git a/Plugins/JExtractSwiftPlugin/JExtractSwiftPlugin.swift b/Plugins/JExtractSwiftPlugin/JExtractSwiftPlugin.swift index b9ff53df..9c2f48a5 100644 --- a/Plugins/JExtractSwiftPlugin/JExtractSwiftPlugin.swift +++ b/Plugins/JExtractSwiftPlugin/JExtractSwiftPlugin.swift @@ -117,11 +117,12 @@ struct JExtractSwiftBuildToolPlugin: SwiftJavaPluginProtocol, BuildToolPlugin { let jextractOutputFiles = outputSwiftFiles - // In JNI mode, emit a linker export list so the linker can DCE unused Swift code. + // In JNI mode, emit a linker version script so the linker can DCE unused Swift code. + // Placed in the plugin work directory root // NOTE: intentionally NOT added to jextractOutputFiles — SPM would otherwise treat - // the .ld file as a resource and force-link Foundation as a side effect. + // the .map file as a resource and force-link Foundation as a side effect. if configuration?.effectiveMode == .jni { - let linkerExportListFile = outputSwiftDirectory.appending(path: "swift-java-jni-exports.ld") + let linkerExportListFile = context.pluginWorkDirectoryURL.appending(path: "swift-java-jni-exports.map") arguments += [ "--linker-export-list-output", linkerExportListFile.path(percentEncoded: false), ] diff --git a/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+SwiftThunkPrinting.swift b/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+SwiftThunkPrinting.swift index 9b48537d..75fc8c1c 100644 --- a/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+SwiftThunkPrinting.swift +++ b/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+SwiftThunkPrinting.swift @@ -119,16 +119,18 @@ extension JNISwift2JavaGenerator { } } - /// Writes a linker export list in lld ``--dynamic-list`` format to the path - /// specified by ``Configuration/linkerExportListOutput``, listing every JNI - /// ``@_cdecl`` symbol generated during this run. + /// Writes a linker version script to the path specified by + /// ``Configuration/linkerExportListOutput``, listing every JNI ``@_cdecl`` + /// symbol generated during this run as global exports and hiding everything + /// else with `local: *`. /// /// Pass the resulting file to the linker with: /// ``` - /// -Xlinker --dynamic-list= -Xlinker --gc-sections + /// -Xlinker --version-script= /// ``` /// This lets lld treat only the JNI entry points as roots during link-time - /// dead-code elimination, removing unreachable Swift code from SPM + /// dead-code elimination and hides all internal Swift symbols from the + /// dynamic symbol table, removing unreachable Swift code from SPM /// dependencies and the Swift standard library. func writeLinkerExportList() throws { guard let outputPath = config.linkerExportListOutput else { @@ -142,7 +144,7 @@ extension JNISwift2JavaGenerator { .sorted() .map { " \($0);" } .joined(separator: "\n") - let contents = "{\n\(symbolLines)\n};\n" + let contents = "{\nglobal:\n\(symbolLines)\nlocal: *;\n};\n" try contents.write( toFile: outputPath, @@ -771,6 +773,9 @@ extension JNISwift2JavaGenerator { // TODO: Think about function overloads printer.printBraceBlock( """ + #if compiler(>=6.3) + @used + #endif @_cdecl("\(cName)") public func \(cName)(\(thunkParameters.joined(separator: ", ")))\(thunkReturnType) """ diff --git a/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator.swift b/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator.swift index 8d6b538d..27ca90e0 100644 --- a/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator.swift +++ b/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator.swift @@ -40,7 +40,7 @@ package class JNISwift2JavaGenerator: Swift2JavaGenerator { var thunkNameRegistry = ThunkNameRegistry() /// Accumulates every ``@_cdecl`` symbol name emitted during thunk printing. - /// Written to a linker export list after generation when + /// Written to a linker version script after generation when /// ``Configuration/linkerExportListOutput`` is set. var generatedCDeclSymbolNames: [String] = [] diff --git a/Sources/SwiftJava/JNI.swift b/Sources/SwiftJava/JNI.swift index 4614906e..c7eeaad3 100644 --- a/Sources/SwiftJava/JNI.swift +++ b/Sources/SwiftJava/JNI.swift @@ -51,6 +51,9 @@ package final class JNI { } } +#if compiler(>=6.3) +@used +#endif @_cdecl("JNI_OnLoad") public func SwiftJava_JNI_OnLoad(javaVM: JavaVMPointer, reserved: UnsafeMutableRawPointer) -> jint { JNI.shared = JNI(fromVM: JavaVirtualMachine(adoptingJVM: javaVM)) diff --git a/Sources/SwiftJavaConfigurationShared/Configuration.swift b/Sources/SwiftJavaConfigurationShared/Configuration.swift index 4c6ea233..e3ab0aea 100644 --- a/Sources/SwiftJavaConfigurationShared/Configuration.swift +++ b/Sources/SwiftJavaConfigurationShared/Configuration.swift @@ -67,12 +67,12 @@ public struct Configuration: Codable { public var generatedJavaSourcesListFileOutput: String? - /// If set, JExtract (JNI mode) will write a linker export list in lld - /// ``--dynamic-list`` format to this path, containing all generated JNI - /// ``@_cdecl`` entry-point symbols. Pass this file to the linker via - /// ``-Xlinker --dynamic-list=`` together with - /// ``-Xlinker --gc-sections`` to enable precise dead-code elimination of - /// unused Swift code in the final shared library. + /// If set, JExtract (JNI mode) will write a linker version script to this + /// path, listing all generated JNI ``@_cdecl`` entry-point symbols as + /// global exports and hiding everything else with `local: *`. Pass this + /// file to the linker via ``-Xlinker --version-script=`` to enable + /// precise dead-code elimination of unused Swift code in the final shared + /// library. public var linkerExportListOutput: String? // ==== wrap-java --------------------------------------------------------- diff --git a/Sources/SwiftJavaDocumentation/Documentation.docc/Android.md b/Sources/SwiftJavaDocumentation/Documentation.docc/Android.md index 68902e87..67d16de8 100644 --- a/Sources/SwiftJavaDocumentation/Documentation.docc/Android.md +++ b/Sources/SwiftJavaDocumentation/Documentation.docc/Android.md @@ -41,4 +41,80 @@ open class OldVersionedClass: JavaObject { Annotations are generated both for "since", "deprecated" and "removed" attributes. -> Note: To use Android platform availability you must use at least Swift 6.3, which introduced the `Android` platform. \ No newline at end of file +> Note: To use Android platform availability you must use at least Swift 6.3, which introduced the `Android` platform. + +## Reducing Binary Size + +When using the `jextract` tool to wrap your Swift APIs as a Java library targeting Android, several compiler and linker options can substantially reduce the final binary size by stripping dead code that would otherwise be retained. + +### Requirements + +Full binary-size optimization requires **Swift 6.3 or later**. Swift 6.3 introduced the `@used` attribute, which `JExtractSwiftPlugin` attaches to every generated JNI entry point so the compiler cannot eliminate them before the linker has a chance to see them. + +### Generated Version Script + +When using the `jextract` tool in JNI mode, `JExtractSwiftPlugin` automatically generates a linker version script alongside the Swift thunks. The version script lists every JNI entry point as a `global:` export and hides everything else with `local: *`, giving the linker precise control over which symbols must be kept and allowing it to discard all internal Swift symbols. + +The file is written to the plugin's work directory: + +``` +.build/plugins/outputs///JExtractSwiftPlugin/swift-java-jni-exports.map +``` + +### Optimization Flags + +The following flags, used together, produce the smallest possible binary: + +| Flag | Effect | +|---|---| +| `-Xswiftc -Osize` | Optimize for binary size rather than speed | +| `-Xlinker --version-script=` | Restrict exported symbols to JNI entry points; hides internal Swift symbols from the dynamic symbol table | +| `--experimental-lto-mode=full` | Full link-time optimization across all modules | +| `-Xfrontend -internalize-at-link` | Internalize Swift symbols at link time, enabling the linker to eliminate more dead code | + +### Package.swift + +Add the flags that don't depend on a dynamic path directly to your `Package.swift`, conditioned on release builds for Android: + +```swift +import PackageDescription + +let package = Package( + name: "MyLibrary", + products: [ + .library(name: "MySwiftLibrary", type: .dynamic, targets: ["MySwiftLibrary"]) + ], + dependencies: [ + .package(url: "https://github.com/swiftlang/swift-java", from: "0.1.0"), + ], + targets: [ + .target( + name: "MySwiftLibrary", + dependencies: [ + .product(name: "SwiftJava", package: "swift-java") + ], + swiftSettings: [ + .unsafeFlags( + ["-Osize", "-Xfrontend", "-internalize-at-link"], + .when(platforms: [.android], configuration: .release) + ), + ], + plugins: [ + .plugin(name: "JExtractSwiftPlugin", package: "swift-java") + ] + ) + ] +) +``` + +Then pass the remaining flags on the command line when invoking the build: + +```bash +swift build \ + --swift-sdk aarch64-unknown-linux-android28 \ + -c release \ + --experimental-lto-mode=full \ + -Xlinker --version-script=.build/plugins/outputs/MyLibrary/MySwiftLibrary/JExtractSwiftPlugin/swift-java-jni-exports.map +``` + +> Tip: Adjust the `--version-script` path to match your package name and target name. Run `find .build/plugins/outputs -name swift-java-jni-exports.map` after the first build if you are unsure of the exact path. diff --git a/Sources/SwiftJavaMacros/ImplementsJavaMacro.swift b/Sources/SwiftJavaMacros/ImplementsJavaMacro.swift index 02a784be..2770a490 100644 --- a/Sources/SwiftJavaMacros/ImplementsJavaMacro.swift +++ b/Sources/SwiftJavaMacros/ImplementsJavaMacro.swift @@ -209,8 +209,11 @@ extension JavaImplementationMacro: PeerMacro { exposedMembers.append( """ + #if compiler(>=6.3) + @used + #endif @_cdecl(\(literal: cName)) - func \(context.makeUniqueName(swiftName))(\(raw: cParameters.map{ $0.description }.joined(separator: ", ")))\(raw: cReturnType) { + public func \(context.makeUniqueName(swiftName))(\(raw: cParameters.map{ $0.description }.joined(separator: ", ")))\(raw: cReturnType) { \(body) } """ diff --git a/Sources/SwiftJavaTool/Commands/JExtractCommand.swift b/Sources/SwiftJavaTool/Commands/JExtractCommand.swift index 7ea3a31e..f03af349 100644 --- a/Sources/SwiftJavaTool/Commands/JExtractCommand.swift +++ b/Sources/SwiftJavaTool/Commands/JExtractCommand.swift @@ -101,10 +101,11 @@ extension SwiftJava { @Option( help: """ - If specified, JExtract (JNI mode) will write a linker export list in lld --dynamic-list - format to this path. The file contains every generated JNI @_cdecl entry-point symbol - and can be passed to the linker to enable dead-code elimination of unreachable Swift code: - -Xlinker --dynamic-list= -Xlinker --gc-sections + If specified, JExtract (JNI mode) will write a linker version script to this path. \ + The file lists every generated JNI @_cdecl entry-point symbol as a global export \ + and hides all other symbols with local: *, enabling dead-code elimination of \ + unreachable Swift code: + -Xlinker --version-script= """ ) var linkerExportListOutput: String? diff --git a/Tests/JExtractSwiftTests/DataImportTests.swift b/Tests/JExtractSwiftTests/DataImportTests.swift index 08652aca..5b106ed4 100644 --- a/Tests/JExtractSwiftTests/DataImportTests.swift +++ b/Tests/JExtractSwiftTests/DataImportTests.swift @@ -510,9 +510,12 @@ final class DataImportTests { input: text, .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024acceptData__J") public func Java_com_example_swift_SwiftModule__00024acceptData__J(environment: UnsafeMutablePointer!, thisClass: jclass, data: jlong) { """ @@ -544,6 +547,9 @@ final class DataImportTests { .swift, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024returnData__") public func Java_com_example_swift_SwiftModule__00024returnData__(environment: UnsafeMutablePointer!, thisClass: jclass) -> jlong { """ diff --git a/Tests/JExtractSwiftTests/DateTests.swift b/Tests/JExtractSwiftTests/DateTests.swift index bf5e9ef8..85f2e9b8 100644 --- a/Tests/JExtractSwiftTests/DateTests.swift +++ b/Tests/JExtractSwiftTests/DateTests.swift @@ -33,6 +33,9 @@ struct DateTests { /* expected Swift chunks */ [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024acceptDate__J") public func Java_com_example_swift_SwiftModule__00024acceptDate__J(environment: UnsafeMutablePointer!, thisClass: jclass, date: jlong) { """ @@ -83,6 +86,9 @@ struct DateTests { /* expected Swift chunks */ [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024returnDate__") public func Java_com_example_swift_SwiftModule__00024returnDate__(environment: UnsafeMutablePointer!, thisClass: jclass) -> jlong { """ @@ -142,10 +148,16 @@ struct DateTests { /* expected Swift chunks */ [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_Date__00024init__D") public func Java_com_example_swift_Date__00024init__D(environment: UnsafeMutablePointer!, thisClass: jclass, timeIntervalSince1970: jdouble) -> jlong { """, """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_Date__00024getTimeIntervalSince1970__J") public func Java_com_example_swift_Date__00024getTimeIntervalSince1970__J(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong) -> jdouble { """, diff --git a/Tests/JExtractSwiftTests/JNI/JNIArrayTest.swift b/Tests/JExtractSwiftTests/JNI/JNIArrayTest.swift index 0689ca9d..48f2ebe9 100644 --- a/Tests/JExtractSwiftTests/JNI/JNIArrayTest.swift +++ b/Tests/JExtractSwiftTests/JNI/JNIArrayTest.swift @@ -44,9 +44,12 @@ struct JNIArrayTest { input: "public func f(array: Array) -> Array {}", .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024f___3B") public func Java_com_example_swift_SwiftModule__00024f___3B(environment: UnsafeMutablePointer!, thisClass: jclass, array: jbyteArray?) -> jbyteArray? { return SwiftModule.f(array: [UInt8](fromJNI: array, in: environment)).getJNILocalRefValue(in: environment) @@ -82,9 +85,12 @@ struct JNIArrayTest { input: "public func f(array: [UInt8]) -> [UInt8] {}", .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024f___3B") public func Java_com_example_swift_SwiftModule__00024f___3B(environment: UnsafeMutablePointer!, thisClass: jclass, array: jbyteArray?) -> jbyteArray? { return SwiftModule.f(array: [UInt8](fromJNI: array, in: environment)).getJNILocalRefValue(in: environment) @@ -120,9 +126,12 @@ struct JNIArrayTest { input: "public func f(array: [Int64]) -> [Int64] {}", .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024f___3J") public func Java_com_example_swift_SwiftModule__00024f___3J(environment: UnsafeMutablePointer!, thisClass: jclass, array: jlongArray?) -> jlongArray? { return SwiftModule.f(array: [Int64](fromJNI: array, in: environment)).getJNILocalRefValue(in: environment) @@ -167,9 +176,12 @@ struct JNIArrayTest { """, .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024f___3J") public func Java_com_example_swift_SwiftModule__00024f___3J(environment: UnsafeMutablePointer!, thisClass: jclass, array: jlongArray?) -> jlongArray? { return SwiftModule.f(array: [Int64](fromJNI: array, in: environment).map( { (pointer$) in diff --git a/Tests/JExtractSwiftTests/JNI/JNIAsyncTests.swift b/Tests/JExtractSwiftTests/JNI/JNIAsyncTests.swift index b7b4a41a..21da814b 100644 --- a/Tests/JExtractSwiftTests/JNI/JNIAsyncTests.swift +++ b/Tests/JExtractSwiftTests/JNI/JNIAsyncTests.swift @@ -25,7 +25,7 @@ struct JNIAsyncTests { input: "public func asyncVoid() async", .jni, .java, - detectChunkByInitialLines: 2, + detectChunkByInitialLines: 4, expectedChunks: [ """ /** @@ -56,9 +56,12 @@ struct JNIAsyncTests { input: "public func asyncVoid() async", .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024asyncVoid__Ljava_util_concurrent_CompletableFuture_2") public func Java_com_example_swift_SwiftModule__00024asyncVoid__Ljava_util_concurrent_CompletableFuture_2(environment: UnsafeMutablePointer!, thisClass: jclass, result_future: jobject?) { let globalFuture = environment.interface.NewGlobalRef(environment, result_future) @@ -101,7 +104,7 @@ struct JNIAsyncTests { input: "public func async() async throws", .jni, .java, - detectChunkByInitialLines: 2, + detectChunkByInitialLines: 4, expectedChunks: [ """ /** @@ -132,9 +135,12 @@ struct JNIAsyncTests { input: "public func async() async throws", .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024async__Ljava_util_concurrent_CompletableFuture_2") public func Java_com_example_swift_SwiftModule__00024async__Ljava_util_concurrent_CompletableFuture_2(environment: UnsafeMutablePointer!, thisClass: jclass, result_future: jobject?) { let globalFuture = environment.interface.NewGlobalRef(environment, result_future) @@ -191,7 +197,7 @@ struct JNIAsyncTests { input: "public func async(i: Int64) async -> Int64", .jni, .java, - detectChunkByInitialLines: 2, + detectChunkByInitialLines: 4, expectedChunks: [ """ /** @@ -222,9 +228,12 @@ struct JNIAsyncTests { input: "public func async(i: Int64) async -> Int64", .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024async__JLjava_util_concurrent_CompletableFuture_2") public func Java_com_example_swift_SwiftModule__00024async__JLjava_util_concurrent_CompletableFuture_2(environment: UnsafeMutablePointer!, thisClass: jclass, i: jlong, result_future: jobject?) { let globalFuture = environment.interface.NewGlobalRef(environment, result_future) @@ -274,7 +283,7 @@ struct JNIAsyncTests { """, .jni, .java, - detectChunkByInitialLines: 2, + detectChunkByInitialLines: 4, expectedChunks: [ """ /** @@ -309,9 +318,12 @@ struct JNIAsyncTests { """, .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024async__JLjava_util_concurrent_CompletableFuture_2") public func Java_com_example_swift_SwiftModule__00024async__JLjava_util_concurrent_CompletableFuture_2(environment: UnsafeMutablePointer!, thisClass: jclass, c: jlong, result_future: jobject?) { assert(c != 0, "c memory address was null") @@ -371,7 +383,7 @@ struct JNIAsyncTests { """, .jni, .java, - detectChunkByInitialLines: 2, + detectChunkByInitialLines: 4, expectedChunks: [ """ public static java.util.concurrent.CompletableFuture async(java.lang.String s) { @@ -398,9 +410,12 @@ struct JNIAsyncTests { """, .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024async__Ljava_lang_String_2Ljava_util_concurrent_CompletableFuture_2") public func Java_com_example_swift_SwiftModule__00024async__Ljava_lang_String_2Ljava_util_concurrent_CompletableFuture_2(environment: UnsafeMutablePointer!, thisClass: jclass, s: jstring?, result_future: jobject?) { let s = environment.interface.NewGlobalRef(environment, s) @@ -434,7 +449,7 @@ struct JNIAsyncTests { config: config, .jni, .java, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ public static java.util.concurrent.Future async(MyClass c, SwiftArena swiftArena) { @@ -467,9 +482,12 @@ struct JNIAsyncTests { config: config, .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024async__JLorg_swift_swiftkit_core_SimpleCompletableFuture_2") public func Java_com_example_swift_SwiftModule__00024async__JLorg_swift_swiftkit_core_SimpleCompletableFuture_2(environment: UnsafeMutablePointer!, thisClass: jclass, c: jlong, result_future: jobject?) { ... diff --git a/Tests/JExtractSwiftTests/JNI/JNIClassTests.swift b/Tests/JExtractSwiftTests/JNI/JNIClassTests.swift index 05d764ea..b08fc8df 100644 --- a/Tests/JExtractSwiftTests/JNI/JNIClassTests.swift +++ b/Tests/JExtractSwiftTests/JNI/JNIClassTests.swift @@ -157,9 +157,12 @@ struct JNIClassTests { input: source, .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_MyClass__00024method__") public func Java_com_example_swift_MyClass__00024method__(environment: UnsafeMutablePointer!, thisClass: jclass) { MyClass.method() @@ -214,9 +217,12 @@ struct JNIClassTests { input: source, .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_MyClass__00024init__JJ") public func Java_com_example_swift_MyClass__00024init__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, x: jlong, y: jlong) -> jlong { let result$ = UnsafeMutablePointer.allocate(capacity: 1) @@ -226,6 +232,9 @@ struct JNIClassTests { } """, """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_MyClass__00024init__") public func Java_com_example_swift_MyClass__00024init__(environment: UnsafeMutablePointer!, thisClass: jclass) -> jlong { let result$ = UnsafeMutablePointer.allocate(capacity: 1) @@ -269,9 +278,12 @@ struct JNIClassTests { input: source, .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_MyClass__00024doSomething__JJ") public func Java_com_example_swift_MyClass__00024doSomething__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, x: jlong, selfPointer: jlong) { assert(selfPointer != 0, "selfPointer memory address was null") @@ -318,9 +330,12 @@ struct JNIClassTests { input: source, .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_MyClass__00024copy__J") public func Java_com_example_swift_MyClass__00024copy__J(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong) -> jlong { assert(selfPointer != 0, "selfPointer memory address was null") @@ -370,9 +385,12 @@ struct JNIClassTests { input: source, .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_MyClass__00024isEqual__JJ") public func Java_com_example_swift_MyClass__00024isEqual__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, other: jlong, selfPointer: jlong) -> jboolean { assert(other != 0, "other memory address was null") diff --git a/Tests/JExtractSwiftTests/JNI/JNIClosureTests.swift b/Tests/JExtractSwiftTests/JNI/JNIClosureTests.swift index 841420d7..dad2f565 100644 --- a/Tests/JExtractSwiftTests/JNI/JNIClosureTests.swift +++ b/Tests/JExtractSwiftTests/JNI/JNIClosureTests.swift @@ -62,9 +62,12 @@ struct JNIClosureTests { input: source, .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024emptyClosure__Lcom_example_swift_SwiftModule_00024emptyClosure_00024closure_2") public func Java_com_example_swift_SwiftModule__00024emptyClosure__Lcom_example_swift_SwiftModule_00024emptyClosure_00024closure_2(environment: UnsafeMutablePointer!, thisClass: jclass, closure: jobject?) { SwiftModule.emptyClosure(closure: { @@ -120,9 +123,12 @@ struct JNIClosureTests { input: source, .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024closureWithArgumentsAndReturn__Lcom_example_swift_SwiftModule_00024closureWithArgumentsAndReturn_00024closure_2") public func Java_com_example_swift_SwiftModule__00024closureWithArgumentsAndReturn__Lcom_example_swift_SwiftModule_00024closureWithArgumentsAndReturn_00024closure_2(environment: UnsafeMutablePointer!, thisClass: jclass, closure: jobject?) { SwiftModule.closureWithArgumentsAndReturn(closure: { _0, _1 in diff --git a/Tests/JExtractSwiftTests/JNI/JNIDictionaryTest.swift b/Tests/JExtractSwiftTests/JNI/JNIDictionaryTest.swift index c09bbaaa..258db9a4 100644 --- a/Tests/JExtractSwiftTests/JNI/JNIDictionaryTest.swift +++ b/Tests/JExtractSwiftTests/JNI/JNIDictionaryTest.swift @@ -44,9 +44,12 @@ struct JNIDictionaryTest { input: "public func f() -> [String: Int64] {}", .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024f__") public func Java_com_example_swift_SwiftModule__00024f__(environment: UnsafeMutablePointer!, thisClass: jclass) -> jlong { return SwiftModule.f().dictionaryGetJNIValue(in: environment) @@ -82,9 +85,12 @@ struct JNIDictionaryTest { input: "public func f(dict: [String: Int64]) {}", .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024f__J") public func Java_com_example_swift_SwiftModule__00024f__J(environment: UnsafeMutablePointer!, thisClass: jclass, dict: jlong) { SwiftModule.f(dict: [String: Int64](fromJNI: dict, in: environment)) @@ -120,9 +126,12 @@ struct JNIDictionaryTest { input: "public func f(dict: [String: Int64]) -> [String: Int64] {}", .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024f__J") public func Java_com_example_swift_SwiftModule__00024f__J(environment: UnsafeMutablePointer!, thisClass: jclass, dict: jlong) -> jlong { return SwiftModule.f(dict: [String: Int64](fromJNI: dict, in: environment)).dictionaryGetJNIValue(in: environment) @@ -158,9 +167,12 @@ struct JNIDictionaryTest { input: "public func f(dict: Dictionary) -> Dictionary {}", .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024f__J") public func Java_com_example_swift_SwiftModule__00024f__J(environment: UnsafeMutablePointer!, thisClass: jclass, dict: jlong) -> jlong { return SwiftModule.f(dict: [String: Int64](fromJNI: dict, in: environment)).dictionaryGetJNIValue(in: environment) @@ -270,9 +282,12 @@ struct JNIDictionaryTest { input: "public func f(a: [String: Int64], b: [String: Bool]) {}", .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024f__JJ") public func Java_com_example_swift_SwiftModule__00024f__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, a: jlong, b: jlong) { SwiftModule.f(a: [String: Int64](fromJNI: a, in: environment), b: [String: Bool](fromJNI: b, in: environment)) @@ -311,9 +326,12 @@ struct JNIDictionaryTest { input: "public func f(dict: [String: Int64], key: String, value: Int64) -> [String: Int64] {}", .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024f__JLjava_lang_String_2J") public func Java_com_example_swift_SwiftModule__00024f__JLjava_lang_String_2J(environment: UnsafeMutablePointer!, thisClass: jclass, dict: jlong, key: jstring?, value: jlong) -> jlong { return SwiftModule.f(dict: [String: Int64](fromJNI: dict, in: environment), key: String(fromJNI: key, in: environment), value: Int64(fromJNI: value, in: environment)).dictionaryGetJNIValue(in: environment) diff --git a/Tests/JExtractSwiftTests/JNI/JNIEnumTests.swift b/Tests/JExtractSwiftTests/JNI/JNIEnumTests.swift index e09c215c..087daaeb 100644 --- a/Tests/JExtractSwiftTests/JNI/JNIEnumTests.swift +++ b/Tests/JExtractSwiftTests/JNI/JNIEnumTests.swift @@ -226,9 +226,12 @@ struct JNIEnumTests { input: source, .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_MyEnum__00024first__") public func Java_com_example_swift_MyEnum__00024first__(environment: UnsafeMutablePointer!, thisClass: jclass) -> jlong { let result$ = UnsafeMutablePointer.allocate(capacity: 1) @@ -238,6 +241,9 @@ struct JNIEnumTests { } """, """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_MyEnum__00024second__Ljava_lang_String_2") public func Java_com_example_swift_MyEnum__00024second__Ljava_lang_String_2(environment: UnsafeMutablePointer!, thisClass: jclass, arg0: jstring?) -> jlong { let result$ = UnsafeMutablePointer.allocate(capacity: 1) @@ -247,6 +253,9 @@ struct JNIEnumTests { } """, """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_MyEnum__00024third__JI") public func Java_com_example_swift_MyEnum__00024third__JI(environment: UnsafeMutablePointer!, thisClass: jclass, x: jlong, y: jint) -> jlong { let result$ = UnsafeMutablePointer.allocate(capacity: 1) @@ -303,9 +312,12 @@ struct JNIEnumTests { input: source, .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_MyEnum__00024getAsSecond__J") public func Java_com_example_swift_MyEnum__00024getAsSecond__J(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong) -> jobject? { ... @@ -321,6 +333,9 @@ struct JNIEnumTests { } """, """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_MyEnum__00024getAsThird__J") public func Java_com_example_swift_MyEnum__00024getAsThird__J(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong) -> jobject? { ... diff --git a/Tests/JExtractSwiftTests/JNI/JNIGenericTypeTests.swift b/Tests/JExtractSwiftTests/JNI/JNIGenericTypeTests.swift index d0cddec3..ebca686d 100644 --- a/Tests/JExtractSwiftTests/JNI/JNIGenericTypeTests.swift +++ b/Tests/JExtractSwiftTests/JNI/JNIGenericTypeTests.swift @@ -125,8 +125,20 @@ struct JNIGenericTypeTests { } ... } - """#, + """# + ] + ) + + try assertOutput( + input: genericFile, + .jni, + .swift, + detectChunkByInitialLines: 4, + expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_MyID__00024getDescription__JJ") public func Java_com_example_swift_MyID__00024getDescription__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong, selfTypePointer: jlong) -> jstring? { let selfTypePointerBits$ = Int(Int64(fromJNI: selfTypePointer, in: environment)) @@ -136,8 +148,8 @@ struct JNIGenericTypeTests { let openerType = unsafeBitCast(selfTypePointer$, to: Any.Type.self) as! (any _SwiftModule_MyID_opener.Type) return openerType._get_description(environment: environment, thisClass: thisClass, selfPointer: selfPointer) } - """, - ] + """ + ], ) } @@ -147,7 +159,7 @@ struct JNIGenericTypeTests { input: genericFile, .jni, .java, - detectChunkByInitialLines: 2, + detectChunkByInitialLines: 4, expectedChunks: [ """ public static MyID makeStringID(java.lang.String value, SwiftArena swiftArena) { @@ -169,9 +181,12 @@ struct JNIGenericTypeTests { input: genericFile, .jni, .swift, - detectChunkByInitialLines: 2, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024makeStringID__Ljava_lang_String_2Lorg_swift_swiftkit_core__1OutSwiftGenericInstance_2") public func Java_com_example_swift_SwiftModule__00024makeStringID__Ljava_lang_String_2Lorg_swift_swiftkit_core__1OutSwiftGenericInstance_2(environment: UnsafeMutablePointer!, thisClass: jclass, value: jstring?, out: jobject?) { let result$ = UnsafeMutablePointer>.allocate(capacity: 1) diff --git a/Tests/JExtractSwiftTests/JNI/JNIIntConversionChecksTests.swift b/Tests/JExtractSwiftTests/JNI/JNIIntConversionChecksTests.swift index aaa24e97..85cc5fc8 100644 --- a/Tests/JExtractSwiftTests/JNI/JNIIntConversionChecksTests.swift +++ b/Tests/JExtractSwiftTests/JNI/JNIIntConversionChecksTests.swift @@ -63,6 +63,9 @@ struct JNIIntConversionChecksTests { .swift, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_MyStruct__00024init__J") public func Java_com_example_swift_MyStruct__00024init__J(environment: UnsafeMutablePointer!, thisClass: jclass, normalInt: jlong) -> jlong { let normalInt$indirect = Int64(fromJNI: normalInt, in: environment) @@ -89,6 +92,9 @@ struct JNIIntConversionChecksTests { .swift, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_MyStruct__00024init__J") public func Java_com_example_swift_MyStruct__00024init__J(environment: UnsafeMutablePointer!, thisClass: jclass, unsignedInt: jlong) -> jlong { let unsignedInt$indirect = UInt64(fromJNI: unsignedInt, in: environment) @@ -115,6 +121,9 @@ struct JNIIntConversionChecksTests { .swift, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_MyStruct__00024setUnsignedInt__JJ") public func Java_com_example_swift_MyStruct__00024setUnsignedInt__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, newValue: jlong, selfPointer: jlong) { let newValue$indirect = UInt64(fromJNI: newValue, in: environment) @@ -144,6 +153,9 @@ struct JNIIntConversionChecksTests { .swift, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_MyStruct__00024getUnsignedInt__J") public func Java_com_example_swift_MyStruct__00024getUnsignedInt__J(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong) -> jlong { assert(selfPointer != 0, "selfPointer memory address was null") @@ -165,6 +177,9 @@ struct JNIIntConversionChecksTests { .swift, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_MyStruct__00024setNormalInt__JJ") public func Java_com_example_swift_MyStruct__00024setNormalInt__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, newValue: jlong, selfPointer: jlong) { let newValue$indirect = Int64(fromJNI: newValue, in: environment) @@ -194,6 +209,9 @@ struct JNIIntConversionChecksTests { .swift, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_MyStruct__00024dummyFunc__JJ") public func Java_com_example_swift_MyStruct__00024dummyFunc__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, arg: jlong, selfPointer: jlong) -> jlong { let arg$indirect = Int64(fromJNI: arg, in: environment) @@ -223,6 +241,9 @@ struct JNIIntConversionChecksTests { .swift, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_MyStruct__00024dummyFunc__JJ") public func Java_com_example_swift_MyStruct__00024dummyFunc__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, arg: jlong, selfPointer: jlong) -> jlong { let arg$indirect = UInt64(fromJNI: arg, in: environment) @@ -251,6 +272,9 @@ struct JNIIntConversionChecksTests { .swift, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_MyEnum__00024secondCase__J") public func Java_com_example_swift_MyEnum__00024secondCase__J(environment: UnsafeMutablePointer!, thisClass: jclass, arg0: jlong) -> jlong { let arg0$indirect = UInt64(fromJNI: arg0, in: environment) diff --git a/Tests/JExtractSwiftTests/JNI/JNIJavaKitTests.swift b/Tests/JExtractSwiftTests/JNI/JNIJavaKitTests.swift index f66e454c..631e1063 100644 --- a/Tests/JExtractSwiftTests/JNI/JNIJavaKitTests.swift +++ b/Tests/JExtractSwiftTests/JNI/JNIJavaKitTests.swift @@ -59,10 +59,13 @@ struct JNIJavaKitTests { input: source, .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, javaClassLookupTable: classLookupTable, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024function__Ljava_lang_Long_2Ljava_lang_Integer_2J") public func Java_com_example_swift_SwiftModule__00024function__Ljava_lang_Long_2Ljava_lang_Integer_2J(environment: UnsafeMutablePointer!, thisClass: jclass, javaLong: jobject?, javaInteger: jobject?, int: jlong) { guard let javaLong_unwrapped$ = javaLong else { diff --git a/Tests/JExtractSwiftTests/JNI/JNIModuleTests.swift b/Tests/JExtractSwiftTests/JNI/JNIModuleTests.swift index 0b6b4870..5e40e3f5 100644 --- a/Tests/JExtractSwiftTests/JNI/JNIModuleTests.swift +++ b/Tests/JExtractSwiftTests/JNI/JNIModuleTests.swift @@ -127,21 +127,30 @@ struct JNIModuleTests { input: globalMethodWithPrimitives, .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024helloWorld__") public func Java_com_example_swift_SwiftModule__00024helloWorld__(environment: UnsafeMutablePointer!, thisClass: jclass) { SwiftModule.helloWorld() } """, """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024takeIntegers__BSIJ") public func Java_com_example_swift_SwiftModule__00024takeIntegers__BSIJ(environment: UnsafeMutablePointer!, thisClass: jclass, i1: jbyte, i2: jshort, i3: jint, i4: jlong) -> jchar { return SwiftModule.takeIntegers(i1: Int8(fromJNI: i1, in: environment), i2: Int16(fromJNI: i2, in: environment), i3: Int32(fromJNI: i3, in: environment), i4: Int64(fromJNI: i4, in: environment)).getJNILocalRefValue(in: environment) } """, """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024otherPrimitives__ZFD") public func Java_com_example_swift_SwiftModule__00024otherPrimitives__ZFD(environment: UnsafeMutablePointer!, thisClass: jclass, b: jboolean, f: jfloat, d: jdouble) { SwiftModule.otherPrimitives(b: Bool(fromJNI: b, in: environment), f: Float(fromJNI: f, in: environment), d: Double(fromJNI: d, in: environment)) @@ -182,9 +191,12 @@ struct JNIModuleTests { input: globalMethodWithString, .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024copy__Ljava_lang_String_2") public func Java_com_example_swift_SwiftModule__00024copy__Ljava_lang_String_2(environment: UnsafeMutablePointer!, thisClass: jclass, string: jstring?) -> jstring? { return SwiftModule.copy(String(fromJNI: string, in: environment)).getJNILocalRefValue(in: environment) @@ -239,9 +251,12 @@ struct JNIModuleTests { input: globalMethodThrowing, .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024methodA__") public func Java_com_example_swift_SwiftModule__00024methodA__(environment: UnsafeMutablePointer!, thisClass: jclass) { do { @@ -253,6 +268,9 @@ struct JNIModuleTests { } """, """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024methodB__") public func Java_com_example_swift_SwiftModule__00024methodB__(environment: UnsafeMutablePointer!, thisClass: jclass) -> jlong { do { @@ -264,6 +282,9 @@ struct JNIModuleTests { } """, """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024methodC__") public func Java_com_example_swift_SwiftModule__00024methodC__(environment: UnsafeMutablePointer!, thisClass: jclass) -> jstring? { do { diff --git a/Tests/JExtractSwiftTests/JNI/JNINestedTypesTests.swift b/Tests/JExtractSwiftTests/JNI/JNINestedTypesTests.swift index 159e496e..03473cd9 100644 --- a/Tests/JExtractSwiftTests/JNI/JNINestedTypesTests.swift +++ b/Tests/JExtractSwiftTests/JNI/JNINestedTypesTests.swift @@ -72,27 +72,39 @@ struct JNINestedTypesTests { input: source1, .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_A__00024typeMetadataAddressDowncall__") public func Java_com_example_swift_A__00024typeMetadataAddressDowncall__(environment: UnsafeMutablePointer!, thisClass: jclass) -> jlong { ... } """, """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_A_00024B__00024typeMetadataAddressDowncall__") public func Java_com_example_swift_A_00024B__00024typeMetadataAddressDowncall__(environment: UnsafeMutablePointer!, thisClass: jclass) -> jlong { ... } """, """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_A_00024B_00024C__00024typeMetadataAddressDowncall__") public func Java_com_example_swift_A_00024B_00024C__00024typeMetadataAddressDowncall__(environment: UnsafeMutablePointer!, thisClass: jclass) -> jlong { ... } """, """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_A_00024B_00024C__00024h__JJ") public func Java_com_example_swift_A_00024B_00024C__00024h__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, b: jlong, selfPointer: jlong) { ... diff --git a/Tests/JExtractSwiftTests/JNI/JNIOptionalTests.swift b/Tests/JExtractSwiftTests/JNI/JNIOptionalTests.swift index 90702944..c3156d5d 100644 --- a/Tests/JExtractSwiftTests/JNI/JNIOptionalTests.swift +++ b/Tests/JExtractSwiftTests/JNI/JNIOptionalTests.swift @@ -66,10 +66,13 @@ struct JNIOptionalTests { input: source, .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, javaClassLookupTable: classLookupTable, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024optionalSugar__BJ") public func Java_com_example_swift_SwiftModule__00024optionalSugar__BJ(environment: UnsafeMutablePointer!, thisClass: jclass, arg_discriminator: jbyte, arg_value: jlong) -> jlong { let result_value$ = SwiftModule.optionalSugar(arg_discriminator == 1 ? Int64(fromJNI: arg_value, in: environment) : nil).map { @@ -116,10 +119,13 @@ struct JNIOptionalTests { input: source, .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, javaClassLookupTable: classLookupTable, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024optionalExplicit__BLjava_lang_String_2_3B") public func Java_com_example_swift_SwiftModule__00024optionalExplicit__BLjava_lang_String_2_3B(environment: UnsafeMutablePointer!, thisClass: jclass, arg_discriminator: jbyte, arg_value: jstring?, result_discriminator$: jbyteArray?) -> jstring? { let result$: jstring? @@ -174,10 +180,13 @@ struct JNIOptionalTests { input: source, .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, javaClassLookupTable: classLookupTable, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024optionalClass__J_3B") public func Java_com_example_swift_SwiftModule__00024optionalClass__J_3B(environment: UnsafeMutablePointer!, thisClass: jclass, arg: jlong, result_discriminator$: jbyteArray?) -> jlong { let argBits$ = Int(Int64(fromJNI: arg, in: environment)) @@ -235,10 +244,13 @@ struct JNIOptionalTests { input: source, .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, javaClassLookupTable: classLookupTable, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024optionalJavaKitClass__Ljava_lang_Long_2") public func Java_com_example_swift_SwiftModule__00024optionalJavaKitClass__Ljava_lang_Long_2(environment: UnsafeMutablePointer!, thisClass: jclass, arg: jobject?) { SwiftModule.optionalJavaKitClass(arg.map { diff --git a/Tests/JExtractSwiftTests/JNI/JNIProtocolTests.swift b/Tests/JExtractSwiftTests/JNI/JNIProtocolTests.swift index 526c8967..5b4e31af 100644 --- a/Tests/JExtractSwiftTests/JNI/JNIProtocolTests.swift +++ b/Tests/JExtractSwiftTests/JNI/JNIProtocolTests.swift @@ -131,6 +131,9 @@ struct JNIProtocolTests { } """, """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024takeProtocol__Ljava_lang_Object_2Ljava_lang_Object_2") public func Java_com_example_swift_SwiftModule__00024takeProtocol__Ljava_lang_Object_2Ljava_lang_Object_2(environment: UnsafeMutablePointer!, thisClass: jclass, x: jobject?, y: jobject?) { let xswiftObject$: (SomeProtocol) @@ -196,7 +199,7 @@ struct JNIProtocolTests { config: config, .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ final class _SwiftModule_takeGeneric_s_Wrapper: SwiftJavaSomeProtocolWrapper { @@ -207,6 +210,9 @@ struct JNIProtocolTests { } """, """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024takeGeneric__Ljava_lang_Object_2") public func Java_com_example_swift_SwiftModule__00024takeGeneric__Ljava_lang_Object_2(environment: UnsafeMutablePointer!, thisClass: jclass, s: jobject?) { let sswiftObject$: (SomeProtocol) @@ -252,7 +258,7 @@ struct JNIProtocolTests { config: config, .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ final class _SwiftModule_takeComposite_x_Wrapper: SwiftJavaSomeProtocolWrapper, SwiftJavaBWrapper { @@ -265,6 +271,9 @@ struct JNIProtocolTests { } """, """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024takeComposite__Ljava_lang_Object_2") public func Java_com_example_swift_SwiftModule__00024takeComposite__Ljava_lang_Object_2(environment: UnsafeMutablePointer!, thisClass: jclass, x: jobject?) { let xswiftObject$: (SomeProtocol & B) diff --git a/Tests/JExtractSwiftTests/JNI/JNISetTest.swift b/Tests/JExtractSwiftTests/JNI/JNISetTest.swift index 4a70fdcd..e6b63ec3 100644 --- a/Tests/JExtractSwiftTests/JNI/JNISetTest.swift +++ b/Tests/JExtractSwiftTests/JNI/JNISetTest.swift @@ -44,9 +44,12 @@ struct JNISetTest { input: "public func f() -> Set {}", .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024f__") public func Java_com_example_swift_SwiftModule__00024f__(environment: UnsafeMutablePointer!, thisClass: jclass) -> jlong { return SwiftModule.f().setGetJNIValue(in: environment) @@ -82,9 +85,12 @@ struct JNISetTest { input: "public func f(set: Set) {}", .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024f__J") public func Java_com_example_swift_SwiftModule__00024f__J(environment: UnsafeMutablePointer!, thisClass: jclass, set: jlong) { SwiftModule.f(set: Set(fromJNI: set, in: environment)) @@ -120,9 +126,12 @@ struct JNISetTest { input: "public func f(set: Set) -> Set {}", .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024f__J") public func Java_com_example_swift_SwiftModule__00024f__J(environment: UnsafeMutablePointer!, thisClass: jclass, set: jlong) -> jlong { return SwiftModule.f(set: Set(fromJNI: set, in: environment)).setGetJNIValue(in: environment) @@ -215,9 +224,12 @@ struct JNISetTest { input: "public func f(a: Set, b: Set) {}", .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024f__JJ") public func Java_com_example_swift_SwiftModule__00024f__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, a: jlong, b: jlong) { SwiftModule.f(a: Set(fromJNI: a, in: environment), b: Set(fromJNI: b, in: environment)) @@ -256,9 +268,12 @@ struct JNISetTest { input: "public func f(set: Set, element: String) -> Set {}", .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024f__JLjava_lang_String_2") public func Java_com_example_swift_SwiftModule__00024f__JLjava_lang_String_2(environment: UnsafeMutablePointer!, thisClass: jclass, set: jlong, element: jstring?) -> jlong { return SwiftModule.f(set: Set(fromJNI: set, in: environment), element: String(fromJNI: element, in: environment)).setGetJNIValue(in: environment) diff --git a/Tests/JExtractSwiftTests/JNI/JNIStructTests.swift b/Tests/JExtractSwiftTests/JNI/JNIStructTests.swift index e7a5cb80..58970cd4 100644 --- a/Tests/JExtractSwiftTests/JNI/JNIStructTests.swift +++ b/Tests/JExtractSwiftTests/JNI/JNIStructTests.swift @@ -143,9 +143,12 @@ struct JNIStructTests { input: source, .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_MyStruct__00024init__JJ") public func Java_com_example_swift_MyStruct__00024init__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, x: jlong, y: jlong) -> jlong { let result$ = UnsafeMutablePointer.allocate(capacity: 1) @@ -189,9 +192,12 @@ struct JNIStructTests { input: source, .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_MyStruct__00024doSomething__JJ") public func Java_com_example_swift_MyStruct__00024doSomething__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, x: jlong, selfPointer: jlong) { assert(selfPointer != 0, "selfPointer memory address was null") diff --git a/Tests/JExtractSwiftTests/JNI/JNISubscriptsTests.swift b/Tests/JExtractSwiftTests/JNI/JNISubscriptsTests.swift index 8ad07564..bebbc1cc 100644 --- a/Tests/JExtractSwiftTests/JNI/JNISubscriptsTests.swift +++ b/Tests/JExtractSwiftTests/JNI/JNISubscriptsTests.swift @@ -98,6 +98,9 @@ struct JNISubscriptsTests { .swift, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_MyStruct__00024getSubscript__J") public func Java_com_example_swift_MyStruct__00024getSubscript__J(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong) -> jdouble { assert(selfPointer != 0, "selfPointer memory address was null") @@ -109,6 +112,9 @@ struct JNISubscriptsTests { return selfPointer$.pointee[].getJNILocalRefValue(in: environment) """, """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_MyStruct__00024setSubscript__DJ") public func Java_com_example_swift_MyStruct__00024setSubscript__DJ(environment: UnsafeMutablePointer!, thisClass: jclass, newValue: jdouble, selfPointer: jlong) { assert(selfPointer != 0, "selfPointer memory address was null") @@ -131,6 +137,9 @@ struct JNISubscriptsTests { .swift, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_MyStruct__00024getSubscript__IJ") public func Java_com_example_swift_MyStruct__00024getSubscript__IJ(environment: UnsafeMutablePointer!, thisClass: jclass, index: jint, selfPointer: jlong) -> jint { assert(selfPointer != 0, "selfPointer memory address was null") @@ -142,6 +151,9 @@ struct JNISubscriptsTests { return selfPointer$.pointee[Int32(fromJNI: index, in: environment)].getJNILocalRefValue(in: environment) """, """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_MyStruct__00024setSubscript__IIJ") public func Java_com_example_swift_MyStruct__00024setSubscript__IIJ(environment: UnsafeMutablePointer!, thisClass: jclass, index: jint, newValue: jint, selfPointer: jlong) { assert(selfPointer != 0, "selfPointer memory address was null") diff --git a/Tests/JExtractSwiftTests/JNI/JNIVariablesTests.swift b/Tests/JExtractSwiftTests/JNI/JNIVariablesTests.swift index 6f13c463..28cee921 100644 --- a/Tests/JExtractSwiftTests/JNI/JNIVariablesTests.swift +++ b/Tests/JExtractSwiftTests/JNI/JNIVariablesTests.swift @@ -69,9 +69,12 @@ struct JNIVariablesTests { input: membersSource, .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_MyClass__00024getConstant__J") public func Java_com_example_swift_MyClass__00024getConstant__J(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong) -> jlong { ... @@ -128,9 +131,12 @@ struct JNIVariablesTests { input: membersSource, .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_MyClass__00024getMutable__J") public func Java_com_example_swift_MyClass__00024getMutable__J(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong) -> jlong { assert(selfPointer != 0, "selfPointer memory address was null") @@ -144,6 +150,9 @@ struct JNIVariablesTests { } """, """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_MyClass__00024setMutable__JJ") public func Java_com_example_swift_MyClass__00024setMutable__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, newValue: jlong, selfPointer: jlong) { assert(selfPointer != 0, "selfPointer memory address was null") @@ -187,9 +196,12 @@ struct JNIVariablesTests { input: membersSource, .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_MyClass__00024getComputed__J") public func Java_com_example_swift_MyClass__00024getComputed__J(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong) -> jlong { ... @@ -232,9 +244,12 @@ struct JNIVariablesTests { input: membersSource, .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_MyClass__00024getComputedThrowing__J") public func Java_com_example_swift_MyClass__00024getComputedThrowing__J(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong) -> jlong { ... @@ -296,9 +311,12 @@ struct JNIVariablesTests { input: membersSource, .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_MyClass__00024getGetterAndSetter__J") public func Java_com_example_swift_MyClass__00024getGetterAndSetter__J(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong) -> jlong { ... @@ -306,6 +324,9 @@ struct JNIVariablesTests { } """, """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_MyClass__00024setGetterAndSetter__JJ") public func Java_com_example_swift_MyClass__00024setGetterAndSetter__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, newValue: jlong, selfPointer: jlong) { ... @@ -362,9 +383,12 @@ struct JNIVariablesTests { input: membersSource, .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_MyClass__00024isSomeBoolean__J") public func Java_com_example_swift_MyClass__00024isSomeBoolean__J(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong) -> jboolean { ... @@ -372,6 +396,9 @@ struct JNIVariablesTests { } """, """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_MyClass__00024setSomeBoolean__ZJ") public func Java_com_example_swift_MyClass__00024setSomeBoolean__ZJ(environment: UnsafeMutablePointer!, thisClass: jclass, newValue: jboolean, selfPointer: jlong) { ... @@ -428,9 +455,12 @@ struct JNIVariablesTests { input: membersSource, .jni, .swift, - detectChunkByInitialLines: 1, + detectChunkByInitialLines: 4, expectedChunks: [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_MyClass__00024isBoolean__J") public func Java_com_example_swift_MyClass__00024isBoolean__J(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong) -> jboolean { ... @@ -438,6 +468,9 @@ struct JNIVariablesTests { } """, """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_MyClass__00024setBoolean__ZJ") public func Java_com_example_swift_MyClass__00024setBoolean__ZJ(environment: UnsafeMutablePointer!, thisClass: jclass, newValue: jboolean, selfPointer: jlong) { ... diff --git a/Tests/JExtractSwiftTests/UUIDTests.swift b/Tests/JExtractSwiftTests/UUIDTests.swift index 1fa3fdfb..d4f96e9f 100644 --- a/Tests/JExtractSwiftTests/UUIDTests.swift +++ b/Tests/JExtractSwiftTests/UUIDTests.swift @@ -33,6 +33,9 @@ struct UUIDTests { /* expected Swift chunks */ [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024acceptUUID__Ljava_lang_String_2") public func Java_com_example_swift_SwiftModule__00024acceptUUID__Ljava_lang_String_2(environment: UnsafeMutablePointer!, thisClass: jclass, uuid: jstring?) { let uuid_string$ = String(fromJNI: uuid, in: environment) @@ -91,6 +94,9 @@ struct UUIDTests { /* expected Swift chunks */ [ """ + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_swift_SwiftModule__00024returnUUID__") public func Java_com_example_swift_SwiftModule__00024returnUUID__(environment: UnsafeMutablePointer!, thisClass: jclass) -> jstring? { return SwiftModule.returnUUID().uuidString.getJNILocalRefValue(in: environment) diff --git a/Tests/SwiftJavaMacrosTests/JavaImplementationMacroTests.swift b/Tests/SwiftJavaMacrosTests/JavaImplementationMacroTests.swift index 2019acd6..de51cabf 100644 --- a/Tests/SwiftJavaMacrosTests/JavaImplementationMacroTests.swift +++ b/Tests/SwiftJavaMacrosTests/JavaImplementationMacroTests.swift @@ -44,8 +44,11 @@ class JavaImplementationMacroTests: XCTestCase { } } + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_org_swift_example_Hello_1World_test_1method") - func __macro_local_11test_methodfMu_(environment: UnsafeMutablePointer!, thisObj: jobject) -> Int32.JNIType { + public func __macro_local_11test_methodfMu_(environment: UnsafeMutablePointer!, thisObj: jobject) -> Int32.JNIType { let obj = HelloWorld(javaThis: thisObj, environment: environment!) return obj.test_method() .getJNILocalRefValue(in: environment) @@ -74,8 +77,11 @@ class JavaImplementationMacroTests: XCTestCase { } } + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_test_MyClass_simpleMethod") - func __macro_local_12simpleMethodfMu_(environment: UnsafeMutablePointer!, thisObj: jobject) -> Int32.JNIType { + public func __macro_local_12simpleMethodfMu_(environment: UnsafeMutablePointer!, thisObj: jobject) -> Int32.JNIType { let obj = MyClass(javaThis: thisObj, environment: environment!) return obj.simpleMethod() .getJNILocalRefValue(in: environment) @@ -104,8 +110,11 @@ class JavaImplementationMacroTests: XCTestCase { } } + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_org_example_Utils_static_1helper") - func __macro_local_13static_helperfMu_(environment: UnsafeMutablePointer!, thisClass: jclass) -> String.JNIType { + public func __macro_local_13static_helperfMu_(environment: UnsafeMutablePointer!, thisClass: jclass) -> String.JNIType { return Utils.static_helper(environment: environment) .getJNILocalRefValue(in: environment) } @@ -141,15 +150,21 @@ class JavaImplementationMacroTests: XCTestCase { } } + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_test_Class_1With_1Underscores_method_1one") - func __macro_local_10method_onefMu_(environment: UnsafeMutablePointer!, thisObj: jobject) -> Int32.JNIType { + public func __macro_local_10method_onefMu_(environment: UnsafeMutablePointer!, thisObj: jobject) -> Int32.JNIType { let obj = ClassWithUnderscores(javaThis: thisObj, environment: environment!) return obj.method_one() .getJNILocalRefValue(in: environment) } + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_test_Class_1With_1Underscores_method_1two") - func __macro_local_10method_twofMu_(environment: UnsafeMutablePointer!, thisObj: jobject) -> Int32.JNIType { + public func __macro_local_10method_twofMu_(environment: UnsafeMutablePointer!, thisObj: jobject) -> Int32.JNIType { let obj = ClassWithUnderscores(javaThis: thisObj, environment: environment!) return obj.method_two() .getJNILocalRefValue(in: environment) @@ -186,14 +201,20 @@ class JavaImplementationMacroTests: XCTestCase { } } + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_org_swift_swiftkit_core_collections_SwiftDictionaryMap__00024size") - func __macro_local_5_sizefMu_(environment: UnsafeMutablePointer!, thisClass: jclass, pointer: Int64.JNIType) -> Int32.JNIType { + public func __macro_local_5_sizefMu_(environment: UnsafeMutablePointer!, thisClass: jclass, pointer: Int64.JNIType) -> Int32.JNIType { return SwiftDictionaryMapJava._size(environment: environment, pointer: Int64(fromJNI: pointer, in: environment!)) .getJNILocalRefValue(in: environment) } + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_org_swift_swiftkit_core_collections_SwiftDictionaryMap__00024destroy") - func __macro_local_8_destroyfMu_(environment: UnsafeMutablePointer!, thisClass: jclass, pointer: Int64.JNIType) { + public func __macro_local_8_destroyfMu_(environment: UnsafeMutablePointer!, thisClass: jclass, pointer: Int64.JNIType) { return SwiftDictionaryMapJava._destroy(environment: environment, pointer: Int64(fromJNI: pointer, in: environment!)) } """, @@ -220,8 +241,11 @@ class JavaImplementationMacroTests: XCTestCase { } } + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_org_example_Processor_process_1data") - func __macro_local_12process_datafMu_(environment: UnsafeMutablePointer!, thisObj: jobject) { + public func __macro_local_12process_datafMu_(environment: UnsafeMutablePointer!, thisObj: jobject) { let obj = Processor(javaThis: thisObj, environment: environment!) return obj.process_data() } From 65c559cf4b1217886f997c2b3a7b225c305bda3d Mon Sep 17 00:00:00 2001 From: Mads Odgaard Date: Sat, 28 Mar 2026 14:09:51 +0100 Subject: [PATCH 3/6] mulitline --- .../JNI/JNISwift2JavaGenerator+SwiftThunkPrinting.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+SwiftThunkPrinting.swift b/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+SwiftThunkPrinting.swift index 75fc8c1c..891d1e97 100644 --- a/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+SwiftThunkPrinting.swift +++ b/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+SwiftThunkPrinting.swift @@ -144,7 +144,14 @@ extension JNISwift2JavaGenerator { .sorted() .map { " \($0);" } .joined(separator: "\n") - let contents = "{\nglobal:\n\(symbolLines)\nlocal: *;\n};\n" + let contents = + """ + { + global: + \(symbolLines) + local: *; + };" + """ try contents.write( toFile: outputPath, From b5accacf19a8ef08858e1830655b2f4fd60270fb Mon Sep 17 00:00:00 2001 From: Mads Odgaard Date: Sat, 28 Mar 2026 14:11:20 +0100 Subject: [PATCH 4/6] revert tests --- .../JExtractSwiftTests/DataImportTests.swift | 8 +--- Tests/JExtractSwiftTests/DateTests.swift | 12 ----- .../JExtractSwiftTests/JNI/JNIArrayTest.swift | 20 ++------ .../JNI/JNIAsyncTests.swift | 42 +++++------------ .../JNI/JNIClassTests.swift | 28 ++--------- .../JNI/JNIClosureTests.swift | 10 +--- .../JNI/JNIDictionaryTest.swift | 30 +++--------- .../JExtractSwiftTests/JNI/JNIEnumTests.swift | 19 +------- .../JNI/JNIGenericTypeTests.swift | 25 ++-------- .../JNI/JNIIntConversionChecksTests.swift | 24 ---------- .../JNI/JNIJavaKitTests.swift | 5 +- .../JNI/JNIModuleTests.swift | 27 ++--------- .../JNI/JNINestedTypesTests.swift | 14 +----- .../JNI/JNIOptionalTests.swift | 20 ++------ .../JNI/JNIProtocolTests.swift | 13 +---- Tests/JExtractSwiftTests/JNI/JNISetTest.swift | 25 ++-------- .../JNI/JNIStructTests.swift | 10 +--- .../JNI/JNISubscriptsTests.swift | 12 ----- .../JNI/JNIVariablesTests.swift | 47 +++---------------- Tests/JExtractSwiftTests/UUIDTests.swift | 6 --- .../JavaImplementationMacroTests.swift | 40 ++++------------ 21 files changed, 70 insertions(+), 367 deletions(-) diff --git a/Tests/JExtractSwiftTests/DataImportTests.swift b/Tests/JExtractSwiftTests/DataImportTests.swift index 5b106ed4..08652aca 100644 --- a/Tests/JExtractSwiftTests/DataImportTests.swift +++ b/Tests/JExtractSwiftTests/DataImportTests.swift @@ -510,12 +510,9 @@ final class DataImportTests { input: text, .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024acceptData__J") public func Java_com_example_swift_SwiftModule__00024acceptData__J(environment: UnsafeMutablePointer!, thisClass: jclass, data: jlong) { """ @@ -547,9 +544,6 @@ final class DataImportTests { .swift, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024returnData__") public func Java_com_example_swift_SwiftModule__00024returnData__(environment: UnsafeMutablePointer!, thisClass: jclass) -> jlong { """ diff --git a/Tests/JExtractSwiftTests/DateTests.swift b/Tests/JExtractSwiftTests/DateTests.swift index 85f2e9b8..bf5e9ef8 100644 --- a/Tests/JExtractSwiftTests/DateTests.swift +++ b/Tests/JExtractSwiftTests/DateTests.swift @@ -33,9 +33,6 @@ struct DateTests { /* expected Swift chunks */ [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024acceptDate__J") public func Java_com_example_swift_SwiftModule__00024acceptDate__J(environment: UnsafeMutablePointer!, thisClass: jclass, date: jlong) { """ @@ -86,9 +83,6 @@ struct DateTests { /* expected Swift chunks */ [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024returnDate__") public func Java_com_example_swift_SwiftModule__00024returnDate__(environment: UnsafeMutablePointer!, thisClass: jclass) -> jlong { """ @@ -148,16 +142,10 @@ struct DateTests { /* expected Swift chunks */ [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_Date__00024init__D") public func Java_com_example_swift_Date__00024init__D(environment: UnsafeMutablePointer!, thisClass: jclass, timeIntervalSince1970: jdouble) -> jlong { """, """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_Date__00024getTimeIntervalSince1970__J") public func Java_com_example_swift_Date__00024getTimeIntervalSince1970__J(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong) -> jdouble { """, diff --git a/Tests/JExtractSwiftTests/JNI/JNIArrayTest.swift b/Tests/JExtractSwiftTests/JNI/JNIArrayTest.swift index 48f2ebe9..0689ca9d 100644 --- a/Tests/JExtractSwiftTests/JNI/JNIArrayTest.swift +++ b/Tests/JExtractSwiftTests/JNI/JNIArrayTest.swift @@ -44,12 +44,9 @@ struct JNIArrayTest { input: "public func f(array: Array) -> Array {}", .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024f___3B") public func Java_com_example_swift_SwiftModule__00024f___3B(environment: UnsafeMutablePointer!, thisClass: jclass, array: jbyteArray?) -> jbyteArray? { return SwiftModule.f(array: [UInt8](fromJNI: array, in: environment)).getJNILocalRefValue(in: environment) @@ -85,12 +82,9 @@ struct JNIArrayTest { input: "public func f(array: [UInt8]) -> [UInt8] {}", .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024f___3B") public func Java_com_example_swift_SwiftModule__00024f___3B(environment: UnsafeMutablePointer!, thisClass: jclass, array: jbyteArray?) -> jbyteArray? { return SwiftModule.f(array: [UInt8](fromJNI: array, in: environment)).getJNILocalRefValue(in: environment) @@ -126,12 +120,9 @@ struct JNIArrayTest { input: "public func f(array: [Int64]) -> [Int64] {}", .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024f___3J") public func Java_com_example_swift_SwiftModule__00024f___3J(environment: UnsafeMutablePointer!, thisClass: jclass, array: jlongArray?) -> jlongArray? { return SwiftModule.f(array: [Int64](fromJNI: array, in: environment)).getJNILocalRefValue(in: environment) @@ -176,12 +167,9 @@ struct JNIArrayTest { """, .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024f___3J") public func Java_com_example_swift_SwiftModule__00024f___3J(environment: UnsafeMutablePointer!, thisClass: jclass, array: jlongArray?) -> jlongArray? { return SwiftModule.f(array: [Int64](fromJNI: array, in: environment).map( { (pointer$) in diff --git a/Tests/JExtractSwiftTests/JNI/JNIAsyncTests.swift b/Tests/JExtractSwiftTests/JNI/JNIAsyncTests.swift index 21da814b..b7b4a41a 100644 --- a/Tests/JExtractSwiftTests/JNI/JNIAsyncTests.swift +++ b/Tests/JExtractSwiftTests/JNI/JNIAsyncTests.swift @@ -25,7 +25,7 @@ struct JNIAsyncTests { input: "public func asyncVoid() async", .jni, .java, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 2, expectedChunks: [ """ /** @@ -56,12 +56,9 @@ struct JNIAsyncTests { input: "public func asyncVoid() async", .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024asyncVoid__Ljava_util_concurrent_CompletableFuture_2") public func Java_com_example_swift_SwiftModule__00024asyncVoid__Ljava_util_concurrent_CompletableFuture_2(environment: UnsafeMutablePointer!, thisClass: jclass, result_future: jobject?) { let globalFuture = environment.interface.NewGlobalRef(environment, result_future) @@ -104,7 +101,7 @@ struct JNIAsyncTests { input: "public func async() async throws", .jni, .java, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 2, expectedChunks: [ """ /** @@ -135,12 +132,9 @@ struct JNIAsyncTests { input: "public func async() async throws", .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024async__Ljava_util_concurrent_CompletableFuture_2") public func Java_com_example_swift_SwiftModule__00024async__Ljava_util_concurrent_CompletableFuture_2(environment: UnsafeMutablePointer!, thisClass: jclass, result_future: jobject?) { let globalFuture = environment.interface.NewGlobalRef(environment, result_future) @@ -197,7 +191,7 @@ struct JNIAsyncTests { input: "public func async(i: Int64) async -> Int64", .jni, .java, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 2, expectedChunks: [ """ /** @@ -228,12 +222,9 @@ struct JNIAsyncTests { input: "public func async(i: Int64) async -> Int64", .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024async__JLjava_util_concurrent_CompletableFuture_2") public func Java_com_example_swift_SwiftModule__00024async__JLjava_util_concurrent_CompletableFuture_2(environment: UnsafeMutablePointer!, thisClass: jclass, i: jlong, result_future: jobject?) { let globalFuture = environment.interface.NewGlobalRef(environment, result_future) @@ -283,7 +274,7 @@ struct JNIAsyncTests { """, .jni, .java, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 2, expectedChunks: [ """ /** @@ -318,12 +309,9 @@ struct JNIAsyncTests { """, .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024async__JLjava_util_concurrent_CompletableFuture_2") public func Java_com_example_swift_SwiftModule__00024async__JLjava_util_concurrent_CompletableFuture_2(environment: UnsafeMutablePointer!, thisClass: jclass, c: jlong, result_future: jobject?) { assert(c != 0, "c memory address was null") @@ -383,7 +371,7 @@ struct JNIAsyncTests { """, .jni, .java, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 2, expectedChunks: [ """ public static java.util.concurrent.CompletableFuture async(java.lang.String s) { @@ -410,12 +398,9 @@ struct JNIAsyncTests { """, .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024async__Ljava_lang_String_2Ljava_util_concurrent_CompletableFuture_2") public func Java_com_example_swift_SwiftModule__00024async__Ljava_lang_String_2Ljava_util_concurrent_CompletableFuture_2(environment: UnsafeMutablePointer!, thisClass: jclass, s: jstring?, result_future: jobject?) { let s = environment.interface.NewGlobalRef(environment, s) @@ -449,7 +434,7 @@ struct JNIAsyncTests { config: config, .jni, .java, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ public static java.util.concurrent.Future async(MyClass c, SwiftArena swiftArena) { @@ -482,12 +467,9 @@ struct JNIAsyncTests { config: config, .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024async__JLorg_swift_swiftkit_core_SimpleCompletableFuture_2") public func Java_com_example_swift_SwiftModule__00024async__JLorg_swift_swiftkit_core_SimpleCompletableFuture_2(environment: UnsafeMutablePointer!, thisClass: jclass, c: jlong, result_future: jobject?) { ... diff --git a/Tests/JExtractSwiftTests/JNI/JNIClassTests.swift b/Tests/JExtractSwiftTests/JNI/JNIClassTests.swift index b08fc8df..05d764ea 100644 --- a/Tests/JExtractSwiftTests/JNI/JNIClassTests.swift +++ b/Tests/JExtractSwiftTests/JNI/JNIClassTests.swift @@ -157,12 +157,9 @@ struct JNIClassTests { input: source, .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_MyClass__00024method__") public func Java_com_example_swift_MyClass__00024method__(environment: UnsafeMutablePointer!, thisClass: jclass) { MyClass.method() @@ -217,12 +214,9 @@ struct JNIClassTests { input: source, .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_MyClass__00024init__JJ") public func Java_com_example_swift_MyClass__00024init__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, x: jlong, y: jlong) -> jlong { let result$ = UnsafeMutablePointer.allocate(capacity: 1) @@ -232,9 +226,6 @@ struct JNIClassTests { } """, """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_MyClass__00024init__") public func Java_com_example_swift_MyClass__00024init__(environment: UnsafeMutablePointer!, thisClass: jclass) -> jlong { let result$ = UnsafeMutablePointer.allocate(capacity: 1) @@ -278,12 +269,9 @@ struct JNIClassTests { input: source, .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_MyClass__00024doSomething__JJ") public func Java_com_example_swift_MyClass__00024doSomething__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, x: jlong, selfPointer: jlong) { assert(selfPointer != 0, "selfPointer memory address was null") @@ -330,12 +318,9 @@ struct JNIClassTests { input: source, .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_MyClass__00024copy__J") public func Java_com_example_swift_MyClass__00024copy__J(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong) -> jlong { assert(selfPointer != 0, "selfPointer memory address was null") @@ -385,12 +370,9 @@ struct JNIClassTests { input: source, .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_MyClass__00024isEqual__JJ") public func Java_com_example_swift_MyClass__00024isEqual__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, other: jlong, selfPointer: jlong) -> jboolean { assert(other != 0, "other memory address was null") diff --git a/Tests/JExtractSwiftTests/JNI/JNIClosureTests.swift b/Tests/JExtractSwiftTests/JNI/JNIClosureTests.swift index dad2f565..841420d7 100644 --- a/Tests/JExtractSwiftTests/JNI/JNIClosureTests.swift +++ b/Tests/JExtractSwiftTests/JNI/JNIClosureTests.swift @@ -62,12 +62,9 @@ struct JNIClosureTests { input: source, .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024emptyClosure__Lcom_example_swift_SwiftModule_00024emptyClosure_00024closure_2") public func Java_com_example_swift_SwiftModule__00024emptyClosure__Lcom_example_swift_SwiftModule_00024emptyClosure_00024closure_2(environment: UnsafeMutablePointer!, thisClass: jclass, closure: jobject?) { SwiftModule.emptyClosure(closure: { @@ -123,12 +120,9 @@ struct JNIClosureTests { input: source, .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024closureWithArgumentsAndReturn__Lcom_example_swift_SwiftModule_00024closureWithArgumentsAndReturn_00024closure_2") public func Java_com_example_swift_SwiftModule__00024closureWithArgumentsAndReturn__Lcom_example_swift_SwiftModule_00024closureWithArgumentsAndReturn_00024closure_2(environment: UnsafeMutablePointer!, thisClass: jclass, closure: jobject?) { SwiftModule.closureWithArgumentsAndReturn(closure: { _0, _1 in diff --git a/Tests/JExtractSwiftTests/JNI/JNIDictionaryTest.swift b/Tests/JExtractSwiftTests/JNI/JNIDictionaryTest.swift index 258db9a4..c09bbaaa 100644 --- a/Tests/JExtractSwiftTests/JNI/JNIDictionaryTest.swift +++ b/Tests/JExtractSwiftTests/JNI/JNIDictionaryTest.swift @@ -44,12 +44,9 @@ struct JNIDictionaryTest { input: "public func f() -> [String: Int64] {}", .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024f__") public func Java_com_example_swift_SwiftModule__00024f__(environment: UnsafeMutablePointer!, thisClass: jclass) -> jlong { return SwiftModule.f().dictionaryGetJNIValue(in: environment) @@ -85,12 +82,9 @@ struct JNIDictionaryTest { input: "public func f(dict: [String: Int64]) {}", .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024f__J") public func Java_com_example_swift_SwiftModule__00024f__J(environment: UnsafeMutablePointer!, thisClass: jclass, dict: jlong) { SwiftModule.f(dict: [String: Int64](fromJNI: dict, in: environment)) @@ -126,12 +120,9 @@ struct JNIDictionaryTest { input: "public func f(dict: [String: Int64]) -> [String: Int64] {}", .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024f__J") public func Java_com_example_swift_SwiftModule__00024f__J(environment: UnsafeMutablePointer!, thisClass: jclass, dict: jlong) -> jlong { return SwiftModule.f(dict: [String: Int64](fromJNI: dict, in: environment)).dictionaryGetJNIValue(in: environment) @@ -167,12 +158,9 @@ struct JNIDictionaryTest { input: "public func f(dict: Dictionary) -> Dictionary {}", .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024f__J") public func Java_com_example_swift_SwiftModule__00024f__J(environment: UnsafeMutablePointer!, thisClass: jclass, dict: jlong) -> jlong { return SwiftModule.f(dict: [String: Int64](fromJNI: dict, in: environment)).dictionaryGetJNIValue(in: environment) @@ -282,12 +270,9 @@ struct JNIDictionaryTest { input: "public func f(a: [String: Int64], b: [String: Bool]) {}", .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024f__JJ") public func Java_com_example_swift_SwiftModule__00024f__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, a: jlong, b: jlong) { SwiftModule.f(a: [String: Int64](fromJNI: a, in: environment), b: [String: Bool](fromJNI: b, in: environment)) @@ -326,12 +311,9 @@ struct JNIDictionaryTest { input: "public func f(dict: [String: Int64], key: String, value: Int64) -> [String: Int64] {}", .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024f__JLjava_lang_String_2J") public func Java_com_example_swift_SwiftModule__00024f__JLjava_lang_String_2J(environment: UnsafeMutablePointer!, thisClass: jclass, dict: jlong, key: jstring?, value: jlong) -> jlong { return SwiftModule.f(dict: [String: Int64](fromJNI: dict, in: environment), key: String(fromJNI: key, in: environment), value: Int64(fromJNI: value, in: environment)).dictionaryGetJNIValue(in: environment) diff --git a/Tests/JExtractSwiftTests/JNI/JNIEnumTests.swift b/Tests/JExtractSwiftTests/JNI/JNIEnumTests.swift index 087daaeb..e09c215c 100644 --- a/Tests/JExtractSwiftTests/JNI/JNIEnumTests.swift +++ b/Tests/JExtractSwiftTests/JNI/JNIEnumTests.swift @@ -226,12 +226,9 @@ struct JNIEnumTests { input: source, .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_MyEnum__00024first__") public func Java_com_example_swift_MyEnum__00024first__(environment: UnsafeMutablePointer!, thisClass: jclass) -> jlong { let result$ = UnsafeMutablePointer.allocate(capacity: 1) @@ -241,9 +238,6 @@ struct JNIEnumTests { } """, """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_MyEnum__00024second__Ljava_lang_String_2") public func Java_com_example_swift_MyEnum__00024second__Ljava_lang_String_2(environment: UnsafeMutablePointer!, thisClass: jclass, arg0: jstring?) -> jlong { let result$ = UnsafeMutablePointer.allocate(capacity: 1) @@ -253,9 +247,6 @@ struct JNIEnumTests { } """, """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_MyEnum__00024third__JI") public func Java_com_example_swift_MyEnum__00024third__JI(environment: UnsafeMutablePointer!, thisClass: jclass, x: jlong, y: jint) -> jlong { let result$ = UnsafeMutablePointer.allocate(capacity: 1) @@ -312,12 +303,9 @@ struct JNIEnumTests { input: source, .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_MyEnum__00024getAsSecond__J") public func Java_com_example_swift_MyEnum__00024getAsSecond__J(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong) -> jobject? { ... @@ -333,9 +321,6 @@ struct JNIEnumTests { } """, """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_MyEnum__00024getAsThird__J") public func Java_com_example_swift_MyEnum__00024getAsThird__J(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong) -> jobject? { ... diff --git a/Tests/JExtractSwiftTests/JNI/JNIGenericTypeTests.swift b/Tests/JExtractSwiftTests/JNI/JNIGenericTypeTests.swift index 379746aa..cf5beded 100644 --- a/Tests/JExtractSwiftTests/JNI/JNIGenericTypeTests.swift +++ b/Tests/JExtractSwiftTests/JNI/JNIGenericTypeTests.swift @@ -129,20 +129,8 @@ struct JNIGenericTypeTests { } ... } - """# - ] - ) - - try assertOutput( - input: genericFile, - .jni, - .swift, - detectChunkByInitialLines: 4, - expectedChunks: [ + """#, """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_MyID__00024getDescription__JJ") public func Java_com_example_swift_MyID__00024getDescription__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong, selfTypePointer: jlong) -> jstring? { let selfTypePointerBits$ = Int(Int64(fromJNI: selfTypePointer, in: environment)) @@ -152,8 +140,8 @@ struct JNIGenericTypeTests { let openerType = unsafeBitCast(selfTypePointer$, to: Any.Type.self) as! (any _SwiftModule_MyID_opener.Type) return openerType._get_description(environment: environment, thisClass: thisClass, selfPointer: selfPointer) } - """ - ], + """, + ] ) } @@ -163,7 +151,7 @@ struct JNIGenericTypeTests { input: genericFile, .jni, .java, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 2, expectedChunks: [ """ public static MyID makeStringID(java.lang.String value, SwiftArena swiftArena) { @@ -193,12 +181,9 @@ struct JNIGenericTypeTests { input: genericFile, .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 2, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024makeStringID__Ljava_lang_String_2Lorg_swift_swiftkit_core__1OutSwiftGenericInstance_2") public func Java_com_example_swift_SwiftModule__00024makeStringID__Ljava_lang_String_2Lorg_swift_swiftkit_core__1OutSwiftGenericInstance_2(environment: UnsafeMutablePointer!, thisClass: jclass, value: jstring?, out: jobject?) { let result$ = UnsafeMutablePointer>.allocate(capacity: 1) diff --git a/Tests/JExtractSwiftTests/JNI/JNIIntConversionChecksTests.swift b/Tests/JExtractSwiftTests/JNI/JNIIntConversionChecksTests.swift index 85cc5fc8..aaa24e97 100644 --- a/Tests/JExtractSwiftTests/JNI/JNIIntConversionChecksTests.swift +++ b/Tests/JExtractSwiftTests/JNI/JNIIntConversionChecksTests.swift @@ -63,9 +63,6 @@ struct JNIIntConversionChecksTests { .swift, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_MyStruct__00024init__J") public func Java_com_example_swift_MyStruct__00024init__J(environment: UnsafeMutablePointer!, thisClass: jclass, normalInt: jlong) -> jlong { let normalInt$indirect = Int64(fromJNI: normalInt, in: environment) @@ -92,9 +89,6 @@ struct JNIIntConversionChecksTests { .swift, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_MyStruct__00024init__J") public func Java_com_example_swift_MyStruct__00024init__J(environment: UnsafeMutablePointer!, thisClass: jclass, unsignedInt: jlong) -> jlong { let unsignedInt$indirect = UInt64(fromJNI: unsignedInt, in: environment) @@ -121,9 +115,6 @@ struct JNIIntConversionChecksTests { .swift, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_MyStruct__00024setUnsignedInt__JJ") public func Java_com_example_swift_MyStruct__00024setUnsignedInt__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, newValue: jlong, selfPointer: jlong) { let newValue$indirect = UInt64(fromJNI: newValue, in: environment) @@ -153,9 +144,6 @@ struct JNIIntConversionChecksTests { .swift, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_MyStruct__00024getUnsignedInt__J") public func Java_com_example_swift_MyStruct__00024getUnsignedInt__J(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong) -> jlong { assert(selfPointer != 0, "selfPointer memory address was null") @@ -177,9 +165,6 @@ struct JNIIntConversionChecksTests { .swift, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_MyStruct__00024setNormalInt__JJ") public func Java_com_example_swift_MyStruct__00024setNormalInt__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, newValue: jlong, selfPointer: jlong) { let newValue$indirect = Int64(fromJNI: newValue, in: environment) @@ -209,9 +194,6 @@ struct JNIIntConversionChecksTests { .swift, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_MyStruct__00024dummyFunc__JJ") public func Java_com_example_swift_MyStruct__00024dummyFunc__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, arg: jlong, selfPointer: jlong) -> jlong { let arg$indirect = Int64(fromJNI: arg, in: environment) @@ -241,9 +223,6 @@ struct JNIIntConversionChecksTests { .swift, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_MyStruct__00024dummyFunc__JJ") public func Java_com_example_swift_MyStruct__00024dummyFunc__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, arg: jlong, selfPointer: jlong) -> jlong { let arg$indirect = UInt64(fromJNI: arg, in: environment) @@ -272,9 +251,6 @@ struct JNIIntConversionChecksTests { .swift, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_MyEnum__00024secondCase__J") public func Java_com_example_swift_MyEnum__00024secondCase__J(environment: UnsafeMutablePointer!, thisClass: jclass, arg0: jlong) -> jlong { let arg0$indirect = UInt64(fromJNI: arg0, in: environment) diff --git a/Tests/JExtractSwiftTests/JNI/JNIJavaKitTests.swift b/Tests/JExtractSwiftTests/JNI/JNIJavaKitTests.swift index 631e1063..f66e454c 100644 --- a/Tests/JExtractSwiftTests/JNI/JNIJavaKitTests.swift +++ b/Tests/JExtractSwiftTests/JNI/JNIJavaKitTests.swift @@ -59,13 +59,10 @@ struct JNIJavaKitTests { input: source, .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, javaClassLookupTable: classLookupTable, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024function__Ljava_lang_Long_2Ljava_lang_Integer_2J") public func Java_com_example_swift_SwiftModule__00024function__Ljava_lang_Long_2Ljava_lang_Integer_2J(environment: UnsafeMutablePointer!, thisClass: jclass, javaLong: jobject?, javaInteger: jobject?, int: jlong) { guard let javaLong_unwrapped$ = javaLong else { diff --git a/Tests/JExtractSwiftTests/JNI/JNIModuleTests.swift b/Tests/JExtractSwiftTests/JNI/JNIModuleTests.swift index 5e40e3f5..0b6b4870 100644 --- a/Tests/JExtractSwiftTests/JNI/JNIModuleTests.swift +++ b/Tests/JExtractSwiftTests/JNI/JNIModuleTests.swift @@ -127,30 +127,21 @@ struct JNIModuleTests { input: globalMethodWithPrimitives, .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024helloWorld__") public func Java_com_example_swift_SwiftModule__00024helloWorld__(environment: UnsafeMutablePointer!, thisClass: jclass) { SwiftModule.helloWorld() } """, """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024takeIntegers__BSIJ") public func Java_com_example_swift_SwiftModule__00024takeIntegers__BSIJ(environment: UnsafeMutablePointer!, thisClass: jclass, i1: jbyte, i2: jshort, i3: jint, i4: jlong) -> jchar { return SwiftModule.takeIntegers(i1: Int8(fromJNI: i1, in: environment), i2: Int16(fromJNI: i2, in: environment), i3: Int32(fromJNI: i3, in: environment), i4: Int64(fromJNI: i4, in: environment)).getJNILocalRefValue(in: environment) } """, """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024otherPrimitives__ZFD") public func Java_com_example_swift_SwiftModule__00024otherPrimitives__ZFD(environment: UnsafeMutablePointer!, thisClass: jclass, b: jboolean, f: jfloat, d: jdouble) { SwiftModule.otherPrimitives(b: Bool(fromJNI: b, in: environment), f: Float(fromJNI: f, in: environment), d: Double(fromJNI: d, in: environment)) @@ -191,12 +182,9 @@ struct JNIModuleTests { input: globalMethodWithString, .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024copy__Ljava_lang_String_2") public func Java_com_example_swift_SwiftModule__00024copy__Ljava_lang_String_2(environment: UnsafeMutablePointer!, thisClass: jclass, string: jstring?) -> jstring? { return SwiftModule.copy(String(fromJNI: string, in: environment)).getJNILocalRefValue(in: environment) @@ -251,12 +239,9 @@ struct JNIModuleTests { input: globalMethodThrowing, .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024methodA__") public func Java_com_example_swift_SwiftModule__00024methodA__(environment: UnsafeMutablePointer!, thisClass: jclass) { do { @@ -268,9 +253,6 @@ struct JNIModuleTests { } """, """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024methodB__") public func Java_com_example_swift_SwiftModule__00024methodB__(environment: UnsafeMutablePointer!, thisClass: jclass) -> jlong { do { @@ -282,9 +264,6 @@ struct JNIModuleTests { } """, """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024methodC__") public func Java_com_example_swift_SwiftModule__00024methodC__(environment: UnsafeMutablePointer!, thisClass: jclass) -> jstring? { do { diff --git a/Tests/JExtractSwiftTests/JNI/JNINestedTypesTests.swift b/Tests/JExtractSwiftTests/JNI/JNINestedTypesTests.swift index 03473cd9..159e496e 100644 --- a/Tests/JExtractSwiftTests/JNI/JNINestedTypesTests.swift +++ b/Tests/JExtractSwiftTests/JNI/JNINestedTypesTests.swift @@ -72,39 +72,27 @@ struct JNINestedTypesTests { input: source1, .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_A__00024typeMetadataAddressDowncall__") public func Java_com_example_swift_A__00024typeMetadataAddressDowncall__(environment: UnsafeMutablePointer!, thisClass: jclass) -> jlong { ... } """, """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_A_00024B__00024typeMetadataAddressDowncall__") public func Java_com_example_swift_A_00024B__00024typeMetadataAddressDowncall__(environment: UnsafeMutablePointer!, thisClass: jclass) -> jlong { ... } """, """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_A_00024B_00024C__00024typeMetadataAddressDowncall__") public func Java_com_example_swift_A_00024B_00024C__00024typeMetadataAddressDowncall__(environment: UnsafeMutablePointer!, thisClass: jclass) -> jlong { ... } """, """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_A_00024B_00024C__00024h__JJ") public func Java_com_example_swift_A_00024B_00024C__00024h__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, b: jlong, selfPointer: jlong) { ... diff --git a/Tests/JExtractSwiftTests/JNI/JNIOptionalTests.swift b/Tests/JExtractSwiftTests/JNI/JNIOptionalTests.swift index c3156d5d..90702944 100644 --- a/Tests/JExtractSwiftTests/JNI/JNIOptionalTests.swift +++ b/Tests/JExtractSwiftTests/JNI/JNIOptionalTests.swift @@ -66,13 +66,10 @@ struct JNIOptionalTests { input: source, .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, javaClassLookupTable: classLookupTable, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024optionalSugar__BJ") public func Java_com_example_swift_SwiftModule__00024optionalSugar__BJ(environment: UnsafeMutablePointer!, thisClass: jclass, arg_discriminator: jbyte, arg_value: jlong) -> jlong { let result_value$ = SwiftModule.optionalSugar(arg_discriminator == 1 ? Int64(fromJNI: arg_value, in: environment) : nil).map { @@ -119,13 +116,10 @@ struct JNIOptionalTests { input: source, .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, javaClassLookupTable: classLookupTable, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024optionalExplicit__BLjava_lang_String_2_3B") public func Java_com_example_swift_SwiftModule__00024optionalExplicit__BLjava_lang_String_2_3B(environment: UnsafeMutablePointer!, thisClass: jclass, arg_discriminator: jbyte, arg_value: jstring?, result_discriminator$: jbyteArray?) -> jstring? { let result$: jstring? @@ -180,13 +174,10 @@ struct JNIOptionalTests { input: source, .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, javaClassLookupTable: classLookupTable, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024optionalClass__J_3B") public func Java_com_example_swift_SwiftModule__00024optionalClass__J_3B(environment: UnsafeMutablePointer!, thisClass: jclass, arg: jlong, result_discriminator$: jbyteArray?) -> jlong { let argBits$ = Int(Int64(fromJNI: arg, in: environment)) @@ -244,13 +235,10 @@ struct JNIOptionalTests { input: source, .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, javaClassLookupTable: classLookupTable, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024optionalJavaKitClass__Ljava_lang_Long_2") public func Java_com_example_swift_SwiftModule__00024optionalJavaKitClass__Ljava_lang_Long_2(environment: UnsafeMutablePointer!, thisClass: jclass, arg: jobject?) { SwiftModule.optionalJavaKitClass(arg.map { diff --git a/Tests/JExtractSwiftTests/JNI/JNIProtocolTests.swift b/Tests/JExtractSwiftTests/JNI/JNIProtocolTests.swift index 5b4e31af..526c8967 100644 --- a/Tests/JExtractSwiftTests/JNI/JNIProtocolTests.swift +++ b/Tests/JExtractSwiftTests/JNI/JNIProtocolTests.swift @@ -131,9 +131,6 @@ struct JNIProtocolTests { } """, """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024takeProtocol__Ljava_lang_Object_2Ljava_lang_Object_2") public func Java_com_example_swift_SwiftModule__00024takeProtocol__Ljava_lang_Object_2Ljava_lang_Object_2(environment: UnsafeMutablePointer!, thisClass: jclass, x: jobject?, y: jobject?) { let xswiftObject$: (SomeProtocol) @@ -199,7 +196,7 @@ struct JNIProtocolTests { config: config, .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ final class _SwiftModule_takeGeneric_s_Wrapper: SwiftJavaSomeProtocolWrapper { @@ -210,9 +207,6 @@ struct JNIProtocolTests { } """, """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024takeGeneric__Ljava_lang_Object_2") public func Java_com_example_swift_SwiftModule__00024takeGeneric__Ljava_lang_Object_2(environment: UnsafeMutablePointer!, thisClass: jclass, s: jobject?) { let sswiftObject$: (SomeProtocol) @@ -258,7 +252,7 @@ struct JNIProtocolTests { config: config, .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ final class _SwiftModule_takeComposite_x_Wrapper: SwiftJavaSomeProtocolWrapper, SwiftJavaBWrapper { @@ -271,9 +265,6 @@ struct JNIProtocolTests { } """, """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024takeComposite__Ljava_lang_Object_2") public func Java_com_example_swift_SwiftModule__00024takeComposite__Ljava_lang_Object_2(environment: UnsafeMutablePointer!, thisClass: jclass, x: jobject?) { let xswiftObject$: (SomeProtocol & B) diff --git a/Tests/JExtractSwiftTests/JNI/JNISetTest.swift b/Tests/JExtractSwiftTests/JNI/JNISetTest.swift index e6b63ec3..4a70fdcd 100644 --- a/Tests/JExtractSwiftTests/JNI/JNISetTest.swift +++ b/Tests/JExtractSwiftTests/JNI/JNISetTest.swift @@ -44,12 +44,9 @@ struct JNISetTest { input: "public func f() -> Set {}", .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024f__") public func Java_com_example_swift_SwiftModule__00024f__(environment: UnsafeMutablePointer!, thisClass: jclass) -> jlong { return SwiftModule.f().setGetJNIValue(in: environment) @@ -85,12 +82,9 @@ struct JNISetTest { input: "public func f(set: Set) {}", .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024f__J") public func Java_com_example_swift_SwiftModule__00024f__J(environment: UnsafeMutablePointer!, thisClass: jclass, set: jlong) { SwiftModule.f(set: Set(fromJNI: set, in: environment)) @@ -126,12 +120,9 @@ struct JNISetTest { input: "public func f(set: Set) -> Set {}", .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024f__J") public func Java_com_example_swift_SwiftModule__00024f__J(environment: UnsafeMutablePointer!, thisClass: jclass, set: jlong) -> jlong { return SwiftModule.f(set: Set(fromJNI: set, in: environment)).setGetJNIValue(in: environment) @@ -224,12 +215,9 @@ struct JNISetTest { input: "public func f(a: Set, b: Set) {}", .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024f__JJ") public func Java_com_example_swift_SwiftModule__00024f__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, a: jlong, b: jlong) { SwiftModule.f(a: Set(fromJNI: a, in: environment), b: Set(fromJNI: b, in: environment)) @@ -268,12 +256,9 @@ struct JNISetTest { input: "public func f(set: Set, element: String) -> Set {}", .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024f__JLjava_lang_String_2") public func Java_com_example_swift_SwiftModule__00024f__JLjava_lang_String_2(environment: UnsafeMutablePointer!, thisClass: jclass, set: jlong, element: jstring?) -> jlong { return SwiftModule.f(set: Set(fromJNI: set, in: environment), element: String(fromJNI: element, in: environment)).setGetJNIValue(in: environment) diff --git a/Tests/JExtractSwiftTests/JNI/JNIStructTests.swift b/Tests/JExtractSwiftTests/JNI/JNIStructTests.swift index 58970cd4..e7a5cb80 100644 --- a/Tests/JExtractSwiftTests/JNI/JNIStructTests.swift +++ b/Tests/JExtractSwiftTests/JNI/JNIStructTests.swift @@ -143,12 +143,9 @@ struct JNIStructTests { input: source, .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_MyStruct__00024init__JJ") public func Java_com_example_swift_MyStruct__00024init__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, x: jlong, y: jlong) -> jlong { let result$ = UnsafeMutablePointer.allocate(capacity: 1) @@ -192,12 +189,9 @@ struct JNIStructTests { input: source, .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_MyStruct__00024doSomething__JJ") public func Java_com_example_swift_MyStruct__00024doSomething__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, x: jlong, selfPointer: jlong) { assert(selfPointer != 0, "selfPointer memory address was null") diff --git a/Tests/JExtractSwiftTests/JNI/JNISubscriptsTests.swift b/Tests/JExtractSwiftTests/JNI/JNISubscriptsTests.swift index bebbc1cc..8ad07564 100644 --- a/Tests/JExtractSwiftTests/JNI/JNISubscriptsTests.swift +++ b/Tests/JExtractSwiftTests/JNI/JNISubscriptsTests.swift @@ -98,9 +98,6 @@ struct JNISubscriptsTests { .swift, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_MyStruct__00024getSubscript__J") public func Java_com_example_swift_MyStruct__00024getSubscript__J(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong) -> jdouble { assert(selfPointer != 0, "selfPointer memory address was null") @@ -112,9 +109,6 @@ struct JNISubscriptsTests { return selfPointer$.pointee[].getJNILocalRefValue(in: environment) """, """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_MyStruct__00024setSubscript__DJ") public func Java_com_example_swift_MyStruct__00024setSubscript__DJ(environment: UnsafeMutablePointer!, thisClass: jclass, newValue: jdouble, selfPointer: jlong) { assert(selfPointer != 0, "selfPointer memory address was null") @@ -137,9 +131,6 @@ struct JNISubscriptsTests { .swift, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_MyStruct__00024getSubscript__IJ") public func Java_com_example_swift_MyStruct__00024getSubscript__IJ(environment: UnsafeMutablePointer!, thisClass: jclass, index: jint, selfPointer: jlong) -> jint { assert(selfPointer != 0, "selfPointer memory address was null") @@ -151,9 +142,6 @@ struct JNISubscriptsTests { return selfPointer$.pointee[Int32(fromJNI: index, in: environment)].getJNILocalRefValue(in: environment) """, """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_MyStruct__00024setSubscript__IIJ") public func Java_com_example_swift_MyStruct__00024setSubscript__IIJ(environment: UnsafeMutablePointer!, thisClass: jclass, index: jint, newValue: jint, selfPointer: jlong) { assert(selfPointer != 0, "selfPointer memory address was null") diff --git a/Tests/JExtractSwiftTests/JNI/JNIVariablesTests.swift b/Tests/JExtractSwiftTests/JNI/JNIVariablesTests.swift index 28cee921..6f13c463 100644 --- a/Tests/JExtractSwiftTests/JNI/JNIVariablesTests.swift +++ b/Tests/JExtractSwiftTests/JNI/JNIVariablesTests.swift @@ -69,12 +69,9 @@ struct JNIVariablesTests { input: membersSource, .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_MyClass__00024getConstant__J") public func Java_com_example_swift_MyClass__00024getConstant__J(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong) -> jlong { ... @@ -131,12 +128,9 @@ struct JNIVariablesTests { input: membersSource, .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_MyClass__00024getMutable__J") public func Java_com_example_swift_MyClass__00024getMutable__J(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong) -> jlong { assert(selfPointer != 0, "selfPointer memory address was null") @@ -150,9 +144,6 @@ struct JNIVariablesTests { } """, """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_MyClass__00024setMutable__JJ") public func Java_com_example_swift_MyClass__00024setMutable__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, newValue: jlong, selfPointer: jlong) { assert(selfPointer != 0, "selfPointer memory address was null") @@ -196,12 +187,9 @@ struct JNIVariablesTests { input: membersSource, .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_MyClass__00024getComputed__J") public func Java_com_example_swift_MyClass__00024getComputed__J(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong) -> jlong { ... @@ -244,12 +232,9 @@ struct JNIVariablesTests { input: membersSource, .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_MyClass__00024getComputedThrowing__J") public func Java_com_example_swift_MyClass__00024getComputedThrowing__J(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong) -> jlong { ... @@ -311,12 +296,9 @@ struct JNIVariablesTests { input: membersSource, .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_MyClass__00024getGetterAndSetter__J") public func Java_com_example_swift_MyClass__00024getGetterAndSetter__J(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong) -> jlong { ... @@ -324,9 +306,6 @@ struct JNIVariablesTests { } """, """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_MyClass__00024setGetterAndSetter__JJ") public func Java_com_example_swift_MyClass__00024setGetterAndSetter__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, newValue: jlong, selfPointer: jlong) { ... @@ -383,12 +362,9 @@ struct JNIVariablesTests { input: membersSource, .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_MyClass__00024isSomeBoolean__J") public func Java_com_example_swift_MyClass__00024isSomeBoolean__J(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong) -> jboolean { ... @@ -396,9 +372,6 @@ struct JNIVariablesTests { } """, """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_MyClass__00024setSomeBoolean__ZJ") public func Java_com_example_swift_MyClass__00024setSomeBoolean__ZJ(environment: UnsafeMutablePointer!, thisClass: jclass, newValue: jboolean, selfPointer: jlong) { ... @@ -455,12 +428,9 @@ struct JNIVariablesTests { input: membersSource, .jni, .swift, - detectChunkByInitialLines: 4, + detectChunkByInitialLines: 1, expectedChunks: [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_MyClass__00024isBoolean__J") public func Java_com_example_swift_MyClass__00024isBoolean__J(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong) -> jboolean { ... @@ -468,9 +438,6 @@ struct JNIVariablesTests { } """, """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_MyClass__00024setBoolean__ZJ") public func Java_com_example_swift_MyClass__00024setBoolean__ZJ(environment: UnsafeMutablePointer!, thisClass: jclass, newValue: jboolean, selfPointer: jlong) { ... diff --git a/Tests/JExtractSwiftTests/UUIDTests.swift b/Tests/JExtractSwiftTests/UUIDTests.swift index d4f96e9f..1fa3fdfb 100644 --- a/Tests/JExtractSwiftTests/UUIDTests.swift +++ b/Tests/JExtractSwiftTests/UUIDTests.swift @@ -33,9 +33,6 @@ struct UUIDTests { /* expected Swift chunks */ [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024acceptUUID__Ljava_lang_String_2") public func Java_com_example_swift_SwiftModule__00024acceptUUID__Ljava_lang_String_2(environment: UnsafeMutablePointer!, thisClass: jclass, uuid: jstring?) { let uuid_string$ = String(fromJNI: uuid, in: environment) @@ -94,9 +91,6 @@ struct UUIDTests { /* expected Swift chunks */ [ """ - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_swift_SwiftModule__00024returnUUID__") public func Java_com_example_swift_SwiftModule__00024returnUUID__(environment: UnsafeMutablePointer!, thisClass: jclass) -> jstring? { return SwiftModule.returnUUID().uuidString.getJNILocalRefValue(in: environment) diff --git a/Tests/SwiftJavaMacrosTests/JavaImplementationMacroTests.swift b/Tests/SwiftJavaMacrosTests/JavaImplementationMacroTests.swift index de51cabf..2019acd6 100644 --- a/Tests/SwiftJavaMacrosTests/JavaImplementationMacroTests.swift +++ b/Tests/SwiftJavaMacrosTests/JavaImplementationMacroTests.swift @@ -44,11 +44,8 @@ class JavaImplementationMacroTests: XCTestCase { } } - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_org_swift_example_Hello_1World_test_1method") - public func __macro_local_11test_methodfMu_(environment: UnsafeMutablePointer!, thisObj: jobject) -> Int32.JNIType { + func __macro_local_11test_methodfMu_(environment: UnsafeMutablePointer!, thisObj: jobject) -> Int32.JNIType { let obj = HelloWorld(javaThis: thisObj, environment: environment!) return obj.test_method() .getJNILocalRefValue(in: environment) @@ -77,11 +74,8 @@ class JavaImplementationMacroTests: XCTestCase { } } - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_com_example_test_MyClass_simpleMethod") - public func __macro_local_12simpleMethodfMu_(environment: UnsafeMutablePointer!, thisObj: jobject) -> Int32.JNIType { + func __macro_local_12simpleMethodfMu_(environment: UnsafeMutablePointer!, thisObj: jobject) -> Int32.JNIType { let obj = MyClass(javaThis: thisObj, environment: environment!) return obj.simpleMethod() .getJNILocalRefValue(in: environment) @@ -110,11 +104,8 @@ class JavaImplementationMacroTests: XCTestCase { } } - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_org_example_Utils_static_1helper") - public func __macro_local_13static_helperfMu_(environment: UnsafeMutablePointer!, thisClass: jclass) -> String.JNIType { + func __macro_local_13static_helperfMu_(environment: UnsafeMutablePointer!, thisClass: jclass) -> String.JNIType { return Utils.static_helper(environment: environment) .getJNILocalRefValue(in: environment) } @@ -150,21 +141,15 @@ class JavaImplementationMacroTests: XCTestCase { } } - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_test_Class_1With_1Underscores_method_1one") - public func __macro_local_10method_onefMu_(environment: UnsafeMutablePointer!, thisObj: jobject) -> Int32.JNIType { + func __macro_local_10method_onefMu_(environment: UnsafeMutablePointer!, thisObj: jobject) -> Int32.JNIType { let obj = ClassWithUnderscores(javaThis: thisObj, environment: environment!) return obj.method_one() .getJNILocalRefValue(in: environment) } - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_test_Class_1With_1Underscores_method_1two") - public func __macro_local_10method_twofMu_(environment: UnsafeMutablePointer!, thisObj: jobject) -> Int32.JNIType { + func __macro_local_10method_twofMu_(environment: UnsafeMutablePointer!, thisObj: jobject) -> Int32.JNIType { let obj = ClassWithUnderscores(javaThis: thisObj, environment: environment!) return obj.method_two() .getJNILocalRefValue(in: environment) @@ -201,20 +186,14 @@ class JavaImplementationMacroTests: XCTestCase { } } - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_org_swift_swiftkit_core_collections_SwiftDictionaryMap__00024size") - public func __macro_local_5_sizefMu_(environment: UnsafeMutablePointer!, thisClass: jclass, pointer: Int64.JNIType) -> Int32.JNIType { + func __macro_local_5_sizefMu_(environment: UnsafeMutablePointer!, thisClass: jclass, pointer: Int64.JNIType) -> Int32.JNIType { return SwiftDictionaryMapJava._size(environment: environment, pointer: Int64(fromJNI: pointer, in: environment!)) .getJNILocalRefValue(in: environment) } - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_org_swift_swiftkit_core_collections_SwiftDictionaryMap__00024destroy") - public func __macro_local_8_destroyfMu_(environment: UnsafeMutablePointer!, thisClass: jclass, pointer: Int64.JNIType) { + func __macro_local_8_destroyfMu_(environment: UnsafeMutablePointer!, thisClass: jclass, pointer: Int64.JNIType) { return SwiftDictionaryMapJava._destroy(environment: environment, pointer: Int64(fromJNI: pointer, in: environment!)) } """, @@ -241,11 +220,8 @@ class JavaImplementationMacroTests: XCTestCase { } } - #if compiler(>=6.3) - @used - #endif @_cdecl("Java_org_example_Processor_process_1data") - public func __macro_local_12process_datafMu_(environment: UnsafeMutablePointer!, thisObj: jobject) { + func __macro_local_12process_datafMu_(environment: UnsafeMutablePointer!, thisObj: jobject) { let obj = Processor(javaThis: thisObj, environment: environment!) return obj.process_data() } From 8268ff3939ef1bd870b5be9c4ae255cf31ea2e32 Mon Sep 17 00:00:00 2001 From: Mads Odgaard Date: Sat, 28 Mar 2026 14:13:48 +0100 Subject: [PATCH 5/6] add explicit test --- .../JNI/JNICDeclAttributesTests.swift | 56 +++++++++++++++++++ .../JavaImplementationMacroTests.swift | 44 +++++++++++---- 2 files changed, 90 insertions(+), 10 deletions(-) create mode 100644 Tests/JExtractSwiftTests/JNI/JNICDeclAttributesTests.swift diff --git a/Tests/JExtractSwiftTests/JNI/JNICDeclAttributesTests.swift b/Tests/JExtractSwiftTests/JNI/JNICDeclAttributesTests.swift new file mode 100644 index 00000000..9ac42d5a --- /dev/null +++ b/Tests/JExtractSwiftTests/JNI/JNICDeclAttributesTests.swift @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2026 Apple Inc. and the Swift.org project authors +// Licensed under Apache License v2.0 +// +// See LICENSE.txt for license information +// See CONTRIBUTORS.txt for the list of Swift.org project authors +// +// SPDX-License-Identifier: Apache-2.0 +// +//===----------------------------------------------------------------------===// + +import JExtractSwiftLib +import Testing + +@Suite +struct JNICDeclAttributesTests { + + @Test + func globalFunc_hasUsedAttribute() throws { + try assertOutput( + input: "public func hello()", + .jni, + .swift, + expectedChunks: [ + """ + #if compiler(>=6.3) + @used + #endif + @_cdecl("Java_com_example_swift_SwiftModule__00024hello__") + ... + """ + ] + ) + } + + @Test + func globalFuncWithArgs_hasUsedAttribute() throws { + try assertOutput( + input: "public func add(a: Int64, b: Int64) -> Int64", + .jni, + .swift, + expectedChunks: [ + """ + #if compiler(>=6.3) + @used + #endif + @_cdecl("Java_com_example_swift_SwiftModule__00024add__JJ") + ... + """ + ] + ) + } +} diff --git a/Tests/SwiftJavaMacrosTests/JavaImplementationMacroTests.swift b/Tests/SwiftJavaMacrosTests/JavaImplementationMacroTests.swift index 2019acd6..43e88946 100644 --- a/Tests/SwiftJavaMacrosTests/JavaImplementationMacroTests.swift +++ b/Tests/SwiftJavaMacrosTests/JavaImplementationMacroTests.swift @@ -44,8 +44,11 @@ class JavaImplementationMacroTests: XCTestCase { } } + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_org_swift_example_Hello_1World_test_1method") - func __macro_local_11test_methodfMu_(environment: UnsafeMutablePointer!, thisObj: jobject) -> Int32.JNIType { + public func __macro_local_11test_methodfMu_(environment: UnsafeMutablePointer!, thisObj: jobject) -> Int32.JNIType { let obj = HelloWorld(javaThis: thisObj, environment: environment!) return obj.test_method() .getJNILocalRefValue(in: environment) @@ -74,8 +77,11 @@ class JavaImplementationMacroTests: XCTestCase { } } + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_com_example_test_MyClass_simpleMethod") - func __macro_local_12simpleMethodfMu_(environment: UnsafeMutablePointer!, thisObj: jobject) -> Int32.JNIType { + public func __macro_local_12simpleMethodfMu_(environment: UnsafeMutablePointer!, thisObj: jobject) -> Int32.JNIType { let obj = MyClass(javaThis: thisObj, environment: environment!) return obj.simpleMethod() .getJNILocalRefValue(in: environment) @@ -104,8 +110,11 @@ class JavaImplementationMacroTests: XCTestCase { } } + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_org_example_Utils_static_1helper") - func __macro_local_13static_helperfMu_(environment: UnsafeMutablePointer!, thisClass: jclass) -> String.JNIType { + public func __macro_local_13static_helperfMu_(environment: UnsafeMutablePointer!, thisClass: jclass) -> String.JNIType { return Utils.static_helper(environment: environment) .getJNILocalRefValue(in: environment) } @@ -141,15 +150,21 @@ class JavaImplementationMacroTests: XCTestCase { } } + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_test_Class_1With_1Underscores_method_1one") - func __macro_local_10method_onefMu_(environment: UnsafeMutablePointer!, thisObj: jobject) -> Int32.JNIType { + public func __macro_local_10method_onefMu_(environment: UnsafeMutablePointer!, thisObj: jobject) -> Int32.JNIType { let obj = ClassWithUnderscores(javaThis: thisObj, environment: environment!) return obj.method_one() .getJNILocalRefValue(in: environment) } + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_test_Class_1With_1Underscores_method_1two") - func __macro_local_10method_twofMu_(environment: UnsafeMutablePointer!, thisObj: jobject) -> Int32.JNIType { + public func __macro_local_10method_twofMu_(environment: UnsafeMutablePointer!, thisObj: jobject) -> Int32.JNIType { let obj = ClassWithUnderscores(javaThis: thisObj, environment: environment!) return obj.method_two() .getJNILocalRefValue(in: environment) @@ -185,15 +200,21 @@ class JavaImplementationMacroTests: XCTestCase { // cleanup } } - + + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_org_swift_swiftkit_core_collections_SwiftDictionaryMap__00024size") - func __macro_local_5_sizefMu_(environment: UnsafeMutablePointer!, thisClass: jclass, pointer: Int64.JNIType) -> Int32.JNIType { + public func __macro_local_5_sizefMu_(environment: UnsafeMutablePointer!, thisClass: jclass, pointer: Int64.JNIType) -> Int32.JNIType { return SwiftDictionaryMapJava._size(environment: environment, pointer: Int64(fromJNI: pointer, in: environment!)) .getJNILocalRefValue(in: environment) } - + + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_org_swift_swiftkit_core_collections_SwiftDictionaryMap__00024destroy") - func __macro_local_8_destroyfMu_(environment: UnsafeMutablePointer!, thisClass: jclass, pointer: Int64.JNIType) { + public func __macro_local_8_destroyfMu_(environment: UnsafeMutablePointer!, thisClass: jclass, pointer: Int64.JNIType) { return SwiftDictionaryMapJava._destroy(environment: environment, pointer: Int64(fromJNI: pointer, in: environment!)) } """, @@ -220,8 +241,11 @@ class JavaImplementationMacroTests: XCTestCase { } } + #if compiler(>=6.3) + @used + #endif @_cdecl("Java_org_example_Processor_process_1data") - func __macro_local_12process_datafMu_(environment: UnsafeMutablePointer!, thisObj: jobject) { + public func __macro_local_12process_datafMu_(environment: UnsafeMutablePointer!, thisObj: jobject) { let obj = Processor(javaThis: thisObj, environment: environment!) return obj.process_data() } From d9eff24ce9facadefe12860983a5ea54738190e3 Mon Sep 17 00:00:00 2001 From: Mads Odgaard Date: Sat, 28 Mar 2026 14:18:26 +0100 Subject: [PATCH 6/6] format --- Package.swift | 4 ++-- .../JNI/JNISwift2JavaGenerator+SwiftThunkPrinting.swift | 3 ++- Tests/SwiftJavaMacrosTests/JavaImplementationMacroTests.swift | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Package.swift b/Package.swift index 8f149129..85229560 100644 --- a/Package.swift +++ b/Package.swift @@ -134,7 +134,7 @@ let package = Package( dependencies: [ "SwiftJava", "SwiftJavaRuntimeSupport", - "SwiftRuntimeFunctions" + "SwiftRuntimeFunctions", ] ), @@ -400,7 +400,7 @@ let package = Package( .testTarget( name: "SwiftRuntimeFunctionsTests", dependencies: [ - "SwiftRuntimeFunctions", + "SwiftRuntimeFunctions" ], swiftSettings: [ .swiftLanguageMode(.v5) diff --git a/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+SwiftThunkPrinting.swift b/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+SwiftThunkPrinting.swift index 891d1e97..7ecddb9f 100644 --- a/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+SwiftThunkPrinting.swift +++ b/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+SwiftThunkPrinting.swift @@ -140,7 +140,8 @@ extension JNISwift2JavaGenerator { return } - let symbolLines = generatedCDeclSymbolNames + let symbolLines = + generatedCDeclSymbolNames .sorted() .map { " \($0);" } .joined(separator: "\n") diff --git a/Tests/SwiftJavaMacrosTests/JavaImplementationMacroTests.swift b/Tests/SwiftJavaMacrosTests/JavaImplementationMacroTests.swift index 43e88946..de51cabf 100644 --- a/Tests/SwiftJavaMacrosTests/JavaImplementationMacroTests.swift +++ b/Tests/SwiftJavaMacrosTests/JavaImplementationMacroTests.swift @@ -200,7 +200,7 @@ class JavaImplementationMacroTests: XCTestCase { // cleanup } } - + #if compiler(>=6.3) @used #endif @@ -209,7 +209,7 @@ class JavaImplementationMacroTests: XCTestCase { return SwiftDictionaryMapJava._size(environment: environment, pointer: Int64(fromJNI: pointer, in: environment!)) .getJNILocalRefValue(in: environment) } - + #if compiler(>=6.3) @used #endif