Skip navigation links
org.reflections

Class Reflections

    • Field Detail

      • log

        @Nullable
        public static org.slf4j.Logger log
      • configuration

        protected final transient Configuration configuration
      • store

        protected Store store
    • Method Detail

      • scan

        protected void scan()
      • scan

        public void scan(URL url)
      • collect

        public static Reflections collect()
        collect saved Reflection xml resources and merge it into a Reflections instance

        by default, resources are collected from all urls that contains the package META-INF/reflections and includes files matching the pattern .*-reflections.xml

      • collect

        public static Reflections collect(String packagePrefix,
                                          com.google.common.base.Predicate<String> resourceNameFilter,
                                          @Nullable
                                          Serializer... optionalSerializer)
        collect saved Reflections resources from all urls that contains the given packagePrefix and matches the given resourceNameFilter and de-serializes them using the default serializer XmlSerializer or using the optionally supplied optionalSerializer

        it is preferred to use a designated resource prefix (for example META-INF/reflections but not just META-INF), so that relevant urls could be found much faster

        Parameters:
        optionalSerializer - - optionally supply one serializer instance. if not specified or null, XmlSerializer will be used
      • collect

        public Reflections collect(InputStream inputStream)
        merges saved Reflections resources from the given input stream, using the serializer configured in this instance's Configuration
        useful if you know the serialized resource location and prefer not to look it up the classpath
      • collect

        public Reflections collect(File file)
        merges saved Reflections resources from the given file, using the serializer configured in this instance's Configuration

        useful if you know the serialized resource location and prefer not to look it up the classpath

      • merge

        public Reflections merge(Reflections reflections)
        merges a Reflections instance metadata into this instance
      • getSubTypesOf

        public <T> Set<Class<? extends T>> getSubTypesOf(Class<T> type)
        gets all sub types in hierarchy of a given type

        depends on SubTypesScanner configured

      • getTypesAnnotatedWith

        public Set<Class<?>> getTypesAnnotatedWith(Class<? extends Annotation> annotation)
        get types annotated with a given annotation, both classes and annotations

        Inherited is not honored by default.

        when honoring @Inherited, meta-annotation should only effect annotated super classes and its sub types

        Note that this (@Inherited) meta-annotation type has no effect if the annotated type is used for anything other than a class. Also, this meta-annotation causes annotations to be inherited only from superclasses; annotations on implemented interfaces have no effect.

        depends on TypeAnnotationsScanner and SubTypesScanner configured

      • getTypesAnnotatedWith

        public Set<Class<?>> getTypesAnnotatedWith(Class<? extends Annotation> annotation,
                                                   boolean honorInherited)
        get types annotated with a given annotation, both classes and annotations

        Inherited is honored according to given honorInherited.

        when honoring @Inherited, meta-annotation should only effect annotated super classes and it's sub types

        when not honoring @Inherited, meta annotation effects all subtypes, including annotations interfaces and classes

        Note that this (@Inherited) meta-annotation type has no effect if the annotated type is used for anything other than a class. Also, this meta-annotation causes annotations to be inherited only from superclasses; annotations on implemented interfaces have no effect.

        depends on TypeAnnotationsScanner and SubTypesScanner configured

      • getTypesAnnotatedWith

        public Set<Class<?>> getTypesAnnotatedWith(Annotation annotation)
        get types annotated with a given annotation, both classes and annotations, including annotation member values matching

        Inherited is not honored by default

        depends on TypeAnnotationsScanner configured

      • getTypesAnnotatedWith

        public Set<Class<?>> getTypesAnnotatedWith(Annotation annotation,
                                                   boolean honorInherited)
        get types annotated with a given annotation, both classes and annotations, including annotation member values matching

        Inherited is honored according to given honorInherited

        depends on TypeAnnotationsScanner configured

      • getMethodsAnnotatedWith

        public Set<Method> getMethodsAnnotatedWith(Class<? extends Annotation> annotation)
        get all methods annotated with a given annotation

        depends on MethodAnnotationsScanner configured

      • getMethodsAnnotatedWith

        public Set<Method> getMethodsAnnotatedWith(Annotation annotation)
        get all methods annotated with a given annotation, including annotation member values matching

        depends on MethodAnnotationsScanner configured

      • getMethodsMatchParams

        public Set<Method> getMethodsMatchParams(Class<?>... types)
        get methods with parameter types matching given types
      • getMethodsReturn

        public Set<Method> getMethodsReturn(Class returnType)
        get methods with return type match given type
      • getMethodsWithAnyParamAnnotated

        public Set<Method> getMethodsWithAnyParamAnnotated(Class<? extends Annotation> annotation)
        get methods with any parameter annotated with given annotation
      • getMethodsWithAnyParamAnnotated

        public Set<Method> getMethodsWithAnyParamAnnotated(Annotation annotation)
        get methods with any parameter annotated with given annotation, including annotation member values matching
      • getConstructorsAnnotatedWith

        public Set<Constructor> getConstructorsAnnotatedWith(Class<? extends Annotation> annotation)
        get all constructors annotated with a given annotation

        depends on MethodAnnotationsScanner configured

      • getConstructorsAnnotatedWith

        public Set<Constructor> getConstructorsAnnotatedWith(Annotation annotation)
        get all constructors annotated with a given annotation, including annotation member values matching

        depends on MethodAnnotationsScanner configured

      • getConstructorsMatchParams

        public Set<Constructor> getConstructorsMatchParams(Class<?>... types)
        get constructors with parameter types matching given types
      • getConstructorsWithAnyParamAnnotated

        public Set<Constructor> getConstructorsWithAnyParamAnnotated(Class<? extends Annotation> annotation)
        get constructors with any parameter annotated with given annotation
      • getConstructorsWithAnyParamAnnotated

        public Set<Constructor> getConstructorsWithAnyParamAnnotated(Annotation annotation)
        get constructors with any parameter annotated with given annotation, including annotation member values matching
      • getFieldsAnnotatedWith

        public Set<Field> getFieldsAnnotatedWith(Class<? extends Annotation> annotation)
        get all fields annotated with a given annotation

        depends on FieldAnnotationsScanner configured

      • getFieldsAnnotatedWith

        public Set<Field> getFieldsAnnotatedWith(Annotation annotation)
        get all methods annotated with a given annotation, including annotation member values matching

        depends on FieldAnnotationsScanner configured

      • getResources

        public Set<String> getResources(com.google.common.base.Predicate<String> namePredicate)
        get resources relative paths where simple name (key) matches given namePredicate

        depends on ResourcesScanner configured

      • getResources

        public Set<String> getResources(Pattern pattern)
        get resources relative paths where simple name (key) matches given regular expression

        depends on ResourcesScanner configured

        Set xmls = reflections.getResources(".\*\.xml");
      • getMethodParamNames

        public List<String> getMethodParamNames(Method method)
        get parameter names of given method

        depends on MethodParameterNamesScanner configured

      • getConstructorParamNames

        public List<String> getConstructorParamNames(Constructor constructor)
        get parameter names of given constructor

        depends on MethodParameterNamesScanner configured

      • getFieldUsage

        public Set<Member> getFieldUsage(Field field)
        get all given field usages in methods and constructors

        depends on MemberUsageScanner configured

      • getMethodUsage

        public Set<Member> getMethodUsage(Method method)
        get all given method usages in methods and constructors

        depends on MemberUsageScanner configured

      • getConstructorUsage

        public Set<Member> getConstructorUsage(Constructor constructor)
        get all given constructors usages in methods and constructors

        depends on MemberUsageScanner configured

      • getAllTypes

        public Set<String> getAllTypes()
        get all types scanned. this is effectively similar to getting all subtypes of Object.

        depends on SubTypesScanner configured with SubTypesScanner(false), otherwise ReflectionsException is thrown

        note using this might be a bad practice. it is better to get types matching some criteria, such as getSubTypesOf(Class) or getTypesAnnotatedWith(Class)

        Returns:
        Set of String, and not of Class, in order to avoid definition of all types in PermGen
      • getStore

        public Store getStore()
        returns the Store used for storing and querying the metadata
      • save

        public File save(String filename)
        serialize to a given directory and filename

        * it is preferred to specify a designated directory (for example META-INF/reflections), so that it could be found later much faster using the load method

        see the documentation for the save method on the configured Serializer

      • save

        public File save(String filename,
                         Serializer serializer)
        serialize to a given directory and filename using given serializer

        * it is preferred to specify a designated directory (for example META-INF/reflections), so that it could be found later much faster using the load method

Copyright © 2016. All rights reserved.