1
1
/*
2
- * Copyright 2002-2022 the original author or authors.
2
+ * Copyright 2002-2024 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
20
20
import java .lang .reflect .Field ;
21
21
import java .lang .reflect .InvocationHandler ;
22
22
import java .lang .reflect .Method ;
23
- import java .lang .reflect .Modifier ;
24
23
import java .lang .reflect .Proxy ;
25
24
import java .util .ResourceBundle ;
26
25
import java .util .function .Function ;
27
26
import java .util .function .Predicate ;
28
27
29
- import org .springframework .aot .hint .MemberCategory ;
30
28
import org .springframework .aot .hint .RuntimeHints ;
31
29
import org .springframework .aot .hint .TypeReference ;
32
30
import org .springframework .aot .hint .predicate .RuntimeHintsPredicates ;
@@ -67,8 +65,7 @@ enum InstrumentedMethod {
67
65
CLASS_GETCLASSES (Class .class , "getClasses" , HintType .REFLECTION ,
68
66
invocation -> {
69
67
Class <?> thisClass = invocation .getInstance ();
70
- return reflection ().onType (TypeReference .of (thisClass ))
71
- .withAnyMemberCategory (MemberCategory .DECLARED_CLASSES , MemberCategory .PUBLIC_CLASSES );
68
+ return reflection ().onType (TypeReference .of (thisClass ));
72
69
}
73
70
),
74
71
@@ -81,7 +78,7 @@ enum InstrumentedMethod {
81
78
if (constructor == null ) {
82
79
return runtimeHints -> false ;
83
80
}
84
- return reflection ().onConstructor (constructor ). introspect ( );
81
+ return reflection ().onType (constructor . getDeclaringClass () );
85
82
}
86
83
),
87
84
@@ -91,9 +88,7 @@ enum InstrumentedMethod {
91
88
CLASS_GETCONSTRUCTORS (Class .class , "getConstructors" , HintType .REFLECTION ,
92
89
invocation -> {
93
90
Class <?> thisClass = invocation .getInstance ();
94
- return reflection ().onType (TypeReference .of (thisClass )).withAnyMemberCategory (
95
- MemberCategory .INTROSPECT_PUBLIC_CONSTRUCTORS , MemberCategory .INTROSPECT_DECLARED_CONSTRUCTORS ,
96
- MemberCategory .INVOKE_PUBLIC_CONSTRUCTORS , MemberCategory .INVOKE_DECLARED_CONSTRUCTORS );
91
+ return reflection ().onType (TypeReference .of (thisClass ));
97
92
}
98
93
),
99
94
@@ -103,7 +98,7 @@ enum InstrumentedMethod {
103
98
CLASS_GETDECLAREDCLASSES (Class .class , "getDeclaredClasses" , HintType .REFLECTION ,
104
99
invocation -> {
105
100
Class <?> thisClass = invocation .getInstance ();
106
- return reflection ().onType (TypeReference .of (thisClass )). withMemberCategory ( MemberCategory . DECLARED_CLASSES ) ;
101
+ return reflection ().onType (TypeReference .of (thisClass ));
107
102
}
108
103
),
109
104
@@ -116,9 +111,7 @@ enum InstrumentedMethod {
116
111
if (constructor == null ) {
117
112
return runtimeHints -> false ;
118
113
}
119
- TypeReference thisType = invocation .getInstanceTypeReference ();
120
- return reflection ().onType (thisType ).withMemberCategory (MemberCategory .INTROSPECT_DECLARED_CONSTRUCTORS )
121
- .or (reflection ().onConstructor (constructor ).introspect ());
114
+ return reflection ().onType (constructor .getDeclaringClass ());
122
115
}
123
116
),
124
117
@@ -128,8 +121,7 @@ enum InstrumentedMethod {
128
121
CLASS_GETDECLAREDCONSTRUCTORS (Class .class , "getDeclaredConstructors" , HintType .REFLECTION ,
129
122
invocation -> {
130
123
Class <?> thisClass = invocation .getInstance ();
131
- return reflection ().onType (TypeReference .of (thisClass ))
132
- .withAnyMemberCategory (MemberCategory .INTROSPECT_DECLARED_CONSTRUCTORS , MemberCategory .INVOKE_DECLARED_CONSTRUCTORS );
124
+ return reflection ().onType (TypeReference .of (thisClass ));
133
125
}),
134
126
135
127
/**
@@ -141,9 +133,7 @@ enum InstrumentedMethod {
141
133
if (field == null ) {
142
134
return runtimeHints -> false ;
143
135
}
144
- TypeReference thisType = invocation .getInstanceTypeReference ();
145
- return reflection ().onType (thisType ).withMemberCategory (MemberCategory .DECLARED_FIELDS )
146
- .or (reflection ().onField (field ));
136
+ return reflection ().onType (field .getDeclaringClass ());
147
137
}
148
138
),
149
139
@@ -153,7 +143,7 @@ enum InstrumentedMethod {
153
143
CLASS_GETDECLAREDFIELDS (Class .class , "getDeclaredFields" , HintType .REFLECTION ,
154
144
invocation -> {
155
145
Class <?> thisClass = invocation .getInstance ();
156
- return reflection ().onType (TypeReference .of (thisClass )). withMemberCategory ( MemberCategory . DECLARED_FIELDS ) ;
146
+ return reflection ().onType (TypeReference .of (thisClass ));
157
147
}
158
148
),
159
149
@@ -166,10 +156,7 @@ enum InstrumentedMethod {
166
156
if (method == null ) {
167
157
return runtimeHints -> false ;
168
158
}
169
- TypeReference thisType = invocation .getInstanceTypeReference ();
170
- return reflection ().onType (thisType )
171
- .withAnyMemberCategory (MemberCategory .INTROSPECT_DECLARED_METHODS , MemberCategory .INVOKE_DECLARED_METHODS )
172
- .or (reflection ().onMethod (method ).introspect ());
159
+ return reflection ().onType (method .getDeclaringClass ());
173
160
}
174
161
),
175
162
@@ -179,8 +166,7 @@ enum InstrumentedMethod {
179
166
CLASS_GETDECLAREDMETHODS (Class .class , "getDeclaredMethods" , HintType .REFLECTION ,
180
167
invocation -> {
181
168
Class <?> thisClass = invocation .getInstance ();
182
- return reflection ().onType (TypeReference .of (thisClass ))
183
- .withAnyMemberCategory (MemberCategory .INTROSPECT_DECLARED_METHODS , MemberCategory .INVOKE_DECLARED_METHODS );
169
+ return reflection ().onType (TypeReference .of (thisClass ));
184
170
}
185
171
),
186
172
@@ -194,10 +180,7 @@ enum InstrumentedMethod {
194
180
if (field == null ) {
195
181
return runtimeHints -> false ;
196
182
}
197
- TypeReference thisType = invocation .getInstanceTypeReference ();
198
- return reflection ().onType (thisType ).withMemberCategory (MemberCategory .PUBLIC_FIELDS )
199
- .and (runtimeHints -> Modifier .isPublic (field .getModifiers ()))
200
- .or (reflection ().onType (thisType ).withMemberCategory (MemberCategory .DECLARED_FIELDS ))
183
+ return reflection ().onType (field .getDeclaringClass ())
201
184
.or (reflection ().onField (invocation .getReturnValue ()));
202
185
}),
203
186
@@ -207,8 +190,7 @@ enum InstrumentedMethod {
207
190
CLASS_GETFIELDS (Class .class , "getFields" , HintType .REFLECTION ,
208
191
invocation -> {
209
192
Class <?> thisClass = invocation .getInstance ();
210
- return reflection ().onType (TypeReference .of (thisClass ))
211
- .withAnyMemberCategory (MemberCategory .PUBLIC_FIELDS , MemberCategory .DECLARED_FIELDS );
193
+ return reflection ().onType (TypeReference .of (thisClass ));
212
194
}
213
195
),
214
196
@@ -221,12 +203,7 @@ enum InstrumentedMethod {
221
203
if (method == null ) {
222
204
return runtimeHints -> false ;
223
205
}
224
- TypeReference thisType = invocation .getInstanceTypeReference ();
225
- return reflection ().onType (thisType ).withAnyMemberCategory (MemberCategory .INTROSPECT_PUBLIC_METHODS , MemberCategory .INVOKE_PUBLIC_METHODS )
226
- .and (runtimeHints -> Modifier .isPublic (method .getModifiers ()))
227
- .or (reflection ().onType (thisType ).withAnyMemberCategory (MemberCategory .INTROSPECT_DECLARED_METHODS , MemberCategory .INVOKE_DECLARED_METHODS ))
228
- .or (reflection ().onMethod (method ).introspect ())
229
- .or (reflection ().onMethod (method ).invoke ());
206
+ return reflection ().onType (method .getDeclaringClass ());
230
207
}
231
208
),
232
209
@@ -236,9 +213,7 @@ enum InstrumentedMethod {
236
213
CLASS_GETMETHODS (Class .class , "getMethods" , HintType .REFLECTION ,
237
214
invocation -> {
238
215
Class <?> thisClass = invocation .getInstance ();
239
- return reflection ().onType (TypeReference .of (thisClass )).withAnyMemberCategory (
240
- MemberCategory .INTROSPECT_PUBLIC_METHODS , MemberCategory .INTROSPECT_DECLARED_METHODS ,
241
- MemberCategory .INVOKE_PUBLIC_METHODS , MemberCategory .INVOKE_DECLARED_METHODS );
216
+ return reflection ().onType (TypeReference .of (thisClass ));
242
217
}
243
218
),
244
219
0 commit comments