Class LambdaExpr

  • All Implemented Interfaces:
    ASTNode, Expression

    public final class LambdaExpr
    extends Object
    implements Expression
    A lambda expression: (params) -> body, whose body is either an Expression or a Statement block.
    • Constructor Detail

      • LambdaExpr

        public LambdaExpr​(List<LambdaParameter> parameters,
                          ASTNode body,
                          SourceType type,
                          SourceLocation location)
        Creates a lambda over a defensive copy of the parameters and reparents the body.
        Parameters:
        parameters - the lambda parameters, or null for none
        body - the body, an Expression or a Statement block
        type - the functional interface type of the lambda
        location - the source location, or null for unknown
        Throws:
        NullPointerException - if body or type is null
      • LambdaExpr

        public LambdaExpr​(List<LambdaParameter> parameters,
                          ASTNode body,
                          SourceType type)
        Creates a lambda with an unknown source location.
        Parameters:
        parameters - the lambda parameters, or null for none
        body - the body, an Expression or a Statement block
        type - the functional interface type of the lambda
        Throws:
        NullPointerException - if body or type is null
    • Method Detail

      • getBody

        public ASTNode getBody()
        Returns:
        the body
      • setBody

        public void setBody​(ASTNode body)
        Replaces the body, reparenting the new child.
        Parameters:
        body - the new body, an Expression or a Statement block
      • getType

        public SourceType getType()
        Description copied from interface: Expression
        Gets the inferred type of this expression.
        Specified by:
        getType in interface Expression
        Returns:
        the type
      • 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)
        Description copied from interface: ASTNode
        Sets the parent node in the AST tree.
        Specified by:
        setParent in interface ASTNode
        Parameters:
        parent - the enclosing AST node
      • getImplMethodKey

        public String getImplMethodKey()
        Returns:
        the impl method key
      • withBody

        public LambdaExpr withBody​(ASTNode body)
        Replaces the body, reparenting the new child and releasing the former one.
        Parameters:
        body - the new body, an Expression or a Statement block
        Returns:
        this expression
      • withImplMethodKey

        public LambdaExpr withImplMethodKey​(String implMethodKey)
        Records the synthetic implementation method key this lambda was built from.
        Parameters:
        implMethodKey - name plus descriptor, e.g. lambda$foo$0()V; null leaves the key unset
        Returns:
        this expression
      • isExpressionBody

        public boolean isExpressionBody()
        Returns:
        true if the body is a single expression
      • isBlockBody

        public boolean isBlockBody()
        Returns:
        true if the body is a statement block
      • getExpressionBody

        public Expression getExpressionBody()
        Returns the body as an expression.
        Returns:
        the expression body
        Throws:
        IllegalStateException - if the body is a statement block
      • getBlockBody

        public Statement getBlockBody()
        Returns the body as a statement block.
        Returns:
        the block body
        Throws:
        IllegalStateException - if the body is a single expression
      • hasImplicitParameterTypes

        public boolean hasImplicitParameterTypes()
        Returns:
        true if every parameter has an implicit type
      • getParameterCount

        public int getParameterCount()
        Returns:
        the number of parameters
      • 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