Interface CtAnnotation<A extends 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​(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

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

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

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

        <T extends CtExpression> T getWrappedValue​(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

        Map<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
      • setAnnotationType

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

        <T extends CtAnnotation<A>> T setElementValues​(Map<String,​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​(Map<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​(String elementName,
                                               Object value)
        Adds a new key-value pair for this annotation
      • addValue

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

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