@@ -401,8 +401,7 @@ private void expandSupertypes(Store store, String key, Class<?> type) {
401401 * <p/>depends on SubTypesScanner configured
402402 */
403403 public <T > Set <Class <? extends T >> getSubTypesOf (final Class <T > type ) {
404- return ReflectionUtils .forNames (
405- store .getAll (SubTypesScanner .class , Collections .singletonList (type .getName ())), loaders ());
404+ return forNames (store .getAll (SubTypesScanner .class , type .getName ()), loaders ());
406405 }
407406
408407 /**
@@ -428,8 +427,8 @@ public Set<Class<?>> getTypesAnnotatedWith(final Class<? extends Annotation> ann
428427 */
429428 public Set <Class <?>> getTypesAnnotatedWith (final Class <? extends Annotation > annotation , boolean honorInherited ) {
430429 Set <String > annotated = store .get (TypeAnnotationsScanner .class , annotation .getName ());
431- Set < String > classes = getAllAnnotated (annotated , annotation . isAnnotationPresent ( Inherited . class ) , honorInherited );
432- return new HashSet <>( concat ( forNames (annotated , loaders ()), forNames ( classes , loaders ()) ));
430+ annotated . addAll ( getAllAnnotated (annotated , annotation , honorInherited ) );
431+ return forNames (annotated , loaders ());
433432 }
434433
435434 /**
@@ -448,25 +447,26 @@ public Set<Class<?>> getTypesAnnotatedWith(final Annotation annotation) {
448447 */
449448 public Set <Class <?>> getTypesAnnotatedWith (final Annotation annotation , boolean honorInherited ) {
450449 Set <String > annotated = store .get (TypeAnnotationsScanner .class , annotation .annotationType ().getName ());
451- Set <Class <?>> filter = filter (forNames (annotated , loaders ()), withAnnotation (annotation ));
452- Set <String > classes = getAllAnnotated (new HashSet <>(names (filter )), annotation .annotationType ().isAnnotationPresent (Inherited .class ), honorInherited );
453- return concat (filter , forNames (filter (classes , s -> !annotated .contains (s )), loaders ()));
450+ Set <Class <?>> allAnnotated = filter (forNames (annotated , loaders ()), withAnnotation (annotation ));
451+ Set <Class <?>> classes = forNames (filter (getAllAnnotated (names (allAnnotated ), annotation .annotationType (), honorInherited ), s -> !annotated .contains (s )), loaders ());
452+ allAnnotated .addAll (classes );
453+ return allAnnotated ;
454454 }
455455
456- protected Set <String > getAllAnnotated (Set <String > annotated , boolean inherited , boolean honorInherited ) {
456+ protected Collection <String > getAllAnnotated (Collection <String > annotated , Class <? extends Annotation > annotation , boolean honorInherited ) {
457457 if (honorInherited ) {
458- if (inherited ) {
459- Set <String > subTypes = store .get (SubTypesScanner .class , filter (annotated , ( Predicate < String >) input -> {
458+ if (annotation . isAnnotationPresent ( Inherited . class ) ) {
459+ Set <String > subTypes = store .get (SubTypesScanner .class , filter (annotated , input -> {
460460 final Class <?> type = forName (input , loaders ());
461461 return type != null && !type .isInterface ();
462462 }));
463- return concat ( subTypes , store .getAll (SubTypesScanner .class , subTypes ) );
463+ return store .getAllIncluding (SubTypesScanner .class , subTypes );
464464 } else {
465465 return annotated ;
466466 }
467467 } else {
468- Set <String > subTypes = concat ( annotated , store .getAll (TypeAnnotationsScanner .class , annotated ) );
469- return concat ( subTypes , store .getAll (SubTypesScanner .class , subTypes ) );
468+ Collection <String > subTypes = store .getAllIncluding (TypeAnnotationsScanner .class , annotated );
469+ return store .getAllIncluding (SubTypesScanner .class , subTypes );
470470 }
471471 }
472472
@@ -475,8 +475,7 @@ protected Set<String> getAllAnnotated(Set<String> annotated, boolean inherited,
475475 * <p/>depends on MethodAnnotationsScanner configured
476476 */
477477 public Set <Method > getMethodsAnnotatedWith (final Class <? extends Annotation > annotation ) {
478- Set <String > methods = store .get (MethodAnnotationsScanner .class , annotation .getName ());
479- return getMethodsFromDescriptors (methods , loaders ());
478+ return getMethodsFromDescriptors (store .get (MethodAnnotationsScanner .class , annotation .getName ()), loaders ());
480479 }
481480
482481 /**
@@ -505,19 +504,15 @@ public Set<Method> getMethodsWithAnyParamAnnotated(Class<? extends Annotation> a
505504
506505 /** get methods with any parameter annotated with given annotation, including annotation member values matching */
507506 public Set <Method > getMethodsWithAnyParamAnnotated (Annotation annotation ) {
508- return getMethodsWithAnyParamAnnotated (annotation .annotationType ())
509- .stream ()
510- .filter (withAnyParameterAnnotation (annotation ))
511- .collect (Collectors .toSet ());
507+ return filter (getMethodsWithAnyParamAnnotated (annotation .annotationType ()), withAnyParameterAnnotation (annotation ));
512508 }
513509
514510 /**
515511 * get all constructors annotated with a given annotation
516512 * <p/>depends on MethodAnnotationsScanner configured
517513 */
518514 public Set <Constructor > getConstructorsAnnotatedWith (final Class <? extends Annotation > annotation ) {
519- Set <String > methods = store .get (MethodAnnotationsScanner .class , annotation .getName ());
520- return getConstructorsFromDescriptors (methods , loaders ());
515+ return getConstructorsFromDescriptors (store .get (MethodAnnotationsScanner .class , annotation .getName ()), loaders ());
521516 }
522517
523518 /**
@@ -540,22 +535,17 @@ public Set<Constructor> getConstructorsWithAnyParamAnnotated(Class<? extends Ann
540535
541536 /** get constructors with any parameter annotated with given annotation, including annotation member values matching */
542537 public Set <Constructor > getConstructorsWithAnyParamAnnotated (Annotation annotation ) {
543- return getConstructorsWithAnyParamAnnotated (annotation .annotationType ())
544- .stream ()
545- .filter (withAnyParameterAnnotation (annotation ))
546- .collect (Collectors .toSet ());
538+ return filter (getConstructorsWithAnyParamAnnotated (annotation .annotationType ()), withAnyParameterAnnotation (annotation ));
547539 }
548540
549541 /**
550542 * get all fields annotated with a given annotation
551543 * <p/>depends on FieldAnnotationsScanner configured
552544 */
553545 public Set <Field > getFieldsAnnotatedWith (final Class <? extends Annotation > annotation ) {
554- final Set <Field > result = new HashSet <>();
555- for (String annotated : store .get (FieldAnnotationsScanner .class , annotation .getName ())) {
556- result .add (getFieldFromString (annotated , loaders ()));
557- }
558- return result ;
546+ return store .get (FieldAnnotationsScanner .class , annotation .getName ()).stream ()
547+ .map (annotated -> getFieldFromString (annotated , loaders ()))
548+ .collect (Collectors .toSet ());
559549 }
560550
561551 /**
@@ -661,7 +651,7 @@ public File save(final String filename) {
661651 */
662652 public File save (final String filename , final Serializer serializer ) {
663653 File file = serializer .save (this , filename );
664- if (log != null ) //noinspection ConstantConditions
654+ if (log != null )
665655 log .info ("Reflections successfully saved in " + file .getAbsolutePath () + " using " + serializer .getClass ().getSimpleName ());
666656 return file ;
667657 }
0 commit comments