Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.jboss.errai.reflections
Class Reflections

    java.lang.Object
      org.jboss.errai.reflections.ReflectionUtils
          org.jboss.errai.reflections.Reflections

    public class Reflections

extends ReflectionUtils

Reflections one-stop-shop object

Reflections scans your classpath, indexes the metadata, allows you to query it on runtime and may save and collect that information for many modules within your project.

Using Reflections you can query your metadata such as:

- get all subtypes of some type
- get all types/methods/fields annotated with some annotation, w/o annotation parameters matching

a typical use of Reflections would be:

     Reflections reflections = new Reflections("my.package.prefix"); //replace my.package.prefix with your package prefix, of course

     Set<Class<? extends SomeType>> subTypes = reflections.getSubTypesOf(SomeType.class);
     Set<Class<?>> annotated = reflections.getTypesAnnotatedWith(SomeAnnotation.class);
     Set<Class<?>> annotated1 = reflections.getTypesAnnotatedWith(
          new SomeAnnotation() {public String value() {return "1";}
                                public Class<? extends Annotation> annotationType() {return SomeAnnotation.class;}});

basically, to use Reflections for scanning and querying, instantiate it with a `Configuration`, for example

          new Reflections(
              new ConfigurationBuilder()
                  .filterInputsBy(new FilterBuilder().include("your project's common package prefix here..."))
                  .setUrls(ClasspathHelper.forClassLoader())
                  .setScanners(new SubTypesScanner(), new TypeAnnotationsScanner().filterResultsBy(myClassAnnotationsFilter)));

and than use the convenient methods to query the metadata, such as `getSubTypesOf(java.lang.Class)`, `getTypesAnnotatedWith(java.lang.Class)`, `getMethodsAnnotatedWith(java.lang.Class)`, `getFieldsAnnotatedWith(java.lang.Class)`, `getResources(com.google.common.base.Predicate)`
use `getStore()` to access and query the store directly

in order to save a metadata use `save(String)` or `save(String, org.jboss.errai.reflections.serializers.Serializer)` for example with `XmlSerializer` or `JavaCodeSerializer`

in order to collect pre saved metadata and avoid re-scanning, use `collect(String, com.google.common.base.Predicate)`

* be aware that when using the constructor new Reflections("my.package"), only urls with prefix 'my.package' will be scanned, and any transitive classes in other urls will not be scanned (for example if my.package.SomeClass extends other.package.OtherClass, than the later will not be scanned). in that case specify the urls manually using `ConfigurationBuilder`

For Javadoc, source code, and more information about Reflections Library, see http://code.google.com/p/reflections/

Field Summary
`protected Configuration` | `configuration`

Fields inherited from class org.reflections.ReflectionUtils
`primitiveDescriptors, primitiveNames, primitiveTypes`

Constructor Summary
`protected` | `Reflections()`
`` | `Reflections(Configuration configuration)` constructs a Reflections instance and scan according to given `Configuration`
`` | `Reflections(java.lang.Object[] urlHints, Scanner... scanners)` a convenient constructor for scanning within given package prefixes and urls containing given classes.
`` | `Reflections(java.lang.String prefix, Scanner... scanners)` a convenient constructor for scanning within a package prefix

