Package org.atmosphere.util.annotation
Class AnnotationDetector
- java.lang.Object
-
- org.atmosphere.util.annotation.AnnotationDetector
-
public final class AnnotationDetector extends java.lang.ObjectAnnotationDetectorreads Java Class File (".class") files and reports the encountered annotations via a simple, developer friendly API. A Java Class File consists of a stream of 8-bit bytes. All 16-bit, 32-bit, and 64-bit quantities are constructed by reading in two, four, and eight consecutive 8-bit bytes, respectively. Multi byte data items are always stored in big-endian order, where the high bytes come first. In the Java and Java 2 platforms, this format is supported by interfacesDataInputandDataOutput. A class file consists of a single ClassFile structure:ClassFile { u4 magic; u2 minor_version; u2 major_version; u2 constant_pool_count; cp_info constant_pool[constant_pool_count-1]; u2 access_flags; u2 this_class; u2 super_class; u2 interfaces_count; u2 interfaces[interfaces_count]; u2 fields_count; field_info fields[fields_count]; u2 methods_count; method_info methods[methods_count]; u2 attributes_count; attribute_info attributes[attributes_count]; } Where: u1 unsigned byteReferences:DataInput.readUnsignedByte()u2 unsigned shortDataInput.readUnsignedShort()u4 unsigned intDataInput.readInt()Annotations are stored as Attributes (i.e. "RuntimeVisibleAnnotations" and "RuntimeInvisibleAnnotations").- Java class file (Wikipedia) (Gentle Introduction);
- Class File Format Specification (Java 6 version) and the Java VM Specification (Chapter 4) for the real work.
- scanning java annotations at runtime.
- JBoss MC Scanning lib;
- Google Reflections, in fact an improved version of scannotation;
- annovention, improved version
of the original Annovention project.
Available from maven:
tv.cntt:annovention:1.2; - If using the Spring Framework, use
ClassPathScanningCandidateComponentProvider
- Since:
- annotation-detector 3.0.0
- Author:
- Ronald K. Muller
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceAnnotationDetector.FieldReporterAReporterfor field annotations.static interfaceAnnotationDetector.MethodReporterAReporterfor method annotations.static interfaceAnnotationDetector.ReporterReporteris the base interface, used to report the detected annotations.static interfaceAnnotationDetector.TypeReporterAReporterfor type annotations.
-
Constructor Summary
Constructors Constructor Description AnnotationDetector(AnnotationDetector.Reporter reporter)Create a newAnnotationDetector, reporting the detected annotations to the specifiedReporter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddestroy()Reclaim memory.voiddetect()Report all Java ClassFile files available on the class path.voiddetect(java.io.File... filesOrDirectories)Report all Java ClassFile files available from the specified files and/or directories, including sub directories.voiddetect(java.lang.String... packageNames)Report all Java ClassFile files available on the class path within the specified packages and sub packages.
-
-
-
Constructor Detail
-
AnnotationDetector
public AnnotationDetector(AnnotationDetector.Reporter reporter)
Create a newAnnotationDetector, reporting the detected annotations to the specifiedReporter.
-
-
Method Detail
-
detect
public void detect() throws java.io.IOExceptionReport all Java ClassFile files available on the class path.- Throws:
java.io.IOException- See Also:
detect(File...)
-
detect
public final void detect(java.lang.String... packageNames) throws java.io.IOExceptionReport all Java ClassFile files available on the class path within the specified packages and sub packages.- Throws:
java.io.IOException- See Also:
detect(File...)
-
detect
public void detect(java.io.File... filesOrDirectories) throws java.io.IOExceptionReport all Java ClassFile files available from the specified files and/or directories, including sub directories. Note that non-class files (files, not starting with the magic numberCAFEBABEare silently ignored.- Throws:
java.io.IOException
-
destroy
public void destroy()
Reclaim memory.
-
-