public class AnnotationBuilder
extends java.lang.Object
Constructing an AnnotationMirror
requires:
setValue
methods
build()
to get the annotation
IllegalStateException
is thrown.
All setter methods throw IllegalArgumentException
if the specified element is not
found, or if the given value is not a subtype of the expected type.
TODO: Doesn't type-check arrays yet
Constructor and Description |
---|
AnnotationBuilder(javax.annotation.processing.ProcessingEnvironment env,
javax.lang.model.element.AnnotationMirror annotation) |
AnnotationBuilder(javax.annotation.processing.ProcessingEnvironment env,
java.lang.CharSequence name) |
AnnotationBuilder(javax.annotation.processing.ProcessingEnvironment env,
java.lang.Class<? extends java.lang.annotation.Annotation> anno) |
Modifier and Type | Method and Description |
---|---|
javax.lang.model.element.AnnotationMirror |
build() |
static void |
clear() |
void |
copyElementValuesFromAnnotation(javax.lang.model.element.AnnotationMirror valueHolder,
java.lang.String... ignorableElements)
Copies every element value from the given annotation.
|
void |
copyRenameElementValuesFromAnnotation(javax.lang.model.element.AnnotationMirror valueHolder,
java.util.Map<java.lang.String,java.lang.String> elementNameRenaming)
Copies the specified element values from the given annotation, using the specified renaming
map.
|
javax.lang.model.element.ExecutableElement |
findElement(java.lang.CharSequence key) |
static javax.lang.model.element.AnnotationMirror |
fromClass(javax.lang.model.util.Elements elements,
java.lang.Class<? extends java.lang.annotation.Annotation> clazz)
Creates an
AnnotationMirror given by a particular annotation class. |
static javax.lang.model.element.AnnotationMirror |
fromName(javax.lang.model.util.Elements elements,
java.lang.CharSequence name)
Creates an
AnnotationMirror given by a particular fully-qualified name. |
AnnotationBuilder |
setValue(java.lang.CharSequence elementName,
javax.lang.model.element.AnnotationMirror value) |
AnnotationBuilder |
setValue(java.lang.CharSequence elementName,
java.lang.Boolean value) |
AnnotationBuilder |
setValue(java.lang.CharSequence elementName,
java.lang.Character value) |
AnnotationBuilder |
setValue(java.lang.CharSequence elementName,
java.lang.Class<?> value) |
AnnotationBuilder |
setValue(java.lang.CharSequence elementName,
java.lang.Double value) |
AnnotationBuilder |
setValue(java.lang.CharSequence elementName,
java.lang.Enum<?> value) |
AnnotationBuilder |
setValue(java.lang.CharSequence elementName,
java.lang.Enum<?>[] values) |
AnnotationBuilder |
setValue(java.lang.CharSequence elementName,
java.lang.Float value) |
AnnotationBuilder |
setValue(java.lang.CharSequence elementName,
java.lang.Integer value) |
AnnotationBuilder |
setValue(java.lang.CharSequence elementName,
java.util.List<? extends java.lang.Object> values) |
AnnotationBuilder |
setValue(java.lang.CharSequence elementName,
java.lang.Long value) |
AnnotationBuilder |
setValue(java.lang.CharSequence elementName,
java.lang.Object[] values) |
AnnotationBuilder |
setValue(java.lang.CharSequence elementName,
java.lang.Short value) |
AnnotationBuilder |
setValue(java.lang.CharSequence elementName,
java.lang.String value) |
AnnotationBuilder |
setValue(java.lang.CharSequence elementName,
javax.lang.model.type.TypeMirror value) |
AnnotationBuilder |
setValue(java.lang.CharSequence elementName,
javax.lang.model.element.VariableElement value) |
AnnotationBuilder |
setValue(java.lang.CharSequence elementName,
javax.lang.model.element.VariableElement[] values) |
public AnnotationBuilder(javax.annotation.processing.ProcessingEnvironment env, java.lang.Class<? extends java.lang.annotation.Annotation> anno)
public AnnotationBuilder(javax.annotation.processing.ProcessingEnvironment env, java.lang.CharSequence name)
public AnnotationBuilder(javax.annotation.processing.ProcessingEnvironment env, javax.lang.model.element.AnnotationMirror annotation)
public static javax.lang.model.element.AnnotationMirror fromClass(javax.lang.model.util.Elements elements, java.lang.Class<? extends java.lang.annotation.Annotation> clazz)
AnnotationMirror
given by a particular annotation class.elements
- the element utilities to useclazz
- the annotation classAnnotationMirror
of type given typepublic static javax.lang.model.element.AnnotationMirror fromName(javax.lang.model.util.Elements elements, java.lang.CharSequence name)
AnnotationMirror
given by a particular fully-qualified name.
getElementValues on the result returns an empty map.elements
- the element utilities to usename
- the name of the annotation to createAnnotationMirror
of type namepublic static void clear()
public javax.lang.model.element.AnnotationMirror build()
public void copyElementValuesFromAnnotation(javax.lang.model.element.AnnotationMirror valueHolder, java.lang.String... ignorableElements)
ignorableElements
.valueHolder
- the annotation that holds the values to be copiedignorableElements
- the elements that can be safely droppedpublic void copyRenameElementValuesFromAnnotation(javax.lang.model.element.AnnotationMirror valueHolder, java.util.Map<java.lang.String,java.lang.String> elementNameRenaming)
valueHolder
- the annotation that holds the values to be copiedelementNameRenaming
- a map from element names in valueHolder
to element names
of the annotation being builtpublic AnnotationBuilder setValue(java.lang.CharSequence elementName, javax.lang.model.element.AnnotationMirror value)
public AnnotationBuilder setValue(java.lang.CharSequence elementName, java.util.List<? extends java.lang.Object> values)
public AnnotationBuilder setValue(java.lang.CharSequence elementName, java.lang.Object[] values)
public AnnotationBuilder setValue(java.lang.CharSequence elementName, java.lang.Boolean value)
public AnnotationBuilder setValue(java.lang.CharSequence elementName, java.lang.Character value)
public AnnotationBuilder setValue(java.lang.CharSequence elementName, java.lang.Double value)
public AnnotationBuilder setValue(java.lang.CharSequence elementName, java.lang.Float value)
public AnnotationBuilder setValue(java.lang.CharSequence elementName, java.lang.Integer value)
public AnnotationBuilder setValue(java.lang.CharSequence elementName, java.lang.Long value)
public AnnotationBuilder setValue(java.lang.CharSequence elementName, java.lang.Short value)
public AnnotationBuilder setValue(java.lang.CharSequence elementName, java.lang.String value)
public AnnotationBuilder setValue(java.lang.CharSequence elementName, javax.lang.model.type.TypeMirror value)
public AnnotationBuilder setValue(java.lang.CharSequence elementName, java.lang.Class<?> value)
public AnnotationBuilder setValue(java.lang.CharSequence elementName, java.lang.Enum<?> value)
public AnnotationBuilder setValue(java.lang.CharSequence elementName, javax.lang.model.element.VariableElement value)
public AnnotationBuilder setValue(java.lang.CharSequence elementName, java.lang.Enum<?>[] values)
public AnnotationBuilder setValue(java.lang.CharSequence elementName, javax.lang.model.element.VariableElement[] values)
public javax.lang.model.element.ExecutableElement findElement(java.lang.CharSequence key)