Class LambdaExpr

  • All Implemented Interfaces:
    NodeWithParameters<LambdaExpr>, NodeWithRange<Node>, NodeWithTokenRange<Node>, Observable, Visitable, HasParentNode<Node>, java.lang.Cloneable

    public class LambdaExpr
    extends Expression
    implements NodeWithParameters<LambdaExpr>

    A lambda expression

    Java 1-7

    Does not exist.

    Java 8+

    (a, b) -> a + b
    a -> ...
    (Long a) -> { println(a); }

    The parameters are on the left side of the ->. If a parameter uses type inference (it has no type specified) then its type is set to UnknownType. If they are in ( ), "isEnclosingParameters" is true.
    The body is to the right of the ->. The body is either a BlockStmt when it is in { } braces, or an ExpressionStmt when it is not in braces.

    Author:
    Raquel Pau
    • Constructor Detail

      • LambdaExpr

        public LambdaExpr()
      • LambdaExpr

        public LambdaExpr​(Parameter parameter,
                          BlockStmt body)
        Creates a single parameter lambda expression.
      • LambdaExpr

        public LambdaExpr​(NodeList<Parameter> parameters,
                          BlockStmt body)
        Creates a zero or multi-parameter lambda expression with its parameters wrapped in ( ).
      • LambdaExpr

        public LambdaExpr​(Parameter parameter,
                          Expression body)
        Creates a single parameter lambda expression.
      • LambdaExpr

        public LambdaExpr​(NodeList<Parameter> parameters,
                          Expression body)
        Creates a zero or multi-parameter lambda expression with its parameters wrapped in ( ).
      • LambdaExpr

        public LambdaExpr​(TokenRange tokenRange,
                          NodeList<Parameter> parameters,
                          Statement body,
                          boolean isEnclosingParameters)
        This constructor is used by the parser and is considered private.
    • Method Detail

      • getBody

        public Statement getBody()
        Returns:
        a BlockStatement or an ExpressionStatement. See class Javadoc.
      • accept

        public <R,​A> R accept​(GenericVisitor<R,​A> v,
                                    A arg)
        Description copied from interface: Visitable
        Accept method for visitor support.
        Specified by:
        accept in interface Visitable
        Type Parameters:
        R - the type of the return value of the visitor
        A - the type the user argument passed to the visitor
        Parameters:
        v - the visitor implementation
        arg - the argument passed to the visitor (of type A)
        Returns:
        the result of the visit (of type R)
      • accept

        public <A> void accept​(VoidVisitor<A> v,
                               A arg)
        Description copied from interface: Visitable
        Accept method for visitor support.
        Specified by:
        accept in interface Visitable
        Type Parameters:
        A - the type the argument passed for the visitor
        Parameters:
        v - the visitor implementation
        arg - any value relevant for the visitor (of type A)
      • isEnclosingParameters

        public boolean isEnclosingParameters()
      • setEnclosingParameters

        public LambdaExpr setEnclosingParameters​(boolean isEnclosingParameters)
      • remove

        public boolean remove​(Node node)
        Overrides:
        remove in class Node
      • getExpressionBody

        public java.util.Optional<Expression> getExpressionBody()
        Returns:
        if the body of this lambda is a simple expression, return that expression. Otherwise (when the body is a block) return Optional.empty().
      • replace

        public boolean replace​(Node node,
                               Node replacementNode)
        Overrides:
        replace in class Node
      • isPolyExpression

        public boolean isPolyExpression()
        Description copied from class: Expression
        See https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.2
        Overrides:
        isPolyExpression in class Expression
        Returns:
        true if the expression is a poly expression
      • isExplicitlyTyped

        public boolean isExplicitlyTyped()