diff --git a/Samples/JavaKitSampleApp/Sources/JavaKitExample/Java2Swift.config b/Samples/JavaKitSampleApp/Sources/JavaKitExample/Java2Swift.config index 5ccb042b..b4e7368d 100644 --- a/Samples/JavaKitSampleApp/Sources/JavaKitExample/Java2Swift.config +++ b/Samples/JavaKitSampleApp/Sources/JavaKitExample/Java2Swift.config @@ -1,6 +1,5 @@ { "classes" : { - "java.util.ArrayList" : "ArrayList", "com.example.swift.HelloSwift" : "HelloSwift", "com.example.swift.HelloSubclass" : "HelloSubclass", "com.example.swift.JavaKitSampleMain" : "JavaKitSampleMain" diff --git a/Samples/JavaKitSampleApp/Sources/JavaKitExample/JavaKitExample.swift b/Samples/JavaKitSampleApp/Sources/JavaKitExample/JavaKitExample.swift index aaaff0bb..56a3cbb7 100644 --- a/Samples/JavaKitSampleApp/Sources/JavaKitExample/JavaKitExample.swift +++ b/Samples/JavaKitSampleApp/Sources/JavaKitExample/JavaKitExample.swift @@ -79,9 +79,3 @@ extension HelloSwift: HelloSwiftNativeMethods { throw SwiftWrappedError.message(message) } } - -func removeLast(arrayList: ArrayList>) { - if let lastObject = arrayList.getLast() { - _ = arrayList.remove(lastObject) - } -} diff --git a/Samples/JavaProbablyPrime/Package.swift b/Samples/JavaProbablyPrime/Package.swift index b35788f8..e837bfdb 100644 --- a/Samples/JavaProbablyPrime/Package.swift +++ b/Samples/JavaProbablyPrime/Package.swift @@ -26,6 +26,7 @@ let package = Package( .executableTarget( name: "JavaProbablyPrime", dependencies: [ + .product(name: "JavaKitCollection", package: "swift-java"), .product(name: "JavaKit", package: "swift-java"), .product(name: "ArgumentParser", package: "swift-argument-parser"), ], diff --git a/Samples/JavaProbablyPrime/README.md b/Samples/JavaProbablyPrime/README.md index f9fe318f..819ecf04 100644 --- a/Samples/JavaProbablyPrime/README.md +++ b/Samples/JavaProbablyPrime/README.md @@ -9,5 +9,4 @@ swift run JavaProbablyPrime The package itself demonstrates how to: * Use the Java2Swift build tool plugin to wrap the `java.math.BigInteger` type in Swift. -* Create a `JavaVirtualMachine` instance in a Swift command-line program. * Create an instance of `BigInteger` in Swift and use its `isProbablyPrime`. diff --git a/Samples/JavaProbablyPrime/Sources/JavaProbablyPrime/prime.swift b/Samples/JavaProbablyPrime/Sources/JavaProbablyPrime/prime.swift index ddebb518..07f701bd 100644 --- a/Samples/JavaProbablyPrime/Sources/JavaProbablyPrime/prime.swift +++ b/Samples/JavaProbablyPrime/Sources/JavaProbablyPrime/prime.swift @@ -24,10 +24,7 @@ struct ProbablyPrime: ParsableCommand { var certainty: Int32 = 10 func run() throws { - let javaVirtualMachine = try JavaVirtualMachine.shared() - let jniEnvironment = try javaVirtualMachine.environment() - - let bigInt = BigInteger(number, environment: jniEnvironment) + let bigInt = BigInteger(number) if bigInt.isProbablePrime(certainty) { print("\(number) is probably prime") } else { diff --git a/Samples/JavaSieve/Sources/JavaMath/Java2Swift.config b/Samples/JavaSieve/Sources/JavaMath/Java2Swift.config index 28e56a35..3c14b885 100644 --- a/Samples/JavaSieve/Sources/JavaMath/Java2Swift.config +++ b/Samples/JavaSieve/Sources/JavaMath/Java2Swift.config @@ -3,7 +3,6 @@ "java.math.BigDecimal" : "BigDecimal", "java.math.BigInteger" : "BigInteger", "java.math.MathContext" : "MathContext", - "java.math.RoundingMode" : "RoundingMode", - "java.lang.Integer" : "JavaInteger", + "java.math.RoundingMode" : "RoundingMode" } } diff --git a/Samples/JavaSieve/Sources/JavaSieve/main.swift b/Samples/JavaSieve/Sources/JavaSieve/main.swift index f2f24a53..c075a8a1 100644 --- a/Samples/JavaSieve/Sources/JavaSieve/main.swift +++ b/Samples/JavaSieve/Sources/JavaSieve/main.swift @@ -13,11 +13,10 @@ //===----------------------------------------------------------------------===// import JavaKit -import JavaKitVM let jvm = try JavaVirtualMachine.shared(classPath: ["QuadraticSieve-1.0.jar"]) do { - let sieveClass = try JavaClass(in: jvm.environment()) + let sieveClass = try JavaClass(environment: jvm.environment()) for prime in sieveClass.findPrimes(100)! { print("Found prime: \(prime.intValue())") } diff --git a/Sources/Java2Swift/JavaToSwift.swift b/Sources/Java2Swift/JavaToSwift.swift index 1cc094c2..80058ccd 100644 --- a/Sources/Java2Swift/JavaToSwift.swift +++ b/Sources/Java2Swift/JavaToSwift.swift @@ -210,7 +210,7 @@ struct JavaToSwift: ParsableCommand { environment: environment ) #else - let classLoader = try JavaClass(in: environment) + let classLoader = try JavaClass(environment: environment) .getSystemClassLoader()! #endif var javaClasses: [JavaClass] = [] diff --git a/Sources/Java2SwiftLib/JavaTranslator.swift b/Sources/Java2SwiftLib/JavaTranslator.swift index c48591b9..fa7e5789 100644 --- a/Sources/Java2SwiftLib/JavaTranslator.swift +++ b/Sources/Java2SwiftLib/JavaTranslator.swift @@ -581,7 +581,7 @@ extension JavaTranslator { } else { try! JavaVirtualMachine.shared().environment() } - let classObj = try! JavaClass(in: _environment) + let classObj = try! JavaClass(environment: _environment) switch enumValue { \(raw: enumFields.map { return """ diff --git a/Sources/JavaKit/Java2Swift.config b/Sources/JavaKit/Java2Swift.config index 7626a380..bace061f 100644 --- a/Sources/JavaKit/Java2Swift.config +++ b/Sources/JavaKit/Java2Swift.config @@ -1,9 +1,20 @@ { "classes" : { + "java.lang.Boolean" : "JavaBoolean", + "java.lang.Byte" : "JavaByte", + "java.lang.Character" : "JavaCharacter", + "java.lang.Class" : "JavaClass", + "java.lang.Double" : "JavaDouble", "java.lang.Error" : "JavaError", "java.lang.Exception" : "Exception", + "java.lang.Float" : "JavaFloat", + "java.lang.Integer" : "JavaInteger", + "java.lang.Long" : "JavaLong", + "java.lang.Number" : "JavaNumber", "java.lang.Object" : "JavaObject", "java.lang.RuntimeException" : "RuntimeException", - "java.lang.Throwable" : "Throwable" + "java.lang.Short" : "JavaShort", + "java.lang.Throwable" : "Throwable", + "java.lang.Void" : "JavaVoid" } } diff --git a/Sources/JavaKit/JavaClass.swift b/Sources/JavaKit/JavaClass+Initialization.swift similarity index 75% rename from Sources/JavaKit/JavaClass.swift rename to Sources/JavaKit/JavaClass+Initialization.swift index c9f0fdd2..a9302bd8 100644 --- a/Sources/JavaKit/JavaClass.swift +++ b/Sources/JavaKit/JavaClass+Initialization.swift @@ -14,12 +14,12 @@ import JavaRuntime -/// Wrapper around a Java class that provides access to the static members of -/// the class. -@JavaClass("java.lang.Class") -public struct JavaClass { +extension JavaClass { + public typealias ObjectType = T + /// Lookup this Java class within the given environment. - public init(in environment: JNIEnvironment) throws { + public init(environment: JNIEnvironment? = nil) throws { + let environment = try environment ?? JavaVirtualMachine.shared().environment() self.init( javaThis: try ObjectType.getJNIClass(in: environment), environment: environment diff --git a/Sources/JavaKit/generated/JavaBoolean.swift b/Sources/JavaKit/generated/JavaBoolean.swift new file mode 100644 index 00000000..c0cfbd04 --- /dev/null +++ b/Sources/JavaKit/generated/JavaBoolean.swift @@ -0,0 +1,87 @@ +// Auto-generated by Java-to-Swift wrapper generator. +import JavaRuntime + +@JavaClass("java.lang.Boolean") +public struct JavaBoolean { + @JavaMethod + public init(_ arg0: Bool, environment: JNIEnvironment? = nil) + + @JavaMethod + public init(_ arg0: String, environment: JNIEnvironment? = nil) + + @JavaMethod + public func equals(_ arg0: JavaObject?) -> Bool + + @JavaMethod + public func toString() -> String + + @JavaMethod + public func hashCode() -> Int32 + + @JavaMethod + public func compareTo(_ arg0: JavaBoolean?) -> Int32 + + @JavaMethod + public func compareTo(_ arg0: JavaObject?) -> Int32 + + @JavaMethod + public func booleanValue() -> Bool + + @JavaMethod + public func getClass() -> JavaClass? + + @JavaMethod + public func notify() + + @JavaMethod + public func notifyAll() + + @JavaMethod + public func wait(_ arg0: Int64) throws + + @JavaMethod + public func wait(_ arg0: Int64, _ arg1: Int32) throws + + @JavaMethod + public func wait() throws +} +extension JavaClass { + @JavaStaticField + public var TRUE: JavaBoolean? + + @JavaStaticField + public var FALSE: JavaBoolean? + + @JavaStaticField + public var TYPE: JavaClass? + + @JavaStaticMethod + public func toString(_ arg0: Bool) -> String + + @JavaStaticMethod + public func hashCode(_ arg0: Bool) -> Int32 + + @JavaStaticMethod + public func getBoolean(_ arg0: String) -> Bool + + @JavaStaticMethod + public func compare(_ arg0: Bool, _ arg1: Bool) -> Int32 + + @JavaStaticMethod + public func valueOf(_ arg0: String) -> JavaBoolean? + + @JavaStaticMethod + public func valueOf(_ arg0: Bool) -> JavaBoolean? + + @JavaStaticMethod + public func parseBoolean(_ arg0: String) -> Bool + + @JavaStaticMethod + public func logicalAnd(_ arg0: Bool, _ arg1: Bool) -> Bool + + @JavaStaticMethod + public func logicalOr(_ arg0: Bool, _ arg1: Bool) -> Bool + + @JavaStaticMethod + public func logicalXor(_ arg0: Bool, _ arg1: Bool) -> Bool +} diff --git a/Sources/JavaKit/generated/JavaByte.swift b/Sources/JavaKit/generated/JavaByte.swift new file mode 100644 index 00000000..c00cae95 --- /dev/null +++ b/Sources/JavaKit/generated/JavaByte.swift @@ -0,0 +1,114 @@ +// Auto-generated by Java-to-Swift wrapper generator. +import JavaRuntime + +@JavaClass("java.lang.Byte", extends: JavaNumber.self) +public struct JavaByte { + @JavaMethod + public init(_ arg0: Int8, environment: JNIEnvironment? = nil) + + @JavaMethod + public init(_ arg0: String, environment: JNIEnvironment? = nil) throws + + @JavaMethod + public func equals(_ arg0: JavaObject?) -> Bool + + @JavaMethod + public func toString() -> String + + @JavaMethod + public func hashCode() -> Int32 + + @JavaMethod + public func compareTo(_ arg0: JavaByte?) -> Int32 + + @JavaMethod + public func compareTo(_ arg0: JavaObject?) -> Int32 + + @JavaMethod + public func byteValue() -> Int8 + + @JavaMethod + public func shortValue() -> Int16 + + @JavaMethod + public func intValue() -> Int32 + + @JavaMethod + public func longValue() -> Int64 + + @JavaMethod + public func floatValue() -> Float + + @JavaMethod + public func doubleValue() -> Double + + @JavaMethod + public func getClass() -> JavaClass? + + @JavaMethod + public func notify() + + @JavaMethod + public func notifyAll() + + @JavaMethod + public func wait(_ arg0: Int64) throws + + @JavaMethod + public func wait(_ arg0: Int64, _ arg1: Int32) throws + + @JavaMethod + public func wait() throws +} +extension JavaClass { + @JavaStaticField + public var MIN_VALUE: Int8 + + @JavaStaticField + public var MAX_VALUE: Int8 + + @JavaStaticField + public var TYPE: JavaClass? + + @JavaStaticField + public var SIZE: Int32 + + @JavaStaticField + public var BYTES: Int32 + + @JavaStaticMethod + public func toString(_ arg0: Int8) -> String + + @JavaStaticMethod + public func hashCode(_ arg0: Int8) -> Int32 + + @JavaStaticMethod + public func compareUnsigned(_ arg0: Int8, _ arg1: Int8) -> Int32 + + @JavaStaticMethod + public func compare(_ arg0: Int8, _ arg1: Int8) -> Int32 + + @JavaStaticMethod + public func valueOf(_ arg0: String) throws -> JavaByte? + + @JavaStaticMethod + public func valueOf(_ arg0: String, _ arg1: Int32) throws -> JavaByte? + + @JavaStaticMethod + public func valueOf(_ arg0: Int8) -> JavaByte? + + @JavaStaticMethod + public func decode(_ arg0: String) throws -> JavaByte? + + @JavaStaticMethod + public func toUnsignedLong(_ arg0: Int8) -> Int64 + + @JavaStaticMethod + public func toUnsignedInt(_ arg0: Int8) -> Int32 + + @JavaStaticMethod + public func parseByte(_ arg0: String) throws -> Int8 + + @JavaStaticMethod + public func parseByte(_ arg0: String, _ arg1: Int32) throws -> Int8 +} diff --git a/Sources/JavaKit/generated/JavaCharacter.swift b/Sources/JavaKit/generated/JavaCharacter.swift new file mode 100644 index 00000000..c5d2e8b9 --- /dev/null +++ b/Sources/JavaKit/generated/JavaCharacter.swift @@ -0,0 +1,510 @@ +// Auto-generated by Java-to-Swift wrapper generator. +import JavaRuntime + +@JavaClass("java.lang.Character") +public struct JavaCharacter { + @JavaMethod + public init(_ arg0: UInt16, environment: JNIEnvironment? = nil) + + @JavaMethod + public func equals(_ arg0: JavaObject?) -> Bool + + @JavaMethod + public func toString() -> String + + @JavaMethod + public func hashCode() -> Int32 + + @JavaMethod + public func compareTo(_ arg0: JavaCharacter?) -> Int32 + + @JavaMethod + public func compareTo(_ arg0: JavaObject?) -> Int32 + + @JavaMethod + public func charValue() -> UInt16 + + @JavaMethod + public func getClass() -> JavaClass? + + @JavaMethod + public func notify() + + @JavaMethod + public func notifyAll() + + @JavaMethod + public func wait(_ arg0: Int64) throws + + @JavaMethod + public func wait(_ arg0: Int64, _ arg1: Int32) throws + + @JavaMethod + public func wait() throws +} +extension JavaClass { + @JavaStaticField + public var MIN_RADIX: Int32 + + @JavaStaticField + public var MAX_RADIX: Int32 + + @JavaStaticField + public var MIN_VALUE: UInt16 + + @JavaStaticField + public var MAX_VALUE: UInt16 + + @JavaStaticField + public var TYPE: JavaClass? + + @JavaStaticField + public var UNASSIGNED: Int8 + + @JavaStaticField + public var UPPERCASE_LETTER: Int8 + + @JavaStaticField + public var LOWERCASE_LETTER: Int8 + + @JavaStaticField + public var TITLECASE_LETTER: Int8 + + @JavaStaticField + public var MODIFIER_LETTER: Int8 + + @JavaStaticField + public var OTHER_LETTER: Int8 + + @JavaStaticField + public var NON_SPACING_MARK: Int8 + + @JavaStaticField + public var ENCLOSING_MARK: Int8 + + @JavaStaticField + public var COMBINING_SPACING_MARK: Int8 + + @JavaStaticField + public var DECIMAL_DIGIT_NUMBER: Int8 + + @JavaStaticField + public var LETTER_NUMBER: Int8 + + @JavaStaticField + public var OTHER_NUMBER: Int8 + + @JavaStaticField + public var SPACE_SEPARATOR: Int8 + + @JavaStaticField + public var LINE_SEPARATOR: Int8 + + @JavaStaticField + public var PARAGRAPH_SEPARATOR: Int8 + + @JavaStaticField + public var CONTROL: Int8 + + @JavaStaticField + public var FORMAT: Int8 + + @JavaStaticField + public var PRIVATE_USE: Int8 + + @JavaStaticField + public var SURROGATE: Int8 + + @JavaStaticField + public var DASH_PUNCTUATION: Int8 + + @JavaStaticField + public var START_PUNCTUATION: Int8 + + @JavaStaticField + public var END_PUNCTUATION: Int8 + + @JavaStaticField + public var CONNECTOR_PUNCTUATION: Int8 + + @JavaStaticField + public var OTHER_PUNCTUATION: Int8 + + @JavaStaticField + public var MATH_SYMBOL: Int8 + + @JavaStaticField + public var CURRENCY_SYMBOL: Int8 + + @JavaStaticField + public var MODIFIER_SYMBOL: Int8 + + @JavaStaticField + public var OTHER_SYMBOL: Int8 + + @JavaStaticField + public var INITIAL_QUOTE_PUNCTUATION: Int8 + + @JavaStaticField + public var FINAL_QUOTE_PUNCTUATION: Int8 + + @JavaStaticField + public var DIRECTIONALITY_UNDEFINED: Int8 + + @JavaStaticField + public var DIRECTIONALITY_LEFT_TO_RIGHT: Int8 + + @JavaStaticField + public var DIRECTIONALITY_RIGHT_TO_LEFT: Int8 + + @JavaStaticField + public var DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC: Int8 + + @JavaStaticField + public var DIRECTIONALITY_EUROPEAN_NUMBER: Int8 + + @JavaStaticField + public var DIRECTIONALITY_EUROPEAN_NUMBER_SEPARATOR: Int8 + + @JavaStaticField + public var DIRECTIONALITY_EUROPEAN_NUMBER_TERMINATOR: Int8 + + @JavaStaticField + public var DIRECTIONALITY_ARABIC_NUMBER: Int8 + + @JavaStaticField + public var DIRECTIONALITY_COMMON_NUMBER_SEPARATOR: Int8 + + @JavaStaticField + public var DIRECTIONALITY_NONSPACING_MARK: Int8 + + @JavaStaticField + public var DIRECTIONALITY_BOUNDARY_NEUTRAL: Int8 + + @JavaStaticField + public var DIRECTIONALITY_PARAGRAPH_SEPARATOR: Int8 + + @JavaStaticField + public var DIRECTIONALITY_SEGMENT_SEPARATOR: Int8 + + @JavaStaticField + public var DIRECTIONALITY_WHITESPACE: Int8 + + @JavaStaticField + public var DIRECTIONALITY_OTHER_NEUTRALS: Int8 + + @JavaStaticField + public var DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING: Int8 + + @JavaStaticField + public var DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE: Int8 + + @JavaStaticField + public var DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING: Int8 + + @JavaStaticField + public var DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE: Int8 + + @JavaStaticField + public var DIRECTIONALITY_POP_DIRECTIONAL_FORMAT: Int8 + + @JavaStaticField + public var DIRECTIONALITY_LEFT_TO_RIGHT_ISOLATE: Int8 + + @JavaStaticField + public var DIRECTIONALITY_RIGHT_TO_LEFT_ISOLATE: Int8 + + @JavaStaticField + public var DIRECTIONALITY_FIRST_STRONG_ISOLATE: Int8 + + @JavaStaticField + public var DIRECTIONALITY_POP_DIRECTIONAL_ISOLATE: Int8 + + @JavaStaticField + public var MIN_HIGH_SURROGATE: UInt16 + + @JavaStaticField + public var MAX_HIGH_SURROGATE: UInt16 + + @JavaStaticField + public var MIN_LOW_SURROGATE: UInt16 + + @JavaStaticField + public var MAX_LOW_SURROGATE: UInt16 + + @JavaStaticField + public var MIN_SURROGATE: UInt16 + + @JavaStaticField + public var MAX_SURROGATE: UInt16 + + @JavaStaticField + public var MIN_SUPPLEMENTARY_CODE_POINT: Int32 + + @JavaStaticField + public var MIN_CODE_POINT: Int32 + + @JavaStaticField + public var MAX_CODE_POINT: Int32 + + @JavaStaticField + public var SIZE: Int32 + + @JavaStaticField + public var BYTES: Int32 + + @JavaStaticMethod + public func getName(_ arg0: Int32) -> String + + @JavaStaticMethod + public func isJavaIdentifierStart(_ arg0: UInt16) -> Bool + + @JavaStaticMethod + public func isJavaIdentifierStart(_ arg0: Int32) -> Bool + + @JavaStaticMethod + public func isJavaIdentifierPart(_ arg0: UInt16) -> Bool + + @JavaStaticMethod + public func isJavaIdentifierPart(_ arg0: Int32) -> Bool + + @JavaStaticMethod + public func toString(_ arg0: Int32) -> String + + @JavaStaticMethod + public func toString(_ arg0: UInt16) -> String + + @JavaStaticMethod + public func hashCode(_ arg0: UInt16) -> Int32 + + @JavaStaticMethod + public func reverseBytes(_ arg0: UInt16) -> UInt16 + + @JavaStaticMethod + public func isDigit(_ arg0: UInt16) -> Bool + + @JavaStaticMethod + public func isDigit(_ arg0: Int32) -> Bool + + @JavaStaticMethod + public func isLowerCase(_ arg0: UInt16) -> Bool + + @JavaStaticMethod + public func isLowerCase(_ arg0: Int32) -> Bool + + @JavaStaticMethod + public func isUpperCase(_ arg0: Int32) -> Bool + + @JavaStaticMethod + public func isUpperCase(_ arg0: UInt16) -> Bool + + @JavaStaticMethod + public func isWhitespace(_ arg0: UInt16) -> Bool + + @JavaStaticMethod + public func isWhitespace(_ arg0: Int32) -> Bool + + @JavaStaticMethod + public func compare(_ arg0: UInt16, _ arg1: UInt16) -> Int32 + + @JavaStaticMethod + public func valueOf(_ arg0: UInt16) -> JavaCharacter? + + @JavaStaticMethod + public func toChars(_ arg0: Int32) -> [UInt16] + + @JavaStaticMethod + public func toChars(_ arg0: Int32, _ arg1: [UInt16], _ arg2: Int32) -> Int32 + + @JavaStaticMethod + public func isHighSurrogate(_ arg0: UInt16) -> Bool + + @JavaStaticMethod + public func isLowSurrogate(_ arg0: UInt16) -> Bool + + @JavaStaticMethod + public func isSurrogate(_ arg0: UInt16) -> Bool + + @JavaStaticMethod + public func isSupplementaryCodePoint(_ arg0: Int32) -> Bool + + @JavaStaticMethod + public func highSurrogate(_ arg0: Int32) -> UInt16 + + @JavaStaticMethod + public func lowSurrogate(_ arg0: Int32) -> UInt16 + + @JavaStaticMethod + public func toCodePoint(_ arg0: UInt16, _ arg1: UInt16) -> Int32 + + @JavaStaticMethod + public func codePointAt(_ arg0: [UInt16], _ arg1: Int32, _ arg2: Int32) -> Int32 + + @JavaStaticMethod + public func codePointAt(_ arg0: [UInt16], _ arg1: Int32) -> Int32 + + @JavaStaticMethod + public func codePointBefore(_ arg0: [UInt16], _ arg1: Int32) -> Int32 + + @JavaStaticMethod + public func codePointBefore(_ arg0: [UInt16], _ arg1: Int32, _ arg2: Int32) -> Int32 + + @JavaStaticMethod + public func codePointCount(_ arg0: [UInt16], _ arg1: Int32, _ arg2: Int32) -> Int32 + + @JavaStaticMethod + public func offsetByCodePoints(_ arg0: [UInt16], _ arg1: Int32, _ arg2: Int32, _ arg3: Int32, _ arg4: Int32) -> Int32 + + @JavaStaticMethod + public func toLowerCase(_ arg0: UInt16) -> UInt16 + + @JavaStaticMethod + public func toLowerCase(_ arg0: Int32) -> Int32 + + @JavaStaticMethod + public func toUpperCase(_ arg0: Int32) -> Int32 + + @JavaStaticMethod + public func toUpperCase(_ arg0: UInt16) -> UInt16 + + @JavaStaticMethod + public func isBmpCodePoint(_ arg0: Int32) -> Bool + + @JavaStaticMethod + public func getType(_ arg0: UInt16) -> Int32 + + @JavaStaticMethod + public func getType(_ arg0: Int32) -> Int32 + + @JavaStaticMethod + public func isLetter(_ arg0: UInt16) -> Bool + + @JavaStaticMethod + public func isLetter(_ arg0: Int32) -> Bool + + @JavaStaticMethod + public func isLetterOrDigit(_ arg0: Int32) -> Bool + + @JavaStaticMethod + public func isLetterOrDigit(_ arg0: UInt16) -> Bool + + @JavaStaticMethod + public func isValidCodePoint(_ arg0: Int32) -> Bool + + @JavaStaticMethod + public func isTitleCase(_ arg0: Int32) -> Bool + + @JavaStaticMethod + public func isTitleCase(_ arg0: UInt16) -> Bool + + @JavaStaticMethod + public func isDefined(_ arg0: UInt16) -> Bool + + @JavaStaticMethod + public func isDefined(_ arg0: Int32) -> Bool + + @JavaStaticMethod + public func isIdeographic(_ arg0: Int32) -> Bool + + @JavaStaticMethod + public func isUnicodeIdentifierStart(_ arg0: Int32) -> Bool + + @JavaStaticMethod + public func isUnicodeIdentifierStart(_ arg0: UInt16) -> Bool + + @JavaStaticMethod + public func isUnicodeIdentifierPart(_ arg0: Int32) -> Bool + + @JavaStaticMethod + public func isUnicodeIdentifierPart(_ arg0: UInt16) -> Bool + + @JavaStaticMethod + public func isIdentifierIgnorable(_ arg0: Int32) -> Bool + + @JavaStaticMethod + public func isIdentifierIgnorable(_ arg0: UInt16) -> Bool + + @JavaStaticMethod + public func isEmoji(_ arg0: Int32) -> Bool + + @JavaStaticMethod + public func isEmojiPresentation(_ arg0: Int32) -> Bool + + @JavaStaticMethod + public func isEmojiModifier(_ arg0: Int32) -> Bool + + @JavaStaticMethod + public func isEmojiModifierBase(_ arg0: Int32) -> Bool + + @JavaStaticMethod + public func isEmojiComponent(_ arg0: Int32) -> Bool + + @JavaStaticMethod + public func isExtendedPictographic(_ arg0: Int32) -> Bool + + @JavaStaticMethod + public func toTitleCase(_ arg0: UInt16) -> UInt16 + + @JavaStaticMethod + public func toTitleCase(_ arg0: Int32) -> Int32 + + @JavaStaticMethod + public func digit(_ arg0: UInt16, _ arg1: Int32) -> Int32 + + @JavaStaticMethod + public func digit(_ arg0: Int32, _ arg1: Int32) -> Int32 + + @JavaStaticMethod + public func getNumericValue(_ arg0: Int32) -> Int32 + + @JavaStaticMethod + public func getNumericValue(_ arg0: UInt16) -> Int32 + + @JavaStaticMethod + public func isSpaceChar(_ arg0: UInt16) -> Bool + + @JavaStaticMethod + public func isSpaceChar(_ arg0: Int32) -> Bool + + @JavaStaticMethod + public func isISOControl(_ arg0: Int32) -> Bool + + @JavaStaticMethod + public func isISOControl(_ arg0: UInt16) -> Bool + + @JavaStaticMethod + public func getDirectionality(_ arg0: UInt16) -> Int8 + + @JavaStaticMethod + public func getDirectionality(_ arg0: Int32) -> Int8 + + @JavaStaticMethod + public func isMirrored(_ arg0: UInt16) -> Bool + + @JavaStaticMethod + public func isMirrored(_ arg0: Int32) -> Bool + + @JavaStaticMethod + public func isSurrogatePair(_ arg0: UInt16, _ arg1: UInt16) -> Bool + + @JavaStaticMethod + public func charCount(_ arg0: Int32) -> Int32 + + @JavaStaticMethod + public func isJavaLetter(_ arg0: UInt16) -> Bool + + @JavaStaticMethod + public func isJavaLetterOrDigit(_ arg0: UInt16) -> Bool + + @JavaStaticMethod + public func isAlphabetic(_ arg0: Int32) -> Bool + + @JavaStaticMethod + public func isSpace(_ arg0: UInt16) -> Bool + + @JavaStaticMethod + public func forDigit(_ arg0: Int32, _ arg1: Int32) -> UInt16 + + @JavaStaticMethod + public func codePointOf(_ arg0: String) -> Int32 +} diff --git a/Sources/JavaKit/generated/JavaClass.swift b/Sources/JavaKit/generated/JavaClass.swift new file mode 100644 index 00000000..1696db8a --- /dev/null +++ b/Sources/JavaKit/generated/JavaClass.swift @@ -0,0 +1,162 @@ +// Auto-generated by Java-to-Swift wrapper generator. +import JavaRuntime + +@JavaClass("java.lang.Class") +public struct JavaClass { + @JavaMethod + public func getName() -> String + + @JavaMethod + public func toString() -> String + + @JavaMethod + public func isAssignableFrom(_ arg0: JavaClass?) -> Bool + + @JavaMethod + public func isInstance(_ arg0: JavaObject?) -> Bool + + @JavaMethod + public func getModifiers() -> Int32 + + @JavaMethod + public func isInterface() -> Bool + + @JavaMethod + public func isArray() -> Bool + + @JavaMethod + public func isPrimitive() -> Bool + + @JavaMethod + public func isHidden() -> Bool + + @JavaMethod + public func getSuperclass() -> JavaClass? + + @JavaMethod + public func cast(_ arg0: JavaObject?) -> JavaObject? + + @JavaMethod + public func componentType() -> JavaClass? + + @JavaMethod + public func getComponentType() -> JavaClass? + + @JavaMethod + public func isAnnotation() -> Bool + + @JavaMethod + public func isEnum() -> Bool + + @JavaMethod + public func isRecord() -> Bool + + @JavaMethod + public func newInstance() throws -> JavaObject? + + @JavaMethod + public func getInterfaces() -> [JavaClass?] + + @JavaMethod + public func isMemberClass() -> Bool + + @JavaMethod + public func isLocalClass() -> Bool + + @JavaMethod + public func isAnonymousClass() -> Bool + + @JavaMethod + public func getEnclosingClass() throws -> JavaClass? + + @JavaMethod + public func arrayType() -> JavaClass? + + @JavaMethod + public func getSimpleName() -> String + + @JavaMethod + public func getCanonicalName() -> String + + @JavaMethod + public func getPackageName() -> String + + @JavaMethod + public func desiredAssertionStatus() -> Bool + + @JavaMethod + public func getNestHost() -> JavaClass? + + @JavaMethod + public func descriptorString() -> String + + @JavaMethod + public func getPermittedSubclasses() -> [JavaClass?] + + @JavaMethod + public func toGenericString() -> String + + @JavaMethod + public func isSynthetic() -> Bool + + @JavaMethod + public func getSigners() -> [JavaObject?] + + @JavaMethod + public func getDeclaringClass() throws -> JavaClass? + + @JavaMethod + public func getTypeName() -> String + + @JavaMethod + public func getClasses() -> [JavaClass?] + + @JavaMethod + public func getDeclaredClasses() throws -> [JavaClass?] + + @JavaMethod + public func getEnumConstants() -> [JavaObject?] + + @JavaMethod + public func asSubclass(_ arg0: JavaClass?) -> JavaClass? + + @JavaMethod + public func isNestmateOf(_ arg0: JavaClass?) -> Bool + + @JavaMethod + public func getNestMembers() -> [JavaClass?] + + @JavaMethod + public func isSealed() -> Bool + + @JavaMethod + public func equals(_ arg0: JavaObject?) -> Bool + + @JavaMethod + public func hashCode() -> Int32 + + @JavaMethod + public func getClass() -> JavaClass? + + @JavaMethod + public func notify() + + @JavaMethod + public func notifyAll() + + @JavaMethod + public func wait(_ arg0: Int64) throws + + @JavaMethod + public func wait(_ arg0: Int64, _ arg1: Int32) throws + + @JavaMethod + public func wait() throws +} +extension JavaClass { + @JavaStaticMethod + public func forName(_ arg0: String) throws -> JavaClass? where ObjectType == JavaClass + + @JavaStaticMethod + public func forPrimitiveName(_ arg0: String) -> JavaClass? where ObjectType == JavaClass +} diff --git a/Sources/JavaKit/generated/JavaDouble.swift b/Sources/JavaKit/generated/JavaDouble.swift new file mode 100644 index 00000000..8d7a9abc --- /dev/null +++ b/Sources/JavaKit/generated/JavaDouble.swift @@ -0,0 +1,153 @@ +// Auto-generated by Java-to-Swift wrapper generator. +import JavaRuntime + +@JavaClass("java.lang.Double", extends: JavaNumber.self) +public struct JavaDouble { + @JavaMethod + public init(_ arg0: Double, environment: JNIEnvironment? = nil) + + @JavaMethod + public init(_ arg0: String, environment: JNIEnvironment? = nil) throws + + @JavaMethod + public func equals(_ arg0: JavaObject?) -> Bool + + @JavaMethod + public func toString() -> String + + @JavaMethod + public func hashCode() -> Int32 + + @JavaMethod + public func isInfinite() -> Bool + + @JavaMethod + public func compareTo(_ arg0: JavaDouble?) -> Int32 + + @JavaMethod + public func compareTo(_ arg0: JavaObject?) -> Int32 + + @JavaMethod + public func byteValue() -> Int8 + + @JavaMethod + public func shortValue() -> Int16 + + @JavaMethod + public func intValue() -> Int32 + + @JavaMethod + public func longValue() -> Int64 + + @JavaMethod + public func floatValue() -> Float + + @JavaMethod + public func doubleValue() -> Double + + @JavaMethod + public func isNaN() -> Bool + + @JavaMethod + public func getClass() -> JavaClass? + + @JavaMethod + public func notify() + + @JavaMethod + public func notifyAll() + + @JavaMethod + public func wait(_ arg0: Int64) throws + + @JavaMethod + public func wait(_ arg0: Int64, _ arg1: Int32) throws + + @JavaMethod + public func wait() throws +} +extension JavaClass { + @JavaStaticField + public var POSITIVE_INFINITY: Double + + @JavaStaticField + public var NEGATIVE_INFINITY: Double + + @JavaStaticField + public var NaN: Double + + @JavaStaticField + public var MAX_VALUE: Double + + @JavaStaticField + public var MIN_NORMAL: Double + + @JavaStaticField + public var MIN_VALUE: Double + + @JavaStaticField + public var SIZE: Int32 + + @JavaStaticField + public var PRECISION: Int32 + + @JavaStaticField + public var MAX_EXPONENT: Int32 + + @JavaStaticField + public var MIN_EXPONENT: Int32 + + @JavaStaticField + public var BYTES: Int32 + + @JavaStaticField + public var TYPE: JavaClass? + + @JavaStaticMethod + public func toString(_ arg0: Double) -> String + + @JavaStaticMethod + public func hashCode(_ arg0: Double) -> Int32 + + @JavaStaticMethod + public func min(_ arg0: Double, _ arg1: Double) -> Double + + @JavaStaticMethod + public func max(_ arg0: Double, _ arg1: Double) -> Double + + @JavaStaticMethod + public func isInfinite(_ arg0: Double) -> Bool + + @JavaStaticMethod + public func isFinite(_ arg0: Double) -> Bool + + @JavaStaticMethod + public func doubleToRawLongBits(_ arg0: Double) -> Int64 + + @JavaStaticMethod + public func doubleToLongBits(_ arg0: Double) -> Int64 + + @JavaStaticMethod + public func longBitsToDouble(_ arg0: Int64) -> Double + + @JavaStaticMethod + public func compare(_ arg0: Double, _ arg1: Double) -> Int32 + + @JavaStaticMethod + public func valueOf(_ arg0: String) throws -> JavaDouble? + + @JavaStaticMethod + public func valueOf(_ arg0: Double) -> JavaDouble? + + @JavaStaticMethod + public func toHexString(_ arg0: Double) -> String + + @JavaStaticMethod + public func isNaN(_ arg0: Double) -> Bool + + @JavaStaticMethod + public func sum(_ arg0: Double, _ arg1: Double) -> Double + + @JavaStaticMethod + public func parseDouble(_ arg0: String) throws -> Double +} diff --git a/Sources/JavaKit/generated/JavaFloat.swift b/Sources/JavaKit/generated/JavaFloat.swift new file mode 100644 index 00000000..83672479 --- /dev/null +++ b/Sources/JavaKit/generated/JavaFloat.swift @@ -0,0 +1,162 @@ +// Auto-generated by Java-to-Swift wrapper generator. +import JavaRuntime + +@JavaClass("java.lang.Float", extends: JavaNumber.self) +public struct JavaFloat { + @JavaMethod + public init(_ arg0: String, environment: JNIEnvironment? = nil) throws + + @JavaMethod + public init(_ arg0: Double, environment: JNIEnvironment? = nil) + + @JavaMethod + public init(_ arg0: Float, environment: JNIEnvironment? = nil) + + @JavaMethod + public func equals(_ arg0: JavaObject?) -> Bool + + @JavaMethod + public func toString() -> String + + @JavaMethod + public func hashCode() -> Int32 + + @JavaMethod + public func isInfinite() -> Bool + + @JavaMethod + public func compareTo(_ arg0: JavaObject?) -> Int32 + + @JavaMethod + public func compareTo(_ arg0: JavaFloat?) -> Int32 + + @JavaMethod + public func byteValue() -> Int8 + + @JavaMethod + public func shortValue() -> Int16 + + @JavaMethod + public func intValue() -> Int32 + + @JavaMethod + public func longValue() -> Int64 + + @JavaMethod + public func floatValue() -> Float + + @JavaMethod + public func doubleValue() -> Double + + @JavaMethod + public func isNaN() -> Bool + + @JavaMethod + public func getClass() -> JavaClass? + + @JavaMethod + public func notify() + + @JavaMethod + public func notifyAll() + + @JavaMethod + public func wait(_ arg0: Int64) throws + + @JavaMethod + public func wait(_ arg0: Int64, _ arg1: Int32) throws + + @JavaMethod + public func wait() throws +} +extension JavaClass { + @JavaStaticField + public var POSITIVE_INFINITY: Float + + @JavaStaticField + public var NEGATIVE_INFINITY: Float + + @JavaStaticField + public var NaN: Float + + @JavaStaticField + public var MAX_VALUE: Float + + @JavaStaticField + public var MIN_NORMAL: Float + + @JavaStaticField + public var MIN_VALUE: Float + + @JavaStaticField + public var SIZE: Int32 + + @JavaStaticField + public var PRECISION: Int32 + + @JavaStaticField + public var MAX_EXPONENT: Int32 + + @JavaStaticField + public var MIN_EXPONENT: Int32 + + @JavaStaticField + public var BYTES: Int32 + + @JavaStaticField + public var TYPE: JavaClass? + + @JavaStaticMethod + public func toString(_ arg0: Float) -> String + + @JavaStaticMethod + public func hashCode(_ arg0: Float) -> Int32 + + @JavaStaticMethod + public func min(_ arg0: Float, _ arg1: Float) -> Float + + @JavaStaticMethod + public func max(_ arg0: Float, _ arg1: Float) -> Float + + @JavaStaticMethod + public func isInfinite(_ arg0: Float) -> Bool + + @JavaStaticMethod + public func isFinite(_ arg0: Float) -> Bool + + @JavaStaticMethod + public func floatToRawIntBits(_ arg0: Float) -> Int32 + + @JavaStaticMethod + public func floatToIntBits(_ arg0: Float) -> Int32 + + @JavaStaticMethod + public func intBitsToFloat(_ arg0: Int32) -> Float + + @JavaStaticMethod + public func float16ToFloat(_ arg0: Int16) -> Float + + @JavaStaticMethod + public func floatToFloat16(_ arg0: Float) -> Int16 + + @JavaStaticMethod + public func compare(_ arg0: Float, _ arg1: Float) -> Int32 + + @JavaStaticMethod + public func valueOf(_ arg0: Float) -> JavaFloat? + + @JavaStaticMethod + public func valueOf(_ arg0: String) throws -> JavaFloat? + + @JavaStaticMethod + public func toHexString(_ arg0: Float) -> String + + @JavaStaticMethod + public func isNaN(_ arg0: Float) -> Bool + + @JavaStaticMethod + public func sum(_ arg0: Float, _ arg1: Float) -> Float + + @JavaStaticMethod + public func parseFloat(_ arg0: String) throws -> Float +} diff --git a/Sources/JavaKit/generated/JavaInteger.swift b/Sources/JavaKit/generated/JavaInteger.swift new file mode 100644 index 00000000..09d27eed --- /dev/null +++ b/Sources/JavaKit/generated/JavaInteger.swift @@ -0,0 +1,195 @@ +// Auto-generated by Java-to-Swift wrapper generator. +import JavaRuntime + +@JavaClass("java.lang.Integer", extends: JavaNumber.self) +public struct JavaInteger { + @JavaMethod + public init(_ arg0: Int32, environment: JNIEnvironment? = nil) + + @JavaMethod + public init(_ arg0: String, environment: JNIEnvironment? = nil) throws + + @JavaMethod + public func equals(_ arg0: JavaObject?) -> Bool + + @JavaMethod + public func toString() -> String + + @JavaMethod + public func hashCode() -> Int32 + + @JavaMethod + public func compareTo(_ arg0: JavaObject?) -> Int32 + + @JavaMethod + public func compareTo(_ arg0: JavaInteger?) -> Int32 + + @JavaMethod + public func byteValue() -> Int8 + + @JavaMethod + public func shortValue() -> Int16 + + @JavaMethod + public func intValue() -> Int32 + + @JavaMethod + public func longValue() -> Int64 + + @JavaMethod + public func floatValue() -> Float + + @JavaMethod + public func doubleValue() -> Double + + @JavaMethod + public func getClass() -> JavaClass? + + @JavaMethod + public func notify() + + @JavaMethod + public func notifyAll() + + @JavaMethod + public func wait(_ arg0: Int64) throws + + @JavaMethod + public func wait(_ arg0: Int64, _ arg1: Int32) throws + + @JavaMethod + public func wait() throws +} +extension JavaClass { + @JavaStaticField + public var MIN_VALUE: Int32 + + @JavaStaticField + public var MAX_VALUE: Int32 + + @JavaStaticField + public var TYPE: JavaClass? + + @JavaStaticField + public var SIZE: Int32 + + @JavaStaticField + public var BYTES: Int32 + + @JavaStaticMethod + public func numberOfLeadingZeros(_ arg0: Int32) -> Int32 + + @JavaStaticMethod + public func numberOfTrailingZeros(_ arg0: Int32) -> Int32 + + @JavaStaticMethod + public func bitCount(_ arg0: Int32) -> Int32 + + @JavaStaticMethod + public func toString(_ arg0: Int32) -> String + + @JavaStaticMethod + public func toString(_ arg0: Int32, _ arg1: Int32) -> String + + @JavaStaticMethod + public func hashCode(_ arg0: Int32) -> Int32 + + @JavaStaticMethod + public func min(_ arg0: Int32, _ arg1: Int32) -> Int32 + + @JavaStaticMethod + public func max(_ arg0: Int32, _ arg1: Int32) -> Int32 + + @JavaStaticMethod + public func signum(_ arg0: Int32) -> Int32 + + @JavaStaticMethod + public func expand(_ arg0: Int32, _ arg1: Int32) -> Int32 + + @JavaStaticMethod + public func compareUnsigned(_ arg0: Int32, _ arg1: Int32) -> Int32 + + @JavaStaticMethod + public func divideUnsigned(_ arg0: Int32, _ arg1: Int32) -> Int32 + + @JavaStaticMethod + public func remainderUnsigned(_ arg0: Int32, _ arg1: Int32) -> Int32 + + @JavaStaticMethod + public func reverse(_ arg0: Int32) -> Int32 + + @JavaStaticMethod + public func reverseBytes(_ arg0: Int32) -> Int32 + + @JavaStaticMethod + public func compress(_ arg0: Int32, _ arg1: Int32) -> Int32 + + @JavaStaticMethod + public func compare(_ arg0: Int32, _ arg1: Int32) -> Int32 + + @JavaStaticMethod + public func valueOf(_ arg0: String) throws -> JavaInteger? + + @JavaStaticMethod + public func valueOf(_ arg0: String, _ arg1: Int32) throws -> JavaInteger? + + @JavaStaticMethod + public func valueOf(_ arg0: Int32) -> JavaInteger? + + @JavaStaticMethod + public func toHexString(_ arg0: Int32) -> String + + @JavaStaticMethod + public func decode(_ arg0: String) throws -> JavaInteger? + + @JavaStaticMethod + public func parseInt(_ arg0: String) throws -> Int32 + + @JavaStaticMethod + public func parseInt(_ arg0: String, _ arg1: Int32) throws -> Int32 + + @JavaStaticMethod + public func toUnsignedLong(_ arg0: Int32) -> Int64 + + @JavaStaticMethod + public func sum(_ arg0: Int32, _ arg1: Int32) -> Int32 + + @JavaStaticMethod + public func toUnsignedString(_ arg0: Int32, _ arg1: Int32) -> String + + @JavaStaticMethod + public func toUnsignedString(_ arg0: Int32) -> String + + @JavaStaticMethod + public func parseUnsignedInt(_ arg0: String) throws -> Int32 + + @JavaStaticMethod + public func parseUnsignedInt(_ arg0: String, _ arg1: Int32) throws -> Int32 + + @JavaStaticMethod + public func getInteger(_ arg0: String, _ arg1: JavaInteger?) -> JavaInteger? + + @JavaStaticMethod + public func getInteger(_ arg0: String, _ arg1: Int32) -> JavaInteger? + + @JavaStaticMethod + public func getInteger(_ arg0: String) -> JavaInteger? + + @JavaStaticMethod + public func toOctalString(_ arg0: Int32) -> String + + @JavaStaticMethod + public func toBinaryString(_ arg0: Int32) -> String + + @JavaStaticMethod + public func highestOneBit(_ arg0: Int32) -> Int32 + + @JavaStaticMethod + public func lowestOneBit(_ arg0: Int32) -> Int32 + + @JavaStaticMethod + public func rotateLeft(_ arg0: Int32, _ arg1: Int32) -> Int32 + + @JavaStaticMethod + public func rotateRight(_ arg0: Int32, _ arg1: Int32) -> Int32 +} diff --git a/Sources/JavaKit/generated/JavaLong.swift b/Sources/JavaKit/generated/JavaLong.swift new file mode 100644 index 00000000..f2aa72bd --- /dev/null +++ b/Sources/JavaKit/generated/JavaLong.swift @@ -0,0 +1,192 @@ +// Auto-generated by Java-to-Swift wrapper generator. +import JavaRuntime + +@JavaClass("java.lang.Long", extends: JavaNumber.self) +public struct JavaLong { + @JavaMethod + public init(_ arg0: String, environment: JNIEnvironment? = nil) throws + + @JavaMethod + public init(_ arg0: Int64, environment: JNIEnvironment? = nil) + + @JavaMethod + public func equals(_ arg0: JavaObject?) -> Bool + + @JavaMethod + public func toString() -> String + + @JavaMethod + public func hashCode() -> Int32 + + @JavaMethod + public func compareTo(_ arg0: JavaObject?) -> Int32 + + @JavaMethod + public func compareTo(_ arg0: JavaLong?) -> Int32 + + @JavaMethod + public func byteValue() -> Int8 + + @JavaMethod + public func shortValue() -> Int16 + + @JavaMethod + public func intValue() -> Int32 + + @JavaMethod + public func longValue() -> Int64 + + @JavaMethod + public func floatValue() -> Float + + @JavaMethod + public func doubleValue() -> Double + + @JavaMethod + public func getClass() -> JavaClass? + + @JavaMethod + public func notify() + + @JavaMethod + public func notifyAll() + + @JavaMethod + public func wait(_ arg0: Int64) throws + + @JavaMethod + public func wait(_ arg0: Int64, _ arg1: Int32) throws + + @JavaMethod + public func wait() throws +} +extension JavaClass { + @JavaStaticField + public var MIN_VALUE: Int64 + + @JavaStaticField + public var MAX_VALUE: Int64 + + @JavaStaticField + public var TYPE: JavaClass? + + @JavaStaticField + public var SIZE: Int32 + + @JavaStaticField + public var BYTES: Int32 + + @JavaStaticMethod + public func numberOfLeadingZeros(_ arg0: Int64) -> Int32 + + @JavaStaticMethod + public func numberOfTrailingZeros(_ arg0: Int64) -> Int32 + + @JavaStaticMethod + public func bitCount(_ arg0: Int64) -> Int32 + + @JavaStaticMethod + public func toString(_ arg0: Int64) -> String + + @JavaStaticMethod + public func toString(_ arg0: Int64, _ arg1: Int32) -> String + + @JavaStaticMethod + public func hashCode(_ arg0: Int64) -> Int32 + + @JavaStaticMethod + public func min(_ arg0: Int64, _ arg1: Int64) -> Int64 + + @JavaStaticMethod + public func max(_ arg0: Int64, _ arg1: Int64) -> Int64 + + @JavaStaticMethod + public func signum(_ arg0: Int64) -> Int32 + + @JavaStaticMethod + public func expand(_ arg0: Int64, _ arg1: Int64) -> Int64 + + @JavaStaticMethod + public func compareUnsigned(_ arg0: Int64, _ arg1: Int64) -> Int32 + + @JavaStaticMethod + public func divideUnsigned(_ arg0: Int64, _ arg1: Int64) -> Int64 + + @JavaStaticMethod + public func remainderUnsigned(_ arg0: Int64, _ arg1: Int64) -> Int64 + + @JavaStaticMethod + public func reverse(_ arg0: Int64) -> Int64 + + @JavaStaticMethod + public func reverseBytes(_ arg0: Int64) -> Int64 + + @JavaStaticMethod + public func compress(_ arg0: Int64, _ arg1: Int64) -> Int64 + + @JavaStaticMethod + public func getLong(_ arg0: String, _ arg1: JavaLong?) -> JavaLong? + + @JavaStaticMethod + public func getLong(_ arg0: String) -> JavaLong? + + @JavaStaticMethod + public func getLong(_ arg0: String, _ arg1: Int64) -> JavaLong? + + @JavaStaticMethod + public func compare(_ arg0: Int64, _ arg1: Int64) -> Int32 + + @JavaStaticMethod + public func valueOf(_ arg0: String) throws -> JavaLong? + + @JavaStaticMethod + public func valueOf(_ arg0: Int64) -> JavaLong? + + @JavaStaticMethod + public func valueOf(_ arg0: String, _ arg1: Int32) throws -> JavaLong? + + @JavaStaticMethod + public func toHexString(_ arg0: Int64) -> String + + @JavaStaticMethod + public func decode(_ arg0: String) throws -> JavaLong? + + @JavaStaticMethod + public func sum(_ arg0: Int64, _ arg1: Int64) -> Int64 + + @JavaStaticMethod + public func toUnsignedString(_ arg0: Int64) -> String + + @JavaStaticMethod + public func toUnsignedString(_ arg0: Int64, _ arg1: Int32) -> String + + @JavaStaticMethod + public func toOctalString(_ arg0: Int64) -> String + + @JavaStaticMethod + public func toBinaryString(_ arg0: Int64) -> String + + @JavaStaticMethod + public func highestOneBit(_ arg0: Int64) -> Int64 + + @JavaStaticMethod + public func lowestOneBit(_ arg0: Int64) -> Int64 + + @JavaStaticMethod + public func rotateLeft(_ arg0: Int64, _ arg1: Int32) -> Int64 + + @JavaStaticMethod + public func rotateRight(_ arg0: Int64, _ arg1: Int32) -> Int64 + + @JavaStaticMethod + public func parseLong(_ arg0: String, _ arg1: Int32) throws -> Int64 + + @JavaStaticMethod + public func parseLong(_ arg0: String) throws -> Int64 + + @JavaStaticMethod + public func parseUnsignedLong(_ arg0: String, _ arg1: Int32) throws -> Int64 + + @JavaStaticMethod + public func parseUnsignedLong(_ arg0: String) throws -> Int64 +} diff --git a/Sources/JavaKit/generated/JavaNumber.swift b/Sources/JavaKit/generated/JavaNumber.swift new file mode 100644 index 00000000..42864a37 --- /dev/null +++ b/Sources/JavaKit/generated/JavaNumber.swift @@ -0,0 +1,53 @@ +// Auto-generated by Java-to-Swift wrapper generator. +import JavaRuntime + +@JavaClass("java.lang.Number") +public struct JavaNumber { + @JavaMethod + public init(environment: JNIEnvironment? = nil) + + @JavaMethod + public func byteValue() -> Int8 + + @JavaMethod + public func shortValue() -> Int16 + + @JavaMethod + public func intValue() -> Int32 + + @JavaMethod + public func longValue() -> Int64 + + @JavaMethod + public func floatValue() -> Float + + @JavaMethod + public func doubleValue() -> Double + + @JavaMethod + public func equals(_ arg0: JavaObject?) -> Bool + + @JavaMethod + public func toString() -> String + + @JavaMethod + public func hashCode() -> Int32 + + @JavaMethod + public func getClass() -> JavaClass? + + @JavaMethod + public func notify() + + @JavaMethod + public func notifyAll() + + @JavaMethod + public func wait(_ arg0: Int64) throws + + @JavaMethod + public func wait(_ arg0: Int64, _ arg1: Int32) throws + + @JavaMethod + public func wait() throws +} diff --git a/Sources/JavaKit/generated/JavaShort.swift b/Sources/JavaKit/generated/JavaShort.swift new file mode 100644 index 00000000..b7c5de3f --- /dev/null +++ b/Sources/JavaKit/generated/JavaShort.swift @@ -0,0 +1,117 @@ +// Auto-generated by Java-to-Swift wrapper generator. +import JavaRuntime + +@JavaClass("java.lang.Short", extends: JavaNumber.self) +public struct JavaShort { + @JavaMethod + public init(_ arg0: Int16, environment: JNIEnvironment? = nil) + + @JavaMethod + public init(_ arg0: String, environment: JNIEnvironment? = nil) throws + + @JavaMethod + public func equals(_ arg0: JavaObject?) -> Bool + + @JavaMethod + public func toString() -> String + + @JavaMethod + public func hashCode() -> Int32 + + @JavaMethod + public func compareTo(_ arg0: JavaShort?) -> Int32 + + @JavaMethod + public func compareTo(_ arg0: JavaObject?) -> Int32 + + @JavaMethod + public func byteValue() -> Int8 + + @JavaMethod + public func shortValue() -> Int16 + + @JavaMethod + public func intValue() -> Int32 + + @JavaMethod + public func longValue() -> Int64 + + @JavaMethod + public func floatValue() -> Float + + @JavaMethod + public func doubleValue() -> Double + + @JavaMethod + public func getClass() -> JavaClass? + + @JavaMethod + public func notify() + + @JavaMethod + public func notifyAll() + + @JavaMethod + public func wait(_ arg0: Int64) throws + + @JavaMethod + public func wait(_ arg0: Int64, _ arg1: Int32) throws + + @JavaMethod + public func wait() throws +} +extension JavaClass { + @JavaStaticField + public var MIN_VALUE: Int16 + + @JavaStaticField + public var MAX_VALUE: Int16 + + @JavaStaticField + public var TYPE: JavaClass? + + @JavaStaticField + public var SIZE: Int32 + + @JavaStaticField + public var BYTES: Int32 + + @JavaStaticMethod + public func toString(_ arg0: Int16) -> String + + @JavaStaticMethod + public func hashCode(_ arg0: Int16) -> Int32 + + @JavaStaticMethod + public func compareUnsigned(_ arg0: Int16, _ arg1: Int16) -> Int32 + + @JavaStaticMethod + public func reverseBytes(_ arg0: Int16) -> Int16 + + @JavaStaticMethod + public func compare(_ arg0: Int16, _ arg1: Int16) -> Int32 + + @JavaStaticMethod + public func valueOf(_ arg0: String, _ arg1: Int32) throws -> JavaShort? + + @JavaStaticMethod + public func valueOf(_ arg0: String) throws -> JavaShort? + + @JavaStaticMethod + public func valueOf(_ arg0: Int16) -> JavaShort? + + @JavaStaticMethod + public func decode(_ arg0: String) throws -> JavaShort? + + @JavaStaticMethod + public func toUnsignedLong(_ arg0: Int16) -> Int64 + + @JavaStaticMethod + public func toUnsignedInt(_ arg0: Int16) -> Int32 + + @JavaStaticMethod + public func parseShort(_ arg0: String) throws -> Int16 + + @JavaStaticMethod + public func parseShort(_ arg0: String, _ arg1: Int32) throws -> Int16 +} diff --git a/Sources/JavaKit/generated/JavaVoid.swift b/Sources/JavaKit/generated/JavaVoid.swift new file mode 100644 index 00000000..f6e0f4a6 --- /dev/null +++ b/Sources/JavaKit/generated/JavaVoid.swift @@ -0,0 +1,36 @@ +// Auto-generated by Java-to-Swift wrapper generator. +import JavaRuntime + +@JavaClass("java.lang.Void") +public struct JavaVoid { + @JavaMethod + public func equals(_ arg0: JavaObject?) -> Bool + + @JavaMethod + public func toString() -> String + + @JavaMethod + public func hashCode() -> Int32 + + @JavaMethod + public func getClass() -> JavaClass? + + @JavaMethod + public func notify() + + @JavaMethod + public func notifyAll() + + @JavaMethod + public func wait(_ arg0: Int64) throws + + @JavaMethod + public func wait(_ arg0: Int64, _ arg1: Int32) throws + + @JavaMethod + public func wait() throws +} +extension JavaClass { + @JavaStaticField + public var TYPE: JavaClass? +} diff --git a/Sources/JavaKitReflection/JavaClass+Reflection.swift b/Sources/JavaKitReflection/JavaClass+Reflection.swift index 13e080ac..569b72e8 100644 --- a/Sources/JavaKitReflection/JavaClass+Reflection.swift +++ b/Sources/JavaKitReflection/JavaClass+Reflection.swift @@ -17,18 +17,6 @@ import JavaKit // TODO: We should be able to autogenerate this as an extension based on // knowing that JavaClass was defined elsewhere. extension JavaClass { - @JavaMethod - public func equals(_ arg0: JavaObject?) -> Bool - - @JavaMethod - public func getName() -> String - - @JavaMethod - public func getSimpleName() -> String - - @JavaMethod - public func getCanonicalName() -> String - @JavaMethod public func getDeclaredMethods() -> [Method?] @@ -44,15 +32,9 @@ extension JavaClass { @JavaMethod public func getParameters() -> [Parameter?] - @JavaMethod - public func getSuperclass() -> JavaClass? - @JavaMethod public func getTypeParameters() -> [TypeVariable>?] @JavaMethod public func getGenericInterfaces() -> [Type?] - - @JavaMethod - public func isInterface() -> Bool } diff --git a/Tests/JavaKitTests/BasicRuntimeTests.swift b/Tests/JavaKitTests/BasicRuntimeTests.swift index 0e5fed0b..5185294e 100644 --- a/Tests/JavaKitTests/BasicRuntimeTests.swift +++ b/Tests/JavaKitTests/BasicRuntimeTests.swift @@ -63,7 +63,7 @@ class BasicRuntimeTests: XCTestCase { func testStaticMethods() throws { let environment = try jvm.environment() - let urlConnectionClass = try JavaClass(in: environment) + let urlConnectionClass = try JavaClass(environment: environment) XCTAssert(urlConnectionClass.getDefaultAllowUserInteraction() == false) } @@ -71,7 +71,7 @@ class BasicRuntimeTests: XCTestCase { let environment = try jvm.environment() do { - _ = try JavaClass(in: environment) + _ = try JavaClass(environment: environment) } catch { XCTAssertEqual(String(describing: error), "org/swift/javakit/Nonexistent") } diff --git a/USER_GUIDE.md b/USER_GUIDE.md index 33e08423..a85fa94e 100644 --- a/USER_GUIDE.md +++ b/USER_GUIDE.md @@ -61,35 +61,43 @@ public struct BigInteger { This Swift type wraps `java.math.BigInteger`, exposing its constructors, methods, and fields for use directly to Swift. Let's try using it! -### Creating a Java Virtual Machine instance from Swift +### Creating a `BigInteger` and determine whether it is probably prime -The `JavaVirtualMachine` class, which is part of the `JavaKitVM` module, provides the ability to create and query the Java Virtual Machine. One can create a shared instance of `JavaVirtualMachine` by calling `JavaVirtualMachine.shared()`, optionally passing along extra options to the JVM (such as the class path): +Now, we can go ahead and create a `BigInteger` instance from a Swift string like this: ```swift -let javaVirtualMachine = try JavaVirtualMachine.shared() +let bigInt = BigInteger(veryBigNumber) ``` -If the JVM is already running, a `JavaVirtualMachine` instance will be created to reference that existing JVM. Given a `JavaVirtualMachine` instance, one can query the JNI environment for the currently-active thread by calling `environment()`, e.g., +And then call methods on it. For example, check whether the big integer is a probable prime with some certainty: ```swift -let jniEnvironment = try javaVirtualMachine.environment() +if bigInt.isProbablePrime(10) { + print("\(bigInt.toString()) is probably prime") +} ``` -This JNI environment can be used to create instances of Java objects. For example, we can create a `BigInteger` instance from a Swift string like this: +Swift ensures that the Java garbage collector will keep the object alive until `bigInt` (and any copies of it) are been destroyed. + +### Creating a Java Virtual Machine instance from Swift + +When JavaKit requires a running Java Virtual Machine to use an operation (for example, to create an instance of `BigInteger`), it will query to determine if one is running and, if not, create one. To exercise more control over the creation and configuration of the Java virtual machine, use the `JavaVirtualMachine` class, which provides creation and query operations. One can create a shared instance by calling `JavaVirtualMachine.shared()`, optionally passing along extra options to the JVM (such as the class path): ```swift -let bigInt = BigInteger(veryBigNumber, environment: jniEnvironment) +let javaVirtualMachine = try JavaVirtualMachine.shared() ``` -And then call methods on it. For example, check whether the big integer is a probable prime with some certainty: +If the JVM is already running, a `JavaVirtualMachine` instance will be created to reference that existing JVM. Given a `JavaVirtualMachine` instance, one can query the JNI environment for the currently-active thread by calling `environment()`, e.g., ```swift -if bigInt.isProbablePrime(10) { - print("\(bigInt.toString()) is probably prime") -} +let jniEnvironment = try javaVirtualMachine.environment() ``` -Swift ensures that the Java garbage collector will keep the object alive until `bigInt` (and any copies of it) are been destroyed. +This JNI environment can be used to create instances of Java objects in a specific JNI environment. For example, we can pass this environment along when we create the `BigInteger` instance from a Swift string, like this: + +```swift +let bigInt = BigInteger(veryBigNumber, environment: jniEnvironment) +``` ### Importing a Jar file into Swift @@ -134,7 +142,7 @@ The resulting configuration file will look something like this: } ``` -As with the previous `JavaProbablyPrime` sample, the `JavaSieve` target in `Package.swift` should depend on the `swift-java` package modules (`JavaKit`, `JavaKitVM`) and apply the `Java2Swift` plugin. This makes all of the Java classes found in the Jar file available to Swift within the `JavaSieve` target. +As with the previous `JavaProbablyPrime` sample, the `JavaSieve` target in `Package.swift` should depend on the `swift-java` package modules (`JavaKit`) and apply the `Java2Swift` plugin. This makes all of the Java classes found in the Jar file available to Swift within the `JavaSieve` target. If you inspect the build output, there are a number of warnings that look like this: @@ -164,8 +172,7 @@ Then define a a Java2Swift configuration file in `Sources/JavaMath/Java2Swift.co "java.math.BigDecimal" : "BigDecimal", "java.math.BigInteger" : "BigInteger", "java.math.MathContext" : "MathContext", - "java.math.RoundingMode" : "RoundingMode", - "java.lang.Integer" : "JavaInteger", + "java.math.RoundingMode" : "RoundingMode" } } ``` @@ -185,7 +192,7 @@ public class SieveOfEratosthenes { In Java, static methods are called as members of the class itself. For Swift to call a Java static method, it needs a representation of the Java class. This is expressed as an instance of the generic type `JavaClass`, which can be created in a particular JNI environment like this: ```swift -let sieveClass = try JavaClass(in: jvm.environment()) +let sieveClass = try JavaClass(environment: jvm.environment()) ``` Now we can call Java's static methods on that class as instance methods on the `JavaClass` instance, e.g., @@ -198,11 +205,10 @@ Putting it all together, we can define a main program in `Sources/JavaSieve/main ```swift import JavaKit -import JavaKitVM let jvm = try JavaVirtualMachine.shared(classPath: ["QuadraticSieve-1.0.jar"]) do { - let sieveClass = try JavaClass(in: jvm.environment()) + let sieveClass = try JavaClass(environment: jvm.environment()) for prime in sieveClass.findPrimes(100)! { print("Found prime: \(prime.intValue())") }