@@ -140,22 +140,23 @@ CodeBlock generateCode(BeanDefinition beanDefinition) {
140
140
141
141
private void addInitDestroyMethods (Builder builder ,
142
142
AbstractBeanDefinition beanDefinition , @ Nullable String [] methodNames , String format ) {
143
-
144
- if (!ObjectUtils .isEmpty (methodNames )) {
145
- Class <?> beanType = ClassUtils
146
- .getUserClass (beanDefinition .getResolvableType ().toClass ());
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
- }
143
+ List <String > filteredMethodNames = (!ObjectUtils .isEmpty (methodNames ))
144
+ ? Arrays .stream (methodNames ).filter (this ::isNotInferredMethod ).toList ()
145
+ : Collections .emptyList ();
146
+ if (!filteredMethodNames .isEmpty ()) {
147
+ Class <?> beanType = ClassUtils .getUserClass (beanDefinition .getResolvableType ().toClass ());
148
+ filteredMethodNames .forEach (methodName -> addInitDestroyHint (beanType , methodName ));
149
+ CodeBlock arguments = filteredMethodNames .stream ()
150
+ .map (name -> CodeBlock .of ("$S" , name ))
151
+ .collect (CodeBlock .joining (", " ));
152
+ builder .addStatement (format , BEAN_DEFINITION_VARIABLE , arguments );
156
153
}
157
154
}
158
155
156
+ private boolean isNotInferredMethod (String candidate ) {
157
+ return !AbstractBeanDefinition .INFER_METHOD .equals (candidate );
158
+ }
159
+
159
160
private void addInitDestroyHint (Class <?> beanUserClass , String methodName ) {
160
161
Method method = ReflectionUtils .findMethod (beanUserClass , methodName );
161
162
if (method != null ) {
@@ -264,12 +265,8 @@ private boolean hasRole(int defaultValue, int actualValue) {
264
265
}
265
266
266
267
private CodeBlock toStringVarArgs (String [] strings ) {
267
- CodeBlock .Builder builder = CodeBlock .builder ();
268
- for (int i = 0 ; i < strings .length ; i ++) {
269
- builder .add ((i != 0 ) ? ", " : "" );
270
- builder .add ("$S" , strings [i ]);
271
- }
272
- return builder .build ();
268
+ return Arrays .stream (strings ).map (string -> CodeBlock .of ("$S" , string ))
269
+ .collect (CodeBlock .joining ("," ));
273
270
}
274
271
275
272
private Object toRole (int value ) {
0 commit comments