Class LambdaExpression


  • public class LambdaExpression
    extends Expression
    Lambda expression AST node type (added in JLS8 API).
     LambdaExpression:
        Identifier -> Body
        ( [ Identifier { , Identifier } ] ) -> Body
        ( [ FormalParameter { , FormalParameter } ] ) -> Body
     

    The first two forms use VariableDeclarationFragment for the parameter or parameters, while the third form uses SingleVariableDeclaration.

    The Body can be either a Block or an Expression.

    Since:
    3.10
    Restriction:
    This class is not intended to be instantiated by clients
    • Method Detail

      • propertyDescriptors

        public static List propertyDescriptors​(int apiLevel)
        Returns a list of structural property descriptors for this node type. Clients must not modify the result.
        Parameters:
        apiLevel - the API level; one of the AST.JLS* constants
        Returns:
        a list of property descriptors (element type: StructuralPropertyDescriptor)
      • hasParentheses

        public boolean hasParentheses()
        Returns whether parentheses around the parameters are present or not.

        Note that parentheses are required unless parameters() contains just a single VariableDeclarationFragment. ASTRewrite may ignore this property if necessary.

        Returns:
        true if this lambda expression has parentheses around its parameters and false otherwise
      • setParentheses

        public void setParentheses​(boolean hasParentheses)
        Sets whether this lambda expression has parentheses around its parameters or not.

        Note that parentheses are required unless parameters() contains just a single VariableDeclarationFragment. ASTRewrite may ignore this property if necessary.

        Parameters:
        hasParentheses - true if this lambda expression has parentheses around its parameters and false otherwise
      • parameters

        public List parameters()
        Returns the live ordered list of formal parameters of this lambda expression. Note that all elements must be of the same type, either
        Returns:
        the live list of formal parameters of this lambda expression (element type: VariableDeclaration)
      • getBody

        public ASTNode getBody()
        Returns the body of this lambda expression.
        Returns:
        the lambda expression body, which can be either a Block or an Expression
      • setBody

        public void setBody​(ASTNode body)
        Sets the body of this lambda expression.
        Parameters:
        body - a block node or an expression node
        Throws:
        IllegalArgumentException - if:
        • the node belongs to a different AST
        • the node already has a parent
        • a cycle in would be created
        • body is neither a Block nor an Expression
      • resolveMethodBinding

        public IMethodBinding resolveMethodBinding()
        Resolves and returns the binding for the lambda expression

        Note that bindings are generally unavailable unless requested when the AST is being built.

        Returns:
        the binding, or null if the binding cannot be resolved