Class AnnotationProvider.Builder

java.lang.Object
org.apache.juneau.commons.reflect.AnnotationProvider.Builder
Enclosing class:
AnnotationProvider

public static class AnnotationProvider.Builder extends Object
Builder for creating configured AnnotationProvider instances.
Example:

AnnotationProvider provider = AnnotationProvider .create() .disableCaching() .build();

See Also:
  • Method Details

    • addRuntimeAnnotations

      Adds runtime annotations to be applied to classes, methods, fields, and constructors.

      This is a convenience method that delegates to addRuntimeAnnotations(List). See that method for detailed documentation on how runtime annotations work.

      // Example: Add multiple runtime annotations using varargs Bean beanAnnotation = BeanAnnotation .create() .onClass(MyClass.class) .typeName("MyType") .build(); Swap swapAnnotation = SwapAnnotation .create() .on("com.example.MyClass.getValue") .value(MySwap.class) .build(); AnnotationProvider provider = AnnotationProvider .create() .addRuntimeAnnotations(beanAnnotation, swapAnnotation) // Varargs .build();

      Parameters:
      annotations - The runtime annotation objects to add (varargs).
      Returns:
      This object for method chaining.
      Throws:
      BeanRuntimeException - If any annotation is invalid.
      See Also:
    • addRuntimeAnnotations

      Adds runtime annotations to be applied to classes, methods, fields, and constructors.

      Runtime annotations are concrete Java objects that implement annotation interfaces (e.g., @Bean). They allow you to dynamically apply annotations to code elements at runtime without modifying source code.

      How It Works:

      1. Create annotation objects using builder classes (e.g., BeanAnnotation.create())
      2. Specify targets using on() or onClass() methods
      3. Set annotation properties (e.g., typeName(), properties())
      4. Build the annotation object
      5. Add to the provider via this method

      Targeting Requirements:

      • Annotations MUST define an onClass() method returning Class[] for type-safe targeting
      • OR an on() method returning String[] for string-based targeting
      • The on() method accepts fully-qualified names:
        • "com.example.MyClass" - targets a class
        • "com.example.MyClass.myMethod" - targets a method
        • "com.example.MyClass.myField" - targets a field

      // Example 1: Target a specific class using type-safe targeting Bean beanAnnotation = BeanAnnotation .create() .onClass(MyClass.class) // Targets MyClass .typeName("MyType") .properties("id,name") .build(); // Example 2: Target multiple classes Bean multiAnnotation = BeanAnnotation .create() .onClass(MyClass.class, OtherClass.class) .sort(true) .build(); // Example 3: Target using string names (useful for dynamic/reflection scenarios) Bean stringAnnotation = BeanAnnotation .create() .on("com.example.MyClass") .findFluentSetters(true) .build(); // Example 4: Target a specific method Swap swapAnnotation = SwapAnnotation .create() .on("com.example.MyClass.getValue") .value(MySwap.class) .build(); // Add all runtime annotations to the provider AnnotationProvider provider = AnnotationProvider .create() .addRuntimeAnnotations(beanAnnotation, multiAnnotation, stringAnnotation, swapAnnotation) .build();

      Priority: Runtime annotations always take precedence over declared annotations at the same level. They are evaluated first when searching for annotations.

      Parameters:
      annotations - The list of runtime annotation objects to add.
      Returns:
      This object for method chaining.
      Throws:
      BeanRuntimeException - If any annotation is invalid (missing on() or onClass() methods, or if the methods return incorrect types).
    • build

      Builds a new AnnotationProvider instance with the configured settings.
      Returns:
      A new immutable AnnotationProvider instance.
    • cacheMode

      Sets the caching mode for annotation lookups.

      Available modes:

      • NONE - Disables all caching (always recompute)
      • WEAK - Uses WeakHashMap (allows GC of cached entries)
      • FULL - Uses ConcurrentHashMap (best performance)
      Parameters:
      value - The caching mode.
      Returns:
      This object for method chaining.
    • logOnExit

      Enables logging of cache statistics on JVM shutdown.
      Returns:
      This object for method chaining.
    • logOnExit

      public AnnotationProvider.Builder logOnExit(boolean value)
      Conditionally enables logging of cache statistics on JVM shutdown.
      Parameters:
      value - Whether to log on exit.
      Returns:
      This object for method chaining.