Class AnnotationContainer

java.lang.Object
io.spring.initializr.generator.language.AnnotationContainer

public class AnnotationContainer extends Object
A container for annotations defined on an annotated element.

Supports both single and repeatable annotations. Single annotations can be customized even after they have been added.

Author:
Stephane Nicoll, Moritz Halbritter
  • Constructor Details

    • AnnotationContainer

      public AnnotationContainer()
  • Method Details

    • isEmpty

      public boolean isEmpty()
      Specify if this container is empty.
      Returns:
      true if no annotation is registered
    • has

      public boolean has(ClassName className)
      Specify if this container has an annotation with the specified class name. Considers both single and repeatable annotations.
      Parameters:
      className - the class name of an annotation
      Returns:
      true if the annotation with the specified class name exists
    • hasSingle

      public boolean hasSingle(ClassName className)
      Whether this container has a single annotation with the specified class name.
      Parameters:
      className - the class name of an annotation
      Returns:
      whether this container has the annotation
    • hasRepeatable

      public boolean hasRepeatable(ClassName className)
      Whether this container has repeatable annotations with the specified class name.
      Parameters:
      className - the class name of an annotation
      Returns:
      whether this container has the annotation
    • values

      public Stream<Annotation> values()
      Return the annotations. Returns both single and repeatable annotations.
      Returns:
      the annotations
    • add

      @Deprecated(forRemoval=true) public void add(ClassName className)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Add a single annotation with the specified class name. Does nothing If the annotation has already been added.
      Parameters:
      className - the class name of an annotation
    • add

      @Deprecated(forRemoval=true) public void add(ClassName className, Consumer<Annotation.Builder> annotation)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Add a single Annotation with the specified class name and Consumer to customize it. If the annotation has already been added, the consumer can be used to further tune attributes.
      Parameters:
      className - the class name of an annotation
      annotation - a Consumer to customize the Annotation
    • addSingle

      public boolean addSingle(ClassName className)
      Add a single annotation.
      Parameters:
      className - the class name of an annotation
      Returns:
      whether the annotation has been added
      Throws:
      IllegalStateException - if the annotation has already been used for repeatable annotations
    • addSingle

      public boolean addSingle(ClassName className, Consumer<Annotation.Builder> annotation)
      Add a single annotation with the specified class name. If the annotation already exists, this method does nothing.
      Parameters:
      className - the class name of an annotation
      annotation - a Consumer to customize the annotation
      Returns:
      whether the annotation has been added
      Throws:
      IllegalStateException - if the annotation has already been used for repeatable annotations
    • customizeSingle

      public void customizeSingle(ClassName className, Consumer<Annotation.Builder> customizer)
      Customize a single annotation if it exists. This method does nothing if the annotation doesn't exist.
      Parameters:
      className - the class name of an annotation
      customizer - the customizer for the annotation
    • addRepeatable

      public void addRepeatable(ClassName className)
      Add a repeatable annotation.
      Parameters:
      className - the class name of an annotation
      Throws:
      IllegalStateException - if the annotation has already been added as a single annotation
    • addRepeatable

      public void addRepeatable(ClassName className, Consumer<Annotation.Builder> annotation)
      Add a repeatable annotation.
      Parameters:
      className - the class name of an annotation
      annotation - a Consumer to customize the annotation
      Throws:
      IllegalStateException - if the annotation has already been added as a single annotation
    • remove

      public boolean remove(ClassName className)
      Remove the annotation with the specified classname from either the single annotation or the repeatable annotations.
      Parameters:
      className - the class name of the annotation
      Returns:
      true if such an annotation exists, false otherwise
    • removeSingle

      public boolean removeSingle(ClassName className)
      Remove a single with the specified classname.
      Parameters:
      className - the class name of an annotation
      Returns:
      whether the annotation has been removed
    • removeAllRepeatable

      public boolean removeAllRepeatable(ClassName className)
      Remove all repeatable annotations with the specified classname.
      Parameters:
      className - the class name of an annotation
      Returns:
      whether any annotation has been removed
    • deepCopy

      public AnnotationContainer deepCopy()