Package org.eclipse.jetty.annotations
Class AnnotationParser
- java.lang.Object
-
- org.eclipse.jetty.annotations.AnnotationParser
-
public class AnnotationParser extends Object
AnnotationParserUse 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAnnotationParser.AbstractHandlerConvenience base class to provide no-ops for all Handler methods.classAnnotationParser.ClassInfoImmutable information gathered by parsing class header.classAnnotationParser.FieldInfoImmutable information gathered by parsing a field on a class.static interfaceAnnotationParser.HandlerSignature for all handlers that respond to parsing class files.classAnnotationParser.MethodInfoImmutable information gathered by parsing a method on a class.classAnnotationParser.MyClassVisitorASM visitor for a class.classAnnotationParser.MyFieldVisitorAn ASM visitor for parsing Fields.classAnnotationParser.MyMethodVisitorASM Visitor for parsing a method.
-
Field Summary
Fields Modifier and Type Field Description protected Map<String,List<String>>_parsedClassNamesprotected static intASM_OPCODE_VERSION
-
Constructor Summary
Constructors Constructor Description AnnotationParser()AnnotationParser(int javaPlatform)AnnotationParser(int javaPlatform, int asmVersion)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddParsedClass(String classname, org.eclipse.jetty.util.resource.Resource location)Add a class as having been parsed.static intasmVersion()Determine the runtime version of asm.List<String>getParsedLocations(String classname)Get the locations of the given classname.booleanisParsed(String className)True if the class has already been processed, false otherwisestatic Stringnormalize(String name)Convert internal name to simple namestatic String[]normalize(String[] list)Convert internal names to simple names.voidparse(Set<? extends AnnotationParser.Handler> handlers, Class<?> clazz, ClassNameResolver resolver, boolean visitSuperClasses)Parse the given class, optionally walking its inheritance hierarchyvoidparse(Set<? extends AnnotationParser.Handler> handlers, ClassLoader loader, boolean visitParents, boolean nullInclusive)Deprecated.voidparse(Set<? extends AnnotationParser.Handler> handlers, String[] classNames, ClassNameResolver resolver)Parse the given classesvoidparse(Set<? extends AnnotationParser.Handler> handlers, String className, ClassNameResolver resolver)Parse a given classvoidparse(Set<? extends AnnotationParser.Handler> handlers, URI[] uris, ClassNameResolver resolver)Parse classes in the supplied uris.voidparse(Set<? extends AnnotationParser.Handler> handlers, URI uri, ClassNameResolver resolver)Parse a particular urivoidparse(Set<? extends AnnotationParser.Handler> handlers, List<String> classNames, ClassNameResolver resolver)Parse the given classesvoidparse(Set<? extends AnnotationParser.Handler> handlers, org.eclipse.jetty.util.resource.Resource r, ClassNameResolver resolver)Parse a resourceprotected voidparseDir(Set<? extends AnnotationParser.Handler> handlers, org.eclipse.jetty.util.resource.Resource root, ClassNameResolver resolver)Parse all classes in a directoryprotected voidparseJar(Set<? extends AnnotationParser.Handler> handlers, org.eclipse.jetty.util.resource.Resource jarResource, ClassNameResolver resolver)Parse a resource that is a jar file.protected voidparseJarEntry(Set<? extends AnnotationParser.Handler> handlers, org.eclipse.jetty.util.resource.Resource jar, org.eclipse.jetty.util.MultiReleaseJarFile.VersionedJarEntry entry, ClassNameResolver resolver)Parse a single entry in a jar filevoidresetParsedClasses()Remove any parsed class names.protected voidscanClass(Set<? extends AnnotationParser.Handler> handlers, org.eclipse.jetty.util.resource.Resource containingResource, InputStream is)Use ASM on a class
-
-
-
Method Detail
-
asmVersion
public static int asmVersion()
Determine the runtime version of asm.- Returns:
- the org.objectweb.asm.Opcode matching the runtime version of asm.
-
normalize
public static String normalize(String name)
Convert internal name to simple name- Parameters:
name- the internal name- Returns:
- the simple name
-
normalize
public static String[] normalize(String[] list)
Convert internal names to simple names.- Parameters:
list- the list of internal names- Returns:
- the list of simple names
-
addParsedClass
public void addParsedClass(String classname, org.eclipse.jetty.util.resource.Resource location)
Add a class as having been parsed.- Parameters:
classname- the name of the classlocation- the fully qualified location of the class
-
isParsed
public boolean isParsed(String className)
True if the class has already been processed, false otherwise- Parameters:
className- the classname- Returns:
- true if class was parsed, false if not
-
getParsedLocations
public List<String> getParsedLocations(String classname)
Get the locations of the given classname. There may be more than one location if there are duplicates of the same class.- Parameters:
classname- the name of the class- Returns:
- an immutable list of locations
-
parse
public void parse(Set<? extends AnnotationParser.Handler> handlers, String className, ClassNameResolver resolver) throws Exception
Parse a given class- Parameters:
handlers- the set of handlers to find classclassName- the class name to parseresolver- the class name resolver to use- Throws:
Exception- if unable to parse
-
parse
public void parse(Set<? extends AnnotationParser.Handler> handlers, Class<?> clazz, ClassNameResolver resolver, boolean visitSuperClasses) throws Exception
Parse the given class, optionally walking its inheritance hierarchy- Parameters:
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 parse- Throws:
Exception- if unable to parse class
-
parse
public void parse(Set<? extends AnnotationParser.Handler> handlers, String[] classNames, ClassNameResolver resolver) throws Exception
Parse the given classes- Parameters:
handlers- the set of handlers to look for class inclassNames- the class nameresolver- the class name resolver- Throws:
Exception- if unable to parse
-
parse
public void parse(Set<? extends AnnotationParser.Handler> handlers, List<String> classNames, ClassNameResolver resolver) throws Exception
Parse the given classes- Parameters:
handlers- the set of handlers to look for class inclassNames- the class namesresolver- the class name resolver- Throws:
Exception- if unable to parse
-
parseDir
protected void parseDir(Set<? extends AnnotationParser.Handler> handlers, org.eclipse.jetty.util.resource.Resource root, ClassNameResolver resolver) throws Exception
Parse all classes in a directory- Parameters:
handlers- the set of handlers to look for classes inroot- the resource directory to look for classesresolver- the class name resolver- Throws:
Exception- if unable to parse
-
parse
@Deprecated public void parse(Set<? extends AnnotationParser.Handler> handlers, ClassLoader loader, boolean visitParents, boolean nullInclusive) throws Exception
Deprecated.Parse classes in the supplied classloader. Only class files in jar files will be scanned.- Parameters:
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 match- Throws:
Exception- if unable to parse
-
parse
public void parse(Set<? extends AnnotationParser.Handler> handlers, URI[] uris, ClassNameResolver resolver) throws Exception
Parse classes in the supplied uris.- Parameters:
handlers- the handlers to look for classes inuris- the uris for the jarsresolver- the class name resolver- Throws:
Exception- if unable to parse
-
parse
public void parse(Set<? extends AnnotationParser.Handler> handlers, URI uri, ClassNameResolver resolver) throws Exception
Parse a particular uri- Parameters:
handlers- the handlers to look for classes inuri- the uri for the jarresolver- the class name resolver- Throws:
Exception- if unable to parse
-
parse
public void parse(Set<? extends AnnotationParser.Handler> handlers, org.eclipse.jetty.util.resource.Resource r, ClassNameResolver resolver) throws Exception
Parse a resource- Parameters:
handlers- the handlers to look for classes inr- the resource to parseresolver- the class name resolver- Throws:
Exception- if unable to parse
-
parseJar
protected void parseJar(Set<? extends AnnotationParser.Handler> handlers, org.eclipse.jetty.util.resource.Resource jarResource, ClassNameResolver resolver) throws Exception
Parse a resource that is a jar file.- Parameters:
handlers- the handlers to look for classes injarResource- the jar resource to parseresolver- the class name resolver- Throws:
Exception- if unable to parse
-
parseJarEntry
protected void parseJarEntry(Set<? extends AnnotationParser.Handler> handlers, org.eclipse.jetty.util.resource.Resource jar, org.eclipse.jetty.util.MultiReleaseJarFile.VersionedJarEntry entry, ClassNameResolver resolver) throws Exception
Parse a single entry in a jar file- Parameters:
handlers- the handlers to look for classes injar- The jar from which entry was obtainedentry- the entry in the potentially MultiRelease jar resource to parseresolver- the class name resolver- Throws:
Exception- if unable to parse
-
scanClass
protected void scanClass(Set<? extends AnnotationParser.Handler> handlers, org.eclipse.jetty.util.resource.Resource containingResource, InputStream is) throws IOException
Use ASM on a class- Parameters:
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 parse- Throws:
IOException- if unable to parse
-
resetParsedClasses
public void resetParsedClasses()
Remove any parsed class names.
-
-