Enum Class AnnotationTraversal

java.lang.Object
java.lang.Enum<AnnotationTraversal>
org.apache.juneau.commons.reflect.AnnotationTraversal
All Implemented Interfaces:
Serializable, Comparable<AnnotationTraversal>, Constable

Defines traversal options for annotation searches.

These enums configure what elements to traverse and in what order when searching for annotations. They are used with AnnotationProvider.find(Class, ClassInfo, AnnotationTraversal...) and related methods.

Each traversal type has an order of precedence that determines the search order. When multiple traversal types are specified, they are automatically sorted by their precedence to ensure consistent behavior regardless of the order they are specified.

Example:

// These produce the same result (automatically sorted by precedence): Stream<AnnotationInfo<MyAnnotation>> s1 = annotationProvider.streamClassAnnotations(MyAnnotation.class, ci, PACKAGE, PARENTS, SELF); Stream<AnnotationInfo<MyAnnotation>> s2 = annotationProvider.streamClassAnnotations(MyAnnotation.class, ci, SELF, PARENTS, PACKAGE);

See Also:
  • Enum Constant Details

    • SELF

      public static final AnnotationTraversal SELF
      Include the element itself (class, method, field, constructor, parameter).

      This searches for annotations directly declared on the target element.

      Applicable to:
      All element types (classes, methods, fields, constructors, parameters).
      Order:
      Precedence: 10 (highest - searched first)
    • PARENTS

      public static final AnnotationTraversal PARENTS
      Include parent classes and interfaces in the traversal.

      For classes: Traverses the superclass hierarchy and all implemented interfaces, interleaved in child-to-parent order (using ClassInfo.getParentsAndInterfaces()). Default order is child-to-parent unless REVERSE is specified.

      Applicable to:
      Classes.
      Example:

      // Given: class Child extends Parent implements Interface // Traverses parents and interfaces interleaved: Parent → Interface → GrandParent → ...

      Order:
      Precedence: 20
    • MATCHING_METHODS

      Include matching methods in the traversal.

      For methods: Searches annotations on methods with the same signature in parent classes and interfaces. This finds annotations on overridden methods.

      Applicable to:
      Methods.
      Example:

      // Given: class Parent { @MyAnnotation public void method() {} } class Child extends Parent { @Override public void method() {} // Will find @MyAnnotation from Parent }

      Order:
      Precedence: 20
    • MATCHING_PARAMETERS

      Include matching parameters in the traversal.

      For parameters: Searches annotations on parameters in matching parent methods or constructors. This finds annotations on parameters in overridden methods or parent constructors.

      Applicable to:
      Parameters.
      Example:

      // Given: class Parent { public void method(@MyAnnotation String param) {} } class Child extends Parent { @Override public void method(String param) {} // Will find @MyAnnotation from Parent }

      Order:
      Precedence: 20
    • RETURN_TYPE

      public static final AnnotationTraversal RETURN_TYPE
      Include the return type in the traversal.

      For methods: Searches annotations on the method's return type and its hierarchy. Automatically includes PARENTS of the return type.

      Applicable to:
      Methods.
      Example:

      // Given: public MyClass myMethod() {...} // Searches: MyClass hierarchy and its interfaces

      Order:
      Precedence: 30
    • DECLARING_CLASS

      public static final AnnotationTraversal DECLARING_CLASS
      Include the declaring class hierarchy in the traversal.

      For methods, fields, and constructors: Searches annotations on the declaring class and its parent hierarchy. Automatically includes the declaring class and all its parents and interfaces.

      Applicable to:
      Methods, fields, and constructors.
      Example:

      // Given: class Child extends Parent { void method() {...} } // Searches: Child hierarchy (Child, Parent, interfaces, etc.)

      Order:
      Precedence: 35
    • PARAMETER_TYPE

      public static final AnnotationTraversal PARAMETER_TYPE
      Include the parameter type in the traversal.

      For parameters: Searches annotations on the parameter's type and its hierarchy. Automatically includes PARENTS and PACKAGE of the parameter type.

      Applicable to:
      Parameters.
      Example:

      // Given: void method(MyClass param) {...} // Searches: MyClass hierarchy, its interfaces, and package

      Order:
      Precedence: 30
    • PACKAGE

      public static final AnnotationTraversal PACKAGE
      Include package annotations in the traversal.

      Searches for annotations on the package-info class.

      Applicable to:
      Classes and parameters (via PARAMETER_TYPE).
      Example:

      // Searches annotations in package-info.java

      Order:
      Precedence: 40 (lowest - searched last)
    • REVERSE

      public static final AnnotationTraversal REVERSE
      Reverse the order of the resulting stream.

      When this flag is present, the final stream is wrapped in rstream() to reverse the order. This allows parent-first ordering (parent annotations before child annotations).

      By default, traversals return results in child-to-parent order (child annotations first). Using REVERSE changes this to parent-to-child order (parent annotations first).

      Applicable to:
      All stream-based traversal methods.
      Example:

      // Default (child-first): Child → Parent → GrandParent Stream<AnnotationInfo<MyAnnotation>> s1 = streamClassAnnotations(MyAnnotation.class, ci, PARENTS); // With REVERSE (parent-first): GrandParent → Parent → Child Stream<AnnotationInfo<MyAnnotation>> s2 = streamClassAnnotations(MyAnnotation.class, ci, PARENTS, REVERSE);

      Order:
      Precedence: 999 (modifier - does not affect traversal order)
  • Method Details

    • values

      public static AnnotationTraversal[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static AnnotationTraversal valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • getOrder

      public int getOrder()
      Returns the precedence order of this traversal type.

      Lower values have higher precedence and are processed first.

      Returns:
      The order value.