Skip to content

Generate JavaKitFunction module #119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ generate-JavaKitCollection: Java2Swift
mkdir -p Sources/JavaKitCollection/generated
$(BUILD_DIR)/debug/Java2Swift --module-name JavaKitCollection --depends-on JavaKit=Sources/JavaKit/Java2Swift.config -o Sources/JavaKitCollection/generated Sources/JavaKitCollection/Java2Swift.config

generate-JavaKitFunction: Java2Swift
mkdir -p Sources/JavaKitFunction/generated
$(BUILD_DIR)/debug/Java2Swift --module-name JavaKitFunction --depends-on JavaKit=Sources/JavaKit/Java2Swift.config -o Sources/JavaKitFunction/generated Sources/JavaKitFunction/Java2Swift.config

generate-JavaKitReflection: Java2Swift generate-JavaKit generate-JavaKitCollection
mkdir -p Sources/JavaKitReflection/generated
$(BUILD_DIR)/debug/Java2Swift --module-name JavaKitReflection --depends-on JavaKit=Sources/JavaKit/Java2Swift.config --depends-on JavaKitCollection=Sources/JavaKitCollection/Java2Swift.config -o Sources/JavaKitReflection/generated Sources/JavaKitReflection/Java2Swift.config
Expand Down
14 changes: 14 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ let package = Package(
targets: ["JavaKitCollection"]
),

.library(
name: "JavaKitFunction",
targets: ["JavaKitFunction"]
),

