21
21
22
22
import org .apache .commons .logging .Log ;
23
23
import org .apache .commons .logging .LogFactory ;
24
-
25
- import org .springframework .aot .generator .CodeContribution ;
24
+ import org .springframework .aot .generate .GenerationContext ;
26
25
import org .springframework .beans .BeansException ;
27
26
import org .springframework .beans .factory .BeanFactory ;
28
27
import org .springframework .beans .factory .BeanFactoryAware ;
29
- import org .springframework .beans .factory .generator .AotContributingBeanPostProcessor ;
30
- import org .springframework .beans .factory .generator .BeanInstantiationContribution ;
28
+ import org .springframework .beans .factory .aot .BeanRegistrationAotContribution ;
29
+ import org .springframework .beans .factory .aot .BeanRegistrationAotProcessor ;
30
+ import org .springframework .beans .factory .aot .BeanRegistrationCode ;
31
+ import org .springframework .beans .factory .support .RegisteredBean ;
31
32
import org .springframework .beans .factory .support .RootBeanDefinition ;
32
33
import org .springframework .core .ResolvableType ;
33
34
import org .springframework .data .ManagedTypes ;
37
38
import org .springframework .util .StringUtils ;
38
39
39
40
/**
40
- * {@link AotContributingBeanPostProcessor } handling {@link #getModulePrefix() prefixed} {@link ManagedTypes} instances.
41
+ * {@link BeanRegistrationAotProcessor } handling {@link #getModulePrefix() prefixed} {@link ManagedTypes} instances.
41
42
* This allows to register store specific handling of discovered types.
42
43
*
43
44
* @author Christoph Strobl
45
+ * @author John Blum
44
46
* @see org.springframework.beans.factory.BeanFactoryAware
45
- * @see org.springframework.beans.factory.generator.AotContributingBeanPostProcessor
47
+ * @see org.springframework.beans.factory.aot.BeanRegistrationAotProcessor
46
48
* @since 3.0
47
49
*/
48
- public class AotManagedTypesPostProcessor implements AotContributingBeanPostProcessor , BeanFactoryAware {
50
+ public class AotManagedTypesPostProcessor implements BeanRegistrationAotProcessor , BeanFactoryAware {
49
51
50
52
private static final Log logger = LogFactory .getLog (AotManagedTypesPostProcessor .class );
51
53
@@ -54,9 +56,13 @@ public class AotManagedTypesPostProcessor implements AotContributingBeanPostProc
54
56
@ Nullable
55
57
private String modulePrefix ;
56
58
57
- @ Nullable
58
59
@ Override
59
- public BeanInstantiationContribution contribute (@ NonNull RootBeanDefinition beanDefinition ,
60
+ public BeanRegistrationAotContribution processAheadOfTime (@ NonNull RegisteredBean registeredBean ) {
61
+ return contribute (registeredBean .getMergedBeanDefinition (), registeredBean .getBeanClass (), registeredBean .getBeanName ());
62
+ }
63
+
64
+ @ Nullable
65
+ protected BeanRegistrationAotContribution contribute (@ NonNull RootBeanDefinition beanDefinition ,
60
66
@ NonNull Class <?> beanType , @ NonNull String beanName ) {
61
67
62
68
return isMatch (beanType , beanName )
@@ -77,33 +83,33 @@ protected boolean matchesPrefix(@Nullable String beanName) {
77
83
}
78
84
79
85
/**
80
- * Hook to provide a customized flavor of {@link BeanInstantiationContribution }. By overriding this method calls to
81
- * {@link #contributeType(ResolvableType, CodeContribution )} might no longer be issued.
86
+ * Hook to provide a customized flavor of {@link BeanRegistrationAotContribution }. By overriding this method
87
+ * calls to {@link #contributeType(ResolvableType, GenerationContext )} might no longer be issued.
82
88
*
83
89
* @param aotContext never {@literal null}.
84
90
* @param managedTypes never {@literal null}.
85
91
* @return new instance of {@link AotManagedTypesPostProcessor} or {@literal null} if nothing to do.
86
92
*/
87
93
@ Nullable
88
- protected BeanInstantiationContribution contribute (AotContext aotContext , ManagedTypes managedTypes ) {
94
+ protected BeanRegistrationAotContribution contribute (AotContext aotContext , ManagedTypes managedTypes ) {
89
95
return new ManagedTypesContribution (aotContext , managedTypes , this ::contributeType );
90
96
}
91
97
92
98
/**
93
99
* Hook to contribute configuration for a given {@literal type}.
94
100
*
95
101
* @param type never {@literal null}.
96
- * @param contribution never {@literal null}.
102
+ * @param generationContext never {@literal null}.
97
103
*/
98
- protected void contributeType (ResolvableType type , CodeContribution contribution ) {
104
+ protected void contributeType (ResolvableType type , GenerationContext generationContext ) {
99
105
100
106
if (logger .isDebugEnabled ()) {
101
107
logger .debug (String .format ("Contributing type information for [%s]." , type .getType ()));
102
108
}
103
109
104
- TypeContributor .contribute (type .toClass (), Collections .singleton (TypeContributor .DATA_NAMESPACE ), contribution );
110
+ TypeContributor .contribute (type .toClass (), Collections .singleton (TypeContributor .DATA_NAMESPACE ), generationContext );
105
111
TypeUtils .resolveUsedAnnotations (type .toClass ()).forEach (annotation -> TypeContributor
106
- .contribute (annotation .getType (), Collections .singleton (TypeContributor .DATA_NAMESPACE ), contribution ));
112
+ .contribute (annotation .getType (), Collections .singleton (TypeContributor .DATA_NAMESPACE ), generationContext ));
107
113
}
108
114
109
115
@ Nullable
@@ -115,24 +121,19 @@ public void setModulePrefix(@Nullable String modulePrefix) {
115
121
this .modulePrefix = modulePrefix ;
116
122
}
117
123
118
- @ Override
119
- public int getOrder () {
120
- return 0 ;
121
- }
122
-
123
124
@ Override
124
125
public void setBeanFactory (@ NonNull BeanFactory beanFactory ) throws BeansException {
125
126
this .beanFactory = beanFactory ;
126
127
}
127
128
128
- static class ManagedTypesContribution implements BeanInstantiationContribution {
129
+ static class ManagedTypesContribution implements BeanRegistrationAotContribution {
129
130
130
131
private final AotContext aotContext ;
131
132
private final ManagedTypes managedTypes ;
132
- private final BiConsumer <ResolvableType , CodeContribution > contributionAction ;
133
+ private final BiConsumer <ResolvableType , GenerationContext > contributionAction ;
133
134
134
135
public ManagedTypesContribution (AotContext aotContext , ManagedTypes managedTypes ,
135
- BiConsumer <ResolvableType , CodeContribution > contributionAction ) {
136
+ BiConsumer <ResolvableType , GenerationContext > contributionAction ) {
136
137
137
138
this .aotContext = aotContext ;
138
139
this .managedTypes = managedTypes ;
@@ -148,12 +149,13 @@ public ManagedTypes getManagedTypes() {
148
149
}
149
150
150
151
@ Override
151
- public void applyTo (@ NonNull CodeContribution contribution ) {
152
+ public void applyTo (@ NonNull GenerationContext generationContext ,
153
+ @ NonNull BeanRegistrationCode beanRegistrationCode ) {
152
154
153
155
List <Class <?>> types = getManagedTypes ().toList ();
154
156
155
157
if (!types .isEmpty ()) {
156
- TypeCollector .inspect (types ).forEach (type -> contributionAction .accept (type , contribution ));
158
+ TypeCollector .inspect (types ).forEach (type -> contributionAction .accept (type , generationContext ));
157
159
}
158
160
}
159
161
}
0 commit comments