public final class AnnotationDetector extends Object
AnnotationDetector reads 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 interfaces DataInput and DataOutput.
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 byte DataInput.readUnsignedByte()
u2 unsigned short DataInput.readUnsignedShort()
u4 unsigned int DataInput.readInt()
Annotations are stored as Attributes (i.e. "RuntimeVisibleAnnotations" and
"RuntimeInvisibleAnnotations").
References:
Similar projects / libraries:
tv.cntt:annovention:1.2;
ClassPathScanningCandidateComponentProvider
All above mentioned projects make use of a byte code manipulation library (like BCEL, ASM or Javassist).
| Modifier and Type | Class and Description |
|---|---|
static interface |
AnnotationDetector.FieldReporter
A
Reporter for field annotations. |
static interface |
AnnotationDetector.MethodReporter
A
Reporter for method annotations. |
static interface |
AnnotationDetector.Reporter
Reporter is the base interface, used to report the detected annotations. |
static interface |
AnnotationDetector.TypeReporter
A
Reporter for type annotations. |
| Constructor and Description |
|---|
AnnotationDetector(AnnotationDetector.Reporter reporter)
Create a new
AnnotationDetector, reporting the detected annotations
to the specified Reporter. |
| Modifier and Type | Method and Description |
|---|---|
void |
detect()
Report all Java ClassFile files available on the class path.
|
void |
detect(File... filesOrDirectories)
Scan all Java ClassFile (
*.class) files available in the specified files
and/or directories. |
void |
detect(String... packageNames)
Report all Java ClassFile files available on the class path within
the specified packages and sub packages.
|
public AnnotationDetector(AnnotationDetector.Reporter reporter)
AnnotationDetector, reporting the detected annotations
to the specified Reporter.public void detect()
throws IOException
IOExceptiondetect(File...)public void detect(String... packageNames) throws IOException
IOExceptiondetect(File...)public void detect(File... filesOrDirectories) throws IOException
*.class) files available in the specified files
and/or directories.
In Java, the Class path contains directories (top level directory as package root) and/or jar files (including zip files).
Note that non-class files (files, not starting with the magic number
CAFEBABE are silently ignored.
filesOrDirectories - Valid files are: jar files, Java *.class files (all other
files are silently ignored) and directories which are package root directoriesIOExceptionCopyright © 2011-2015 XIAM Solutions B.V.. All Rights Reserved.