|
21 | 21 | import java.beans.Introspector;
|
22 | 22 | import java.beans.PropertyDescriptor;
|
23 | 23 | import java.lang.reflect.Method;
|
| 24 | +import java.util.Arrays; |
24 | 25 | import java.util.Collections;
|
25 | 26 | import java.util.HashMap;
|
| 27 | +import java.util.List; |
26 | 28 | import java.util.Map;
|
27 | 29 | import java.util.Objects;
|
28 | 30 | import java.util.function.BiFunction;
|
@@ -142,16 +144,14 @@ private void addInitDestroyMethods(Builder builder,
|
142 | 144 | if (!ObjectUtils.isEmpty(methodNames)) {
|
143 | 145 | Class<?> beanType = ClassUtils
|
144 | 146 | .getUserClass(beanDefinition.getResolvableType().toClass());
|
145 |
| - Builder arguments = CodeBlock.builder(); |
146 |
| - for (int i = 0; i < methodNames.length; i++) { |
147 |
| - String methodName = methodNames[i]; |
148 |
| - if (!AbstractBeanDefinition.INFER_METHOD.equals(methodName)) { |
149 |
| - arguments.add((i != 0) ? ", $S" : "$S", methodName); |
150 |
| - addInitDestroyHint(beanType, methodName); |
151 |
| - } |
152 |
| - } |
153 |
| - if (!arguments.isEmpty()) { |
154 |
| - 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); |
155 | 155 | }
|
156 | 156 | }
|
157 | 157 | }
|
@@ -274,11 +274,11 @@ private CodeBlock toStringVarArgs(String[] strings) {
|
274 | 274 |
|
275 | 275 | private Object toRole(int value) {
|
276 | 276 | return switch (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; |
| 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; |
282 | 282 | };
|
283 | 283 | }
|
284 | 284 |
|
|
0 commit comments