REFLECTK is a Java-based framework capable to inspect any classpaths and to search for relevant entities that match a specified condition. It operates on bytecode as well as on source code level. According to the Java language, supported entities are:

  • Classpath entries
  • Packages
  • Classes
  • Methods
  • Fields
  • Annotation
  • Instructions

To enable all kind of search criterion, concepts similar to propositional logic and first-order logic can be used. This is achieved by composition of search filters. Each filter is responsible for a specific task, e.g. filtering all classes that implement a certain interface. The underlying search engine uses the passed search filters to determine matching entities.

To switch to the surrounding context of the inspected entity, so called context switch strategies can be used. If the inspected entity is a package object, it is possible to get all included classes within this package by selecting the proper strategy. Another example would be to determine all packages within a classpath entry (e.g. reflectk.jar). These strategies work along the transition of the containment relation:

  • Classpath entries contain packages and classes
  • Packages contain classes and annotations
  • Classes contain annotations, methods, constructors and fields
  • Methods contain annotations and instructions
  • Constructors contain annotations and instructions
  • Fields contain annotations
  • Annotation
  • Instructions

All this concepts are used by REFLECTK's search engine. To react to exception during the search process, which may be raised by unresolveable references or inconsistent classpaths, a custom exception handler can be plugged in. Furthermore the visitor pattern is utilized to keep track of found entities.

Usage Examples

Here are some code examples that implement diverse searches using the REFLECTK framework. To realize a custom search, only the following code is necessary - isn't that simple?

Example 1: Inheritance

Example 2: Modifier

Example 3: Reference

The first example (inheritance example) finds all classes that extend java.util.Set. The second example (modifier example) lists all fields that are declared public static final. The last example (reference example) searchs fields that either reference java.util.Set, java.util.Map or java.util.List.