Enum Class AnnotationTraversal
- All Implemented Interfaces:
Serializable,Comparable<AnnotationTraversal>,Constable
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:
See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionInclude the declaring class hierarchy in the traversal.Include matching methods in the traversal.Include matching parameters in the traversal.Include package annotations in the traversal.Include the parameter type in the traversal.Include parent classes and interfaces in the traversal.Include the return type in the traversal.Reverse the order of the resulting stream.Include the element itself (class, method, field, constructor, parameter). -
Method Summary
Modifier and TypeMethodDescriptionintgetOrder()Returns the precedence order of this traversal type.static AnnotationTraversalReturns the enum constant of this class with the specified name.static AnnotationTraversal[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
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
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 unlessREVERSEis 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 Childextends 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 Stringparam ) {} }class Childextends Parent {@Override public void method(Stringparam ) {}// Will find @MyAnnotation from Parent }Order:
Precedence: 20 -
RETURN_TYPE
Include the return type in the traversal.For methods: Searches annotations on the method's return type and its hierarchy. Automatically includes
PARENTSof the return type.Applicable to:
Methods.Example:
// Given: public MyClass myMethod() {...} // Searches: MyClass hierarchy and its interfaces Order:
Precedence: 30 -
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
Include the parameter type in the traversal.For parameters: Searches annotations on the parameter's type and its hierarchy. Automatically includes
PARENTSandPACKAGEof the parameter type.Applicable to:
Parameters.Example:
// Given: void method(MyClass param) {...} // Searches: MyClass hierarchy, its interfaces, and package Order:
Precedence: 30 -
PACKAGE
Include package annotations in the traversal.Searches for annotations on the package-info class.
Applicable to:
Classes and parameters (viaPARAMETER_TYPE).Example:
// Searches annotations in package-info.java Order:
Precedence: 40 (lowest - searched last) -
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
REVERSEchanges 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
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
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 nameNullPointerException- if the argument is null
-
getOrder
Returns the precedence order of this traversal type.Lower values have higher precedence and are processed first.
- Returns:
- The order value.
-