24
24
import java .util .Optional ;
25
25
import java .util .Set ;
26
26
import java .util .regex .Pattern ;
27
+ import java .util .stream .Stream ;
27
28
28
29
import javax .annotation .Nonnull ;
29
30
@@ -129,24 +130,6 @@ public AnnotationRepositoryConfigurationSource(AnnotationMetadata metadata, Clas
129
130
this .hasExplicitFilters = hasExplicitFilters (attributes );
130
131
}
131
132
132
- /**
133
- * Returns whether there's explicit configuration of include- or exclude filters.
134
- *
135
- * @param attributes must not be {@literal null}.
136
- * @return
137
- */
138
- private static boolean hasExplicitFilters (AnnotationAttributes attributes ) {
139
-
140
- for (String attribute : Arrays .asList ("includeFilters" , "excludeFilters" )) {
141
-
142
- if (attributes .getAnnotationArray (attribute ).length > 0 ) {
143
- return true ;
144
- }
145
- }
146
-
147
- return false ;
148
- }
149
-
150
133
/*
151
134
* (non-Javadoc)
152
135
* @see org.springframework.data.repository.config.RepositoryConfigurationSource#getBasePackages()
@@ -226,25 +209,6 @@ public Streamable<TypeFilter> getExcludeFilters() {
226
209
return parseFilters ("excludeFilters" );
227
210
}
228
211
229
- private Streamable <TypeFilter > parseFilters (String attributeName ) {
230
-
231
- AnnotationAttributes [] filters = attributes .getAnnotationArray (attributeName );
232
-
233
- return Streamable .of (() -> Arrays .stream (filters ).flatMap (it -> typeFiltersFor (it ).stream ()));
234
- }
235
-
236
- /**
237
- * Returns the {@link String} attribute with the given name and defaults it to {@literal Optional#empty()} in case
238
- * it's empty.
239
- *
240
- * @param attributeName
241
- * @return
242
- */
243
- private Optional <String > getNullDefaultedAttribute (String attributeName ) {
244
- String attribute = attributes .getString (attributeName );
245
- return StringUtils .hasText (attribute ) ? Optional .of (attribute ) : Optional .empty ();
246
- }
247
-
248
212
/*
249
213
* (non-Javadoc)
250
214
* @see org.springframework.data.repository.config.RepositoryConfigurationSource#getRepositoryFactoryBeanClassName()
@@ -288,55 +252,6 @@ public AnnotationMetadata getEnableAnnotationMetadata() {
288
252
return enableAnnotationMetadata ;
289
253
}
290
254
291
- /**
292
- * Copy of {@code ComponentScanAnnotationParser#typeFiltersFor}.
293
- *
294
- * @param filterAttributes
295
- * @return
296
- */
297
- private List <TypeFilter > typeFiltersFor (AnnotationAttributes filterAttributes ) {
298
-
299
- List <TypeFilter > typeFilters = new ArrayList <>();
300
- FilterType filterType = filterAttributes .getEnum ("type" );
301
-
302
- for (Class <?> filterClass : filterAttributes .getClassArray ("value" )) {
303
- switch (filterType ) {
304
- case ANNOTATION :
305
- Assert .isAssignable (Annotation .class , filterClass ,
306
- "An error occured when processing a @ComponentScan " + "ANNOTATION type filter: " );
307
- @ SuppressWarnings ("unchecked" )
308
- Class <Annotation > annoClass = (Class <Annotation >) filterClass ;
309
- typeFilters .add (new AnnotationTypeFilter (annoClass ));
310
- break ;
311
- case ASSIGNABLE_TYPE :
312
- typeFilters .add (new AssignableTypeFilter (filterClass ));
313
- break ;
314
- case CUSTOM :
315
- Assert .isAssignable (TypeFilter .class , filterClass ,
316
- "An error occured when processing a @ComponentScan " + "CUSTOM type filter: " );
317
- typeFilters .add (BeanUtils .instantiateClass (filterClass , TypeFilter .class ));
318
- break ;
319
- default :
320
- throw new IllegalArgumentException ("Unknown filter type " + filterType );
321
- }
322
- }
323
-
324
- for (String expression : getPatterns (filterAttributes )) {
325
-
326
- String rawName = filterType .toString ();
327
-
328
- if ("REGEX" .equals (rawName )) {
329
- typeFilters .add (new RegexPatternTypeFilter (Pattern .compile (expression )));
330
- } else if ("ASPECTJ" .equals (rawName )) {
331
- typeFilters .add (new AspectJTypeFilter (expression , this .resourceLoader .getClassLoader ()));
332
- } else {
333
- throw new IllegalArgumentException ("Unknown filter type " + filterType );
334
- }
335
- }
336
-
337
- return typeFilters ;
338
- }
339
-
340
255
/*
341
256
* (non-Javadoc)
342
257
* @see org.springframework.data.repository.config.RepositoryConfigurationSourceSupport#shouldConsiderNestedRepositories()
@@ -406,6 +321,76 @@ public BootstrapMode getBootstrapMode() {
406
321
}
407
322
}
408
323
324
+ private Streamable <TypeFilter > parseFilters (String attributeName ) {
325
+
326
+ AnnotationAttributes [] filters = attributes .getAnnotationArray (attributeName );
327
+
328
+ return Streamable .of (() -> Arrays .stream (filters ).flatMap (it -> typeFiltersFor (it ).stream ()));
329
+ }
330
+
331
+ /**
332
+ * Returns the {@link String} attribute with the given name and defaults it to {@literal Optional#empty()} in case
333
+ * it's empty.
334
+ *
335
+ * @param attributeName
336
+ * @return
337
+ */
338
+ private Optional <String > getNullDefaultedAttribute (String attributeName ) {
339
+
340
+ String attribute = attributes .getString (attributeName );
341
+
342
+ return StringUtils .hasText (attribute ) ? Optional .of (attribute ) : Optional .empty ();
343
+ }
344
+
345
+ /**
346
+ * Copy of {@code ComponentScanAnnotationParser#typeFiltersFor}.
347
+ *
348
+ * @param filterAttributes
349
+ * @return
350
+ */
351
+ private List <TypeFilter > typeFiltersFor (AnnotationAttributes filterAttributes ) {
352
+
353
+ List <TypeFilter > typeFilters = new ArrayList <>();
354
+ FilterType filterType = filterAttributes .getEnum ("type" );
355
+
356
+ for (Class <?> filterClass : filterAttributes .getClassArray ("value" )) {
357
+ switch (filterType ) {
358
+ case ANNOTATION :
359
+ Assert .isAssignable (Annotation .class , filterClass ,
360
+ "An error occured when processing a @ComponentScan " + "ANNOTATION type filter: " );
361
+ @ SuppressWarnings ("unchecked" )
362
+ Class <Annotation > annoClass = (Class <Annotation >) filterClass ;
363
+ typeFilters .add (new AnnotationTypeFilter (annoClass ));
364
+ break ;
365
+ case ASSIGNABLE_TYPE :
366
+ typeFilters .add (new AssignableTypeFilter (filterClass ));
367
+ break ;
368
+ case CUSTOM :
369
+ Assert .isAssignable (TypeFilter .class , filterClass ,
370
+ "An error occured when processing a @ComponentScan " + "CUSTOM type filter: " );
371
+ typeFilters .add (BeanUtils .instantiateClass (filterClass , TypeFilter .class ));
372
+ break ;
373
+ default :
374
+ throw new IllegalArgumentException ("Unknown filter type " + filterType );
375
+ }
376
+ }
377
+
378
+ for (String expression : getPatterns (filterAttributes )) {
379
+
380
+ String rawName = filterType .toString ();
381
+
382
+ if ("REGEX" .equals (rawName )) {
383
+ typeFilters .add (new RegexPatternTypeFilter (Pattern .compile (expression )));
384
+ } else if ("ASPECTJ" .equals (rawName )) {
385
+ typeFilters .add (new AspectJTypeFilter (expression , this .resourceLoader .getClassLoader ()));
386
+ } else {
387
+ throw new IllegalArgumentException ("Unknown filter type " + filterType );
388
+ }
389
+ }
390
+
391
+ return typeFilters ;
392
+ }
393
+
409
394
/**
410
395
* Safely reads the {@code pattern} attribute from the given {@link AnnotationAttributes} and returns an empty list if
411
396
* the attribute is not present.
@@ -422,6 +407,18 @@ private String[] getPatterns(AnnotationAttributes filterAttributes) {
422
407
}
423
408
}
424
409
410
+ /**
411
+ * Returns whether there's explicit configuration of include- or exclude filters.
412
+ *
413
+ * @param attributes must not be {@literal null}.
414
+ * @return
415
+ */
416
+ private static boolean hasExplicitFilters (AnnotationAttributes attributes ) {
417
+
418
+ return Stream .of ("includeFilters" , "excludeFilters" ) //
419
+ .anyMatch (it -> attributes .getAnnotationArray (it ).length > 0 );
420
+ }
421
+
425
422
/**
426
423
* Returns the {@link BeanNameGenerator} to use falling back to an {@link AnnotationBeanNameGenerator} if either the
427
424
* given generator is {@literal null} or it's the one locally declared in {@link ConfigurationClassPostProcessor}'s
@@ -430,6 +427,7 @@ private String[] getPatterns(AnnotationAttributes filterAttributes) {
430
427
*
431
428
* @param generator can be {@literal null}.
432
429
* @return
430
+ * @since 2.2
433
431
*/
434
432
private static BeanNameGenerator defaultBeanNameGenerator (@ Nullable BeanNameGenerator generator ) {
435
433
0 commit comments