Search in sources :

Example 11 with MethodAnnotationsScanner

use of org.reflections.scanners.MethodAnnotationsScanner in project motech by motech.

the class ReflectionsUtil method getMethods.

/**
 * Looks for methods annotated with the given annotation.
 *
 * @param annotation an annotation to look for.
 * @param bundle a bundle to look in.
 * @return a list of moethods, annotated with the given annotation
 */
public static Set<Method> getMethods(Class<? extends Annotation> annotation, Bundle bundle) {
    LOGGER.debug("Searching for methods with annotations: {}", annotation.getName());
    Reflections reflections = configureReflection(bundle, new WrappedBundleClassLoader(bundle), new MethodAnnotationsScanner());
    Set<Method> methods = reflections.getMethodsAnnotatedWith(annotation);
    LOGGER.debug("Searched for methods with annotations: {}", annotation.getName());
    LOGGER.trace("Found {} methods with annotations: {}", methods.size(), annotation.getName());
    return methods;
}
Also used : MethodAnnotationsScanner(org.reflections.scanners.MethodAnnotationsScanner) Method(java.lang.reflect.Method) Reflections(org.reflections.Reflections)

Example 12 with MethodAnnotationsScanner

use of org.reflections.scanners.MethodAnnotationsScanner in project serenity-jbehave by serenity-bdd.

the class ClassFinder method annotatedClassesInPackage.

public List<Class<?>> annotatedClassesInPackage(String packageName) {
    Reflections reflections = new Reflections(packageName, new SubTypesScanner(), new TypeAnnotationsScanner(), new MethodAnnotationsScanner(), new ResourcesScanner(), getClassLoader());
    Set<Class<?>> matchingClasses = new HashSet<>();
    for (Class<? extends Annotation> expectedAnnotation : expectedAnnotations) {
        matchingClasses.addAll(reflections.getTypesAnnotatedWith(expectedAnnotation));
        matchingClasses.addAll(classesFrom(reflections.getMethodsAnnotatedWith(expectedAnnotation)));
    }
    return ImmutableList.copyOf(matchingClasses);
}
Also used : MethodAnnotationsScanner(org.reflections.scanners.MethodAnnotationsScanner) SubTypesScanner(org.reflections.scanners.SubTypesScanner) TypeAnnotationsScanner(org.reflections.scanners.TypeAnnotationsScanner) ResourcesScanner(org.reflections.scanners.ResourcesScanner) Reflections(org.reflections.Reflections)

Aggregations

Reflections (org.reflections.Reflections)12 MethodAnnotationsScanner (org.reflections.scanners.MethodAnnotationsScanner)12 Method (java.lang.reflect.Method)6 SubTypesScanner (org.reflections.scanners.SubTypesScanner)4 TypeAnnotationsScanner (org.reflections.scanners.TypeAnnotationsScanner)4 ConfigurationBuilder (org.reflections.util.ConfigurationBuilder)4 URL (java.net.URL)3 FileWriter (java.io.FileWriter)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 DataSave (me.shadorc.shadbot.data.annotation.DataSave)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 MethodParameterScanner (org.reflections.scanners.MethodParameterScanner)2 FilterBuilder (org.reflections.util.FilterBuilder)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 File (java.io.File)1 InputStream (java.io.InputStream)1 MalformedURLException (java.net.MalformedURLException)1 URLClassLoader (java.net.URLClassLoader)1