Java Annotation Indexer 1.0.0.Final-redhat-1

org.jboss.jandex
Class Index

java.lang.Object
  extended by org.jboss.jandex.Index

public final class Index
extends Object

An index useful for quickly processing annotations. The index is read-only and supports concurrent access. Also the index is optimized for memory efficiency by using componentized DotName values.

It contains the following information:

  1. All annotations and a collection of targets they refer to
  2. All classes (including interfaces) scanned during the indexing process (typical all classes in a jar)
  3. All subclasses indexed by super class known to this index
  4. <

Author:
Jason T. Greene

Method Summary
static Index create(Map<DotName,List<AnnotationInstance>> annotations, Map<DotName,List<ClassInfo>> subclasses, Map<DotName,List<ClassInfo>> implementors, Map<DotName,ClassInfo> classes)
          Constructs a "mock" Index using the passed values.
 List<AnnotationInstance> getAnnotations(DotName annotationName)
          Obtains a list of instances for the specified annotation.
 ClassInfo getClassByName(DotName className)
          Gets the class (or interface, or annotation) that was scanned during the indexing phase.
 Collection<ClassInfo> getKnownClasses()
          Gets all known classes by this index (those which were scanned).
 List<ClassInfo> getKnownDirectImplementors(DotName className)
          Gets all known direct implementors of the specified interface name.
 List<ClassInfo> getKnownDirectSubclasses(DotName className)
          Gets all known direct subclasses of the specified class name.
 void printAnnotations()
          Print all annotations known by this index to stdout.
 void printSubclasses()
          Print all classes that have known subclasses, and all their subclasses
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

create

public static Index create(Map<DotName,List<AnnotationInstance>> annotations,
                           Map<DotName,List<ClassInfo>> subclasses,
                           Map<DotName,List<ClassInfo>> implementors,
                           Map<DotName,ClassInfo> classes)
Constructs a "mock" Index using the passed values. All passed values MUST NOT BE MODIFIED AFTER THIS CALL. Otherwise the resulting object would not conform to the contract outlined above. Also, to conform to the memory efficiency contract this method should be passed componentized DotNames, which all share common root instances. Of course for testing code this doesn't really matter.

Parameters:
annotations - A map to lookup annotation instances by class name
subclasses - A map to lookup subclasses by super class name
implementors - A map to lookup implementing classes by interface name
classes - A map to lookup classes by class name
Returns:
the index

getAnnotations

public List<AnnotationInstance> getAnnotations(DotName annotationName)
Obtains a list of instances for the specified annotation. This is done using an O(1) lookup. Valid instance targets include field, method, parameter, and class.

Parameters:
annotationName - the name of the annotation to look for
Returns:
a non-null list of annotation instances

getKnownDirectSubclasses

public List<ClassInfo> getKnownDirectSubclasses(DotName className)
Gets all known direct subclasses of the specified class name. A known direct subclass is one which was found during the scanning process; however, this is often not the complete universe of subclasses, since typically indexes are constructed per jar. It is expected that several indexes will need to be searched when analyzing a jar that is a part of a complex multi-module/classloader environment (like an EE application server).

Note that this will only pick up direct subclasses of the class. It will not pick up subclasses of subclasses.

Parameters:
className - the super class of the desired subclasses
Returns:
a non-null list of all known subclasses of className

getKnownDirectImplementors

public List<ClassInfo> getKnownDirectImplementors(DotName className)
Gets all known direct implementors of the specified interface name. A known direct implementor is one which was found during the scanning process; however, this is often not the complete universe of implementors, since typically indexes are constructed per jar. It is expected that several indexes will need to be searched when analyzing a jar that is a part of a complex multi-module/classloader environment (like an EE application server).

The list of implementors may also include other interfaces, in order to get a complete list of all classes that are assignable to a given interface it is necessary to recursively call getKnownDirectImplementors(DotName) for every implementing interface found.

Parameters:
className - the super class of the desired subclasses
Returns:
a non-null list of all known subclasses of className

getClassByName

public ClassInfo getClassByName(DotName className)
Gets the class (or interface, or annotation) that was scanned during the indexing phase.

Parameters:
className - the name of the class
Returns:
information about the class or null if it is not known

getKnownClasses

public Collection<ClassInfo> getKnownClasses()
Gets all known classes by this index (those which were scanned).

Returns:
a collection of known classes

printAnnotations

public void printAnnotations()
Print all annotations known by this index to stdout.


printSubclasses

public void printSubclasses()
Print all classes that have known subclasses, and all their subclasses


Java Annotation Indexer 1.0.0.Final-redhat-1

Copyright © 2011 JBoss, a division of Red Hat, Inc.. All Rights Reserved.