Method Summary
`static Reflections` | `collect()` collect saved Reflection xml resources and merge it into a Reflections instance
`Reflections` | `collect(java.io.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
`Reflections` | `collect(java.io.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
`Reflections` | `collect(java.lang.String packagePrefix, com.google.common.base.Predicate<java.lang.String> resourceNameFilter)` collect saved Reflections resources from all urls that contains the given packagePrefix and matches the given resourceNameFilter and de-serializes them using the serializer configured in the configuration
`Reflections` | `collect(java.lang.String packagePrefix, com.google.common.base.Predicate<java.lang.String> resourceNameFilter, Serializer serializer)` collect saved Reflections resources from all urls that contains the given packagePrefix and matches the given resourceNameFilter and de-serializes them using the serializer configured in the configuration
`java.util.Set<java.lang.reflect.Method>` | `getConverters(java.lang.Class<?> from, java.lang.Class<?> to)` get 'converter' methods that could effectively convert from type 'from' to type 'to'
`java.util.Set<java.lang.reflect.Field>` | `getFieldsAnnotatedWith(java.lang.annotation.Annotation annotation)` get all methods annotated with a given annotation, including annotation member values matching depends on FieldAnnotationsScanner configured, otherwise an empty set is returned
`java.util.Set<java.lang.reflect.Field>` | `getFieldsAnnotatedWith(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)` get all fields annotated with a given annotation depends on FieldAnnotationsScanner configured, otherwise an empty set is returned
`java.util.Set<java.lang.reflect.Method>` | `getMethodsAnnotatedWith(java.lang.annotation.Annotation annotation)` get all methods annotated with a given annotation, including annotation member values matching depends on MethodAnnotationsScanner configured, otherwise an empty set is returned
`java.util.Set<java.lang.reflect.Method>` | `getMethodsAnnotatedWith(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)` get all methods annotated with a given annotation depends on MethodAnnotationsScanner configured, otherwise an empty set is returned
`java.util.Set<java.lang.String>` | `getResources(java.util.regex.Pattern pattern)` get resources relative paths where simple name (key) matches given regular expression
`java.util.Set<java.lang.String>` | `getResources(com.google.common.base.Predicate<java.lang.String> namePredicate)` get resources relative paths where simple name (key) matches given namePredicate
`Store` | `getStore()` returns the store used for storing and querying the metadata
`
`<T> java.util.Set<java.lang.Class<? extends T>>`
` | `getSubTypesOf(java.lang.Class<T> type)` gets all sub types in hierarchy of a given type depends on SubTypesScanner configured, otherwise an empty set is returned
`java.util.Set<java.lang.Class<?>>` | `getTypesAnnotatedWith(java.lang.annotation.Annotation annotation)` get types annotated with a given annotation, both classes and annotations, including annotation member values matching
`java.util.Set<java.lang.Class<?>>` | `getTypesAnnotatedWith(java.lang.annotation.Annotation annotation, boolean honorInherited)` get types annotated with a given annotation, both classes and annotations, including annotation member values matching
`java.util.Set<java.lang.Class<?>>` | `getTypesAnnotatedWith(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)` get types annotated with a given annotation, both classes and annotations
`java.util.Set<java.lang.Class<?>>` | `getTypesAnnotatedWith(java.lang.Class<? extends java.lang.annotation.Annotation> annotation, boolean honorInherited)` get types annotated with a given annotation, both classes and annotations
`Reflections` | `merge(Reflections reflections)` merges a Reflections instance metadata into this instance
`java.io.File` | `save(java.lang.String filename)` serialize to a given directory and filename
`java.io.File` | `save(java.lang.String filename, Serializer serializer)` serialize to a given directory and filename using given serializer
`protected void` | `scan()`

Methods inherited from class org.reflections.ReflectionUtils
`areAnnotationMembersMatching, areAnnotationMembersMatching, forName, forNames, getAllSuperTypes, getAllSuperTypesAnnotatedWith, getMatchingAnnotations`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### configuration

    protected final transient Configuration configuration

Constructor Detail

### Reflections

    public Reflections(Configuration configuration)

  constructs a Reflections instance and scan according to given `Configuration`

  it is preferred to use `ConfigurationBuilder`

### Reflections

    public Reflections(java.lang.String prefix,
                       Scanner... scanners)

  a convenient constructor for scanning within a package prefix

  this actually create a `Configuration` with:
  - urls that contain resources with name `prefix`
  - acceptsInput where name starts with the given `prefix`
  - scanners set to the given `scanners`, otherwise defaults to `TypeAnnotationsScanner` and `SubTypesScanner`.
  - scanner results filter is set to accept results matching given `prefix`

### Reflections

    public Reflections(java.lang.Object[] urlHints,
                       Scanner... scanners)

  a convenient constructor for scanning within given package prefixes and urls containing given classes.

  given urlHints is an array of either String or Class elements, where Strings results in scanning package prefix and Class results in scanning url that contains that class, for example

           new Reflections(new Object[] {"my.package", com.google.inject.Module, "javax.persistence"})

  would result in scanning packages 'my.package' and 'javax.persistence' and also the url that contains the class of com.google.inject.Module

  this actually create a `Configuration` with:
  - urls that contain resources with name `prefix` or that contains given classes
  - acceptsInput where name starts with the given `prefix` or with the classes package name
  - scanners set to the given `scanners`, otherwise defaults to `TypeAnnotationsScanner` and `SubTypesScanner`.
  - scanner results filter is set to accept results matching given `prefix` or the given classes package name

  Parameters:
    `urlHints` - is an array of either String or Class elements, where Strings results in scanning package prefix and Class results in scanning urls containing the class

### Reflections

    protected Reflections()

Method Detail

### scan

    protected void scan()

### 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 Reflections collect(java.lang.String packagePrefix,
                               com.google.common.base.Predicate<java.lang.String> resourceNameFilter)

  collect saved Reflections resources from all urls that contains the given packagePrefix and matches the given resourceNameFilter and de-serializes them using the serializer configured in the configuration

  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

