16
16
package org .springframework .data .aot ;
17
17
18
18
import java .util .Collections ;
19
- import java .util .List ;
20
- import java .util .function .BiConsumer ;
19
+ import java .util .Set ;
21
20
22
21
import org .apache .commons .logging .Log ;
23
22
import org .apache .commons .logging .LogFactory ;
23
+
24
24
import org .springframework .aot .generate .GenerationContext ;
25
25
import org .springframework .beans .BeansException ;
26
26
import org .springframework .beans .factory .BeanFactory ;
27
27
import org .springframework .beans .factory .BeanFactoryAware ;
28
28
import org .springframework .beans .factory .aot .BeanRegistrationAotContribution ;
29
29
import org .springframework .beans .factory .aot .BeanRegistrationAotProcessor ;
30
- import org .springframework .beans .factory .aot .BeanRegistrationCode ;
31
30
import org .springframework .beans .factory .support .RegisteredBean ;
32
31
import org .springframework .beans .factory .support .RootBeanDefinition ;
33
32
import org .springframework .core .ResolvableType ;
38
37
import org .springframework .util .StringUtils ;
39
38
40
39
/**
41
- * {@link BeanRegistrationAotProcessor} handling {@link #getModulePrefix() prefixed} {@link ManagedTypes} instances.
42
- * This allows to register store specific handling of discovered types.
40
+ * {@link BeanRegistrationAotProcessor} handling {@link #getModulePrefix() module prefixed} {@link ManagedTypes}
41
+ * instances. This AOT processor allows store specific handling of discovered types to be registered .
43
42
*
44
43
* @author Christoph Strobl
45
44
* @author John Blum
46
45
* @see org.springframework.beans.factory.BeanFactoryAware
47
46
* @see org.springframework.beans.factory.aot.BeanRegistrationAotProcessor
48
47
* @since 3.0
49
48
*/
50
- public class AotManagedTypesPostProcessor implements BeanRegistrationAotProcessor , BeanFactoryAware {
49
+ public class ManagedTypesRegistrationAotProcessor implements BeanRegistrationAotProcessor , BeanFactoryAware {
51
50
52
- private static final Log logger = LogFactory .getLog (AotManagedTypesPostProcessor . class );
51
+ private final Log logger = LogFactory .getLog (getClass () );
53
52
54
53
private BeanFactory beanFactory ;
55
54
@@ -62,6 +61,7 @@ public BeanRegistrationAotContribution processAheadOfTime(@NonNull RegisteredBea
62
61
}
63
62
64
63
@ Nullable
64
+ @ SuppressWarnings ("unused" )
65
65
protected BeanRegistrationAotContribution contribute (@ NonNull RootBeanDefinition beanDefinition ,
66
66
@ NonNull Class <?> beanType , @ NonNull String beanName ) {
67
67
@@ -88,11 +88,11 @@ protected boolean matchesPrefix(@Nullable String beanName) {
88
88
*
89
89
* @param aotContext never {@literal null}.
90
90
* @param managedTypes never {@literal null}.
91
- * @return new instance of {@link AotManagedTypesPostProcessor } or {@literal null} if nothing to do.
91
+ * @return new instance of {@link ManagedTypesRegistrationAotProcessor } or {@literal null} if nothing to do.
92
92
*/
93
93
@ Nullable
94
94
protected BeanRegistrationAotContribution contribute (AotContext aotContext , ManagedTypes managedTypes ) {
95
- return new ManagedTypesContribution (aotContext , managedTypes , this ::contributeType );
95
+ return new ManagedTypesRegistrationAotContribution (aotContext , managedTypes , this ::contributeType );
96
96
}
97
97
98
98
/**
@@ -104,59 +104,28 @@ protected BeanRegistrationAotContribution contribute(AotContext aotContext, Mana
104
104
protected void contributeType (ResolvableType type , GenerationContext generationContext ) {
105
105
106
106
if (logger .isDebugEnabled ()) {
107
- logger .debug (String .format ("Contributing type information for [%s]. " , type .getType ()));
107
+ logger .debug (String .format ("Contributing type information for [%s]" , type .getType ()));
108
108
}
109
109
110
- TypeContributor .contribute (type .toClass (), Collections .singleton (TypeContributor .DATA_NAMESPACE ), generationContext );
111
- TypeUtils .resolveUsedAnnotations (type .toClass ()).forEach (annotation -> TypeContributor
112
- .contribute (annotation .getType (), Collections .singleton (TypeContributor .DATA_NAMESPACE ), generationContext ));
113
- }
110
+ Set <String > annotationNamespaces = Collections .singleton (TypeContributor .DATA_NAMESPACE );
114
111
115
- @ Nullable
116
- public String getModulePrefix () {
117
- return modulePrefix ;
118
- }
112
+ TypeContributor .contribute (type .toClass (), annotationNamespaces , generationContext );
119
113
120
- public void setModulePrefix ( @ Nullable String modulePrefix ) {
121
- this . modulePrefix = modulePrefix ;
114
+ TypeUtils . resolveUsedAnnotations ( type . toClass ()). forEach ( annotation ->
115
+ TypeContributor . contribute ( annotation . getType (), annotationNamespaces , generationContext )) ;
122
116
}
123
117
124
118
@ Override
125
119
public void setBeanFactory (@ NonNull BeanFactory beanFactory ) throws BeansException {
126
120
this .beanFactory = beanFactory ;
127
121
}
128
122
129
- static class ManagedTypesContribution implements BeanRegistrationAotContribution {
130
-
131
- private final AotContext aotContext ;
132
- private final ManagedTypes managedTypes ;
133
- private final BiConsumer <ResolvableType , GenerationContext > contributionAction ;
134
-
135
- public ManagedTypesContribution (AotContext aotContext , ManagedTypes managedTypes ,
136
- BiConsumer <ResolvableType , GenerationContext > contributionAction ) {
137
-
138
- this .aotContext = aotContext ;
139
- this .managedTypes = managedTypes ;
140
- this .contributionAction = contributionAction ;
141
- }
142
-
143
- public AotContext getAotContext () {
144
- return aotContext ;
145
- }
146
-
147
- public ManagedTypes getManagedTypes () {
148
- return managedTypes ;
149
- }
150
-
151
- @ Override
152
- public void applyTo (@ NonNull GenerationContext generationContext ,
153
- @ NonNull BeanRegistrationCode beanRegistrationCode ) {
154
-
155
- List <Class <?>> types = getManagedTypes ().toList ();
123
+ public void setModulePrefix (@ Nullable String modulePrefix ) {
124
+ this .modulePrefix = modulePrefix ;
125
+ }
156
126
157
- if (!types .isEmpty ()) {
158
- TypeCollector .inspect (types ).forEach (type -> contributionAction .accept (type , generationContext ));
159
- }
160
- }
127
+ @ Nullable
128
+ public String getModulePrefix () {
129
+ return this .modulePrefix ;
161
130
}
162
131
}
0 commit comments