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,
ClassNameResolver resolver,
boolean visitSuperClasses)
Parse the given class, optionally walking its inheritance hierarchy
|
void |
parse(Set<? extends AnnotationParser.Handler> handlers,
ClassLoader loader,
boolean visitParents,
boolean nullInclusive,
ClassNameResolver resolver)
Parse classes in the supplied classloader.
|
void |
parse(Set<? extends AnnotationParser.Handler> handlers,
List<String> classNames,
ClassNameResolver resolver)
Parse the given classes
|
void |
parse(Set<? extends AnnotationParser.Handler> handlers,
Resource r,
ClassNameResolver resolver)
Parse a resource
|
void |
parse(Set<? extends AnnotationParser.Handler> handlers,
String[] classNames,
ClassNameResolver resolver)
Parse the given classes
|
void |
parse(Set<? extends AnnotationParser.Handler> handlers,
String className,
ClassNameResolver resolver)
Parse a given class
|
void |
parse(Set<? extends AnnotationParser.Handler> handlers,
URI[] uris,
ClassNameResolver resolver)
Parse classes in the supplied uris.
|
void |
parse(Set<? extends AnnotationParser.Handler> handlers,
URI uri,
ClassNameResolver resolver)
Parse a particular uri
|
protected void |
parseDir(Set<? extends AnnotationParser.Handler> handlers,
Resource dir,
ClassNameResolver resolver)
Parse all classes in a directory
|
protected void |
parseJar(Set<? extends AnnotationParser.Handler> handlers,
Resource jarResource,
ClassNameResolver resolver)
Parse a resource that is a jar file.
|
protected void |
parseJarEntry(Set<? extends AnnotationParser.Handler> handlers,
Resource jar,
JarEntry entry,
ClassNameResolver resolver)
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, ClassNameResolver resolver) throws Exception
handlers
- the set of handlers to find classclassName
- the class name to parseresolver
- the class name resolver to useException
- if unable to parsepublic void parse(Set<? extends AnnotationParser.Handler> handlers, Class<?> clazz, ClassNameResolver resolver, boolean visitSuperClasses) throws Exception
handlers
- the handlers to look for class inclazz
- the class to look forresolver
- the resolver to look up class withvisitSuperClasses
- if true, also visit super classes for parseException
- if unable to parse classpublic void parse(Set<? extends AnnotationParser.Handler> handlers, String[] classNames, ClassNameResolver resolver) throws Exception
handlers
- the set of handlers to look for class inclassNames
- the class nameresolver
- the class name resolverException
- if unable to parsepublic void parse(Set<? extends AnnotationParser.Handler> handlers, List<String> classNames, ClassNameResolver resolver) throws Exception
handlers
- the set of handlers to look for class inclassNames
- the class namesresolver
- the class name resolverException
- if unable to parseprotected void parseDir(Set<? extends AnnotationParser.Handler> handlers, Resource dir, ClassNameResolver resolver) throws Exception
handlers
- the set of handlers to look for classes indir
- the resource directory to look for classesresolver
- the class name resolverException
- if unable to parsepublic void parse(Set<? extends AnnotationParser.Handler> handlers, ClassLoader loader, boolean visitParents, boolean nullInclusive, ClassNameResolver resolver) 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 matchresolver
- the class name resolverException
- if unable to parsepublic void parse(Set<? extends AnnotationParser.Handler> handlers, URI[] uris, ClassNameResolver resolver) throws Exception
handlers
- the handlers to look for classes inuris
- the uris for the jarsresolver
- the class name resolverException
- if unable to parsepublic void parse(Set<? extends AnnotationParser.Handler> handlers, URI uri, ClassNameResolver resolver) throws Exception
handlers
- the handlers to look for classes inuri
- the uri for the jarresolver
- the class name resolverException
- if unable to parsepublic void parse(Set<? extends AnnotationParser.Handler> handlers, Resource r, ClassNameResolver resolver) throws Exception
handlers
- the handlers to look for classes inr
- the resource to parseresolver
- the class name resolverException
- if unable to parseprotected void parseJar(Set<? extends AnnotationParser.Handler> handlers, Resource jarResource, ClassNameResolver resolver) throws Exception
handlers
- the handlers to look for classes injarResource
- the jar resource to parseresolver
- the class name resolverException
- if unable to parseprotected void parseJarEntry(Set<? extends AnnotationParser.Handler> handlers, Resource jar, JarEntry entry, ClassNameResolver resolver) throws Exception
handlers
- the handlers to look for classes injar
- the jar resource to parseentry
- the entry in the jar resource to parseresolver
- the class name resolverException
- 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-2016 Webtide. All Rights Reserved.