Class AnnotationParser

java.lang.Object
org.eclipse.jetty.ee10.annotations.AnnotationParser
Direct Known Subclasses:
AnnotationParser

public class AnnotationParser extends Object
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.

  • Field Details

    • _parsedClassNames

      protected Map<String,URI> _parsedClassNames
      Map of classnames scanned and the first location from which scan occurred
  • Constructor Details

    • AnnotationParser

      public AnnotationParser()
    • AnnotationParser

      public AnnotationParser(int asmVersion)
      Parameters:
      asmVersion - The target asm version or 0 for the internal version.
  • Method Details

    • 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 array of simple names
    • parse

      public void parse(Set<? extends AnnotationParser.Handler> handlers, Resource r) throws Exception
      Parse a resource
      Parameters:
      handlers - the handlers to look for classes in
      r - the resource to parse
      Throws:
      Exception - if unable to parse
    • parseDir

      protected void parseDir(Set<? extends AnnotationParser.Handler> handlers, Resource dirResource) throws Exception
      Parse all classes in a directory
      Parameters:
      handlers - the set of handlers to look for classes in
      dirResource - the resource representing the baseResource being scanned (jar, dir, etc)
      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 in
      jarResource - the jar resource to parse
      Throws:
      Exception - if unable to parse
    • parseClass

      protected void parseClass(Set<? extends AnnotationParser.Handler> handlers, Resource containingResource, Path classFile) throws IOException
      Use ASM on a class
      Parameters:
      handlers - the handlers to look for classes in
      containingResource - the dir or jar that the class is contained within, can be null if not known
      classFile - the class file to parse
      Throws:
      IOException - if unable to parse