### collect

    public Reflections collect(java.lang.String packagePrefix,
                               com.google.common.base.Predicate<java.lang.String> resourceNameFilter,
                               Serializer serializer)

  collect saved Reflections resources from all urls that contains the given packagePrefix and matches the given resourceNameFilter and de-serializes them using the serializer configured in the configuration

  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

### collect

    public Reflections collect(java.io.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(java.io.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> java.util.Set<java.lang.Class<? extends T>> getSubTypesOf(java.lang.Class<T> type)

  gets all sub types in hierarchy of a given type

  depends on SubTypesScanner configured, otherwise an empty set is returned

### getTypesAnnotatedWith

    public java.util.Set<java.lang.Class<?>> getTypesAnnotatedWith(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)

  get types annotated with a given annotation, both classes and annotations

  `Inherited` is honored

  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, otherwise an empty set is returned

### getTypesAnnotatedWith

    public java.util.Set<java.lang.Class<?>> getTypesAnnotatedWith(java.lang.Class<? extends java.lang.annotation.Annotation> annotation,
                                                                   boolean honorInherited)

  get types annotated with a given annotation, both classes and annotations

  `Inherited` is honored according to given honorInherited

  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, otherwise an empty set is returned

### getTypesAnnotatedWith

    public java.util.Set<java.lang.Class<?>> getTypesAnnotatedWith(java.lang.annotation.Annotation annotation)

  get types annotated with a given annotation, both classes and annotations, including annotation member values matching

  `Inherited` is honored

  depends on TypeAnnotationsScanner configured, otherwise an empty set is returned

### getTypesAnnotatedWith

    public java.util.Set<java.lang.Class<?>> getTypesAnnotatedWith(java.lang.annotation.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, otherwise an empty set is returned

### getMethodsAnnotatedWith

    public java.util.Set<java.lang.reflect.Method> getMethodsAnnotatedWith(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)

  get all methods annotated with a given annotation

  depends on MethodAnnotationsScanner configured, otherwise an empty set is returned

### getMethodsAnnotatedWith

    public java.util.Set<java.lang.reflect.Method> getMethodsAnnotatedWith(java.lang.annotation.Annotation annotation)

  get all methods annotated with a given annotation, including annotation member values matching

  depends on MethodAnnotationsScanner configured, otherwise an empty set is returned

### getFieldsAnnotatedWith

    public java.util.Set<java.lang.reflect.Field> getFieldsAnnotatedWith(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)

  get all fields annotated with a given annotation

  depends on FieldAnnotationsScanner configured, otherwise an empty set is returned

### getFieldsAnnotatedWith

    public java.util.Set<java.lang.reflect.Field> getFieldsAnnotatedWith(java.lang.annotation.Annotation annotation)

  get all methods annotated with a given annotation, including annotation member values matching

  depends on FieldAnnotationsScanner configured, otherwise an empty set is returned

### getConverters

    public java.util.Set<java.lang.reflect.Method> getConverters(java.lang.Class<?> from,
                                                                 java.lang.Class<?> to)

  get 'converter' methods that could effectively convert from type 'from' to type 'to'

  depends on ConvertersScanner configured, otherwise an empty set is returned

  Parameters:
    `from` - - the type to convert from
    `to` - - the required return type

### getResources

    public java.util.Set<java.lang.String> getResources(com.google.common.base.Predicate<java.lang.String> namePredicate)

  get resources relative paths where simple name (key) matches given namePredicate

  depends on ResourcesScanner configured, otherwise an empty set is returned

### getResources

    public java.util.Set<java.lang.String> getResources(java.util.regex.Pattern pattern)

  get resources relative paths where simple name (key) matches given regular expression

  depends on ResourcesScanner configured, otherwise an empty set is returned

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

### getStore

    public Store getStore()

  returns the store used for storing and querying the metadata

### save

    public java.io.File save(java.lang.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 java.io.File save(java.lang.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

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2011. All Rights Reserved.