@@ -113,26 +113,34 @@ class BeanDefinitionPropertiesCodeGenerator {
113
113
114
114
CodeBlock generateCode (RootBeanDefinition beanDefinition ) {
115
115
CodeBlock .Builder code = CodeBlock .builder ();
116
- addStatementForValue (code , beanDefinition , BeanDefinition ::isPrimary ,
117
- "$L.setPrimary($L)" );
118
- addStatementForValue (code , beanDefinition , BeanDefinition ::isFallback ,
119
- "$L.setFallback($L)" );
120
116
addStatementForValue (code , beanDefinition , BeanDefinition ::getScope ,
121
117
this ::hasScope , "$L.setScope($S)" );
118
+ addStatementForValue (code , beanDefinition , AbstractBeanDefinition ::isBackgroundInit ,
119
+ "$L.setBackgroundInit($L)" );
120
+ addStatementForValue (code , beanDefinition , AbstractBeanDefinition ::getLazyInit ,
121
+ "$L.setLazyInit($L)" );
122
122
addStatementForValue (code , beanDefinition , BeanDefinition ::getDependsOn ,
123
123
this ::hasDependsOn , "$L.setDependsOn($L)" , this ::toStringVarArgs );
124
124
addStatementForValue (code , beanDefinition , BeanDefinition ::isAutowireCandidate ,
125
125
"$L.setAutowireCandidate($L)" );
126
- addStatementForValue (code , beanDefinition , BeanDefinition ::getRole ,
127
- this ::hasRole , "$L.setRole($L)" , this ::toRole );
128
- addStatementForValue (code , beanDefinition , AbstractBeanDefinition ::getLazyInit ,
129
- "$L.setLazyInit($L)" );
126
+ addStatementForValue (code , beanDefinition , AbstractBeanDefinition ::isDefaultCandidate ,
127
+ "$L.setDefaultCandidate($L)" );
128
+ addStatementForValue (code , beanDefinition , BeanDefinition ::isPrimary ,
129
+ "$L.setPrimary($L)" );
130
+ addStatementForValue (code , beanDefinition , BeanDefinition ::isFallback ,
131
+ "$L.setFallback($L)" );
130
132
addStatementForValue (code , beanDefinition , AbstractBeanDefinition ::isSynthetic ,
131
133
"$L.setSynthetic($L)" );
134
+ addStatementForValue (code , beanDefinition , BeanDefinition ::getRole ,
135
+ this ::hasRole , "$L.setRole($L)" , this ::toRole );
132
136
addInitDestroyMethods (code , beanDefinition , beanDefinition .getInitMethodNames (),
133
137
"$L.setInitMethodNames($L)" );
134
138
addInitDestroyMethods (code , beanDefinition , beanDefinition .getDestroyMethodNames (),
135
139
"$L.setDestroyMethodNames($L)" );
140
+ if (beanDefinition .getFactoryBeanName () != null ) {
141
+ addStatementForValue (code , beanDefinition , BeanDefinition ::getFactoryBeanName ,
142
+ "$L.setFactoryBeanName(\" $L\" )" );
143
+ }
136
144
addConstructorArgumentValues (code , beanDefinition );
137
145
addPropertyValues (code , beanDefinition );
138
146
addAttributes (code , beanDefinition );
@@ -142,6 +150,7 @@ CodeBlock generateCode(RootBeanDefinition beanDefinition) {
142
150
143
151
private void addInitDestroyMethods (Builder code , AbstractBeanDefinition beanDefinition ,
144
152
@ Nullable String [] methodNames , String format ) {
153
+
145
154
// For Publisher-based destroy methods
146
155
this .hints .reflection ().registerType (TypeReference .of ("org.reactivestreams.Publisher" ));
147
156
if (!ObjectUtils .isEmpty (methodNames )) {
@@ -210,7 +219,6 @@ private void addConstructorArgumentValues(CodeBlock.Builder code, BeanDefinition
210
219
else if (valueHolder .getType () != null ) {
211
220
code .addStatement ("$L.getConstructorArgumentValues().addGenericArgumentValue($L, $S)" ,
212
221
BEAN_DEFINITION_VARIABLE , valueCode , valueHolder .getType ());
213
-
214
222
}
215
223
else {
216
224
code .addStatement ("$L.getConstructorArgumentValues().addGenericArgumentValue($L)" ,
@@ -224,7 +232,8 @@ private void addPropertyValues(CodeBlock.Builder code, RootBeanDefinition beanDe
224
232
MutablePropertyValues propertyValues = beanDefinition .getPropertyValues ();
225
233
if (!propertyValues .isEmpty ()) {
226
234
Class <?> infrastructureType = getInfrastructureType (beanDefinition );
227
- Map <String , Method > writeMethods = (infrastructureType != Object .class ) ? getWriteMethods (infrastructureType ) : Collections .emptyMap ();
235
+ Map <String , Method > writeMethods = (infrastructureType != Object .class ?
236
+ getWriteMethods (infrastructureType ) : Collections .emptyMap ());
228
237
for (PropertyValue propertyValue : propertyValues ) {
229
238
String name = propertyValue .getName ();
230
239
CodeBlock valueCode = generateValue (name , propertyValue .getValue ());
@@ -266,8 +275,8 @@ private void addQualifiers(CodeBlock.Builder code, RootBeanDefinition beanDefini
266
275
}
267
276
268
277
private CodeBlock generateValue (@ Nullable String name , @ Nullable Object value ) {
278
+ PropertyNamesStack .push (name );
269
279
try {
270
- PropertyNamesStack .push (name );
271
280
return this .valueCodeGenerator .generateCode (value );
272
281
}
273
282
finally {
@@ -308,8 +317,7 @@ private void addAttributes(CodeBlock.Builder code, BeanDefinition beanDefinition
308
317
}
309
318
310
319
private boolean hasScope (String defaultValue , String actualValue ) {
311
- return StringUtils .hasText (actualValue ) &&
312
- !ConfigurableBeanFactory .SCOPE_SINGLETON .equals (actualValue );
320
+ return (StringUtils .hasText (actualValue ) && !ConfigurableBeanFactory .SCOPE_SINGLETON .equals (actualValue ));
313
321
}
314
322
315
323
private boolean hasDependsOn (String [] defaultValue , String [] actualValue ) {
@@ -335,8 +343,7 @@ private Object toRole(int value) {
335
343
}
336
344
337
345
private <B extends BeanDefinition , T > void addStatementForValue (
338
- CodeBlock .Builder code , BeanDefinition beanDefinition ,
339
- Function <B , T > getter , String format ) {
346
+ CodeBlock .Builder code , BeanDefinition beanDefinition , Function <B , T > getter , String format ) {
340
347
341
348
addStatementForValue (code , beanDefinition , getter ,
342
349
(defaultValue , actualValue ) -> !Objects .equals (defaultValue , actualValue ), format );
@@ -351,9 +358,8 @@ private <B extends BeanDefinition, T> void addStatementForValue(
351
358
352
359
@ SuppressWarnings ("unchecked" )
353
360
private <B extends BeanDefinition , T > void addStatementForValue (
354
- CodeBlock .Builder code , BeanDefinition beanDefinition ,
355
- Function <B , T > getter , BiPredicate <T , T > filter , String format ,
356
- Function <T , Object > formatter ) {
361
+ CodeBlock .Builder code , BeanDefinition beanDefinition , Function <B , T > getter ,
362
+ BiPredicate <T , T > filter , String format , Function <T , Object > formatter ) {
357
363
358
364
T defaultValue = getter .apply ((B ) DEFAULT_BEAN_DEFINITION );
359
365
T actualValue = getter .apply ((B ) beanDefinition );
@@ -363,9 +369,8 @@ private <B extends BeanDefinition, T> void addStatementForValue(
363
369
}
364
370
365
371
/**
366
- * Cast the specified {@code valueCode} to the specified {@code castType} if
367
- * the {@code castNecessary} is {@code true}. Otherwise return the valueCode
368
- * as is.
372
+ * Cast the specified {@code valueCode} to the specified {@code castType} if the
373
+ * {@code castNecessary} is {@code true}. Otherwise, return the valueCode as-is.
369
374
* @param castNecessary whether a cast is necessary
370
375
* @param castType the type to cast to
371
376
* @param valueCode the code for the value
0 commit comments