Class CtAnnotationImpl<A extends Annotation>
java.lang.Object
spoon.support.reflect.declaration.CtElementImpl
spoon.support.reflect.code.CtCodeElementImpl
spoon.support.reflect.code.CtExpressionImpl<A>
spoon.support.reflect.declaration.CtAnnotationImpl<A>
- All Implemented Interfaces:
Serializable
,Cloneable
,FactoryAccessor
,CtCodeElement
,CtExpression<A>
,SourcePositionHolder
,CtAnnotation<A>
,CtElement
,CtShadowable
,CtTypedElement<A>
,CtQueryable
,CtVisitable
,TemplateParameter<A>
public class CtAnnotationImpl<A extends Annotation>
extends CtExpressionImpl<A>
implements CtAnnotation<A>
The implementation for
CtAnnotation
.- Author:
- Renaud Pawlak
- See Also:
- Serialized Form
-
Field Summary
Fields inherited from class spoon.support.reflect.declaration.CtElementImpl
ERROR_MESSAGE_TO_STRING, factory, LOGGER, parent
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Accepts a visitor<T extends CtAnnotation<A>>
TAdds a new key-value pair for this annotation<T extends CtAnnotation<A>>
TaddValue(String elementName, CtFieldAccess<?> value)
Adds a new key-field access pair for this annotation.<T extends CtAnnotation<A>>
TAdds a new key-literal pair for this annotation.<T extends CtAnnotation<A>>
TaddValue(String elementName, CtNewArray<? extends CtExpression> value)
Adds a new key-array pair for this annotation.<T extends CtAnnotation<A>>
TaddValue(String elementName, CtAnnotation<?> value)
Adds a new key-annotation pair for this annotation.clone()
Clone the element which calls this method in a new object.Returns the actual annotation (a dynamic proxy for this element).Get all values ofCtAnnotation.getValues()
, plus the default ones defined in the annotation type.Returns the element which is annotated by this annotation.Returns the type of the element which is annotated by this annotation.Returns the annotation type of this annotation.getName()
Returns the class name of the annotation, eg "Deprecated" for @Deprecated.List<CtTypeReference<?>>
Returns the type casts if any.<T extends CtExpression>
TGets a value, as a CtExpression, for a given key without any conversion.int
getValueAsInt(String key)
Returns the actual value of an annotation property, as an integer (utility method)getValueAsObject(String key)
Returns the actual value of an annotation propertygetValueAsString(String key)
Returns the actual value of an annotation property, as a String (utility method)Returns this annotation's elements and their values.<T extends CtExpression>
TgetWrappedValue(String key)
Gets a value for a given key and try to fix its type based on the annotation type.boolean
isShadow()
When an element isn't present in the factory (created in another factory), this element is considered as "shadow".<T extends CtAnnotation<A>>
TsetAnnotationType(CtTypeReference<? extends Annotation> annotationType)
Sets the annotation's type.<T extends CtAnnotation<A>>
TsetElementValues(Map<String,Object> values)
Set's this annotation's element names and their values.<E extends CtShadowable>
EsetShadow(boolean isShadow)
Marks an element as shadow.<C extends CtExpression<A>>
CsetTypeCasts(List<CtTypeReference<?>> casts)
Sets the type casts.<T extends CtAnnotation<A>>
TsetValues(Map<String,CtExpression> values)
Set's this annotation's element names and their values.Methods inherited from class spoon.support.reflect.code.CtExpressionImpl
addTypeCast, getType, S, setType
Methods inherited from class spoon.support.reflect.code.CtCodeElementImpl
partiallyEvaluate
Methods inherited from class spoon.support.reflect.declaration.CtElementImpl
addAnnotation, addComment, asIterable, comment, delete, descendantIterator, emptyList, emptySet, equals, filterChildren, getAllMetadata, getAnnotatedChildren, getAnnotation, getAnnotation, getAnnotations, getComments, getDirectChildren, getDocComment, getElements, getFactory, getMetadata, getMetadataKeys, getOriginalSourceFragment, getParent, getParent, getParent, getPath, getPosition, getReferencedTypes, getRoleInParent, getShortRepresentation, getValueByRole, hasAnnotation, hashCode, hasParent, isImplicit, isParentInitialized, map, map, prettyprint, putMetadata, removeAnnotation, removeComment, replace, replace, setAllMetadata, setAnnotations, setComments, setDocComment, setFactory, setImplicit, setParent, setPosition, setPositions, setValueByRole, toString, toStringDebug, unmodifiableList, updateAllParentsBelow
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface spoon.reflect.code.CtCodeElement
partiallyEvaluate
Methods inherited from interface spoon.reflect.declaration.CtElement
addAnnotation, addComment, asIterable, delete, descendantIterator, getAllMetadata, getAnnotatedChildren, getAnnotation, getAnnotation, getAnnotations, getComments, getDirectChildren, getDocComment, getElements, getMetadata, getMetadataKeys, getOriginalSourceFragment, getParent, getParent, getParent, getPath, getPosition, getReferencedTypes, getRoleInParent, getShortRepresentation, getValueByRole, hasAnnotation, hasParent, isImplicit, isParentInitialized, prettyprint, putMetadata, removeAnnotation, removeComment, replace, replace, setAllMetadata, setAnnotations, setComments, setDocComment, setImplicit, setParent, setPosition, setPositions, setValueByRole, toString, toStringDebug, updateAllParentsBelow
Methods inherited from interface spoon.reflect.code.CtExpression
addTypeCast
Methods inherited from interface spoon.reflect.visitor.chain.CtQueryable
filterChildren, map, map
Methods inherited from interface spoon.reflect.declaration.CtTypedElement
getType, setType
Methods inherited from interface spoon.processing.FactoryAccessor
getFactory, setFactory
Methods inherited from interface spoon.template.TemplateParameter
S
-
Constructor Details
-
CtAnnotationImpl
public CtAnnotationImpl()
-
-
Method Details
-
accept
Description copied from interface:CtVisitable
Accepts a visitor- Specified by:
accept
in interfaceCtVisitable
-
addValue
Description copied from interface:CtAnnotation
Adds a new key-value pair for this annotation- Specified by:
addValue
in interfaceCtAnnotation<A extends Annotation>
-
addValue
Description copied from interface:CtAnnotation
Adds a new key-literal pair for this annotation.- Specified by:
addValue
in interfaceCtAnnotation<A extends Annotation>
-
addValue
public <T extends CtAnnotation<A>> T addValue(String elementName, CtNewArray<? extends CtExpression> value)Description copied from interface:CtAnnotation
Adds a new key-array pair for this annotation.- Specified by:
addValue
in interfaceCtAnnotation<A extends Annotation>
-
addValue
Description copied from interface:CtAnnotation
Adds a new key-field access pair for this annotation.- Specified by:
addValue
in interfaceCtAnnotation<A extends Annotation>
-
addValue
Description copied from interface:CtAnnotation
Adds a new key-annotation pair for this annotation.- Specified by:
addValue
in interfaceCtAnnotation<A extends Annotation>
-
getAnnotationType
Description copied from interface:CtAnnotation
Returns the annotation type of this annotation.- Specified by:
getAnnotationType
in interfaceCtAnnotation<A extends Annotation>
- Returns:
- a reference to the type of this annotation
-
getValue
Description copied from interface:CtAnnotation
Gets a value, as a CtExpression, for a given key without any conversion. If you need the actual value (eg an integer and not a literal, seeCtAnnotation.getValueAsObject(String)
and similar methods. Note that this value type does not necessarily corresponds to the annotation type member. For example, in case the annotation type expect an array of Object, and a single value is given, Spoon will return only the object without the CtNewArray. If you want to get a type closer to the annotation type one, seeCtAnnotation.getWrappedValue(String)
.- Specified by:
getValue
in interfaceCtAnnotation<A extends Annotation>
- Parameters:
key
- Name of searched value.- Returns:
- the value expression or null if not found.
-
getValueAsInt
Description copied from interface:CtAnnotation
Returns the actual value of an annotation property, as an integer (utility method)- Specified by:
getValueAsInt
in interfaceCtAnnotation<A extends Annotation>
-
getValueAsString
Description copied from interface:CtAnnotation
Returns the actual value of an annotation property, as a String (utility method)- Specified by:
getValueAsString
in interfaceCtAnnotation<A extends Annotation>
-
getValueAsObject
Description copied from interface:CtAnnotation
Returns the actual value of an annotation property- Specified by:
getValueAsObject
in interfaceCtAnnotation<A extends Annotation>
-
getWrappedValue
Description copied from interface:CtAnnotation
Gets a value for a given key and try to fix its type based on the annotation type. For example, if the annotation type member expects an array of String, and it can be resolved, this method will return a CtNewArray instead of a CtLiteral. Warning: the returned element might be detached from the model- Specified by:
getWrappedValue
in interfaceCtAnnotation<A extends Annotation>
- Parameters:
key
- Name of searched value.- Returns:
- the value expression or null if not found.
-
getElementValues
-
getValues
Description copied from interface:CtAnnotation
Returns this annotation's elements and their values. This is returned in the form of a map that associates element names with their corresponding values. If you iterate over the map with entrySet(), the iteration order complies with the order of annotation values in the source code.- Specified by:
getValues
in interfaceCtAnnotation<A extends Annotation>
- Returns:
- this annotation's element names and their values, or an empty map if there are none
-
getAllValues
Description copied from interface:CtAnnotation
Get all values ofCtAnnotation.getValues()
, plus the default ones defined in the annotation type.- Specified by:
getAllValues
in interfaceCtAnnotation<A extends Annotation>
-
setAnnotationType
public <T extends CtAnnotation<A>> T setAnnotationType(CtTypeReference<? extends Annotation> annotationType)Description copied from interface:CtAnnotation
Sets the annotation's type.- Specified by:
setAnnotationType
in interfaceCtAnnotation<A extends Annotation>
- Parameters:
annotationType
- reference to the type of this annotation
-
setElementValues
Description copied from interface:CtAnnotation
Set's this annotation's element names and their values. This is in the form of a map that associates element names with their corresponding values. Note that type values are stored asCtTypeReference
.- Specified by:
setElementValues
in interfaceCtAnnotation<A extends Annotation>
-
setValues
Description copied from interface:CtAnnotation
Set's this annotation's element names and their values. This is in the form of a map that associates element names with their corresponding values.- Specified by:
setValues
in interfaceCtAnnotation<A extends Annotation>
-
getAnnotatedElement
Description copied from interface:CtAnnotation
Returns the element which is annotated by this annotation.- Specified by:
getAnnotatedElement
in interfaceCtAnnotation<A extends Annotation>
- Returns:
- annotated
CtElement
-
getAnnotatedElementType
Description copied from interface:CtAnnotation
Returns the type of the element which is annotated by this annotation.- Specified by:
getAnnotatedElementType
in interfaceCtAnnotation<A extends Annotation>
- Returns:
CtAnnotatedElementType
-
getActualAnnotation
Description copied from interface:CtAnnotation
Returns the actual annotation (a dynamic proxy for this element).NOTE: before using an annotation proxy, you have to make sure that all the types referenced by the annotation have been compiled and are in the classpath so that accessed values can be converted into the actual types.
- Specified by:
getActualAnnotation
in interfaceCtAnnotation<A extends Annotation>
-
isShadow
public boolean isShadow()Description copied from interface:CtShadowable
When an element isn't present in the factory (created in another factory), this element is considered as "shadow". e.g., a shadow element can be a CtType of java.lang.Class built when we callCtTypeReference.getTypeDeclaration()
on a reference of java.lang.Class.- Specified by:
isShadow
in interfaceCtShadowable
- Returns:
- true if the element is a shadow element, otherwise false.
-
setShadow
Description copied from interface:CtShadowable
Marks an element as shadow. To know what is a shadow element, see the javadoc ofCtShadowable.isShadow()
.- Specified by:
setShadow
in interfaceCtShadowable
-
clone
Description copied from interface:CtElement
Clone the element which calls this method in a new object. Note that that references are kept as is, and thus, so if you clone whole classes or methods, some parts of the cloned element (eg executable references) may still point to the initial element. In this case, consider using methodsRefactoring.copyType(CtType)
andRefactoring.copyMethod(CtMethod)
instead which does additional work beyond cloning.- Specified by:
clone
in interfaceCtAnnotation<A extends Annotation>
- Specified by:
clone
in interfaceCtCodeElement
- Specified by:
clone
in interfaceCtElement
- Specified by:
clone
in interfaceCtExpression<A extends Annotation>
- Overrides:
clone
in classCtExpressionImpl<A extends Annotation>
-
getTypeCasts
Description copied from interface:CtExpression
Returns the type casts if any.- Specified by:
getTypeCasts
in interfaceCtExpression<A extends Annotation>
- Overrides:
getTypeCasts
in classCtExpressionImpl<A extends Annotation>
-
setTypeCasts
Description copied from interface:CtExpression
Sets the type casts.- Specified by:
setTypeCasts
in interfaceCtAnnotation<A extends Annotation>
- Specified by:
setTypeCasts
in interfaceCtExpression<A extends Annotation>
- Overrides:
setTypeCasts
in classCtExpressionImpl<A extends Annotation>
-
getName
Description copied from interface:CtAnnotation
Returns the class name of the annotation, eg "Deprecated" for @Deprecated.- Specified by:
getName
in interfaceCtAnnotation<A extends Annotation>
- Returns:
- the name of the annotation
-