.library(
name: "JavaKitJar",
targets: ["JavaKitReflection"]
Expand Down Expand Up @@ -183,6 +188,15 @@ let package = Package(
.unsafeFlags(["-I\(javaIncludePath)", "-I\(javaPlatformIncludePath)"])
]
),
.target(
name: "JavaKitFunction",
dependencies: ["JavaKit"],
exclude: ["Java2Swift.config"],
swiftSettings: [
.swiftLanguageMode(.v5),
.unsafeFlags(["-I\(javaIncludePath)", "-I\(javaPlatformIncludePath)"])
]
),
.target(
name: "JavaKitJar",
dependencies: ["JavaKit", "JavaKitCollection"],
Expand Down
1 change: 1 addition & 0 deletions Samples/JavaKitSampleApp/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ let package = Package(
name: "JavaKitExample",
dependencies: [
.product(name: "JavaKit", package: "swift-java"),
.product(name: "JavaKitFunction", package: "swift-java"),
.product(name: "JavaKitJar", package: "swift-java"),
],
swiftSettings: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===//

import JavaKit
import JavaKitFunction

enum SwiftWrappedError: Error {
case message(String)
Expand Down Expand Up @@ -44,6 +45,10 @@ extension HelloSwift: HelloSwiftNativeMethods {
self.name = "a 🗑️-collected language"
_ = self.sayHelloBack(42)

let predicate: JavaPredicate<JavaInteger> = self.lessThanTen()!
let value = predicate.test(JavaInteger(3).as(JavaObject.self))
print("Running a JavaPredicate from swift 3 < 10 = \(value)")
Comment on lines +48 to +50
Copy link
Contributor Author

@iainsmith iainsmith Oct 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a particular compelling example, but illustrates the module working.

Copy link
Collaborator

@ktoso ktoso Oct 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine, just at least some soundness check that it works at all 👍

I'd put it into a test file in this project and we're good them IMHO.


let strings = doublesToStrings([3.14159, 2.71828])
print("Converting doubles to strings: \(strings)")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

package com.example.swift;

import java.util.function.Predicate;

public class HelloSwift {
public double value;
public static double initialValue = 3.14159;
Expand All @@ -40,6 +42,11 @@ public void greet(String name) {
System.out.println("Salutations, " + name);
}

public Predicate<Integer> lessThanTen() {
Predicate<Integer> predicate = i -> (i < 10);
return predicate;
}

public String[] doublesToStrings(double[] doubles) {
int size = doubles.length;
String[] strings = new String[size];
Expand Down
51 changes: 51 additions & 0 deletions Sources/JavaKitFunction/Java2Swift.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"classes" : {
"java.util.function.BiConsumer" : "JavaBiConsumer",
"java.util.function.BiFunction" : "JavaBiFunction",
"java.util.function.BinaryOperator" : "JavaBinaryOperator",
"java.util.function.BiPredicate" : "JavaBiPredicate",
"java.util.function.BinaryOperator" : "JavaBinaryOperator",
"java.util.function.BooleanSupplier" : "JavaBooleanSupplier",
"java.util.function.Consumer" : "JavaConsumer",
"java.util.function.DoubleBinaryOperator" : "JavaDoubleBinaryOperator",
"java.util.function.DoubleConsumer" : "JavaDoubleConsumer",
"java.util.function.DoubleFunction" : "JavaDoubleFunction",
"java.util.function.DoublePredicate" : "JavaDoublePredicate",
"java.util.function.DoubleSupplier" : "JavaDoubleSupplier",
"java.util.function.DoubleToIntFunction" : "JavaDoubleToIntFunction",
"java.util.function.DoubleToLongFunction" : "JavaDoubleToLongFunction",
"java.util.function.DoubleUnaryOperator" : "JavaDoubleUnaryOperator",
"java.util.function.Function" : "JavaFunction",
"java.util.function.IntBinaryOperator" : "JavaIntBinaryOperator",
"java.util.function.IntConsumer" : "JavaIntConsumer",
"java.util.function.IntConsumer" : "JavaIntConsumer",
"java.util.function.IntFunction" : "JavaIntFunction",
"java.util.function.IntPredicate" : "JavaIntPredicate",
"java.util.function.IntSupplier" : "JavaIntSupplier",
"java.util.function.IntToDoubleFunction" : "JavaIntToDoubleFunction",
"java.util.function.IntToLongFunction" : "JavaIntToLongFunction",
"java.util.function.IntUnaryOperator" : "JavaIntUnaryOperator",
"java.util.function.LongBinaryOperator" : "JavaLongBinaryOperator",
"java.util.function.LongConsumer" : "JavaLongConsumer",
"java.util.function.LongFunction" : "JavaLongFunction",
"java.util.function.LongPredicate" : "JavaLongPredicate",
"java.util.function.LongSupplier" : "JavaLongSupplier",
"java.util.function.LongToDoubleFunction" : "JavaLongToDoubleFunction",
"java.util.function.LongToIntFunction" : "JavaLongToIntFunction",
"java.util.function.LongUnaryOperator" : "JavaLongUnaryOperator",
"java.util.function.ObjDoubleConsumer" : "JavaObjDoubleConsumer",
"java.util.function.ObjIntConsumer" : "JavaObjIntConsumer",
"java.util.function.ObjLongConsumer" : "JavaObjLongConsumer",
"java.util.function.Predicate" : "JavaPredicate",
"java.util.function.Supplier" : "JavaSupplier",
"java.util.function.ToDoubleBiFunction" : "JavaToDoubleBiFunction",
"java.util.function.ToDoubleFunction" : "JavaToDoubleFunction",
"java.util.function.ToIntBiFunction" : "JavaToIntBiFunction",
"java.util.function.ToIntFunction" : "JavaToIntFunction",
"java.util.function.ToLongBiFunction" : "JavaToLongBiFunction",
"java.util.function.ToLongFunction" : "JavaToLongFunction",
"java.util.function.UnaryOperator" : "JavaUnaryOperator"
}
}


14 changes: 14 additions & 0 deletions Sources/JavaKitFunction/generated/JavaBiConsumer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Auto-generated by Java-to-Swift wrapper generator.
import JavaKit
import JavaRuntime

@JavaInterface("java.util.function.BiConsumer")
public struct JavaBiConsumer<T: AnyJavaObject, U: AnyJavaObject> {
@JavaMethod
public func accept(_ arg0: JavaObject?, _ arg1: JavaObject?)

@JavaMethod
public func andThen(_ arg0: JavaBiConsumer<JavaObject, JavaObject>?) -> JavaBiConsumer<
JavaObject, JavaObject
>?
}
14 changes: 14 additions & 0 deletions Sources/JavaKitFunction/generated/JavaBiFunction.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Auto-generated by Java-to-Swift wrapper generator.
import JavaKit
import JavaRuntime

@JavaInterface("java.util.function.BiFunction")
public struct JavaBiFunction<T: AnyJavaObject, U: AnyJavaObject, R: AnyJavaObject> {
@JavaMethod
public func apply(_ arg0: JavaObject?, _ arg1: JavaObject?) -> JavaObject?

@JavaMethod
public func andThen(_ arg0: JavaFunction<JavaObject, JavaObject>?) -> JavaBiFunction<
JavaObject, JavaObject, JavaObject
>?
}
22 changes: 22 additions & 0 deletions Sources/JavaKitFunction/generated/JavaBiPredicate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Auto-generated by Java-to-Swift wrapper generator.
import JavaKit
import JavaRuntime

@JavaInterface("java.util.function.BiPredicate")
public struct JavaBiPredicate<T: AnyJavaObject, U: AnyJavaObject> {
@JavaMethod
public func test(_ arg0: JavaObject?, _ arg1: JavaObject?) -> Bool

@JavaMethod
public func or(_ arg0: JavaBiPredicate<JavaObject, JavaObject>?) -> JavaBiPredicate<
JavaObject, JavaObject
>?

@JavaMethod
public func and(_ arg0: JavaBiPredicate<JavaObject, JavaObject>?) -> JavaBiPredicate<
JavaObject, JavaObject
>?

@JavaMethod
public func negate() -> JavaBiPredicate<JavaObject, JavaObject>?
}
16 changes: 16 additions & 0 deletions Sources/JavaKitFunction/generated/JavaBinaryOperator.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Auto-generated by Java-to-Swift wrapper generator.
import JavaKit
import JavaRuntime

@JavaInterface(
"java.util.function.BinaryOperator",
extends: JavaBiFunction<JavaObject, JavaObject, JavaObject>.self)
public struct JavaBinaryOperator<T: AnyJavaObject> {
@JavaMethod
public func apply(_ arg0: JavaObject?, _ arg1: JavaObject?) -> JavaObject?

@JavaMethod
public func andThen(_ arg0: JavaFunction<JavaObject, JavaObject>?) -> JavaBiFunction<
JavaObject, JavaObject, JavaObject
>?
}
9 changes: 9 additions & 0 deletions Sources/JavaKitFunction/generated/JavaBooleanSupplier.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Auto-generated by Java-to-Swift wrapper generator.
import JavaKit
import JavaRuntime

@JavaInterface("java.util.function.BooleanSupplier")
public struct JavaBooleanSupplier {
@JavaMethod
public func getAsBoolean() -> Bool
}
12 changes: 12 additions & 0 deletions Sources/JavaKitFunction/generated/JavaConsumer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Auto-generated by Java-to-Swift wrapper generator.
import JavaKit
import JavaRuntime

@JavaInterface("java.util.function.Consumer")
public struct JavaConsumer<T: AnyJavaObject> {
@JavaMethod
public func accept(_ arg0: JavaObject?)

@JavaMethod
public func andThen(_ arg0: JavaConsumer<JavaObject>?) -> JavaConsumer<JavaObject>?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Auto-generated by Java-to-Swift wrapper generator.
import JavaKit
import JavaRuntime

@JavaInterface("java.util.function.DoubleBinaryOperator")
public struct JavaDoubleBinaryOperator {
@JavaMethod
public func applyAsDouble(_ arg0: Double, _ arg1: Double) -> Double
}
12 changes: 12 additions & 0 deletions Sources/JavaKitFunction/generated/JavaDoubleConsumer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Auto-generated by Java-to-Swift wrapper generator.
import JavaKit
import JavaRuntime

@JavaInterface("java.util.function.DoubleConsumer")
public struct JavaDoubleConsumer {
@JavaMethod
public func accept(_ arg0: Double)

@JavaMethod
public func andThen(_ arg0: JavaDoubleConsumer?) -> JavaDoubleConsumer?
}
9 changes: 9 additions & 0 deletions Sources/JavaKitFunction/generated/JavaDoubleFunction.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Auto-generated by Java-to-Swift wrapper generator.
import JavaKit
import JavaRuntime

@JavaInterface("java.util.function.DoubleFunction")
public struct JavaDoubleFunction<R: AnyJavaObject> {
@JavaMethod
public func apply(_ arg0: Double) -> JavaObject?
}
18 changes: 18 additions & 0 deletions Sources/JavaKitFunction/generated/JavaDoublePredicate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Auto-generated by Java-to-Swift wrapper generator.
import JavaKit
import JavaRuntime

@JavaInterface("java.util.function.DoublePredicate")
public struct JavaDoublePredicate {
@JavaMethod
public func test(_ arg0: Double) -> Bool

@JavaMethod
public func or(_ arg0: JavaDoublePredicate?) -> JavaDoublePredicate?

@JavaMethod
public func and(_ arg0: JavaDoublePredicate?) -> JavaDoublePredicate?

@JavaMethod
public func negate() -> JavaDoublePredicate?
}
9 changes: 9 additions & 0 deletions Sources/JavaKitFunction/generated/JavaDoubleSupplier.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Auto-generated by Java-to-Swift wrapper generator.
import JavaKit
import JavaRuntime

@JavaInterface("java.util.function.DoubleSupplier")
public struct JavaDoubleSupplier {
@JavaMethod
public func getAsDouble() -> Double
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Auto-generated by Java-to-Swift wrapper generator.
import JavaKit
import JavaRuntime

@JavaInterface("java.util.function.DoubleToIntFunction")
public struct JavaDoubleToIntFunction {
@JavaMethod
public func applyAsInt(_ arg0: Double) -> Int32
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Auto-generated by Java-to-Swift wrapper generator.
import JavaKit
import JavaRuntime

@JavaInterface("java.util.function.DoubleToLongFunction")
public struct JavaDoubleToLongFunction {
@JavaMethod
public func applyAsLong(_ arg0: Double) -> Int64
}
19 changes: 19 additions & 0 deletions Sources/JavaKitFunction/generated/JavaDoubleUnaryOperator.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Auto-generated by Java-to-Swift wrapper generator.
import JavaKit
import JavaRuntime

@JavaInterface("java.util.function.DoubleUnaryOperator")
public struct JavaDoubleUnaryOperator {
@JavaMethod
public func applyAsDouble(_ arg0: Double) -> Double

@JavaMethod
public func compose(_ arg0: JavaDoubleUnaryOperator?) -> JavaDoubleUnaryOperator?

@JavaMethod
public func andThen(_ arg0: JavaDoubleUnaryOperator?) -> JavaDoubleUnaryOperator?
}
extension JavaClass<JavaDoubleUnaryOperator> {
@JavaStaticMethod
public func identity() -> JavaDoubleUnaryOperator?
}
25 changes: 25 additions & 0 deletions Sources/JavaKitFunction/generated/JavaFunction.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Auto-generated by Java-to-Swift wrapper generator.
import JavaKit
import JavaRuntime

@JavaInterface("java.util.function.Function")
public struct JavaFunction<T: AnyJavaObject, R: AnyJavaObject> {
@JavaMethod
public func apply(_ arg0: JavaObject?) -> JavaObject?

@JavaMethod
public func compose(_ arg0: JavaFunction<JavaObject, JavaObject>?) -> JavaFunction<
JavaObject, JavaObject
>?

@JavaMethod
public func andThen(_ arg0: JavaFunction<JavaObject, JavaObject>?) -> JavaFunction<
JavaObject, JavaObject
>?
}
extension JavaClass {
@JavaStaticMethod
public func identity<T: AnyJavaObject, R: AnyJavaObject>() -> JavaFunction<
JavaObject, JavaObject
>? where ObjectType == JavaFunction<T, R>
}
9 changes: 9 additions & 0 deletions Sources/JavaKitFunction/generated/JavaIntBinaryOperator.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Auto-generated by Java-to-Swift wrapper generator.
import JavaKit
import JavaRuntime

@JavaInterface("java.util.function.IntBinaryOperator")
public struct JavaIntBinaryOperator {
@JavaMethod
public func applyAsInt(_ arg0: Int32, _ arg1: Int32) -> Int32
}
12 changes: 12 additions & 0 deletions Sources/JavaKitFunction/generated/JavaIntConsumer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Auto-generated by Java-to-Swift wrapper generator.
import JavaKit
import JavaRuntime

@JavaInterface("java.util.function.IntConsumer")
public struct JavaIntConsumer {
@JavaMethod
public func accept(_ arg0: Int32)

@JavaMethod
public func andThen(_ arg0: JavaIntConsumer?) -> JavaIntConsumer?
}
9 changes: 9 additions & 0 deletions Sources/JavaKitFunction/generated/JavaIntFunction.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Auto-generated by Java-to-Swift wrapper generator.
import JavaKit
import JavaRuntime

@JavaInterface("java.util.function.IntFunction")
public struct JavaIntFunction<R: AnyJavaObject> {
@JavaMethod
public func apply(_ arg0: Int32) -> JavaObject?
}
Loading