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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAccepts 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.intgetValueAsInt(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.booleanisShadow()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, setTypeMethods inherited from class spoon.support.reflect.code.CtCodeElementImpl
partiallyEvaluateMethods 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, updateAllParentsBelowMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface spoon.reflect.code.CtCodeElement
partiallyEvaluateMethods 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, updateAllParentsBelowMethods inherited from interface spoon.reflect.code.CtExpression
addTypeCastMethods inherited from interface spoon.reflect.visitor.chain.CtQueryable
filterChildren, map, mapMethods inherited from interface spoon.reflect.declaration.CtTypedElement
getType, setTypeMethods inherited from interface spoon.processing.FactoryAccessor
getFactory, setFactoryMethods inherited from interface spoon.template.TemplateParameter
S
-
Constructor Details
-
CtAnnotationImpl
public CtAnnotationImpl()
-
-
Method Details
-
accept
Description copied from interface:CtVisitableAccepts a visitor- Specified by:
acceptin interfaceCtVisitable
-
addValue
Description copied from interface:CtAnnotationAdds a new key-value pair for this annotation- Specified by:
addValuein interfaceCtAnnotation<A extends Annotation>
-
addValue
Description copied from interface:CtAnnotationAdds a new key-literal pair for this annotation.- Specified by:
addValuein interfaceCtAnnotation<A extends Annotation>
-
addValue
public <T extends CtAnnotation<A>> T addValue(String elementName, CtNewArray<? extends CtExpression> value)Description copied from interface:CtAnnotationAdds a new key-array pair for this annotation.- Specified by:
addValuein interfaceCtAnnotation<A extends Annotation>
-
addValue
Description copied from interface:CtAnnotationAdds a new key-field access pair for this annotation.- Specified by:
addValuein interfaceCtAnnotation<A extends Annotation>
-
addValue
Description copied from interface:CtAnnotationAdds a new key-annotation pair for this annotation.- Specified by:
addValuein interfaceCtAnnotation<A extends Annotation>
-
getAnnotationType
Description copied from interface:CtAnnotationReturns the annotation type of this annotation.- Specified by:
getAnnotationTypein interfaceCtAnnotation<A extends Annotation>- Returns:
- a reference to the type of this annotation
-
getValue
Description copied from interface:CtAnnotationGets 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:
getValuein interfaceCtAnnotation<A extends Annotation>- Parameters:
key- Name of searched value.- Returns:
- the value expression or null if not found.
-
getValueAsInt
Description copied from interface:CtAnnotationReturns the actual value of an annotation property, as an integer (utility method)- Specified by:
getValueAsIntin interfaceCtAnnotation<A extends Annotation>
-
getValueAsString
Description copied from interface:CtAnnotationReturns the actual value of an annotation property, as a String (utility method)- Specified by:
getValueAsStringin interfaceCtAnnotation<A extends Annotation>
-
getValueAsObject
Description copied from interface:CtAnnotationReturns the actual value of an annotation property- Specified by:
getValueAsObjectin interfaceCtAnnotation<A extends Annotation>
-
getWrappedValue
Description copied from interface:CtAnnotationGets 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:
getWrappedValuein 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:CtAnnotationReturns 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:
getValuesin 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:CtAnnotationGet all values ofCtAnnotation.getValues(), plus the default ones defined in the annotation type.- Specified by:
getAllValuesin interfaceCtAnnotation<A extends Annotation>
-
setAnnotationType
public <T extends CtAnnotation<A>> T setAnnotationType(CtTypeReference<? extends Annotation> annotationType)Description copied from interface:CtAnnotationSets the annotation's type.- Specified by:
setAnnotationTypein interfaceCtAnnotation<A extends Annotation>- Parameters:
annotationType- reference to the type of this annotation
-
setElementValues
Description copied from interface:CtAnnotationSet'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:
setElementValuesin interfaceCtAnnotation<A extends Annotation>
-
setValues
Description copied from interface:CtAnnotationSet'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:
setValuesin interfaceCtAnnotation<A extends Annotation>
-
getAnnotatedElement
Description copied from interface:CtAnnotationReturns the element which is annotated by this annotation.- Specified by:
getAnnotatedElementin interfaceCtAnnotation<A extends Annotation>- Returns:
- annotated
CtElement
-
getAnnotatedElementType
Description copied from interface:CtAnnotationReturns the type of the element which is annotated by this annotation.- Specified by:
getAnnotatedElementTypein interfaceCtAnnotation<A extends Annotation>- Returns:
CtAnnotatedElementType
-
getActualAnnotation
Description copied from interface:CtAnnotationReturns 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:
getActualAnnotationin interfaceCtAnnotation<A extends Annotation>
-
isShadow
public boolean isShadow()Description copied from interface:CtShadowableWhen 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:
isShadowin interfaceCtShadowable- Returns:
- true if the element is a shadow element, otherwise false.
-
setShadow
Description copied from interface:CtShadowableMarks an element as shadow. To know what is a shadow element, see the javadoc ofCtShadowable.isShadow().- Specified by:
setShadowin interfaceCtShadowable
-
clone
Description copied from interface:CtElementClone 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:
clonein interfaceCtAnnotation<A extends Annotation>- Specified by:
clonein interfaceCtCodeElement- Specified by:
clonein interfaceCtElement- Specified by:
clonein interfaceCtExpression<A extends Annotation>- Overrides:
clonein classCtExpressionImpl<A extends Annotation>
-
getTypeCasts
Description copied from interface:CtExpressionReturns the type casts if any.- Specified by:
getTypeCastsin interfaceCtExpression<A extends Annotation>- Overrides:
getTypeCastsin classCtExpressionImpl<A extends Annotation>
-
setTypeCasts
Description copied from interface:CtExpressionSets the type casts.- Specified by:
setTypeCastsin interfaceCtAnnotation<A extends Annotation>- Specified by:
setTypeCastsin interfaceCtExpression<A extends Annotation>- Overrides:
setTypeCastsin classCtExpressionImpl<A extends Annotation>
-
getName
Description copied from interface:CtAnnotationReturns the class name of the annotation, eg "Deprecated" for @Deprecated.- Specified by:
getNamein interfaceCtAnnotation<A extends Annotation>- Returns:
- the name of the annotation
-