Interface CtAnnotation<A extends java.lang.annotation.Annotation>

    • Method Detail

      • getActualAnnotation

        A getActualAnnotation()
        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.

      • getAnnotationType

        CtTypeReference<A> getAnnotationType()
        Returns the annotation type of this annotation.
        Returns:
        a reference to the type of this annotation
      • getValue

        <T extends CtExpression> T getValue​(java.lang.String key)
        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, see 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, see getWrappedValue(String).
        Parameters:
        key - Name of searched value.
        Returns:
        the value expression or null if not found.
      • getValueAsObject

        java.lang.Object getValueAsObject​(java.lang.String key)
        Returns the actual value of an annotation property
      • getValueAsInt

        int getValueAsInt​(java.lang.String key)
        Returns the actual value of an annotation property, as an integer (utility method)
      • getValueAsString

        java.lang.String getValueAsString​(java.lang.String key)
        Returns the actual value of an annotation property, as a String (utility method)
      • getWrappedValue

        <T extends CtExpression> T getWrappedValue​(java.lang.String key)
        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
        Parameters:
        key - Name of searched value.
        Returns:
        the value expression or null if not found.
      • getValues

        java.util.Map<java.lang.String,​CtExpression> getValues()
        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.
        Returns:
        this annotation's element names and their values, or an empty map if there are none
      • getAllValues

        java.util.Map<java.lang.String,​CtExpression> getAllValues()
        Get all values of getValues(), plus the default ones defined in the annotation type.
      • setAnnotationType

        <T extends CtAnnotation<A>> T setAnnotationType​(CtTypeReference<? extends java.lang.annotation.Annotation> type)
        Sets the annotation's type.
        Parameters:
        type - reference to the type of this annotation
      • setElementValues

        <T extends CtAnnotation<A>> T setElementValues​(java.util.Map<java.lang.String,​java.lang.Object> values)
        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 as CtTypeReference.
      • setValues

        <T extends CtAnnotation<A>> T setValues​(java.util.Map<java.lang.String,​CtExpression> values)
        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.
      • getAnnotatedElement

        CtElement getAnnotatedElement()
        Returns the element which is annotated by this annotation.
        Returns:
        annotated CtElement
      • addValue

        <T extends CtAnnotation<A>> T addValue​(java.lang.String elementName,
                                               java.lang.Object value)
        Adds a new key-value pair for this annotation
      • addValue

        <T extends CtAnnotation<A>> T addValue​(java.lang.String elementName,
                                               CtLiteral<?> value)
        Adds a new key-literal pair for this annotation.
      • addValue

        <T extends CtAnnotation<A>> T addValue​(java.lang.String elementName,
                                               CtNewArray<? extends CtExpression> value)
        Adds a new key-array pair for this annotation.
      • addValue

        <T extends CtAnnotation<A>> T addValue​(java.lang.String elementName,
                                               CtFieldAccess<?> value)
        Adds a new key-field access pair for this annotation.
      • addValue

        <T extends CtAnnotation<A>> T addValue​(java.lang.String elementName,
                                               CtAnnotation<?> value)
        Adds a new key-annotation pair for this annotation.
      • clone

        CtAnnotation<A> 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 methods Refactoring.copyType(CtType) and Refactoring.copyMethod(CtMethod) instead which does additional work beyond cloning.
        Specified by:
        clone in interface CtCodeElement
        Specified by:
        clone in interface CtElement
        Specified by:
        clone in interface CtExpression<A extends java.lang.annotation.Annotation>
      • getName

        java.lang.String getName()
        Returns the class name of the annotation, eg "Deprecated" for @Deprecated.
        Returns:
        the name of the annotation