15
15
*/
16
16
package org .contextmapper .discovery .strategies .helper ;
17
17
18
- import org .reflections .Configuration ;
19
18
import org .reflections .Reflections ;
20
- import org .reflections .ReflectionsException ;
21
- import org .reflections .Store ;
22
- import org .reflections .scanners .MethodAnnotationsScanner ;
23
- import org .reflections .scanners .Scanner ;
24
- import org .reflections .scanners .SubTypesScanner ;
25
- import org .reflections .scanners .TypeAnnotationsScanner ;
26
19
import org .reflections .util .ClasspathHelper ;
27
20
import org .reflections .util .ConfigurationBuilder ;
28
21
import org .reflections .util .FilterBuilder ;
29
- import org .slf4j .Logger ;
30
22
31
23
import java .lang .annotation .Annotation ;
32
24
import java .lang .reflect .Method ;
33
25
import java .util .HashSet ;
34
26
import java .util .Set ;
35
27
import java .util .stream .Collectors ;
36
28
37
- import static org .reflections .util . Utils . findLogger ;
29
+ import static org .reflections .scanners . Scanners .* ;
38
30
39
31
/**
40
32
* Provides methods for annotation scanning.
43
35
*/
44
36
public class AnnotationScanner {
45
37
46
- public static Logger log = findLogger (AnnotationScanner .class );
47
-
48
38
/**
49
39
* Finds all types within a package annotated with a given annotation.
50
40
*
@@ -53,7 +43,7 @@ public class AnnotationScanner {
53
43
* @return the set of types within the given package which are annotated with the given annotation
54
44
*/
55
45
public Set <Class <?>> scanForAnnotatedType (String packageName , Class <? extends Annotation > annotation ) {
56
- Reflections reflections = new Reflections (packageName , new SubTypesScanner ( false ), new TypeAnnotationsScanner () );
46
+ Reflections reflections = new Reflections (packageName );
57
47
return reflections .getTypesAnnotatedWith (annotation );
58
48
}
59
49
@@ -66,20 +56,13 @@ public Set<Class<?>> scanForAnnotatedType(String packageName, Class<? extends An
66
56
*/
67
57
public Set <Method > scanForAnnotatedMethods (Class <?> type , Class <? extends Annotation >... annotations ) {
68
58
Set <Method > methods = new HashSet <>();
69
- try {
70
- Reflections reflections = new Reflections (new ConfigurationBuilder ()
71
- .setUrls (ClasspathHelper .forClass (type ))
72
- .setScanners (new SubTypesScanner (), new TypeAnnotationsScanner (), new MethodAnnotationsScanner ())
73
- .filterInputsBy (new FilterBuilder ().includePackage (type ))
74
- );
75
- for (Class <? extends Annotation > annotation : annotations ) {
76
- methods .addAll (reflections .getMethodsAnnotatedWith (annotation ));
77
- }
78
- } catch (ReflectionsException e ) {
79
- // unfortunately the reflections library in version 0.9.12 (needed for Java 11) throws an exception if nothing is found
80
- // just log errors here for now; should no longer be needed to catch this when the following issue is fixed:
81
- // https://github.com/ronmamo/reflections/issues/273
82
- log .error (e .getMessage ());
59
+ Reflections reflections = new Reflections (new ConfigurationBuilder ()
60
+ .setUrls (ClasspathHelper .forClass (type ))
61
+ .setScanners (TypesAnnotated , MethodsAnnotated , MethodsReturn )
62
+ .filterInputsBy (new FilterBuilder ().includePackage (type .getPackageName ()))
63
+ );
64
+ for (Class <? extends Annotation > annotation : annotations ) {
65
+ methods .addAll (reflections .getMethodsAnnotatedWith (annotation ));
83
66
}
84
67
return methods .stream ().filter (m -> m .getDeclaringClass ().equals (type )).collect (Collectors .toSet ());
85
68
}
0 commit comments