Class AnnotationInstanceBuilder


  • public final class AnnotationInstanceBuilder
    extends java.lang.Object
    Builder for AnnotationInstance. Instances of the builder are not reusable.

    Expected usage is: call add() as many times as required to add annotation members, and then call build() to create an AnnotationInstance without target, or buildWithTarget() to create an AnnotationInstance with target. Attempt to add() a member with the same name multiple times leads to an exception.

    This builder does not check whether the annotation type declares a member with given name or whether that member declares a default value.

    • Field Detail

      • annotationType

        private final DotName annotationType
      • runtimeVisible

        private final boolean runtimeVisible
      • alreadyAdded

        private final java.util.Set<java.lang.String> alreadyAdded
    • Constructor Detail

      • AnnotationInstanceBuilder

        AnnotationInstanceBuilder​(DotName annotationType,
                                  boolean runtimeVisible)
    • Method Detail

      • add

        public AnnotationInstanceBuilder add​(AnnotationValue value)
        Adds a pre-defined annotation member whose name and value are defined by given value.
        Parameters:
        value - the pre-defined annotation member, must not be null
        Returns:
        this builder
      • addAll

        public AnnotationInstanceBuilder addAll​(java.util.List<AnnotationValue> values)
        Adds all pre-defined annotation members whose names and values are defined by given values.
        Parameters:
        values - the pre-defined annotation members, must not be null or contain null
        Returns:
        this builder
      • add

        public AnnotationInstanceBuilder add​(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 builder
      • add

        public AnnotationInstanceBuilder add​(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 builder
      • add

        public AnnotationInstanceBuilder add​(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 builder
      • add

        public AnnotationInstanceBuilder add​(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 builder
      • add

        public AnnotationInstanceBuilder add​(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 builder
      • add

        public AnnotationInstanceBuilder add​(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 builder
      • add

        public AnnotationInstanceBuilder add​(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 builder
      • add

        public AnnotationInstanceBuilder add​(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 builder
      • add

        public AnnotationInstanceBuilder add​(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 builder
      • add

        public AnnotationInstanceBuilder add​(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 builder
      • add

        public AnnotationInstanceBuilder add​(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 builder
      • add

        public AnnotationInstanceBuilder add​(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 builder
      • add

        public AnnotationInstanceBuilder add​(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 builder
      • add

        public AnnotationInstanceBuilder add​(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 builder
      • add

        public AnnotationInstanceBuilder add​(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 builder
      • add

        public AnnotationInstanceBuilder add​(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 builder
      • add

        public AnnotationInstanceBuilder add​(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 builder
      • add

        public AnnotationInstanceBuilder add​(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 builder
      • add

        public AnnotationInstanceBuilder add​(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 builder
      • add

        public AnnotationInstanceBuilder add​(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 builder
      • add

        public AnnotationInstanceBuilder add​(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 builder
      • add

        public AnnotationInstanceBuilder add​(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 builder
      • add

        public AnnotationInstanceBuilder add​(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 builder
      • add

        public AnnotationInstanceBuilder add​(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 builder
      • add

        public AnnotationInstanceBuilder add​(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 builder
      • add

        public AnnotationInstanceBuilder add​(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 builder
      • add

        public AnnotationInstanceBuilder add​(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 builder
      • add

        public AnnotationInstanceBuilder add​(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 builder
      • validateType

        private void validateType​(Type type)
      • add

        public AnnotationInstanceBuilder add​(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 builder
        Throws:
        java.lang.IllegalArgumentException - if given type is invalid, as described above
      • add

        public AnnotationInstanceBuilder add​(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 builder
        Throws:
        java.lang.IllegalArgumentException - if any given type is invalid, as described above
      • add

        public AnnotationInstanceBuilder add​(java.lang.String name,
                                             AnnotationInstance 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 builder
      • add

        public AnnotationInstanceBuilder add​(java.lang.String name,
                                             AnnotationInstance[] 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 builder
      • value

        public AnnotationInstanceBuilder value​(boolean value)
        Adds a boolean-valued annotation member called value.
        Parameters:
        value - the boolean value
        Returns:
        this builder
      • value

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

        public AnnotationInstanceBuilder value​(byte value)
        Adds a byte-valued annotation member called value.
        Parameters:
        value - the byte value
        Returns:
        this builder
      • value

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

        public AnnotationInstanceBuilder value​(short value)
        Adds a short-valued annotation member called value.
        Parameters:
        value - the short value
        Returns:
        this builder
      • value

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

        public AnnotationInstanceBuilder value​(int value)
        Adds an int-valued annotation member called value.
        Parameters:
        value - the int value
        Returns:
        this builder
      • value

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

        public AnnotationInstanceBuilder value​(long value)
        Adds a long-valued annotation member called value.
        Parameters:
        value - the long value
        Returns:
        this builder
      • value

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

        public AnnotationInstanceBuilder value​(float value)
        Adds a float-valued annotation member called value.
        Parameters:
        value - the float value
        Returns:
        this builder
      • value

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

        public AnnotationInstanceBuilder value​(double value)
        Adds a double-valued annotation member called value.
        Parameters:
        value - the double value
        Returns:
        this builder
      • value

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

        public AnnotationInstanceBuilder value​(char value)
        Adds a char-valued annotation member called value.
        Parameters:
        value - the char value
        Returns:
        this builder
      • value

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

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

        public AnnotationInstanceBuilder 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 builder
      • value

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

        public AnnotationInstanceBuilder 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 builder
      • value

        public AnnotationInstanceBuilder 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 builder
      • value

        public AnnotationInstanceBuilder 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 builder
      • value

        public AnnotationInstanceBuilder 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 builder
      • value

        public AnnotationInstanceBuilder 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 builder
      • value

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

        public AnnotationInstanceBuilder 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 builder
      • value

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

        public AnnotationInstanceBuilder 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 builder
      • value

        public AnnotationInstanceBuilder 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 builder
        Throws:
        java.lang.IllegalArgumentException - if any given type is invalid, as described above
      • value

        public AnnotationInstanceBuilder value​(AnnotationInstance value)
        Adds an annotation-valued annotation member called value.
        Parameters:
        value - the annotation value, must not be null
        Returns:
        this builder
      • value

        public AnnotationInstanceBuilder value​(AnnotationInstance[] values)
        Adds an annotation array-valued annotation member called value.
        Parameters:
        values - the annotation array, must not be null or contain null
        Returns:
        this builder
      • with

        public AnnotationInstanceBuilder with​(java.util.function.Consumer<AnnotationInstanceBuilder> action)
        Calls given action with this builder as an argument, and returns this builder after the action finishes. This is useful to express a non-trivial control flow without breaking fluent usage.
        Parameters:
        action - an action to be performed on this builder, must not be null
        Returns:
        this builder
      • build

        public AnnotationInstance build()
        Returns an AnnotationInstance that includes all annotation members defined by previous method calls on this builder. The returned AnnotationInstance has no target. After build() is called, this builder instance should be discarded.
        Returns:
        the built AnnotationInstance, never null
      • buildWithTarget

        public AnnotationInstance buildWithTarget​(AnnotationTarget target)
        Returns an AnnotationInstance that includes all annotation members defined by previous method calls on this builder. The returned AnnotationInstance has given target. After buildWithTarget() is called, this builder instance should be discarded.
        Parameters:
        target - the target of the built annotation instance; if null, the built annotation instance has no target
        Returns:
        the built AnnotationInstance, never null