Module jakarta.cdi

Interface AnnotationBuilder


  • public interface AnnotationBuilder
    Builder for annotations of given type. Expected usage is:
    1. create the builder using of(Class) or of(ClassInfo);
    2. use the value() and member() methods to define annotation members;
    3. call build() to create an AnnotationInfo.
    One builder instance should not be used to create multiple annotations.

    Note that values of all members of given annotation type must be defined before calling build(), except of annotation members that declare a default value. If a value is not defined for an annotation member that does not have a default value, build() will throw an exception.

    Defining values of members that do not exist on given annotation type is possible, and such members will be retained in the resulting AnnotationInfo. However, if that AnnotationInfo is later transformed to an instance of the annotation type, the non-existing members will disappear.

    Since:
    4.0
    • Method Detail

      • of

        static AnnotationBuilder of​(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
        Returns a new AnnotationBuilder that builds an annotation of given type.
        Parameters:
        annotationType - the annotation type, must not be null
        Returns:
        a new AnnotationBuilder, never null
      • of

        static AnnotationBuilder of​(ClassInfo annotationType)
        Returns a new AnnotationBuilder that builds an annotation of given type.
        Parameters:
        annotationType - the annotation type, must not be null
        Returns:
        a new AnnotationBuilder
      • value

        default AnnotationBuilder value​(AnnotationMember value)
        Adds an annotation member called value, whose value is given value.
        Parameters:
        value - value of the annotation member
        Returns:
        this AnnotationBuilder
      • value

        default AnnotationBuilder value​(boolean value)
        Adds a boolean-valued annotation member called value.
        Parameters:
        value - the boolean value
        Returns:
        this AnnotationBuilder
      • value

        default AnnotationBuilder value​(boolean[] values)
        Adds a boolean array-valued annotation member called value.
        Parameters:
        values - the boolean array, must not be null
        Returns:
        this AnnotationBuilder
      • value

        default AnnotationBuilder value​(byte value)
        Adds a byte-valued annotation member called value.
        Parameters:
        value - the byte value
        Returns:
        this AnnotationBuilder
      • value

        default AnnotationBuilder value​(byte[] values)
        Adds a byte array-valued annotation member called value.
        Parameters:
        values - the byte array, must not be null
        Returns:
        this AnnotationBuilder
      • value

        default AnnotationBuilder value​(short value)
        Adds a short-valued annotation member called value.
        Parameters:
        value - the short value
        Returns:
        this AnnotationBuilder
      • value

        default AnnotationBuilder value​(short[] values)
        Adds a short array-valued annotation member called value.
        Parameters:
        values - the short array, must not be null
        Returns:
        this AnnotationBuilder
      • value

        default AnnotationBuilder value​(int value)
        Adds an int-valued annotation member called value.
        Parameters:
        value - the int value
        Returns:
        this AnnotationBuilder
      • value

        default AnnotationBuilder value​(int[] values)
        Adds an int array-valued annotation member called value.
        Parameters:
        values - the int array, must not be null
        Returns:
        this AnnotationBuilder
      • value

        default AnnotationBuilder value​(long value)
        Adds a long-valued annotation member called value.
        Parameters:
        value - the long value
        Returns:
        this AnnotationBuilder
      • value

        default AnnotationBuilder value​(long[] values)
        Adds a long array-valued annotation member called value.
        Parameters:
        values - the long array, must not be null
        Returns:
        this AnnotationBuilder
      • value

        default AnnotationBuilder value​(float value)
        Adds a float-valued annotation member called value.
        Parameters:
        value - the float value
        Returns:
        this AnnotationBuilder
      • value

        default AnnotationBuilder value​(float[] values)
        Adds a float array-valued annotation member called value.
        Parameters:
        values - the float array, must not be null
        Returns:
        this AnnotationBuilder
      • value

        default AnnotationBuilder value​(double value)
        Adds a double-valued annotation member called value.
        Parameters:
        value - the double value
        Returns:
        this AnnotationBuilder
      • value

        default AnnotationBuilder value​(double[] values)
        Adds a double array-valued annotation member called value.
        Parameters:
        values - the double array, must not be null
        Returns:
        this AnnotationBuilder
      • value

        default AnnotationBuilder value​(char value)
        Adds a char-valued annotation member called value.
        Parameters:
        value - the char value
        Returns:
        this AnnotationBuilder
      • value

        default AnnotationBuilder value​(char[] values)
        Adds a char array-valued annotation member called value.
        Parameters:
        values - the char array, must not be null
        Returns:
        this AnnotationBuilder
      • value

        default AnnotationBuilder value​(java.lang.String value)
        Adds a String-valued annotation member called value.
        Parameters:
        value - the String value, must not be null
        Returns:
        this AnnotationBuilder
      • value

        default AnnotationBuilder value​(java.lang.String[] values)
        Adds a String array-valued annotation member called value.
        Parameters:
        values - the String array, must not be null or contain null
        Returns:
        this AnnotationBuilder
      • value

        default AnnotationBuilder value​(java.lang.Enum<?> value)
        Adds an enum-valued annotation member called value.
        Parameters:
        value - the enum value, must not be null
        Returns:
        this AnnotationBuilder
      • value

        default AnnotationBuilder value​(java.lang.Enum<?>[] values)
        Adds an enum array-valued annotation member called value.
        Parameters:
        values - the enum array, must not be null or contain null
        Returns:
        this AnnotationBuilder
      • value

        default AnnotationBuilder value​(java.lang.Class<? extends java.lang.Enum<?>> enumType,
                                        java.lang.String enumValue)
        Adds an enum-valued annotation member called value.
        Parameters:
        enumType - the enum type, must not be null
        enumValue - name of the enum constant, must not be null
        Returns:
        this AnnotationBuilder
      • value

        default AnnotationBuilder value​(java.lang.Class<? extends java.lang.Enum<?>> enumType,
                                        java.lang.String[] enumValues)
        Adds an enum array-valued annotation member called value.
        Parameters:
        enumType - the enum type, must not be null
        enumValues - names of the enum constants, must not be null or contain null
        Returns:
        this AnnotationBuilder
      • value

        default AnnotationBuilder value​(ClassInfo enumType,
                                        java.lang.String enumValue)
        Adds an enum-valued annotation member called value.
        Parameters:
        enumType - the enum type, must not be null
        enumValue - name of the enum constant, must not be null
        Returns:
        this AnnotationBuilder
      • value

        default AnnotationBuilder value​(ClassInfo enumType,
                                        java.lang.String[] enumValues)
        Adds an enum array-valued annotation member called value.
        Parameters:
        enumType - the enum type, must not be null
        enumValues - names of the enum constants, must not be null or contain null
        Returns:
        this AnnotationBuilder
      • value

        default AnnotationBuilder value​(java.lang.Class<?> value)
        Adds a class-valued annotation member called value.
        Parameters:
        value - the class value, must not be null
        Returns:
        this AnnotationBuilder
      • value

        default AnnotationBuilder value​(java.lang.Class<?>[] values)
        Adds a class array-valued annotation member called value.
        Parameters:
        values - the class array, must not be null or contain null
        Returns:
        this AnnotationBuilder
      • value

        default AnnotationBuilder value​(ClassInfo value)
        Adds a class-valued annotation member called value.
        Parameters:
        value - the class value, must not be null
        Returns:
        this AnnotationBuilder
      • value

        default AnnotationBuilder value​(ClassInfo[] values)
        Adds a class array-valued annotation member called value.
        Parameters:
        values - the class array, must not be null or contain null
        Returns:
        this AnnotationBuilder
      • value

        default AnnotationBuilder value​(Type value)
        Adds a class-valued annotation member called value. The value parameter may only be:
        Parameters:
        value - the class value, must not be null
        Returns:
        this AnnotationBuilder
        Throws:
        java.lang.IllegalArgumentException - if given type is invalid, as described above
      • value

        default AnnotationBuilder value​(Type[] values)
        Adds a class array-valued annotation member called value. The values parameter may only contain:
        Parameters:
        values - the class array, must not be null or contain null
        Returns:
        this AnnotationBuilder
        Throws:
        java.lang.IllegalArgumentException - if any given type is invalid, as described above
      • value

        default AnnotationBuilder value​(AnnotationInfo value)
        Adds an annotation-valued annotation member called value.
        Parameters:
        value - the annotation value, must not be null
        Returns:
        this AnnotationBuilder
      • value

        default AnnotationBuilder value​(AnnotationInfo[] values)
        Adds an annotation array-valued annotation member called value.
        Parameters:
        values - the annotation array, must not be null or contain null
        Returns:
        this AnnotationBuilder
      • value

        default AnnotationBuilder value​(java.lang.annotation.Annotation value)
        Adds an annotation-valued annotation member called value.
        Parameters:
        value - the annotation value, must not be null
        Returns:
        this AnnotationBuilder
      • value

        default AnnotationBuilder value​(java.lang.annotation.Annotation[] values)
        Adds an annotation array-valued annotation member called value.
        Parameters:
        values - the annotation array, must not be null or contain null
        Returns:
        this AnnotationBuilder
      • member

        AnnotationBuilder member​(java.lang.String name,
                                 AnnotationMember value)
        Adds an annotation member with given name, whose value is given value.
        Parameters:
        name - name of the annotation member, must not be null
        value - value of the annotation member, must not be null
        Returns:
        this AnnotationBuilder
      • member

        AnnotationBuilder member​(java.lang.String name,
                                 boolean value)
        Adds a boolean-valued annotation member with given name.
        Parameters:
        name - the member name, must not be null
        value - the boolean value
        Returns:
        this AnnotationBuilder
      • member

        AnnotationBuilder member​(java.lang.String name,
                                 boolean[] values)
        Adds a boolean array-valued annotation member with given name.
        Parameters:
        name - the member name, must not be null
        values - the boolean array, must not be null
        Returns:
        this AnnotationBuilder
      • member

        AnnotationBuilder member​(java.lang.String name,
                                 byte value)
        Adds a byte-valued annotation member with given name.
        Parameters:
        name - the member name, must not be null
        value - the byte value
        Returns:
        this AnnotationBuilder
      • member

        AnnotationBuilder member​(java.lang.String name,
                                 byte[] values)
        Adds a byte array-valued annotation member with given name.
        Parameters:
        name - the member name, must not be null
        values - the byte array, must not be null
        Returns:
        this AnnotationBuilder
      • member

        AnnotationBuilder member​(java.lang.String name,
                                 short value)
        Adds a short-valued annotation member with given name.
        Parameters:
        name - the member name, must not be null
        value - the short value
        Returns:
        this AnnotationBuilder
      • member

        AnnotationBuilder member​(java.lang.String name,
                                 short[] values)
        Adds a short array-valued annotation member with given name.
        Parameters:
        name - the member name, must not be null
        values - the short array, must not be null
        Returns:
        this AnnotationBuilder
      • member

        AnnotationBuilder member​(java.lang.String name,
                                 int value)
        Adds an int-valued annotation member with given name.
        Parameters:
        name - the member name, must not be null
        value - the int value
        Returns:
        this AnnotationBuilder
      • member

        AnnotationBuilder member​(java.lang.String name,
                                 int[] values)
        Adds an int array-valued annotation member with given name.
        Parameters:
        name - the member name, must not be null
        values - the int array, must not be null
        Returns:
        this AnnotationBuilder
      • member

        AnnotationBuilder member​(java.lang.String name,
                                 long value)
        Adds a long-valued annotation member with given name.
        Parameters:
        name - the member name, must not be null
        value - the long value
        Returns:
        this AnnotationBuilder
      • member

        AnnotationBuilder member​(java.lang.String name,
                                 long[] values)
        Adds a long array-valued annotation member with given name.
        Parameters:
        name - the member name, must not be null
        values - the long array, must not be null
        Returns:
        this AnnotationBuilder
      • member

        AnnotationBuilder member​(java.lang.String name,
                                 float value)
        Adds a float-valued annotation member with given name.
        Parameters:
        name - the member name, must not be null
        value - the float value
        Returns:
        this AnnotationBuilder
      • member

        AnnotationBuilder member​(java.lang.String name,
                                 float[] values)
        Adds a float array-valued annotation member with given name.
        Parameters:
        name - the member name, must not be null
        values - the float array, must not be null
        Returns:
        this AnnotationBuilder
      • member

        AnnotationBuilder member​(java.lang.String name,
                                 double value)
        Adds a double-valued annotation member with given name.
        Parameters:
        name - the member name, must not be null
        value - the double value
        Returns:
        this AnnotationBuilder
      • member

        AnnotationBuilder member​(java.lang.String name,
                                 double[] values)
        Adds a double array-valued annotation member with given name.
        Parameters:
        name - the member name, must not be null
        values - the double array, must not be null
        Returns:
        this AnnotationBuilder
      • member

        AnnotationBuilder member​(java.lang.String name,
                                 char value)
        Adds a char-valued annotation member with given name.
        Parameters:
        name - the member name, must not be null
        value - the char value
        Returns:
        this AnnotationBuilder
      • member

        AnnotationBuilder member​(java.lang.String name,
                                 char[] values)
        Adds a char array-valued annotation member with given name.
        Parameters:
        name - the member name, must not be null
        values - the char array, must not be null
        Returns:
        this AnnotationBuilder
      • member

        AnnotationBuilder member​(java.lang.String name,
                                 java.lang.String value)
        Adds a String-valued annotation member with given name.
        Parameters:
        name - the member name, must not be null
        value - the String value, must not be null
        Returns:
        this AnnotationBuilder
      • member

        AnnotationBuilder member​(java.lang.String name,
                                 java.lang.String[] values)
        Adds a String array-valued annotation member with given name.
        Parameters:
        name - the member name, must not be null
        values - the String array, must not be null or contain null
        Returns:
        this AnnotationBuilder
      • member

        AnnotationBuilder member​(java.lang.String name,
                                 java.lang.Enum<?> value)
        Adds an enum-valued annotation member with given name.
        Parameters:
        name - the member name, must not be null
        value - the enum value, must not be null
        Returns:
        this AnnotationBuilder
      • member

        AnnotationBuilder member​(java.lang.String name,
                                 java.lang.Enum<?>[] values)
        Adds an enum array-valued annotation member with given name.
        Parameters:
        name - the member name, must not be null
        values - the enum array, must not be null or contain null
        Returns:
        this AnnotationBuilder
      • member

        AnnotationBuilder member​(java.lang.String name,
                                 java.lang.Class<? extends java.lang.Enum<?>> enumType,
                                 java.lang.String enumValue)
        Adds an enum-valued annotation member with given name.
        Parameters:
        name - the member name, must not be null
        enumType - the enum type, must not be null
        enumValue - name of the enum constant, must not be null
        Returns:
        this AnnotationBuilder
      • member

        AnnotationBuilder member​(java.lang.String name,
                                 java.lang.Class<? extends java.lang.Enum<?>> enumType,
                                 java.lang.String[] enumValues)
        Adds an enum array-valued annotation member with given name.
        Parameters:
        name - the member name, must not be null
        enumType - the enum type, must not be null
        enumValues - names of the enum constants, must not be null or contain null
        Returns:
        this AnnotationBuilder
      • member

        AnnotationBuilder member​(java.lang.String name,
                                 ClassInfo enumType,
                                 java.lang.String enumValue)
        Adds an enum-valued annotation member with given name.
        Parameters:
        name - the member name, must not be null
        enumType - the enum type, must not be null
        enumValue - name of the enum constant, must not be null
        Returns:
        this AnnotationBuilder
      • member

        AnnotationBuilder member​(java.lang.String name,
                                 ClassInfo enumType,
                                 java.lang.String[] enumValues)
        Adds an enum array-valued annotation member with given name.
        Parameters:
        name - the member name, must not be null
        enumType - the enum type, must not be null
        enumValues - names of the enum constants, must not be null or contain null
        Returns:
        this AnnotationBuilder
      • member

        AnnotationBuilder member​(java.lang.String name,
                                 java.lang.Class<?> value)
        Adds a class-valued annotation member with given name.
        Parameters:
        name - the member name, must not be null
        value - the class value, must not be null
        Returns:
        this AnnotationBuilder
      • member

        AnnotationBuilder member​(java.lang.String name,
                                 java.lang.Class<?>[] values)
        Adds a class array-valued annotation member with given name.
        Parameters:
        name - the member name, must not be null
        values - the class array, must not be null or contain null
        Returns:
        this AnnotationBuilder
      • member

        AnnotationBuilder member​(java.lang.String name,
                                 ClassInfo value)
        Adds a class-valued annotation member with given name.
        Parameters:
        name - the member name, must not be null
        value - the class value, must not be null
        Returns:
        this AnnotationBuilder
      • member

        AnnotationBuilder member​(java.lang.String name,
                                 ClassInfo[] values)
        Adds a class array-valued annotation member with given name.
        Parameters:
        name - the member name, must not be null
        values - the class array, must not be null or contain null
        Returns:
        this AnnotationBuilder
      • member

        AnnotationBuilder member​(java.lang.String name,
                                 Type value)
        Adds a class-valued annotation member with given name. The value parameter may only be: Any other value results in an exception.
        Parameters:
        name - the member name, must not be null
        value - the class value, must not be null
        Returns:
        this AnnotationBuilder
        Throws:
        java.lang.IllegalArgumentException - if given type is invalid, as described above
      • member

        AnnotationBuilder member​(java.lang.String name,
                                 Type[] values)
        Adds a class array-valued annotation member with given name. The values parameter may only include:
        Parameters:
        name - the member name, must not be null
        values - the class array, must not be null or contain null
        Returns:
        this AnnotationBuilder
        Throws:
        java.lang.IllegalArgumentException - if any given type is invalid, as described above
      • member

        AnnotationBuilder member​(java.lang.String name,
                                 AnnotationInfo value)
        Adds an annotation-valued annotation member with given name.
        Parameters:
        name - the member name, must not be null
        value - the annotation value, must not be null
        Returns:
        this AnnotationBuilder
      • member

        AnnotationBuilder member​(java.lang.String name,
                                 AnnotationInfo[] values)
        Adds an annotation array-valued annotation member with given name.
        Parameters:
        name - the member name, must not be null
        values - the annotation array, must not be null or contain null
        Returns:
        this AnnotationBuilder
      • member

        AnnotationBuilder member​(java.lang.String name,
                                 java.lang.annotation.Annotation value)
        Adds an annotation-valued annotation member with given name.
        Parameters:
        name - the member name, must not be null
        value - the annotation value, must not be null
        Returns:
        this AnnotationBuilder
      • member

        AnnotationBuilder member​(java.lang.String name,
                                 java.lang.annotation.Annotation[] values)
        Adds an annotation array-valued annotation member with given name.
        Parameters:
        name - the member name, must not be null
        values - the annotation array, must not be null or contain null
        Returns:
        this AnnotationBuilder
      • build

        AnnotationInfo build()
        Returns an AnnotationInfo that includes all annotation members defined by previous method calls on this builder. After build() is called, this builder instance should be discarded.
        Returns:
        the built AnnotationInfo, never null
        Throws:
        java.lang.IllegalStateException - if a value of some annotation member was not set, and that member does not declare a default value