Package org.eclipse.jetty.annotations
Class AnnotationParser
- java.lang.Object
-
- org.eclipse.jetty.annotations.AnnotationParser
-
- Direct Known Subclasses:
AnnotationParser
public class AnnotationParser extends java.lang.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 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.
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<java.lang.String,Resource>
_parsedClassNames
Map of classnames scanned and the first location from which scan occurred
-
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 void
addParsedClass(java.lang.String classname, Resource location)
Add a class as having been parsed.java.util.List<java.lang.String>
getParsedLocations(java.lang.String classname)
Deprecated.List of duplicate locations no longer storedboolean
isValidClassFileName(java.lang.String name)
Check that the given path represents a valid class file name.boolean
isValidClassFilePath(java.lang.String path)
Check that the given path does not contain hidden directoriesstatic java.lang.String
normalize(java.lang.String name)
Convert internal name to simple namestatic 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 hierarchyvoid
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 classvoid
parse(java.util.Set<? extends AnnotationParser.Handler> handlers, java.lang.String[] classNames)
Parse the given classesvoid
parse(java.util.Set<? extends AnnotationParser.Handler> handlers, java.net.URI uri)
Parse a particular urivoid
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 classesvoid
parse(java.util.Set<? extends AnnotationParser.Handler> handlers, Resource r)
Parse a resourceprotected void
parseDir(java.util.Set<? extends AnnotationParser.Handler> handlers, Resource root)
Parse all classes in a directoryprotected 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 filevoid
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
-
-
-
Field Detail
-
_parsedClassNames
protected java.util.Map<java.lang.String,Resource> _parsedClassNames
Map of classnames scanned and the first location from which scan occurred
-
-
Method Detail
-
normalize
public static java.lang.String normalize(java.lang.String name)
Convert internal name to simple name- Parameters:
name
- the internal name- Returns:
- the simple name
-
normalize
public static java.lang.String[] normalize(java.lang.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(java.lang.String classname, Resource location)
Add a class as having been parsed.- Parameters:
classname
- the name of the classlocation
- the fully qualified location of the class
-
getParsedLocations
@Deprecated public java.util.List<java.lang.String> getParsedLocations(java.lang.String classname)
Deprecated.List of duplicate locations no longer storedGet 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(java.util.Set<? extends AnnotationParser.Handler> handlers, java.lang.String className) throws java.lang.Exception
Parse a given class- Parameters:
handlers
- the set of handlers to find classclassName
- the class name to parse- Throws:
java.lang.Exception
- if unable to parse
-
parse
public void parse(java.util.Set<? extends AnnotationParser.Handler> handlers, java.lang.Class<?> clazz, boolean visitSuperClasses) throws java.lang.Exception
Parse the given class, optionally walking its inheritance hierarchy- Parameters:
handlers
- the handlers to look for class inclazz
- the class to look forvisitSuperClasses
- if true, also visit super classes for parse- Throws:
java.lang.Exception
- if unable to parse class
-
parse
public void parse(java.util.Set<? extends AnnotationParser.Handler> handlers, java.lang.String[] classNames) throws java.lang.Exception
Parse the given classes- Parameters:
handlers
- the set of handlers to look for class inclassNames
- the class name- Throws:
java.lang.Exception
- if unable to parse
-
parse
public void parse(java.util.Set<? extends AnnotationParser.Handler> handlers, java.util.List<java.lang.String> classNames) throws java.lang.Exception
Parse the given classes- Parameters:
handlers
- the set of handlers to look for class inclassNames
- the class names- Throws:
java.lang.Exception
- if unable to parse
-
parseDir
protected void parseDir(java.util.Set<? extends AnnotationParser.Handler> handlers, Resource root) throws java.lang.Exception
Parse all classes in a directory- Parameters:
handlers
- the set of handlers to look for classes inroot
- the resource directory to look for classes- Throws:
java.lang.Exception
- if unable to parse
-
parse
@Deprecated public void parse(java.util.Set<? extends AnnotationParser.Handler> handlers, java.lang.ClassLoader loader, boolean visitParents, boolean nullInclusive) throws java.lang.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:
java.lang.Exception
- if unable to parse
-
parse
public void parse(java.util.Set<? extends AnnotationParser.Handler> handlers, java.net.URI[] uris) throws java.lang.Exception
Parse classes in the supplied uris.- Parameters:
handlers
- the handlers to look for classes inuris
- the uris for the jars- Throws:
java.lang.Exception
- if unable to parse
-
parse
public void parse(java.util.Set<? extends AnnotationParser.Handler> handlers, java.net.URI uri) throws java.lang.Exception
Parse a particular uri- Parameters:
handlers
- the handlers to look for classes inuri
- the uri for the jar- Throws:
java.lang.Exception
- if unable to parse
-
parse
public void parse(java.util.Set<? extends AnnotationParser.Handler> handlers, Resource r) throws java.lang.Exception
Parse a resource- Parameters:
handlers
- the handlers to look for classes inr
- the resource to parse- Throws:
java.lang.Exception
- if unable to parse
-
parseJar
protected void parseJar(java.util.Set<? extends AnnotationParser.Handler> handlers, Resource jarResource) throws java.lang.Exception
Parse a resource that is a jar file.- Parameters:
handlers
- the handlers to look for classes injarResource
- the jar resource to parse- Throws:
java.lang.Exception
- if unable to parse
-
parseJarEntry
protected void parseJarEntry(java.util.Set<? extends AnnotationParser.Handler> handlers, Resource jar, MultiReleaseJarFile.VersionedJarEntry entry) throws java.lang.Exception
Parse a single entry in a jar file- Parameters:
handlers
- the handlers to look for classes inentry
- the entry in the potentially MultiRelease jar resource to parsejar
- the jar file- Throws:
java.lang.Exception
- if unable to parse
-
scanClass
protected void scanClass(java.util.Set<? extends AnnotationParser.Handler> handlers, Resource containingResource, java.io.InputStream is) throws java.io.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:
java.io.IOException
- if unable to parse
-
resetParsedClasses
public void resetParsedClasses()
Remove any parsed class names.
-
isValidClassFileName
public boolean isValidClassFileName(java.lang.String name)
Check that the given path represents a valid class file name. The check is fairly cursory, checking that:- the name ends with .class
- it isn't a dot file or in a hidden directory
- the name of the class at least begins with a valid identifier for a class name
- Parameters:
name
- the class file name- Returns:
- whether the class file name is valid
-
isValidClassFilePath
public boolean isValidClassFilePath(java.lang.String path)
Check that the given path does not contain hidden directories- Parameters:
path
- the class file path- Returns:
- whether the class file path is valid
-
-