Class EnumConstantDecl

  • All Implemented Interfaces:
    ASTNode

    public final class EnumConstantDecl
    extends Object
    implements ASTNode
    A single enum constant, with optional constructor arguments and an optional class body of fields and methods.
    • Constructor Detail

      • EnumConstantDecl

        public EnumConstantDecl​(String name,
                                SourceLocation location)
        Creates an enum constant with no arguments or body.
        Parameters:
        name - the constant name
        location - the source location, or null for unknown
      • EnumConstantDecl

        public EnumConstantDecl​(String name)
        Creates an enum constant at an unknown location.
        Parameters:
        name - the constant name
    • Method Detail

      • getName

        public String getName()
        Returns:
        the name
      • setName

        public void setName​(String name)
        Sets the constant name.
        Parameters:
        name - the constant name
      • 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
      • withName

        public EnumConstantDecl withName​(String name)
        Sets the constant name.
        Parameters:
        name - the constant name
        Returns:
        this declaration
      • addAnnotation

        public EnumConstantDecl addAnnotation​(AnnotationExpr annotation)
        Adds an annotation.
        Parameters:
        annotation - the annotation to add
        Returns:
        this declaration
      • addArgument

        public EnumConstantDecl addArgument​(Expression argument)
        Adds a constructor argument.
        Parameters:
        argument - the argument expression
        Returns:
        this declaration
      • addMethod

        public EnumConstantDecl addMethod​(MethodDecl method)
        Adds a method to the constant's class body.
        Parameters:
        method - the method declaration
        Returns:
        this declaration
      • addField

        public EnumConstantDecl addField​(FieldDecl field)
        Adds a field to the constant's class body.
        Parameters:
        field - the field declaration
        Returns:
        this declaration
      • hasArguments

        public boolean hasArguments()
        Returns:
        true if the constant passes constructor arguments
      • hasBody

        public boolean hasBody()
        Returns:
        true if the constant declares a class body
      • 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