Class EnumDecl

  • All Implemented Interfaces:
    ASTNode, TypeDecl

    public final class EnumDecl
    extends Object
    implements TypeDecl
    A Java enum declaration: constants plus ordinary members (fields, methods, constructors, inner types).
    • Constructor Detail

      • EnumDecl

        public EnumDecl​(String name,
                        SourceLocation location)
        Creates an empty enum declaration.
        Parameters:
        name - the simple enum name
        location - the source location, or null for unknown
      • EnumDecl

        public EnumDecl​(String name)
        Creates an empty enum declaration at an unknown location.
        Parameters:
        name - the simple enum name
    • Method Detail

      • setName

        public void setName​(String name)
        Sets the enum name.
        Parameters:
        name - the simple enum 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 EnumDecl withName​(String name)
        Sets the enum name.
        Parameters:
        name - the simple enum name
        Returns:
        this declaration
      • withModifiers

        public EnumDecl withModifiers​(Set<Modifier> modifiers)
        Replaces all modifiers with the given set.
        Parameters:
        modifiers - the modifiers to apply
        Returns:
        this declaration
      • addModifier

        public EnumDecl addModifier​(Modifier modifier)
        Adds a modifier.
        Parameters:
        modifier - the modifier to add
        Returns:
        this declaration
      • addAnnotation

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

        public EnumDecl addInterface​(SourceType iface)
        Adds an implemented interface.
        Parameters:
        iface - the interface type
        Returns:
        this declaration
      • addConstant

        public EnumDecl addConstant​(EnumConstantDecl constant)
        Adds an enum constant.
        Parameters:
        constant - the constant declaration
        Returns:
        this declaration
      • addField

        public EnumDecl addField​(FieldDecl field)
        Adds a field member.
        Parameters:
        field - the field declaration
        Returns:
        this declaration
      • addMethod

        public EnumDecl addMethod​(MethodDecl method)
        Adds a method member.
        Parameters:
        method - the method declaration
        Returns:
        this declaration
      • addConstructor

        public EnumDecl addConstructor​(ConstructorDecl constructor)
        Adds a constructor.
        Parameters:
        constructor - the constructor declaration
        Returns:
        this declaration
      • addInnerType

        public EnumDecl addInnerType​(TypeDecl innerType)
        Adds a nested type.
        Parameters:
        innerType - the nested type declaration
        Returns:
        this declaration
      • getConstant

        public EnumConstantDecl getConstant​(String name)
        Finds an enum constant by name.
        Parameters:
        name - the constant name
        Returns:
        the matching constant, or null if none
      • 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