Class FieldDecl

  • All Implemented Interfaces:
    ASTNode

    public final class FieldDecl
    extends Object
    implements ASTNode
    A Java field declaration: name, type, modifiers, annotations, and optional initializer.
    • Constructor Detail

      • FieldDecl

        public FieldDecl​(String name,
                         SourceType type,
                         SourceLocation location)
        Creates a field declaration without an initializer.
        Parameters:
        name - the field name
        type - the field type
        location - the source location, or null for unknown
      • FieldDecl

        public FieldDecl​(String name,
                         SourceType type)
        Creates a field declaration at an unknown location.
        Parameters:
        name - the field name
        type - the field type
    • Method Detail

      • getName

        public String getName()
        Returns:
        the name
      • setName

        public void setName​(String name)
        Sets the field name.
        Parameters:
        name - the field name
      • getModifiers

        public Set<Modifier> getModifiers()
        Returns:
        the modifiers
      • getType

        public SourceType getType()
        Returns:
        the type
      • setType

        public void setType​(SourceType type)
        Sets the field type.
        Parameters:
        type - the field type
      • getInitializer

        public Expression getInitializer()
        Returns:
        the initializer
      • setInitializer

        public void setInitializer​(Expression initializer)
        Sets the initializer expression.
        Parameters:
        initializer - the initial value, or null for none
      • getLocation

        public SourceLocation getLocation()
        Description copied from interface: ASTNode
        Gets the source location of this node.
        Specified by:
        getLocation in interface ASTNode
        Returns:
        the source location, or null if unknown
      • 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 FieldDecl withName​(String name)
        Sets the field name.
        Parameters:
        name - the field name
        Returns:
        this declaration
      • withType

        public FieldDecl withType​(SourceType type)
        Sets the field type.
        Parameters:
        type - the field type
        Returns:
        this declaration
      • withModifiers

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

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

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

        public FieldDecl withInitializer​(Expression initializer)
        Replaces the initializer, adopting the new expression and releasing the old one.
        Parameters:
        initializer - the initial value, or null for none
        Returns:
        this declaration
      • hasInitializer

        public boolean hasInitializer()
        Returns:
        true if the field has an initializer
      • isPublic

        public boolean isPublic()
        Returns:
        true if the public modifier is present
      • isProtected

        public boolean isProtected()
        Returns:
        true if the protected modifier is present
      • isPrivate

        public boolean isPrivate()
        Returns:
        true if the private modifier is present
      • isStatic

        public boolean isStatic()
        Returns:
        true if the static modifier is present
      • isFinal

        public boolean isFinal()
        Returns:
        true if the final modifier is present
      • isTransient

        public boolean isTransient()
        Returns:
        true if the transient modifier is present
      • isVolatile

        public boolean isVolatile()
        Returns:
        true if the volatile modifier is present
      • 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