Package spoon.reflect.code
Interface CtLambda<T>
- Type Parameters:
T- created type
- All Superinterfaces:
Cloneable,CtBodyHolder,CtCodeElement,CtElement,CtExecutable<T>,CtExpression<T>,CtNamedElement,CtQueryable,CtTypedElement<T>,CtVisitable,FactoryAccessor,Serializable,SourcePositionHolder,TemplateParameter<T>
- All Known Implementing Classes:
CtLambdaImpl
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.
-
Field Summary
Fields inherited from interface spoon.reflect.declaration.CtExecutable
EXECUTABLE_SEPARATOR -
Method Summary
Modifier and TypeMethodDescriptionclone()Clone the element which calls this method in a new object.Gets the expression in the body.<R> CtMethod<R>setExpression(CtExpression<T> expression)Sets the expression in the body of the lambda.<T1 extends CtExecutable<T>>
T1setThrownTypes(Set<CtTypeReference<? extends Throwable>> thrownTypes)Sets the thrown types.Methods inherited from interface spoon.reflect.code.CtBodyHolder
setBodyMethods inherited from interface spoon.reflect.code.CtCodeElement
partiallyEvaluateMethods inherited from interface spoon.reflect.declaration.CtElement
addAnnotation, addComment, asIterable, delete, descendantIterator, getAllMetadata, getAnnotatedChildren, getAnnotation, getAnnotation, getAnnotations, getComments, getDirectChildren, getDocComment, getElements, getMetadata, getMetadataKeys, getOriginalSourceFragment, getParent, getParent, getParent, getPath, getPosition, getReferencedTypes, getRoleInParent, getShortRepresentation, getValueByRole, hasAnnotation, hasParent, isImplicit, isParentInitialized, prettyprint, putMetadata, removeAnnotation, removeComment, replace, replace, setAllMetadata, setAnnotations, setComments, setDocComment, setImplicit, setParent, setPosition, setPositions, setValueByRole, toString, toStringDebug, updateAllParentsBelowMethods inherited from interface spoon.reflect.declaration.CtExecutable
addParameter, addParameterAt, addThrownType, getBody, getParameters, getReference, getSignature, getThrownTypes, removeParameter, removeThrownType, setParametersMethods inherited from interface spoon.reflect.code.CtExpression
addTypeCast, getTypeCasts, setTypeCastsMethods inherited from interface spoon.reflect.declaration.CtNamedElement
getSimpleName, setSimpleNameMethods inherited from interface spoon.reflect.visitor.chain.CtQueryable
filterChildren, map, mapMethods inherited from interface spoon.reflect.declaration.CtTypedElement
getType, setTypeMethods inherited from interface spoon.reflect.visitor.CtVisitable
acceptMethods inherited from interface spoon.processing.FactoryAccessor
getFactory, setFactoryMethods inherited from interface spoon.template.TemplateParameter
S
-
Method Details
-
getExpression
CtExpression<T> getExpression()Gets the expression in the body. Null if the body is a list of statements. -
getOverriddenMethod
- Returns:
- the method that this lambda expression implements. Must be defined as a non-default method in an interface, e.g. Consumer.accept().
-
setExpression
Sets the expression in the body of the lambda. Nothing will change if the lambda already has a value in the body attribute. -
clone
Description copied from interface:CtElementClone the element which calls this method in a new object. Note that that references are kept as is, and thus, so if you clone whole classes or methods, some parts of the cloned element (eg executable references) may still point to the initial element. In this case, consider using methodsRefactoring.copyType(CtType)andRefactoring.copyMethod(CtMethod)instead which does additional work beyond cloning.- Specified by:
clonein interfaceCtCodeElement- Specified by:
clonein interfaceCtElement- Specified by:
clonein interfaceCtExecutable<T>- Specified by:
clonein interfaceCtExpression<T>- Specified by:
clonein interfaceCtNamedElement
-
setThrownTypes
<T1 extends CtExecutable<T>> T1 setThrownTypes(Set<CtTypeReference<? extends Throwable>> thrownTypes)Description copied from interface:CtExecutableSets the thrown types.- Specified by:
setThrownTypesin interfaceCtExecutable<T>
-