Skip to content

Commit dcb75bf

Browse files
authored
wrap-java: Update subtyping logic for generic method overrides (#618)
* Fix incorrect test case about overriding * Stop to convert java bounds when checking equality * Generate Constructor and other related classes * Add more strict logic
1 parent 14bd5e9 commit dcb75bf

10 files changed

Lines changed: 761 additions & 89 deletions

File tree

Sources/JavaStdlib/JavaLangReflect/generated/AccessibleObject.swift

Lines changed: 82 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,113 @@ import SwiftJavaJNICore
44

55
@JavaClass("java.lang.reflect.AccessibleObject")
66
open class AccessibleObject: JavaObject {
7+
/// Java method `setAccessible`.
8+
///
9+
/// ### Java method signature
10+
/// ```java
11+
/// public void java.lang.reflect.AccessibleObject.setAccessible(boolean)
12+
/// ```
713
@JavaMethod
8-
open func isAnnotationPresent(_ arg0: JavaClass<Annotation>?) -> Bool
14+
open func setAccessible(_ arg0: Bool)
915

16+
/// Java method `isAnnotationPresent`.
17+
///
18+
/// ### Java method signature
19+
/// ```java
20+
/// public boolean java.lang.reflect.AccessibleObject.isAnnotationPresent(java.lang.Class<? extends java.lang.annotation.Annotation>)
21+
/// ```
1022
@JavaMethod
11-
open func getAnnotation(_ arg0: JavaClass<Annotation>?) -> Annotation!
23+
open func isAnnotationPresent(_ arg0: JavaClass<Annotation>?) -> Bool
24+
25+
/// Java method `getAnnotation`.
26+
///
27+
/// ### Java method signature
28+
/// ```java
29+
/// public <T extends java.lang.annotation.Annotation> T java.lang.reflect.AccessibleObject.getAnnotation(java.lang.Class<T>)
30+
/// ```
31+
@JavaMethod(typeErasedResult: "T!")
32+
open func getAnnotation<T: AnyJavaObject>(_ arg0: JavaClass<T>?) -> T!
1233

34+
/// Java method `getAnnotationsByType`.
35+
///
36+
/// ### Java method signature
37+
/// ```java
38+
/// public <T extends java.lang.annotation.Annotation> T[] java.lang.reflect.AccessibleObject.getAnnotationsByType(java.lang.Class<T>)
39+
/// ```
1340
@JavaMethod
14-
open func getAnnotationsByType(_ arg0: JavaClass<Annotation>?) -> [Annotation?]
41+
open func getAnnotationsByType<T: AnyJavaObject>(_ arg0: JavaClass<T>?) -> [T?]
1542

43+
/// Java method `getAnnotations`.
44+
///
45+
/// ### Java method signature
46+
/// ```java
47+
/// public java.lang.annotation.Annotation[] java.lang.reflect.AccessibleObject.getAnnotations()
48+
/// ```
1649
@JavaMethod
1750
open func getAnnotations() -> [Annotation?]
1851

19-
@JavaMethod
20-
open func getDeclaredAnnotation(_ arg0: JavaClass<Annotation>?) -> Annotation!
52+
/// Java method `getDeclaredAnnotation`.
53+
///
54+
/// ### Java method signature
55+
/// ```java
56+
/// public <T extends java.lang.annotation.Annotation> T java.lang.reflect.AccessibleObject.getDeclaredAnnotation(java.lang.Class<T>)
57+
/// ```
58+
@JavaMethod(typeErasedResult: "T!")
59+
open func getDeclaredAnnotation<T: AnyJavaObject>(_ arg0: JavaClass<T>?) -> T!
2160

61+
/// Java method `getDeclaredAnnotationsByType`.
62+
///
63+
/// ### Java method signature
64+
/// ```java
65+
/// public <T extends java.lang.annotation.Annotation> T[] java.lang.reflect.AccessibleObject.getDeclaredAnnotationsByType(java.lang.Class<T>)
66+
/// ```
2267
@JavaMethod
23-
open func getDeclaredAnnotationsByType(_ arg0: JavaClass<Annotation>?) -> [Annotation?]
68+
open func getDeclaredAnnotationsByType<T: AnyJavaObject>(_ arg0: JavaClass<T>?) -> [T?]
2469

70+
/// Java method `getDeclaredAnnotations`.
71+
///
72+
/// ### Java method signature
73+
/// ```java
74+
/// public java.lang.annotation.Annotation[] java.lang.reflect.AccessibleObject.getDeclaredAnnotations()
75+
/// ```
2576
@JavaMethod
2677
open func getDeclaredAnnotations() -> [Annotation?]
2778

28-
@JavaMethod
29-
open func setAccessible(_ arg0: Bool)
30-
79+
/// Java method `trySetAccessible`.
80+
///
81+
/// ### Java method signature
82+
/// ```java
83+
/// public final boolean java.lang.reflect.AccessibleObject.trySetAccessible()
84+
/// ```
3185
@JavaMethod
3286
open func trySetAccessible() -> Bool
3387

88+
/// Java method `canAccess`.
89+
///
90+
/// ### Java method signature
91+
/// ```java
92+
/// public final boolean java.lang.reflect.AccessibleObject.canAccess(java.lang.Object)
93+
/// ```
3494
@JavaMethod
3595
open func canAccess(_ arg0: JavaObject?) -> Bool
3696

97+
/// Java method `isAccessible`.
98+
///
99+
/// ### Java method signature
100+
/// ```java
101+
/// public boolean java.lang.reflect.AccessibleObject.isAccessible()
102+
/// ```
103+
@available(*, deprecated)
37104
@JavaMethod
38105
open func isAccessible() -> Bool
39106
}
40107
extension JavaClass<AccessibleObject> {
108+
/// Java method `setAccessible`.
109+
///
110+
/// ### Java method signature
111+
/// ```java
112+
/// public static void java.lang.reflect.AccessibleObject.setAccessible(java.lang.reflect.AccessibleObject[],boolean)
113+
/// ```
41114
@JavaStaticMethod
42115
public func setAccessible(_ arg0: [AccessibleObject?], _ arg1: Bool)
43116
}

Sources/JavaStdlib/JavaLangReflect/generated/Constructor.swift

Lines changed: 143 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,76 +4,201 @@ import SwiftJavaJNICore
44

55
@JavaClass("java.lang.reflect.Constructor")
66
open class Constructor<T: AnyJavaObject>: Executable {
7+
/// Java method `getName`.
8+
///
9+
/// ### Java method signature
10+
/// ```java
11+
/// public java.lang.String java.lang.reflect.Constructor.getName()
12+
/// ```
713
@JavaMethod
814
open override func getName() -> String
915

16+
/// Java method `equals`.
17+
///
18+
/// ### Java method signature
19+
/// ```java
20+
/// public boolean java.lang.reflect.Constructor.equals(java.lang.Object)
21+
/// ```
1022
@JavaMethod
1123
open override func equals(_ arg0: JavaObject?) -> Bool
1224

25+
/// Java method `toString`.
26+
///
27+
/// ### Java method signature
28+
/// ```java
29+
/// public java.lang.String java.lang.reflect.Constructor.toString()
30+
/// ```
1331
@JavaMethod
1432
open override func toString() -> String
1533

34+
/// Java method `hashCode`.
35+
///
36+
/// ### Java method signature
37+
/// ```java
38+
/// public int java.lang.reflect.Constructor.hashCode()
39+
/// ```
1640
@JavaMethod
1741
open override func hashCode() -> Int32
1842

43+
/// Java method `getModifiers`.
44+
///
45+
/// ### Java method signature
46+
/// ```java
47+
/// public int java.lang.reflect.Constructor.getModifiers()
48+
/// ```
1949
@JavaMethod
2050
open override func getModifiers() -> Int32
2151

52+
/// Java method `getTypeParameters`.
53+
///
54+
/// ### Java method signature
55+
/// ```java
56+
/// public java.lang.reflect.TypeVariable<java.lang.reflect.Constructor<T>>[] java.lang.reflect.Constructor.getTypeParameters()
57+
/// ```
2258
@JavaMethod
23-
open func getTypeParameters() -> [TypeVariable<Constructor<JavaObject>>?]
59+
open func getTypeParameters() -> [TypeVariable<Constructor<T>>?]
2460

61+
/// Java method `setAccessible`.
62+
///
63+
/// ### Java method signature
64+
/// ```java
65+
/// public void java.lang.reflect.Constructor.setAccessible(boolean)
66+
/// ```
2567
@JavaMethod
26-
open func newInstance(_ arg0: [JavaObject?]) throws -> JavaObject!
68+
open override func setAccessible(_ arg0: Bool)
2769

70+
/// Java method `newInstance`.
71+
///
72+
/// ### Java method signature
73+
/// ```java
74+
/// public T java.lang.reflect.Constructor.newInstance(java.lang.Object...) throws java.lang.InstantiationException,java.lang.IllegalAccessException,java.lang.IllegalArgumentException,java.lang.reflect.InvocationTargetException
75+
/// ```
76+
@JavaMethod(typeErasedResult: "T!")
77+
open func newInstance(_ arg0: [JavaObject?]) throws -> T!
78+
79+
/// Java method `getParameterTypes`.
80+
///
81+
/// ### Java method signature
82+
/// ```java
83+
/// public java.lang.Class<?>[] java.lang.reflect.Constructor.getParameterTypes()
84+
/// ```
2885
@JavaMethod
2986
open override func getParameterTypes() -> [JavaClass<JavaObject>?]
3087

88+
/// Java method `toGenericString`.
89+
///
90+
/// ### Java method signature
91+
/// ```java
92+
/// public java.lang.String java.lang.reflect.Constructor.toGenericString()
93+
/// ```
3194
@JavaMethod
3295
open override func toGenericString() -> String
3396

97+
/// Java method `isSynthetic`.
98+
///
99+
/// ### Java method signature
100+
/// ```java
101+
/// public boolean java.lang.reflect.Constructor.isSynthetic()
102+
/// ```
34103
@JavaMethod
35104
open override func isSynthetic() -> Bool
36105

37-
@JavaMethod
38-
open override func getDeclaringClass() -> JavaClass<JavaObject>!
39-
40-
@JavaMethod
41-
open override func getAnnotation(_ arg0: JavaClass<Annotation>?) -> Annotation!
42-
106+
/// Java method `getDeclaringClass`.
107+
///
108+
/// ### Java method signature
109+
/// ```java
110+
/// public java.lang.Class<T> java.lang.reflect.Constructor.getDeclaringClass()
111+
/// ```
112+
@JavaMethod
113+
open func getDeclaringClass() -> JavaClass<T>!
114+
115+
/// Java method `getAnnotation`.
116+
///
117+
/// ### Java method signature
118+
/// ```java
119+
/// public <T extends java.lang.annotation.Annotation> T java.lang.reflect.Constructor.getAnnotation(java.lang.Class<T>)
120+
/// ```
121+
@JavaMethod(typeErasedResult: "T!")
122+
open override func getAnnotation<T: AnyJavaObject>(_ arg0: JavaClass<T>?) -> T!
123+
124+
/// Java method `getDeclaredAnnotations`.
125+
///
126+
/// ### Java method signature
127+
/// ```java
128+
/// public java.lang.annotation.Annotation[] java.lang.reflect.Constructor.getDeclaredAnnotations()
129+
/// ```
43130
@JavaMethod
44131
open override func getDeclaredAnnotations() -> [Annotation?]
45132

46-
@JavaMethod
47-
open override func setAccessible(_ arg0: Bool)
48-
133+
/// Java method `isVarArgs`.
134+
///
135+
/// ### Java method signature
136+
/// ```java
137+
/// public boolean java.lang.reflect.Constructor.isVarArgs()
138+
/// ```
49139
@JavaMethod
50140
open override func isVarArgs() -> Bool
51141

142+
/// Java method `getParameterCount`.
143+
///
144+
/// ### Java method signature
145+
/// ```java
146+
/// public int java.lang.reflect.Constructor.getParameterCount()
147+
/// ```
52148
@JavaMethod
53149
open override func getParameterCount() -> Int32
54150

151+
/// Java method `getParameterAnnotations`.
152+
///
153+
/// ### Java method signature
154+
/// ```java
155+
/// public java.lang.annotation.Annotation[][] java.lang.reflect.Constructor.getParameterAnnotations()
156+
/// ```
55157
@JavaMethod
56158
open override func getParameterAnnotations() -> [[Annotation?]]
57159

160+
/// Java method `getGenericParameterTypes`.
161+
///
162+
/// ### Java method signature
163+
/// ```java
164+
/// public java.lang.reflect.Type[] java.lang.reflect.Constructor.getGenericParameterTypes()
165+
/// ```
58166
@JavaMethod
59167
open override func getGenericParameterTypes() -> [Type?]
60168

169+
/// Java method `getGenericExceptionTypes`.
170+
///
171+
/// ### Java method signature
172+
/// ```java
173+
/// public java.lang.reflect.Type[] java.lang.reflect.Constructor.getGenericExceptionTypes()
174+
/// ```
61175
@JavaMethod
62176
open override func getGenericExceptionTypes() -> [Type?]
63177

178+
/// Java method `getExceptionTypes`.
179+
///
180+
/// ### Java method signature
181+
/// ```java
182+
/// public java.lang.Class<?>[] java.lang.reflect.Constructor.getExceptionTypes()
183+
/// ```
64184
@JavaMethod
65185
open override func getExceptionTypes() -> [JavaClass<JavaObject>?]
66186

187+
/// Java method `getAnnotatedReturnType`.
188+
///
189+
/// ### Java method signature
190+
/// ```java
191+
/// public java.lang.reflect.AnnotatedType java.lang.reflect.Constructor.getAnnotatedReturnType()
192+
/// ```
67193
@JavaMethod
68194
open override func getAnnotatedReturnType() -> AnnotatedType!
69195

196+
/// Java method `getAnnotatedReceiverType`.
197+
///
198+
/// ### Java method signature
199+
/// ```java
200+
/// public java.lang.reflect.AnnotatedType java.lang.reflect.Constructor.getAnnotatedReceiverType()
201+
/// ```
70202
@JavaMethod
71203
open override func getAnnotatedReceiverType() -> AnnotatedType!
72204
}
73-
extension JavaClass {
74-
@JavaStaticField(isFinal: true)
75-
public var PUBLIC: Int32
76-
77-
@JavaStaticField(isFinal: true)
78-
public var DECLARED: Int32
79-
}

0 commit comments

Comments
 (0)