Package org.eclipse.jetty.annotations
Class AnnotationParser
java.lang.Object
org.eclipse.jetty.annotations.AnnotationParser
- Direct Known Subclasses:
AnnotationParser
AnnotationParser
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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Convenience base class to provide no-ops for all Handler methods.static class
Immutable information gathered by parsing class header.static class
Immutable information gathered by parsing a field on a class.static interface
Signature for all handlers that respond to parsing class files.static class
Immutable information gathered by parsing a method on a class.static class
ASM visitor for a class.static class
An ASM visitor for parsing Fields.static class
ASM Visitor for parsing a method. -
Field Summary
Modifier and TypeFieldDescriptionMap of classnames scanned and the first location from which scan occurred -
Constructor Summary
ConstructorDescriptionAnnotationParser
(int javaPlatform) AnnotationParser
(int javaPlatform, int asmVersion) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addParsedClass
(String classname, Resource location) Add a class as having been parsed.boolean
isValidClassFileName
(String name) Check that the given path represents a valid class file name.boolean
isValidClassFilePath
(String path) Check that the given path does not contain hidden directoriesstatic String
Convert internal name to simple namestatic String[]
Convert internal names to simple names.void
parse
(Set<? extends AnnotationParser.Handler> handlers, Class<?> clazz, boolean visitSuperClasses) Parse the given class, optionally walking its inheritance hierarchyvoid
parse
(Set<? extends AnnotationParser.Handler> handlers, String className) Parse a given classvoid
parse
(Set<? extends AnnotationParser.Handler> handlers, String[] classNames) Parse the given classesvoid
parse
(Set<? extends AnnotationParser.Handler> handlers, URI uri) Parse a particular urivoid
parse
(Set<? extends AnnotationParser.Handler> handlers, URI[] uris) Parse classes in the supplied uris.void
parse
(Set<? extends AnnotationParser.Handler> handlers, List<String> classNames) Parse the given classesvoid
parse
(Set<? extends AnnotationParser.Handler> handlers, Resource r) Parse a resourceprotected void
parseDir
(Set<? extends AnnotationParser.Handler> handlers, Resource root) Parse all classes in a directoryprotected void
parseJar
(Set<? extends AnnotationParser.Handler> handlers, Resource jarResource) Parse a resource that is a jar file.protected void
parseJarEntry
(Set<? extends AnnotationParser.Handler> handlers, Resource jar, MultiReleaseJarFile.VersionedJarEntry entry) Parse a single entry in a jar filevoid
Remove any parsed class names.protected void
scanClass
(Set<? extends AnnotationParser.Handler> handlers, Resource containingResource, InputStream is) Use ASM on a class
-
Field Details
-
_parsedClassNames
Map of classnames scanned and the first location from which scan occurred
-
-
Constructor Details
-
AnnotationParser
public AnnotationParser() -
AnnotationParser
public AnnotationParser(int javaPlatform) - Parameters:
javaPlatform
- The target java version or 0 for the current runtime.
-
AnnotationParser
public AnnotationParser(int javaPlatform, int asmVersion)
-
-
Method Details
-
normalize
Convert internal name to simple name- Parameters:
name
- the internal name- Returns:
- the simple name
-
normalize
Convert internal names to simple names.- Parameters:
list
- the list of internal names- Returns:
- the list of simple names
-
addParsedClass
Add a class as having been parsed.- Parameters:
classname
- the name of the classlocation
- the fully qualified location of the class
-
parse
public void parse(Set<? extends AnnotationParser.Handler> handlers, String className) throws Exception Parse a given class- Parameters:
handlers
- the set of handlers to find classclassName
- the class name to parse- Throws:
Exception
- if unable to parse
-
parse
public void parse(Set<? extends AnnotationParser.Handler> handlers, Class<?> clazz, 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 forvisitSuperClasses
- 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) throws Exception Parse the given classes- Parameters:
handlers
- the set of handlers to look for class inclassNames
- the class name- Throws:
Exception
- if unable to parse
-
parse
public void parse(Set<? extends AnnotationParser.Handler> handlers, List<String> classNames) throws Exception Parse the given classes- Parameters:
handlers
- the set of handlers to look for class inclassNames
- the class names- Throws:
Exception
- if unable to parse
-
parse
Parse classes in the supplied uris.- Parameters:
handlers
- the handlers to look for classes inuris
- the uris for the jars- Throws:
Exception
- if unable to parse
-
parse
Parse a particular uri- Parameters:
handlers
- the handlers to look for classes inuri
- the uri for the jar- Throws:
Exception
- if unable to parse
-
parse
Parse a resource- Parameters:
handlers
- the handlers to look for classes inr
- the resource to parse- Throws:
Exception
- if unable to parse
-
parseDir
protected void parseDir(Set<? extends AnnotationParser.Handler> handlers, Resource root) 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 classes- Throws:
Exception
- if unable to parse
-
parseJar
protected void parseJar(Set<? extends AnnotationParser.Handler> handlers, Resource jarResource) throws Exception Parse a resource that is a jar file.- Parameters:
handlers
- the handlers to look for classes injarResource
- the jar resource to parse- Throws:
Exception
- if unable to parse
-
parseJarEntry
protected void parseJarEntry(Set<? extends AnnotationParser.Handler> handlers, Resource jar, MultiReleaseJarFile.VersionedJarEntry entry) throws 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:
Exception
- if unable to parse
-
scanClass
protected void scanClass(Set<? extends AnnotationParser.Handler> handlers, 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. -
isValidClassFileName
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
Check that the given path does not contain hidden directories- Parameters:
path
- the class file path- Returns:
- whether the class file path is valid
-