spoon.reflect.code.CtLambda Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spoon-core Show documentation
Show all versions of spoon-core Show documentation
Spoon is a tool for meta-programming, analysis and transformation of Java programs.
/*
* SPDX-License-Identifier: (MIT OR CECILL-C)
*
* Copyright (C) 2006-2023 INRIA and contributors
*
* Spoon is available either under the terms of the MIT License (see LICENSE-MIT.txt) or the Cecill-C License (see LICENSE-CECILL-C.txt). You as the user are entitled to choose the terms under which to adopt Spoon.
*/
package spoon.reflect.code;
import org.jspecify.annotations.Nullable;
import spoon.reflect.declaration.CtExecutable;
import spoon.reflect.declaration.CtMethod;
import spoon.reflect.declaration.CtReceiverParameter;
import spoon.reflect.reference.CtTypeReference;
import spoon.support.DerivedProperty;
import spoon.reflect.annotations.PropertyGetter;
import spoon.reflect.annotations.PropertySetter;
import spoon.support.UnsettableProperty;
import java.util.Set;
import static spoon.reflect.path.CtRole.EXPRESSION;
/**
* This code element represents the creation of a lambda. A lambda
* can have two sorts of body : an simple expression or a block of
* statements. The usage of this concept in this class is:
*
*
* java.util.List l = new java.util.ArrayList();
* l.stream().map(
* x -> { return x.toString(); } // a lambda
* );
*
*
*
* -
* If your lambda has an expression, getBody method will
* return null and getExpression method will return a
* CtExpression.
*
* -
* If your lambda has a block of statement, getExpression
* method will return null and getBody will returns a CtBlock
* with all statements.
*
*
*
* So keep this in mind when you would like the body of a CtLambda.
*
* @param
* created type
*/
public interface CtLambda extends CtExpression, CtExecutable {
/**
* Gets the expression in the body. Null if the body is a list
* of statements.
*/
@PropertyGetter(role = EXPRESSION)
CtExpression getExpression();
/**
* @return the method that this lambda expression implements.
* Must be defined as a non-default method in an interface, e.g. Consumer.accept().
*/
@DerivedProperty
CtMethod getOverriddenMethod();
/**
* Sets the expression in the body of the lambda. Nothing will change
* if the lambda already has a value in the body attribute.
*/
@PropertySetter(role = EXPRESSION)
> C setExpression(CtExpression expression);
@Override
CtLambda clone();
@Override
@UnsettableProperty
> T1 setThrownTypes(Set> thrownTypes);
@UnsettableProperty
CtExecutable> setReceiverParameter(CtReceiverParameter receiverParameter);
@UnsettableProperty
@Nullable
CtReceiverParameter getReceiverParameter();
}