Class LambdaExpr
- java.lang.Object
-
- com.tonic.analysis.source.ast.expr.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 Summary
Constructors Constructor Description LambdaExpr(List<LambdaParameter> parameters, ASTNode body, SourceType type)Creates a lambda with an unknown source location.LambdaExpr(List<LambdaParameter> parameters, ASTNode body, SourceType type, SourceLocation location)Creates a lambda over a defensive copy of the parameters and reparents the body.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> Taccept(SourceVisitor<T> visitor)Accepts a visitor for this node.StatementgetBlockBody()Returns the body as a statement block.ASTNodegetBody()List<ASTNode>getChildren()Lists the direct children a node holds, in source order.ExpressiongetExpressionBody()Returns the body as an expression.StringgetImplMethodKey()SourceLocationgetLocation()Gets the source location of this node.intgetParameterCount()List<LambdaParameter>getParameters()ASTNodegetParent()Gets the parent node in the AST tree.SourceTypegetType()Gets the inferred type of this expression.booleanhasImplicitParameterTypes()booleanisBlockBody()booleanisExpressionBody()voidsetBody(ASTNode body)Replaces the body, reparenting the new child.voidsetParent(ASTNode parent)Sets the parent node in the AST tree.StringtoString()LambdaExprwithBody(ASTNode body)Replaces the body, reparenting the new child and releasing the former one.LambdaExprwithImplMethodKey(String implMethodKey)Records the synthetic implementation method key this lambda was built from.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.tonic.analysis.source.ast.ASTNode
deepClone, findAll, findAll, findAncestor, findFirst, findFirst, getRoot, isDescendantOf, remove, replaceWith, stream, stream, walk
-
-
-
-
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 nonebody- the body, an Expression or a Statement blocktype- the functional interface type of the lambdalocation- 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 nonebody- the body, an Expression or a Statement blocktype- the functional interface type of the lambda- Throws:
NullPointerException- if body or type is null
-
-
Method Detail
-
getParameters
public List<LambdaParameter> getParameters()
- Returns:
- the parameters
-
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:ExpressionGets the inferred type of this expression.- Specified by:
getTypein interfaceExpression- Returns:
- the type
-
getLocation
public SourceLocation getLocation()
Description copied from interface:ASTNodeGets the source location of this node.- Specified by:
getLocationin interfaceASTNode- Returns:
- the location
-
getParent
public ASTNode getParent()
Description copied from interface:ASTNodeGets the parent node in the AST tree.
-
setParent
public void setParent(ASTNode parent)
Description copied from interface:ASTNodeSets the parent node in the AST tree.
-
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:ASTNodeLists the direct children a node holds, in source order.- Specified by:
getChildrenin interfaceASTNode- Returns:
- the direct children, empty for a leaf
-
accept
public <T> T accept(SourceVisitor<T> visitor)
Description copied from interface:ASTNodeAccepts a visitor for this node.
-
-