Class AnnotationInstanceBuilder

java.lang.Object
org.jboss.jandex.AnnotationInstanceBuilder

public final class AnnotationInstanceBuilder extends 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 Details

  • Constructor Details

    • AnnotationInstanceBuilder

      AnnotationInstanceBuilder(DotName annotationType, boolean runtimeVisible)
  • Method Details

    • add

      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

      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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(String name, 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(String name, 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(String name, 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(String name, 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(String name, Class<? extends Enum<?>> enumType, 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(String name, Class<? extends Enum<?>> enumType, 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(String name, ClassInfo enumType, 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(String name, ClassInfo enumType, 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(String name, 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(String name, 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(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(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(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:
      IllegalArgumentException - if given type is invalid, as described above
    • add

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

      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(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(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(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(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(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(Class<? extends Enum<?>> enumType, 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(Class<? extends Enum<?>> enumType, 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, 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, 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(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(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 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 builder
      Throws:
      IllegalArgumentException - if given type is invalid, as described above
    • 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:
      IllegalArgumentException - if any given type is invalid, as described above
    • value

      Adds an annotation-valued annotation member called value.
      Parameters:
      value - the annotation value, must not be null
      Returns:
      this builder
    • value

      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

      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