Class AnnotationExpr

  • All Implemented Interfaces:
    ASTNode, Expression

    public final class AnnotationExpr
    extends Object
    implements Expression
    A Java annotation use, in marker, single-value, or normal (named-values) form.
    • Constructor Detail

      • AnnotationExpr

        public AnnotationExpr​(SourceType annotationType,
                              SourceLocation location)
        Creates an annotation use with no values.
        Parameters:
        annotationType - the annotation type
        location - the source location, or null for unknown
      • AnnotationExpr

        public AnnotationExpr​(SourceType annotationType)
        Creates an annotation use with no values at an unknown location.
        Parameters:
        annotationType - the annotation type
    • Method Detail

      • getAnnotationType

        public SourceType getAnnotationType()
        Returns:
        the annotation type
      • setAnnotationType

        public void setAnnotationType​(SourceType annotationType)
        Sets the annotation type.
        Parameters:
        annotationType - the annotation type
      • getLocation

        public SourceLocation getLocation()
        Description copied from interface: ASTNode
        Gets the source location of this node.
        Specified by:
        getLocation in interface ASTNode
        Returns:
        the location
      • getParent

        public ASTNode getParent()
        Description copied from interface: ASTNode
        Gets the parent node in the AST tree.
        Specified by:
        getParent in interface ASTNode
        Returns:
        the parent
      • setParent

        public void setParent​(ASTNode parent)
        Sets the parent node.
        Specified by:
        setParent in interface ASTNode
        Parameters:
        parent - the new parent
      • withAnnotationType

        public AnnotationExpr withAnnotationType​(SourceType annotationType)
        Sets the annotation type.
        Parameters:
        annotationType - the annotation type
        Returns:
        this annotation
      • addValue

        public AnnotationExpr addValue​(AnnotationValue value)
        Adds an element-value pair.
        Parameters:
        value - the pair to add
        Returns:
        this annotation
      • addValue

        public AnnotationExpr addValue​(String name,
                                       Expression value)
        Adds an element-value pair from a name and value.
        Parameters:
        name - the element name
        value - the element value
        Returns:
        this annotation
      • isMarker

        public boolean isMarker()
        Returns:
        true if this annotation has no element values (marker form)
      • isSingleValue

        public boolean isSingleValue()
        Returns:
        true if the only element is named "value" (single-value form)
      • isNormal

        public boolean isNormal()
        Returns:
        true if this annotation is neither marker nor single-value form
      • getSingleValue

        public Expression getSingleValue()
        Returns the lone "value" element's expression.
        Returns:
        the value expression, or null if not in single-value form
      • getValue

        public Expression getValue​(String name)
        Looks up an element value by name.
        Parameters:
        name - the element name
        Returns:
        the value expression, or null if no such element
      • getType

        public SourceType getType()
        Description copied from interface: Expression
        Gets the inferred type of this expression.
        Specified by:
        getType in interface Expression
        Returns:
        the type of this expression
      • getChildren

        public List<ASTNode> getChildren()
        Description copied from interface: ASTNode
        Lists the direct children a node holds, in source order.
        Specified by:
        getChildren in interface ASTNode
        Returns:
        the direct children, empty for a leaf
      • accept

        public <T> T accept​(SourceVisitor<T> visitor)
        Description copied from interface: ASTNode
        Accepts a visitor for this node.
        Specified by:
        accept in interface ASTNode
        Type Parameters:
        T - the return type of the visitor
        Parameters:
        visitor - the visitor to accept
        Returns:
        the result from the visitor