Class ConstructorDecl

  • All Implemented Interfaces:
    ASTNode

    public final class ConstructorDecl
    extends Object
    implements ASTNode
    A Java constructor declaration: modifiers, parameters, throws clause, and body.
    • Constructor Detail

      • ConstructorDecl

        public ConstructorDecl​(String name,
                               SourceLocation location)
        Creates an empty constructor declaration.
        Parameters:
        name - the declaring class's simple name
        location - the source location, or null for unknown
      • ConstructorDecl

        public ConstructorDecl​(String name)
        Creates an empty constructor declaration at an unknown location.
        Parameters:
        name - the declaring class's simple name
    • Method Detail

      • getName

        public String getName()
        Returns:
        the name
      • setName

        public void setName​(String name)
        Sets the constructor name.
        Parameters:
        name - the declaring class's simple name
      • getModifiers

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

        public NodeList<SourceType> getTypeParameters()
        Returns:
        the type parameters
      • getBody

        public BlockStmt getBody()
        Returns:
        the body
      • setBody

        public void setBody​(BlockStmt body)
        Sets the constructor body.
        Parameters:
        body - the body block, 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 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 ConstructorDecl withName​(String name)
        Sets the constructor name.
        Parameters:
        name - the declaring class's simple name
        Returns:
        this declaration
      • withModifiers

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

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

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

        public ConstructorDecl addParameter​(ParameterDecl parameter)
        Adds a parameter.
        Parameters:
        parameter - the parameter declaration
        Returns:
        this declaration
      • addTypeParameter

        public ConstructorDecl addTypeParameter​(SourceType typeParam)
        Adds a type parameter.
        Parameters:
        typeParam - the type parameter
        Returns:
        this declaration
      • addThrowsType

        public ConstructorDecl addThrowsType​(SourceType throwsType)
        Adds a declared thrown exception type.
        Parameters:
        throwsType - the exception type
        Returns:
        this declaration
      • withBody

        public ConstructorDecl withBody​(BlockStmt body)
        Replaces the body, adopting the new block and releasing the old one.
        Parameters:
        body - the body block, or null for none
        Returns:
        this declaration
      • 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
      • getSignature

        public String getSignature()
        Builds a name-and-parameter-types signature string.
        Returns:
        the signature, e.g. Foo(int,String)
      • 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