Skip to content

JavaKit: Enable imported Java classes as Swift classes by default #141

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
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
2 changes: 1 addition & 1 deletion Sources/Java2Swift/JavaToSwift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ struct JavaToSwift: ParsableCommand {
let translator = JavaTranslator(
swiftModuleName: moduleName,
environment: environment,
translateAsClass: false
translateAsClass: true
)

// Keep track of all of the Java classes that will have
Expand Down
3 changes: 0 additions & 3 deletions Sources/JavaKit/AnyJavaObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ public protocol AnyJavaObject {
/// Retrieve the full Java class name (e.g., java.util.Vector)
static var fullJavaClassName: String { get }

/// The Java superclass type
associatedtype JavaSuperclass: AnyJavaObject

/// Initialize a Java object from the Swift instance that keeps it alive.
init(javaHolder: JavaObjectHolder)

Expand Down
7 changes: 0 additions & 7 deletions Sources/JavaKit/Exceptions/Exception+Error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@
//
//===----------------------------------------------------------------------===//

// Translate all Java Exception instances in a Swift error.
extension Exception: Error, CustomStringConvertible {
public var description: String {
return getMessage()
}
}

extension JavaClass<Exception> {
/// Determine whether this instance is a checked exception (which must be
/// handled) vs. an unchecked exception (which is not handled).
Expand Down
3 changes: 2 additions & 1 deletion Sources/JavaKit/JavaClass+Initialization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ extension JavaClass {
public typealias ObjectType = T

/// Lookup this Java class within the given environment.
public init(environment: JNIEnvironment? = nil) throws {
@_nonoverride
public convenience init(environment: JNIEnvironment? = nil) throws {
let environment = try environment ?? JavaVirtualMachine.shared().environment()
self.init(
javaThis: try ObjectType.getJNIClass(in: environment),
Expand Down
5 changes: 0 additions & 5 deletions Sources/JavaKit/JavaObject+Inheritance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
import JavaRuntime

extension AnyJavaObject {
/// Retrieve the same object instance but with the superclass type.
public var `super`: JavaSuperclass {
JavaSuperclass(javaHolder: javaHolder)
}

/// Look up the other class type
///
/// - Returns: `nil` when either `OtherClass` isn't known to the
Expand Down
2 changes: 1 addition & 1 deletion Sources/JavaKit/JavaObject+MethodCalls.swift
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ extension JavaClass {
return FieldType(fromJNI: jniMethod(javaEnvironment, javaThis, fieldID), in: javaEnvironment)
}

nonmutating set {
set {
let fieldID = getJNIStaticFieldID(fieldName, fieldType: fieldType)!
let jniMethod = FieldType.jniStaticFieldSet(in: javaEnvironment)
jniMethod(javaEnvironment, javaThis, fieldID, newValue.getJNIValue(in: javaEnvironment))
Expand Down
63 changes: 6 additions & 57 deletions Sources/JavaKit/generated/Exception.swift
Original file line number Diff line number Diff line change
@@ -1,68 +1,17 @@
// Auto-generated by Java-to-Swift wrapper generator.
import JavaRuntime

@JavaClass("java.lang.Exception", extends: Throwable.self)
public struct Exception {
@JavaClass("java.lang.Exception")
open class Exception: Throwable {
@JavaMethod
public init(_ arg0: Throwable?, environment: JNIEnvironment? = nil)
@_nonoverride public convenience init(_ arg0: Throwable?, environment: JNIEnvironment? = nil)

@JavaMethod
public init(_ arg0: String, _ arg1: Throwable?, environment: JNIEnvironment? = nil)
@_nonoverride public convenience init(_ arg0: String, _ arg1: Throwable?, environment: JNIEnvironment? = nil)

@JavaMethod
public init(_ arg0: String, environment: JNIEnvironment? = nil)
@_nonoverride public convenience init(_ arg0: String, environment: JNIEnvironment? = nil)

@JavaMethod
public init(environment: JNIEnvironment? = nil)

@JavaMethod
public func printStackTrace()

@JavaMethod
public func fillInStackTrace() -> Throwable!

@JavaMethod
public func getCause() -> Throwable!

@JavaMethod
public func initCause(_ arg0: Throwable?) -> Throwable!

@JavaMethod
public func toString() -> String

@JavaMethod
public func getMessage() -> String

@JavaMethod
public func getSuppressed() -> [Throwable?]

@JavaMethod
public func getLocalizedMessage() -> String

@JavaMethod
public func addSuppressed(_ arg0: Throwable?)

@JavaMethod
public func equals(_ arg0: JavaObject?) -> Bool

@JavaMethod
public func hashCode() -> Int32

@JavaMethod
public func getClass() -> JavaClass<JavaObject>!

@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
@_nonoverride public convenience init(environment: JNIEnvironment? = nil)
}
29 changes: 2 additions & 27 deletions Sources/JavaKit/generated/JavaArray.swift
Original file line number Diff line number Diff line change
@@ -1,34 +1,9 @@
// Auto-generated by Java-to-Swift wrapper generator.
import JavaRuntime

@JavaClass("java.lang.reflect.Array", extends: JavaObject.self)
public struct JavaArray {
@JavaMethod
public func equals(_ arg0: JavaObject?) -> Bool
@JavaClass("java.lang.reflect.Array")
open class JavaArray: JavaObject {

@JavaMethod
public func toString() -> String

@JavaMethod
public func hashCode() -> Int32

@JavaMethod
public func getClass() -> JavaClass<JavaObject>!

@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<JavaArray> {
@JavaStaticMethod
Expand Down
38 changes: 10 additions & 28 deletions Sources/JavaKit/generated/JavaBoolean.swift
Original file line number Diff line number Diff line change
@@ -1,49 +1,31 @@
// Auto-generated by Java-to-Swift wrapper generator.
import JavaRuntime

@JavaClass("java.lang.Boolean", extends: JavaObject.self)
public struct JavaBoolean {
@JavaClass("java.lang.Boolean")
open class JavaBoolean: JavaObject {
@JavaMethod
public init(_ arg0: Bool, environment: JNIEnvironment? = nil)
@_nonoverride public convenience init(_ arg0: Bool, environment: JNIEnvironment? = nil)

@JavaMethod
public init(_ arg0: String, environment: JNIEnvironment? = nil)
@_nonoverride public convenience init(_ arg0: String, environment: JNIEnvironment? = nil)

@JavaMethod
public func equals(_ arg0: JavaObject?) -> Bool
open override func equals(_ arg0: JavaObject?) -> Bool

@JavaMethod
public func toString() -> String
open override func toString() -> String

@JavaMethod
public func hashCode() -> Int32
open override func hashCode() -> Int32

@JavaMethod
public func compareTo(_ arg0: JavaBoolean?) -> Int32
open func compareTo(_ arg0: JavaBoolean?) -> Int32

@JavaMethod
public func compareTo(_ arg0: JavaObject?) -> Int32
open func compareTo(_ arg0: JavaObject?) -> Int32

@JavaMethod
public func booleanValue() -> Bool

@JavaMethod
public func getClass() -> JavaClass<JavaObject>!

@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
open func booleanValue() -> Bool
}
extension JavaClass<JavaBoolean> {
@JavaStaticField(isFinal: true)
Expand Down
48 changes: 15 additions & 33 deletions Sources/JavaKit/generated/JavaByte.swift
Original file line number Diff line number Diff line change
@@ -1,64 +1,46 @@
// Auto-generated by Java-to-Swift wrapper generator.
import JavaRuntime

@JavaClass("java.lang.Byte", extends: JavaNumber.self)
public struct JavaByte {
@JavaClass("java.lang.Byte")
open class JavaByte: JavaNumber {
@JavaMethod
public init(_ arg0: Int8, environment: JNIEnvironment? = nil)
@_nonoverride public convenience init(_ arg0: Int8, environment: JNIEnvironment? = nil)

@JavaMethod
public init(_ arg0: String, environment: JNIEnvironment? = nil) throws
@_nonoverride public convenience init(_ arg0: String, environment: JNIEnvironment? = nil) throws

@JavaMethod
public func equals(_ arg0: JavaObject?) -> Bool
open override func equals(_ arg0: JavaObject?) -> Bool

@JavaMethod
public func toString() -> String
open override func toString() -> String

@JavaMethod
public func hashCode() -> Int32
open override func hashCode() -> Int32

@JavaMethod
public func compareTo(_ arg0: JavaByte?) -> Int32
open func compareTo(_ arg0: JavaByte?) -> Int32

@JavaMethod
public func compareTo(_ arg0: JavaObject?) -> Int32
open func compareTo(_ arg0: JavaObject?) -> Int32

@JavaMethod
public func byteValue() -> Int8
open override func byteValue() -> Int8

@JavaMethod
public func shortValue() -> Int16
open override func shortValue() -> Int16

@JavaMethod
public func intValue() -> Int32
open override func intValue() -> Int32

@JavaMethod
public func longValue() -> Int64
open override func longValue() -> Int64

@JavaMethod
public func floatValue() -> Float
open override func floatValue() -> Float

@JavaMethod
public func doubleValue() -> Double

@JavaMethod
public func getClass() -> JavaClass<JavaObject>!

@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
open override func doubleValue() -> Double
}
extension JavaClass<JavaByte> {
@JavaStaticField(isFinal: true)
Expand Down
Loading