public class AnnotationParser extends Object
Use asm to scan classes for annotations. A SAX-style parsing is done. Handlers are registered which will be called back when various types of entity are encountered, eg a class, a method, a field.
Handlers are not called back in any particular order and are assumed to be order-independent.
As a registered Handler will be called back for each annotation discovered on a class, a method, a field, the Handler should test to see if the annotation is one that it is interested in.
For the servlet spec, we are only interested in annotations on classes, methods and fields, so the callbacks for handling finding a class, a method a field are themselves not fully implemented.
Modifier and Type | Class and Description |
---|---|
static class |
AnnotationParser.AbstractHandler
AbstractHandler
Convenience base class to provide no-ops for all Handler methods.
|
class |
AnnotationParser.ClassInfo
ClassInfo
Immutable information gathered by parsing class header.
|
class |
AnnotationParser.FieldInfo
FieldInfo
Immutable information gathered by parsing a field on a class.
|
static interface |
AnnotationParser.Handler
Handler
Signature for all handlers that respond to parsing class files.
|
class |
AnnotationParser.MethodInfo
MethodInfo
Immutable information gathered by parsing a method on a class.
|
class |
AnnotationParser.MyClassVisitor
MyClassVisitor
ASM visitor for a class.
|
class |
AnnotationParser.MyFieldVisitor
MyFieldVisitor
An ASM visitor for parsing Fields.
|
class |
AnnotationParser.MyMethodVisitor
MyMethodVisitor
ASM Visitor for parsing a method.
|
Modifier and Type | Field and Description |
---|---|
protected Set<String> |
_parsedClassNames |
protected static int |
ASM_OPCODE_VERSION |
Constructor and Description |
---|
AnnotationParser() |
Modifier and Type | Method and Description |
---|---|
boolean |
isParsed(String className)
True if the class has already been processed, false otherwise
|
static String |
normalize(String name)
Convert internal name to simple name
|
static String[] |
normalize(String[] list)
Convert internal names to simple names.
|
void |
parse(Set<? extends AnnotationParser.Handler> handlers,
Class<?> clazz,
boolean visitSuperClasses)
Parse the given class, optionally walking its inheritance hierarchy
|
void |
parse(Set<? extends AnnotationParser.Handler> handlers,
ClassLoader loader,
boolean visitParents,
boolean nullInclusive)
Parse classes in the supplied classloader.
|
void |
parse(Set<? extends AnnotationParser.Handler> handlers,
List<String> classNames)
Parse the given classes
|
void |
parse(Set<? extends AnnotationParser.Handler> handlers,
Resource r)
Parse a resource
|
void |
parse(Set<? extends AnnotationParser.Handler> handlers,
String className)
Parse a given class
|
void |
parse(Set<? extends AnnotationParser.Handler> handlers,
String[] classNames)
Parse the given classes
|
void |
parse(Set<? extends AnnotationParser.Handler> handlers,
URI uri)
Parse a particular uri
|
void |
parse(Set<? extends AnnotationParser.Handler> handlers,
URI[] uris)
Parse classes in the supplied uris.
|
protected void |
parseDir(Set<? extends AnnotationParser.Handler> handlers,
Resource dir)
Parse all classes in a directory
|
protected void |
parseJar(Set<? extends AnnotationParser.Handler> handlers,
Resource jarResource)
Parse a resource that is a jar file.
|
protected void |
parseJarEntry(Set<? extends AnnotationParser.Handler> handlers,
Resource jar,
JarEntry entry)
Parse a single entry in a jar file
|
protected void |
scanClass(Set<? extends AnnotationParser.Handler> handlers,
Resource containingResource,
InputStream is)
Use ASM on a class
|
public static String normalize(String name)
name
- the internal namepublic static String[] normalize(String[] list)
list
- the list of internal namespublic boolean isParsed(String className)
className
- the classnamepublic void parse(Set<? extends AnnotationParser.Handler> handlers, String className) throws Exception
handlers
- the set of handlers to find classclassName
- the class name to parseException
- if unable to parsepublic void parse(Set<? extends AnnotationParser.Handler> handlers, Class<?> clazz, boolean visitSuperClasses) throws Exception
handlers
- the handlers to look for class inclazz
- the class to look forvisitSuperClasses
- if true, also visit super classes for parseException
- if unable to parse classpublic void parse(Set<? extends AnnotationParser.Handler> handlers, String[] classNames) throws Exception
handlers
- the set of handlers to look for class inclassNames
- the class nameException
- if unable to parsepublic void parse(Set<? extends AnnotationParser.Handler> handlers, List<String> classNames) throws Exception
handlers
- the set of handlers to look for class inclassNames
- the class namesException
- if unable to parseprotected void parseDir(Set<? extends AnnotationParser.Handler> handlers, Resource dir) throws Exception
handlers
- the set of handlers to look for classes indir
- the resource directory to look for classesException
- if unable to parsepublic void parse(Set<? extends AnnotationParser.Handler> handlers, ClassLoader loader, boolean visitParents, boolean nullInclusive) throws Exception
handlers
- the handlers to look for classes inloader
- the classloader for the classesvisitParents
- if true, visit parent classloaders toonullInclusive
- if true, an empty pattern means all names match, if false, none matchException
- if unable to parsepublic void parse(Set<? extends AnnotationParser.Handler> handlers, URI[] uris) throws Exception
handlers
- the handlers to look for classes inuris
- the uris for the jarsException
- if unable to parsepublic void parse(Set<? extends AnnotationParser.Handler> handlers, URI uri) throws Exception
handlers
- the handlers to look for classes inuri
- the uri for the jarException
- if unable to parsepublic void parse(Set<? extends AnnotationParser.Handler> handlers, Resource r) throws Exception
handlers
- the handlers to look for classes inr
- the resource to parseException
- if unable to parseprotected void parseJar(Set<? extends AnnotationParser.Handler> handlers, Resource jarResource) throws Exception
handlers
- the handlers to look for classes injarResource
- the jar resource to parseException
- if unable to parseprotected void parseJarEntry(Set<? extends AnnotationParser.Handler> handlers, Resource jar, JarEntry entry) throws Exception
handlers
- the handlers to look for classes injar
- the jar resource to parseentry
- the entry in the jar resource to parseException
- if unable to parseprotected void scanClass(Set<? extends AnnotationParser.Handler> handlers, Resource containingResource, InputStream is) throws IOException
handlers
- the handlers to look for classes incontainingResource
- the dir or jar that the class is contained within, can be null if not knownis
- the input stream to parseIOException
- if unable to parseCopyright © 1995–2017 Webtide. All rights reserved.