public class AnnotationParser
extends java.lang.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 java.util.Set<java.lang.String> |
_parsedClassNames |
protected static int |
ASM_OPCODE_VERSION |
Constructor and Description |
---|
AnnotationParser() |
Modifier and Type | Method and Description |
---|---|
boolean |
isParsed(java.lang.String className)
True if the class has already been processed, false otherwise
|
static java.lang.String |
normalize(java.lang.String name)
Convert internal name to simple name
|
static java.lang.String[] |
normalize(java.lang.String[] list)
Convert internal names to simple names.
|
void |
parse(java.util.Set<? extends AnnotationParser.Handler> handlers,
java.lang.Class<?> clazz,
boolean visitSuperClasses)
Parse the given class, optionally walking its inheritance hierarchy
|
void |
parse(java.util.Set<? extends AnnotationParser.Handler> handlers,
java.lang.ClassLoader loader,
boolean visitParents,
boolean nullInclusive)
Parse classes in the supplied classloader.
|
void |
parse(java.util.Set<? extends AnnotationParser.Handler> handlers,
java.util.List<java.lang.String> classNames)
Parse the given classes
|
void |
parse(java.util.Set<? extends AnnotationParser.Handler> handlers,
Resource r)
Parse a resource
|
void |
parse(java.util.Set<? extends AnnotationParser.Handler> handlers,
java.lang.String className)
Parse a given class
|
void |
parse(java.util.Set<? extends AnnotationParser.Handler> handlers,
java.lang.String[] classNames)
Parse the given classes
|
void |
parse(java.util.Set<? extends AnnotationParser.Handler> handlers,
java.net.URI uri)
Parse a particular uri
|
void |
parse(java.util.Set<? extends AnnotationParser.Handler> handlers,
java.net.URI[] uris)
Parse classes in the supplied uris.
|
protected void |
parseDir(java.util.Set<? extends AnnotationParser.Handler> handlers,
Resource dir)
Parse all classes in a directory
|
protected void |
parseJar(java.util.Set<? extends AnnotationParser.Handler> handlers,
Resource jarResource)
Parse a resource that is a jar file.
|
protected void |
parseJarEntry(java.util.Set<? extends AnnotationParser.Handler> handlers,
Resource jar,
java.util.jar.JarEntry entry)
Parse a single entry in a jar file
|
protected void |
scanClass(java.util.Set<? extends AnnotationParser.Handler> handlers,
Resource containingResource,
java.io.InputStream is)
Use ASM on a class
|
protected java.util.Set<java.lang.String> _parsedClassNames
protected static int ASM_OPCODE_VERSION
public static java.lang.String normalize(java.lang.String name)
name
- the internal namepublic static java.lang.String[] normalize(java.lang.String[] list)
list
- the list of internal namespublic boolean isParsed(java.lang.String className)
className
- the classnamepublic void parse(java.util.Set<? extends AnnotationParser.Handler> handlers, java.lang.String className) throws java.lang.Exception
handlers
- the set of handlers to find classclassName
- the class name to parsejava.lang.Exception
- if unable to parsepublic void parse(java.util.Set<? extends AnnotationParser.Handler> handlers, java.lang.Class<?> clazz, boolean visitSuperClasses) throws java.lang.Exception
handlers
- the handlers to look for class inclazz
- the class to look forvisitSuperClasses
- if true, also visit super classes for parsejava.lang.Exception
- if unable to parse classpublic void parse(java.util.Set<? extends AnnotationParser.Handler> handlers, java.lang.String[] classNames) throws java.lang.Exception
handlers
- the set of handlers to look for class inclassNames
- the class namejava.lang.Exception
- if unable to parsepublic void parse(java.util.Set<? extends AnnotationParser.Handler> handlers, java.util.List<java.lang.String> classNames) throws java.lang.Exception
handlers
- the set of handlers to look for class inclassNames
- the class namesjava.lang.Exception
- if unable to parseprotected void parseDir(java.util.Set<? extends AnnotationParser.Handler> handlers, Resource dir) throws java.lang.Exception
handlers
- the set of handlers to look for classes indir
- the resource directory to look for classesjava.lang.Exception
- if unable to parsepublic void parse(java.util.Set<? extends AnnotationParser.Handler> handlers, java.lang.ClassLoader loader, boolean visitParents, boolean nullInclusive) throws java.lang.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 matchjava.lang.Exception
- if unable to parsepublic void parse(java.util.Set<? extends AnnotationParser.Handler> handlers, java.net.URI[] uris) throws java.lang.Exception
handlers
- the handlers to look for classes inuris
- the uris for the jarsjava.lang.Exception
- if unable to parsepublic void parse(java.util.Set<? extends AnnotationParser.Handler> handlers, java.net.URI uri) throws java.lang.Exception
handlers
- the handlers to look for classes inuri
- the uri for the jarjava.lang.Exception
- if unable to parsepublic void parse(java.util.Set<? extends AnnotationParser.Handler> handlers, Resource r) throws java.lang.Exception
handlers
- the handlers to look for classes inr
- the resource to parsejava.lang.Exception
- if unable to parseprotected void parseJar(java.util.Set<? extends AnnotationParser.Handler> handlers, Resource jarResource) throws java.lang.Exception
handlers
- the handlers to look for classes injarResource
- the jar resource to parsejava.lang.Exception
- if unable to parseprotected void parseJarEntry(java.util.Set<? extends AnnotationParser.Handler> handlers, Resource jar, java.util.jar.JarEntry entry) throws java.lang.Exception
handlers
- the handlers to look for classes injar
- the jar resource to parseentry
- the entry in the jar resource to parsejava.lang.Exception
- if unable to parseprotected void scanClass(java.util.Set<? extends AnnotationParser.Handler> handlers, Resource containingResource, java.io.InputStream is) throws java.io.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 parsejava.io.IOException
- if unable to parseCopyright © 1995–2017 Webtide. All rights reserved.