-
Notifications
You must be signed in to change notification settings - Fork 67
WIP: Lots of fixes wrapping java APIs #397
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
Draft
ktoso
wants to merge
25
commits into
swiftlang:main
Choose a base branch
from
ktoso:wip-cleanup-wrapping-java-apis
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,314
−654
Draft
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
bcd5f76
WIP: fixing up wrap-java behavior, also adding tests which compile and
ktoso d1f29d8
WIP: need the parameterized parent types
ktoso 45a4a3e
SwiftJava: regenerate and add JavaType and JavaParameterizedType
ktoso 9283f57
Rename "javakitvm" to just JVM; and add JavaReflectArray
ktoso fe84b0a
fix throwable to print class type and message
ktoso 8da01de
work towards handling generic methods with generic return type
ktoso 7608b7a
handle the return type being the generic type
ktoso 49e5949
multiple generic types on a method
ktoso 64d3e18
wrap-java: prune not used generic parameters from methods
ktoso eca6bc5
cleanup assert output for wrap-java to be not whitespace sensitive
ktoso a13656c
revamp testing infra for wrap-java, use classloader per test
ktoso 883969f
[jextract/jni] Add support for importing nested types (#429)
madsodgaard 0765c74
fix rendering of inheritance clause when parameterized superclass
ktoso e9cfec1
further correct generic handling and type variables
ktoso 3b87d8f
test fixes
ktoso 2d932e6
try debugging JNI on CI
ktoso d81ff4f
undo work directory changes in resolve command
ktoso 010db5e
disable experimental prebuilts in example run
ktoso b3aa62f
get more detailed output from JavaDependencySampleApp sample
ktoso 070ae87
wip on enums so we can not crash in JavaDependencySampleApp
ktoso 94c70c3
implement improved include/exclude filtering for wrap-java
ktoso e054f36
move JavaType equality extensions to separate file
ktoso b5de9d9
rename to SWIFT_JAVA_JAVA_OPTS
ktoso 636387a
remove verbose output options
ktoso 31e1d9b
shouldn't we use the deferEnv here?
ktoso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
Samples/JavaDependencySampleApp/Sources/JavaCommonsCSV/swift-java.config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,4 +44,4 @@ public enum NestedEnum { | |
| public struct OneStruct { | ||
| public init() {} | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
Sources/JavaStdlib/JavaLangReflect/TypeVariable+Extensions.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This source file is part of the Swift.org open source project | ||
| // | ||
| // Copyright (c) 2025 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 CSwiftJavaJNI | ||
| import SwiftJava | ||
|
|
||
| // FIXME: all interfaces should ahve these https://github.com/swiftlang/swift-java/issues/430 | ||
| extension TypeVariable { | ||
|
|
||
| @JavaMethod | ||
| public func toString() -> String | ||
|
|
||
| @JavaMethod | ||
| public func getClass() -> JavaClass<JavaObject>! | ||
|
|
||
| @JavaMethod | ||
| public func equals(_ arg0: JavaObject?) -> Bool | ||
|
|
||
| @JavaMethod | ||
| public func hashCode() -> Int32 | ||
|
|
||
| } | ||
|
|
||
| // FIXME: All Java objects are Hashable, we should handle that accordingly. | ||
| extension TypeVariable: Hashable { | ||
|
|
||
| public func hash(into hasher: inout Hasher) { | ||
| guard let pojo = self.as(JavaObject.self) else { | ||
| return | ||
| } | ||
|
|
||
| hasher.combine(pojo.hashCode()) | ||
| } | ||
|
|
||
| public static func == (lhs: TypeVariable<D>, rhs: TypeVariable<D>) -> Bool { | ||
| guard let lhpojo: JavaObject = lhs.as(JavaObject.self) else { | ||
| return false | ||
| } | ||
| guard let rhpojo: JavaObject = rhs.as(JavaObject.self) else { | ||
| return false | ||
| } | ||
|
|
||
| return lhpojo.equals(rhpojo) | ||
| } | ||
|
|
||
| } | ||
|
|
||
| extension TypeVariable { | ||
| public var description: String { | ||
| toString() | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This source file is part of the Swift.org open source project | ||
| // | ||
| // Copyright (c) 2024 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 SwiftJava | ||
| import CSwiftJavaJNI | ||
|
|
||
| import Foundation | ||
| public typealias SwiftJavaFoundationURL = Foundation.URL | ||
|
|
||
| extension SwiftJavaFoundationURL { | ||
| public static func fromJava(_ url: URL) throws -> SwiftJavaFoundationURL { | ||
| guard let converted = SwiftJavaFoundationURL(string: try url.toURI().toString()) else { | ||
| throw SwiftJavaConversionError("Failed to convert \(URL.self) to \(SwiftJavaFoundationURL.self)") | ||
| } | ||
| return converted | ||
| } | ||
| } | ||
|
|
||
| extension URL { | ||
| public static func fromSwift(_ url: SwiftJavaFoundationURL) throws -> URL { | ||
| return try URL(url.absoluteString) | ||
| } | ||
| } |
22 changes: 22 additions & 0 deletions
22
Sources/JavaStdlib/JavaNet/URLClassLoader+Workaround.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This source file is part of the Swift.org open source project | ||
| // | ||
| // Copyright (c) 2024 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 CSwiftJavaJNI | ||
| import SwiftJava | ||
|
|
||
| // FIXME: workaround until importing properly would make UCL inherit from CL https://github.com/swiftlang/swift-java/issues/423 | ||
| extension URLClassLoader /* workaround for missing inherits from ClassLoader */ { | ||
| @JavaMethod | ||
| public func loadClass(_ name: String) throws -> JavaClass<JavaObject>? | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to properly fix this for all interfaces #430
understanding what's going on without being able to get toString of the java types is quite a problem, i'll tackle it next. This is obviously going to be thrown away (the edit in the generated source)