Interface AnnotatableCreator

All Known Subinterfaces:
AbstractMethodCreator, AnonymousClassCreator, ClassCreator, ConstructorCreator, ExecutableCreator, FieldCreator, InstanceExecutableCreator, InstanceFieldCreator, InstanceMethodCreator, InterfaceCreator, MemberCreator, MethodCreator, ModifiableCreator, ParamCreator, StaticExecutableCreator, StaticFieldCreator, StaticMethodCreator, TypeCreator, TypeParameterCreator

public sealed interface AnnotatableCreator permits ModifiableCreator, TypeParameterCreator (not exhaustive)
An element that can be annotated.
  • Method Details

    • addAnnotation

      default <A extends Annotation> void addAnnotation(A annotation)
      Add the given annotation object to this creator.
      Type Parameters:
      A - the annotation type
      Parameters:
      annotation - the annotation object (must not be null)
    • addAnnotation

      default void addAnnotation(Class<? extends Annotation> annotationClass)
      Add an annotation with no elements. If annotationClass has no Retention annotation, RetentionPolicy.RUNTIME is assumed. This is the most commonly used value, even though CLASS is the specified default.

      If the annotation is repeatable, and adding this annotation would cause there to be more than one instance of the given annotation on this element, then the existing annotation and the given annotation are automatically wrapped in the container annotation.

      Parameters:
      annotationClass - the class of the annotation (must not be null)
      Throws:
      IllegalArgumentException - if the annotation is not repeatable and appears more than once on this element
    • addAnnotation

      <A extends Annotation> void addAnnotation(Class<A> annotationClass, Consumer<AnnotationCreator<A>> builder)
      Add an annotation with elements provided by given builder. If annotationClass has no Retention annotation, RetentionPolicy.RUNTIME is assumed. This is the most commonly used value, even though CLASS is the specified default.

      If the annotation is repeatable, and adding this annotation would cause there to be more than one instance of the given annotation on this element, then the existing annotation and the given annotation are automatically wrapped in the container annotation.

      Type Parameters:
      A - the annotation type
      Parameters:
      annotationClass - the class of the annotation (must not be null)
      builder - the builder which adds annotation values (must not be null)
      Throws:
      IllegalArgumentException - if the annotation is not repeatable and appears more than once on this element
    • addAnnotation

      void addAnnotation(ClassDesc annotationClass, RetentionPolicy retentionPolicy, Consumer<AnnotationCreator<Annotation>> builder)
      Add an annotation of given class with given retention policy and with elements provided by given builder.

      If the annotation is repeatable, then it is the responsibility of the caller to ensure that the repeated values are appropriately wrapped in the container annotation if necessary.

      Parameters:
      annotationClass - the class of the annotation (must not be null)
      retentionPolicy - the retention policy of the annotation (must not be null)
      builder - the builder which adds annotation values (must not be null)
      Throws:
      IllegalArgumentException - if the annotation appears more than once on this element