Class ParameterDecl

  • All Implemented Interfaces:
    ASTNode

    public final class ParameterDecl
    extends Object
    implements ASTNode
    A method or constructor parameter in the source AST, carrying its type, annotations, and the final and varargs flags.
    • Constructor Detail

      • ParameterDecl

        public ParameterDecl​(String name,
                             SourceType type,
                             SourceLocation location)
        Creates a parameter that is neither final nor varargs and has no annotations.
        Parameters:
        name - the parameter name
        type - the declared type
        location - the source position, or null for UNKNOWN
      • ParameterDecl

        public ParameterDecl​(String name,
                             SourceType type)
        Creates a parameter with no source position.
        Parameters:
        name - the parameter name
        type - the declared type
    • Method Detail

      • getName

        public String getName()
        Returns:
        the name
      • setName

        public void setName​(String name)
        Renames the parameter.
        Parameters:
        name - the new name
      • getType

        public SourceType getType()
        Returns:
        the type
      • setType

        public void setType​(SourceType type)
        Replaces the declared type.
        Parameters:
        type - the new type
      • isFinal

        public boolean isFinal()
        Returns:
        whether final
      • setFinal

        public void setFinal​(boolean isFinal)
        Marks the parameter final or not.
        Parameters:
        isFinal - true to print a final modifier
      • isVarArgs

        public boolean isVarArgs()
        Returns:
        whether var args
      • setVarArgs

        public void setVarArgs​(boolean isVarArgs)
        Marks the parameter varargs or not.
        Parameters:
        isVarArgs - true to print the type with a trailing ellipsis
      • 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)
        Records the node this parameter hangs under.
        Specified by:
        setParent in interface ASTNode
        Parameters:
        parent - the enclosing node
      • withName

        public ParameterDecl withName​(String name)
        Renames the parameter.
        Parameters:
        name - the new name
        Returns:
        this parameter
      • withType

        public ParameterDecl withType​(SourceType type)
        Replaces the declared type.
        Parameters:
        type - the new type
        Returns:
        this parameter
      • withFinal

        public ParameterDecl withFinal​(boolean isFinal)
        Marks the parameter final or not.
        Parameters:
        isFinal - true to print a final modifier
        Returns:
        this parameter
      • withVarArgs

        public ParameterDecl withVarArgs​(boolean isVarArgs)
        Marks the parameter varargs or not.
        Parameters:
        isVarArgs - true to print the type with a trailing ellipsis
        Returns:
        this parameter
      • addAnnotation

        public ParameterDecl addAnnotation​(AnnotationExpr annotation)
        Appends an annotation.
        Parameters:
        annotation - the annotation to add
        Returns:
        this parameter
      • 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