Skip to content

Remove duplicate Java wrapper classes#617

Merged
ktoso merged 2 commits intoswiftlang:mainfrom
sidepelican:remove_duplicated_type
Mar 14, 2026
Merged

Remove duplicate Java wrapper classes#617
ktoso merged 2 commits intoswiftlang:mainfrom
sidepelican:remove_duplicated_type

Conversation

@sidepelican
Copy link
Contributor

Motivation

I noticed that java.lang.reflect.Type and java.lang.reflect.ParameterizedType were generated in both the SwiftJava and JavaLangReflect packages.
To avoid confusion, I want to ensure that these are generated into a single package.

Changes

I have removed these classes from SwiftJava.
All classes under the java.lang.reflect namespace are moved into JavaLangReflect package.

@sidepelican sidepelican requested a review from ktoso as a code owner March 13, 2026 01:56
import SwiftJavaJNICore

@JavaClass("java.lang.reflect.Array")
open class Array: JavaObject {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if we should call it JavaArray hmmm

import SwiftJavaJNICore

@JavaClass("java.lang.Class", implements: JavaReflectType.self)
@JavaClass("java.lang.Class")
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's not great that we lost this implements here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

GenericDeclaration wasn't originally included here, so this took the same form.
I understand this isn't ideal.

open func getGenericSuperclass() -> JavaReflectType!

@JavaMethod
open func getGenericInterfaces() -> [JavaReflectType?]
Copy link
Collaborator

Choose a reason for hiding this comment

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

seems we lost this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These were manually moved to JavaClass+Reflection.swift.

do {
swiftSuperclassName = try translator.getSwiftTypeName(javaSuperclassNonOpt, preferValueTypes: false).swiftName
if let javaGenericSuperclass = javaGenericSuperclass?.as(JavaReflectParameterizedType.self) {
if let javaGenericSuperclass = javaGenericSuperclass?.as(ParameterizedType.self) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This one comes from where now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ParameterizedType was already present in the JavaLangReflect package.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Gotcha thanks, the types inside SwiftJava are generally there so we could bootstrap the tool and generate the other JavaStdlib... perhaps we can get away from that actually... I'll think about it some more but PR looks ok

@ktoso ktoso merged commit 14bd5e9 into swiftlang:main Mar 14, 2026
61 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants