|
24 | 24 | import java.util.Arrays; |
25 | 25 | import java.util.Collections; |
26 | 26 | import java.util.HashMap; |
| 27 | +import java.util.List; |
27 | 28 | import java.util.Map; |
28 | 29 | import java.util.Objects; |
29 | 30 | import java.util.function.BiFunction; |
|
74 | 75 | * |
75 | 76 | * @author Phillip Webb |
76 | 77 | * @author Stephane Nicoll |
77 | | - * @author Olga Maciaszek-Sharma |
78 | 78 | * @since 6.0 |
79 | 79 | */ |
80 | 80 | class BeanDefinitionPropertiesCodeGenerator { |
@@ -144,17 +144,14 @@ private void addInitDestroyMethods(Builder builder, |
144 | 144 | if (!ObjectUtils.isEmpty(methodNames)) { |
145 | 145 | Class<?> beanType = ClassUtils |
146 | 146 | .getUserClass(beanDefinition.getResolvableType().toClass()); |
147 | | - Builder arguments = CodeBlock.builder(); |
148 | | - String[] filteredMethodNames = Arrays.stream(methodNames) |
149 | | - .filter(methodName -> !AbstractBeanDefinition.INFER_METHOD.equals(methodName)) |
150 | | - .toArray(String[]::new); |
151 | | - for (int i = 0; i < filteredMethodNames.length; i++) { |
152 | | - String methodName = filteredMethodNames[i]; |
153 | | - arguments.add((i != 0) ? ", $S" : "$S", methodName); |
154 | | - addInitDestroyHint(beanType, methodName); |
155 | | - } |
156 | | - if (!arguments.isEmpty()) { |
157 | | - builder.addStatement(format, BEAN_DEFINITION_VARIABLE, arguments.build()); |
| 147 | + List<String> filteredMethodNames = Arrays.stream(methodNames) |
| 148 | + .filter(candidate -> !AbstractBeanDefinition.INFER_METHOD.equals(candidate)) |
| 149 | + .toList(); |
| 150 | + if (!ObjectUtils.isEmpty(filteredMethodNames)) { |
| 151 | + filteredMethodNames.forEach(methodName -> addInitDestroyHint(beanType, methodName)); |
| 152 | + CodeBlock arguments = CodeBlock.join(filteredMethodNames.stream() |
| 153 | + .map(name -> CodeBlock.of("$S", name)).toList(), ", "); |
| 154 | + builder.addStatement(format, BEAN_DEFINITION_VARIABLE, arguments); |
158 | 155 | } |
159 | 156 | } |
160 | 157 | } |
@@ -277,11 +274,11 @@ private CodeBlock toStringVarArgs(String[] strings) { |
277 | 274 |
|
278 | 275 | private Object toRole(int value) { |
279 | 276 | return switch (value) { |
280 | | - case BeanDefinition.ROLE_INFRASTRUCTURE -> CodeBlock.builder() |
281 | | - .add("$T.ROLE_INFRASTRUCTURE", BeanDefinition.class).build(); |
282 | | - case BeanDefinition.ROLE_SUPPORT -> CodeBlock.builder() |
283 | | - .add("$T.ROLE_SUPPORT", BeanDefinition.class).build(); |
284 | | - default -> value; |
| 277 | + case BeanDefinition.ROLE_INFRASTRUCTURE -> CodeBlock.builder() |
| 278 | + .add("$T.ROLE_INFRASTRUCTURE", BeanDefinition.class).build(); |
| 279 | + case BeanDefinition.ROLE_SUPPORT -> CodeBlock.builder() |
| 280 | + .add("$T.ROLE_SUPPORT", BeanDefinition.class).build(); |
| 281 | + default -> value; |
285 | 282 | }; |
286 | 283 | } |
287 | 284 |
|
|
0 commit comments