15
15
*/
16
16
package org .springframework .data .aot ;
17
17
18
- import java .lang .reflect .Executable ;
19
18
import java .lang .reflect .Method ;
20
19
import java .util .Collections ;
21
20
import java .util .List ;
69
68
* @author John Blum
70
69
* @author Christoph Strobl
71
70
* @author Mark Paluch
72
- * @see org.springframework.beans.factory.aot.BeanRegistrationAotContribution
73
71
* @since 3.0
72
+ * @see org.springframework.beans.factory.aot.BeanRegistrationAotContribution
74
73
*/
75
74
class ManagedTypesRegistrationAotContribution implements RegisteredBeanAotContribution {
76
75
@@ -126,7 +125,7 @@ static class ManagedTypesInstanceCodeFragment extends BeanRegistrationCodeFragme
126
125
public static final ResolvableType MANAGED_TYPES_TYPE = ResolvableType .forType (ManagedTypes .class );
127
126
private final List <Class <?>> sourceTypes ;
128
127
private final RegisteredBean source ;
129
- private final Lazy <Method > instanceMethod = Lazy . of ( this :: findInstanceFactory ) ;
128
+ private final Lazy <Method > instanceMethod ;
130
129
131
130
private static final TypeName WILDCARD = WildcardTypeName .subtypeOf (Object .class );
132
131
private static final TypeName CLASS_OF_ANY = ParameterizedTypeName .get (ClassName .get (Class .class ), WILDCARD );
@@ -139,6 +138,7 @@ protected ManagedTypesInstanceCodeFragment(List<Class<?>> sourceTypes, Registere
139
138
140
139
this .sourceTypes = sourceTypes ;
141
140
this .source = source ;
141
+ this .instanceMethod = Lazy .of (() -> findInstanceFactory (source .getBeanClass ()));
142
142
}
143
143
144
144
@ Override
@@ -230,15 +230,15 @@ private CodeBlock toCodeBlock(List<Class<?>> values, boolean allPublic) {
230
230
}
231
231
232
232
@ Nullable
233
- private Method findInstanceFactory () {
233
+ private static Method findInstanceFactory (Class <?> beanClass ) {
234
234
235
- for (Method beanMethod : ReflectionUtils .getDeclaredMethods (source . getBeanClass () )) {
235
+ for (Method beanMethod : ReflectionUtils .getDeclaredMethods (beanClass )) {
236
236
237
237
if (!isInstanceFactory (beanMethod )) {
238
238
continue ;
239
239
}
240
240
241
- ResolvableType parameterType = ResolvableType .forMethodParameter (beanMethod , 0 , source . getBeanClass () );
241
+ ResolvableType parameterType = ResolvableType .forMethodParameter (beanMethod , 0 , beanClass );
242
242
243
243
if (parameterType .isAssignableFrom (LIST_TYPE ) || parameterType .isAssignableFrom (MANAGED_TYPES_TYPE )) {
244
244
return beanMethod ;
0 commit comments