Class AnnotationContainer
java.lang.Object
io.spring.initializr.generator.language.AnnotationContainer
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidDeprecated, for removal: This API element is subject to removal in a future version.voidadd(ClassName className, Consumer<Annotation.Builder> annotation) Deprecated, for removal: This API element is subject to removal in a future version.in favor ofaddSingle(ClassName, Consumer)andaddRepeatable(ClassName)voidaddRepeatable(ClassName className) Add a repeatable annotation.voidaddRepeatable(ClassName className, Consumer<Annotation.Builder> annotation) Add a repeatable annotation.booleanAdd a single annotation.booleanaddSingle(ClassName className, Consumer<Annotation.Builder> annotation) Add a single annotation with the specified class name.voidcustomizeSingle(ClassName className, Consumer<Annotation.Builder> customizer) Customize a single annotation if it exists.deepCopy()booleanSpecify if this container has an annotation with the specified class name.booleanhasRepeatable(ClassName className) Whether this container has repeatable annotations with the specified class name.booleanWhether this container has a single annotation with the specified class name.booleanisEmpty()Specify if this container is empty.booleanRemove the annotation with the specified classname from either the single annotation or the repeatable annotations.booleanremoveAllRepeatable(ClassName className) Remove all repeatable annotations with the specified classname.booleanremoveSingle(ClassName className) Remove a single with the specified classname.values()Return the annotations.
-
Constructor Details
-
AnnotationContainer
public AnnotationContainer()
-
-
Method Details
-
isEmpty
public boolean isEmpty()Specify if this container is empty.- Returns:
trueif no annotation is registered
-
has
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:
trueif the annotation with the specified class name exists
-
hasSingle
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
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
Return the annotations. Returns both single and repeatable annotations.- Returns:
- the annotations
-
add
Deprecated, for removal: This API element is subject to removal in a future version.in favor ofaddSingle(ClassName)andaddRepeatable(ClassName)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.in favor ofaddSingle(ClassName, Consumer)andaddRepeatable(ClassName)Add a singleAnnotationwith the specified class name andConsumerto 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 annotationannotation- aConsumerto customize theAnnotation
-
addSingle
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
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 annotationannotation- aConsumerto customize the annotation- Returns:
- whether the annotation has been added
- Throws:
IllegalStateException- if the annotation has already been used for repeatable annotations
-
customizeSingle
Customize a single annotation if it exists. This method does nothing if the annotation doesn't exist.- Parameters:
className- the class name of an annotationcustomizer- the customizer for the annotation
-
addRepeatable
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
Add a repeatable annotation.- Parameters:
className- the class name of an annotationannotation- aConsumerto customize the annotation- Throws:
IllegalStateException- if the annotation has already been added as a single annotation
-
remove
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:
trueif such an annotation exists,falseotherwise
-
removeSingle
Remove a single with the specified classname.- Parameters:
className- the class name of an annotation- Returns:
- whether the annotation has been removed
-
removeAllRepeatable
Remove all repeatable annotations with the specified classname.- Parameters:
className- the class name of an annotation- Returns:
- whether any annotation has been removed
-
deepCopy
-
addSingle(ClassName)andaddRepeatable(ClassName)