36
36
* Gather the need for reflection at runtime.
37
37
*
38
38
* @author Stephane Nicoll
39
+ * @author Phillip Webb
40
+ * @author Andy Wilkinson
39
41
* @since 6.0
40
42
*/
41
43
public class ReflectionHints {
@@ -79,6 +81,7 @@ public TypeHint getTypeHint(Class<?> type) {
79
81
* @param type the type to customize
80
82
* @param typeHint a builder to further customize hints for that type
81
83
* @return {@code this}, to facilitate method chaining
84
+ * @see #registerType(TypeReference, MemberCategory...)
82
85
*/
83
86
public ReflectionHints registerType (TypeReference type , Consumer <TypeHint .Builder > typeHint ) {
84
87
Builder builder = this .types .computeIfAbsent (type , TypeHint .Builder ::new );
@@ -93,29 +96,30 @@ public ReflectionHints registerType(TypeReference type, Consumer<TypeHint.Builde
93
96
* @param memberCategories the member categories to apply
94
97
* @return {@code this}, to facilitate method chaining
95
98
*/
96
- public ReflectionHints registerType (Class <?> type , MemberCategory ... memberCategories ) {
97
- return registerType (TypeReference . of ( type ), memberCategories );
99
+ public ReflectionHints registerType (TypeReference type , MemberCategory ... memberCategories ) {
100
+ return registerType (type , TypeHint . builtWith ( memberCategories ) );
98
101
}
99
102
100
103
/**
101
- * Register or customize reflection hints for the specified type
102
- * using the specified {@link MemberCategory MemberCategories}.
104
+ * Register or customize reflection hints for the specified type.
103
105
* @param type the type to customize
104
- * @param memberCategories the member categories to apply
106
+ * @param typeHint a builder to further customize hints for that type
105
107
* @return {@code this}, to facilitate method chaining
108
+ * @see #registerType(Class, MemberCategory...)
106
109
*/
107
- public ReflectionHints registerType (TypeReference type , MemberCategory ... memberCategories ) {
108
- return registerType (type , TypeHint . builtWith ( memberCategories ) );
110
+ public ReflectionHints registerType (Class <?> type , Consumer < TypeHint . Builder > typeHint ) {
111
+ return registerType (TypeReference . of ( type ), typeHint );
109
112
}
110
113
111
114
/**
112
- * Register or customize reflection hints for the specified type.
115
+ * Register or customize reflection hints for the specified type
116
+ * using the specified {@link MemberCategory MemberCategories}.
113
117
* @param type the type to customize
114
- * @param typeHint a builder to further customize hints for that type
118
+ * @param memberCategories the member categories to apply
115
119
* @return {@code this}, to facilitate method chaining
116
120
*/
117
- public ReflectionHints registerType (Class <?> type , Consumer < TypeHint . Builder > typeHint ) {
118
- return registerType (TypeReference .of (type ), typeHint );
121
+ public ReflectionHints registerType (Class <?> type , MemberCategory ... memberCategories ) {
122
+ return registerType (TypeReference .of (type ), memberCategories );
119
123
}
120
124
121
125
/**
@@ -125,6 +129,7 @@ public ReflectionHints registerType(Class<?> type, Consumer<TypeHint.Builder> ty
125
129
* @param typeName the type to customize
126
130
* @param typeHint a builder to further customize hints for that type
127
131
* @return {@code this}, to facilitate method chaining
132
+ * @see #registerTypeIfPresent(ClassLoader, String, MemberCategory...)
128
133
*/
129
134
public ReflectionHints registerTypeIfPresent (@ Nullable ClassLoader classLoader ,
130
135
String typeName , Consumer <TypeHint .Builder > typeHint ) {
@@ -134,6 +139,19 @@ public ReflectionHints registerTypeIfPresent(@Nullable ClassLoader classLoader,
134
139
return this ;
135
140
}
136
141
142
+ /**
143
+ * Register or customize reflection hints for the specified type if it
144
+ * is available using the specified {@link ClassLoader}.
145
+ * @param classLoader the classloader to use to check if the type is present
146
+ * @param typeName the type to customize
147
+ * @param memberCategories the member categories to apply
148
+ * @return {@code this}, to facilitate method chaining
149
+ */
150
+ public ReflectionHints registerTypeIfPresent (@ Nullable ClassLoader classLoader ,
151
+ String typeName , MemberCategory ... memberCategories ) {
152
+ return registerTypeIfPresent (classLoader , typeName , TypeHint .builtWith (memberCategories ));
153
+ }
154
+
137
155
/**
138
156
* Register or customize reflection hints for the types defined by the
139
157
* specified list of {@link TypeReference type references}. The specified
@@ -162,7 +180,9 @@ public ReflectionHints registerField(Field field) {
162
180
* enabling {@link ExecutableMode#INVOKE}.
163
181
* @param constructor the constructor that requires reflection
164
182
* @return {@code this}, to facilitate method chaining
183
+ * @deprecated in favor of {@link #registerConstructor(Constructor, ExecutableMode)}
165
184
*/
185
+ @ Deprecated
166
186
public ReflectionHints registerConstructor (Constructor <?> constructor ) {
167
187
return registerConstructor (constructor , ExecutableMode .INVOKE );
168
188
}
@@ -175,16 +195,19 @@ public ReflectionHints registerConstructor(Constructor<?> constructor) {
175
195
* @return {@code this}, to facilitate method chaining
176
196
*/
177
197
public ReflectionHints registerConstructor (Constructor <?> constructor , ExecutableMode mode ) {
178
- return registerConstructor (constructor , ExecutableHint .builtWith (mode ));
198
+ return registerType (TypeReference .of (constructor .getDeclaringClass ()),
199
+ typeHint -> typeHint .withConstructor (mapParameters (constructor ), mode ));
179
200
}
180
201
181
202
/**
182
203
* Register the need for reflection on the specified {@link Constructor}.
183
204
* @param constructor the constructor that requires reflection
184
205
* @param constructorHint a builder to further customize the hints of this
185
206
* constructor
186
- * @return {@code this}, to facilitate method chaining
207
+ * @return {@code this}, to facilitate method chaining`
208
+ * @deprecated in favor of {@link #registerConstructor(Constructor, ExecutableMode)}
187
209
*/
210
+ @ Deprecated
188
211
public ReflectionHints registerConstructor (Constructor <?> constructor , Consumer <ExecutableHint .Builder > constructorHint ) {
189
212
return registerType (TypeReference .of (constructor .getDeclaringClass ()),
190
213
typeHint -> typeHint .withConstructor (mapParameters (constructor ), constructorHint ));
@@ -195,7 +218,9 @@ public ReflectionHints registerConstructor(Constructor<?> constructor, Consumer<
195
218
* enabling {@link ExecutableMode#INVOKE}.
196
219
* @param method the method that requires reflection
197
220
* @return {@code this}, to facilitate method chaining
221
+ * @deprecated in favor of {@link #registerMethod(Method, ExecutableMode)}
198
222
*/
223
+ @ Deprecated
199
224
public ReflectionHints registerMethod (Method method ) {
200
225
return registerMethod (method , ExecutableMode .INVOKE );
201
226
}
@@ -208,15 +233,18 @@ public ReflectionHints registerMethod(Method method) {
208
233
* @return {@code this}, to facilitate method chaining
209
234
*/
210
235
public ReflectionHints registerMethod (Method method , ExecutableMode mode ) {
211
- return registerMethod (method , ExecutableHint .builtWith (mode ));
236
+ return registerType (TypeReference .of (method .getDeclaringClass ()),
237
+ typeHint -> typeHint .withMethod (method .getName (), mapParameters (method ), mode ));
212
238
}
213
239
214
240
/**
215
241
* Register the need for reflection on the specified {@link Method}.
216
242
* @param method the method that requires reflection
217
243
* @param methodHint a builder to further customize the hints of this method
218
244
* @return {@code this}, to facilitate method chaining
245
+ * @deprecated in favor of {@link #registerMethod(Method, ExecutableMode)}
219
246
*/
247
+ @ Deprecated
220
248
public ReflectionHints registerMethod (Method method , Consumer <ExecutableHint .Builder > methodHint ) {
221
249
return registerType (TypeReference .of (method .getDeclaringClass ()),
222
250
typeHint -> typeHint .withMethod (method .getName (), mapParameters (method ), methodHint ));
0 commit comments