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 | Description |
---|---|---|
static class |
AnnotationParser.AbstractHandler |
Convenience base class to provide no-ops for all Handler methods.
|
class |
AnnotationParser.ClassInfo |
Immutable information gathered by parsing class header.
|
class |
AnnotationParser.FieldInfo |
Immutable information gathered by parsing a field on a class.
|
static interface |
AnnotationParser.Handler |
Signature for all handlers that respond to parsing class files.
|
class |
AnnotationParser.MethodInfo |
Immutable information gathered by parsing a method on a class.
|
class |
AnnotationParser.MyClassVisitor |
ASM visitor for a class.
|
class |
AnnotationParser.MyFieldVisitor |
An ASM visitor for parsing Fields.
|
class |
AnnotationParser.MyMethodVisitor |
ASM Visitor for parsing a method.
|
Modifier and Type | Field | Description |
---|---|---|
protected java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
_parsedClassNames |
|
protected static int |
ASM_OPCODE_VERSION |
Constructor | Description |
---|---|
AnnotationParser() |
|
AnnotationParser(int javaPlatform) |
|
AnnotationParser(int javaPlatform,
int asmVersion) |
Modifier and Type | Method | Description |
---|---|---|
void |
addParsedClass(java.lang.String classname,
Resource location) |
Add a class as having been parsed.
|
static int |
asmVersion() |
Determine the runtime version of asm.
|
java.util.List<java.lang.String> |
getParsedLocations(java.lang.String classname) |
Get the locations of the given classname.
|
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) |
Deprecated.
|
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.
|
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
|
protected void |
parseDir(java.util.Set<? extends AnnotationParser.Handler> handlers,
Resource root) |
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,
MultiReleaseJarFile.VersionedJarEntry entry) |
Parse a single entry in a jar file
|
void |
resetParsedClasses() |
Remove any parsed class names.
|
protected void |
scanClass(java.util.Set<? extends AnnotationParser.Handler> handlers,
Resource containingResource,
java.io.InputStream is) |
Use ASM on a class
|
protected static int ASM_OPCODE_VERSION
protected java.util.Map<java.lang.String,java.util.List<java.lang.String>> _parsedClassNames
public AnnotationParser()
public AnnotationParser(int javaPlatform)
javaPlatform
- The target java version or 0 for the current runtime.public AnnotationParser(int javaPlatform, int asmVersion)
public static int asmVersion()
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 void addParsedClass(java.lang.String classname, Resource location)
classname
- the name of the classlocation
- the fully qualified location of the classpublic java.util.List<java.lang.String> getParsedLocations(java.lang.String classname)
classname
- the name of the classpublic 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 root) throws java.lang.Exception
handlers
- the set of handlers to look for classes inroot
- the resource directory to look for classesjava.lang.Exception
- if unable to parse@Deprecated public 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, MultiReleaseJarFile.VersionedJarEntry entry) throws java.lang.Exception
handlers
- the handlers to look for classes inentry
- the entry in the potentially MultiRelease 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 parsepublic void resetParsedClasses()
Copyright © 1995–2017 Webtide. All rights reserved.