Skip to content

Commit 5764bc2

Browse files
committed
add a test using wrap-java and a java stdlib type
1 parent b9ce5c8 commit 5764bc2

4 files changed

Lines changed: 52 additions & 4 deletions

File tree

Plugins/SwiftJavaPlugin/SwiftJavaPlugin.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,12 @@ extension SwiftJavaBuildToolPlugin {
264264
}
265265

266266
return stdlibDirContents.compactMap { url in
267+
let swiftJavaConfigURL = url.appending(path: "swift-java.config")
268+
guard fileManager.fileExists(atPath: swiftJavaConfigURL.absoluteString) else {
269+
warn("Expected JavaStdlib directory \(url) to contain swift-java.config but it was missing!")
270+
return nil
271+
}
272+
267273
guard let resourceValues = try? url.resourceValues(forKeys: [.isDirectoryKey]),
268274
let isDirectory = resourceValues.isDirectory,
269275
isDirectory else {

Sources/SwiftJavaTool/Commands/WrapJavaCommand.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ extension SwiftJava.WrapJavaCommand {
8686
// Load all of the dependent configurations and associate them with Swift modules.
8787
let dependentConfigs = try loadDependentConfigs(dependsOn: self.dependsOn).map { moduleName, config in
8888
guard let moduleName else {
89-
throw JavaToSwiftError.badConfigOption
89+
throw JavaToSwiftError.badConfigOption(self.dependsOn.joined(separator: " "))
9090
}
9191
return (moduleName, config)
9292
}

Sources/SwiftJavaTool/SwiftJava.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,14 @@ struct SwiftJava: AsyncParsableCommand {
8888
}
8989

9090
enum JavaToSwiftError: Error {
91-
case badConfigOption
91+
case badConfigOption(String)
9292
}
9393

9494
extension JavaToSwiftError: CustomStringConvertible {
9595
var description: String {
9696
switch self {
97-
case .badConfigOption:
98-
"configuration option must be of the form '<swift module name>=<path to config file>"
97+
case .badConfigOption(let string):
98+
"configuration option must be of the form '<swift module name>=<path to config file>. Was: \(string)"
9999
}
100100
}
101101
}

Tests/SwiftJavaToolLibTests/WrapJavaTests/BasicWrapJavaTests.swift

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,46 @@ final class BasicWrapJavaTests: XCTestCase {
198198
]
199199
)
200200
}
201+
202+
func test_wrapJava_inheritFromBiFunction() async throws {
203+
let classpathURL = try await compileJava(
204+
"""
205+
package com.example;
206+
207+
import java.util.function.BiFunction;
208+
209+
interface CallMe<ValueType> extends BiFunction<ValueType, ValueType, ValueType> {
210+
@Override
211+
ValueType apply(
212+
ValueType newest,
213+
ValueType oldest
214+
);
215+
}
216+
""")
217+
218+
try assertWrapJavaOutput(
219+
javaClassNames: [
220+
"java.util.function.BiFunction",
221+
"com.example.CallMe",
222+
],
223+
classpath: [classpathURL],
224+
expectedChunks: [
225+
"""
226+
@JavaInterface("com.example.CallMe", extends: BiFunction<ValueType, ValueType, ValueType>.self)
227+
public struct CallMe<ValueType: AnyJavaObject> {
228+
/**
229+
* Java method `apply`.
230+
*
231+
* ### Java method signature
232+
* ```java
233+
* public abstract ValueType com.example.CallMe.apply(ValueType,ValueType)
234+
* ```
235+
*/
236+
@JavaMethod(typeErasedResult: "ValueType!")
237+
public func apply(_ arg0: ValueType?, _ arg1: ValueType?) -> ValueType!
238+
}
239+
""",
240+
]
241+
)
242+
}
201243
}

0 commit comments

Comments
 (0)