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
setBody
Methods inherited from interface spoon.reflect.code.CtCodeElement
partiallyEvaluate
Methods 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, updateAllParentsBelow
Methods inherited from interface spoon.reflect.declaration.CtExecutable
addParameter, addParameterAt, addThrownType, getBody, getParameters, getReference, getSignature, getThrownTypes, removeParameter, removeThrownType, setParameters
Methods inherited from interface spoon.reflect.code.CtExpression
addTypeCast, getTypeCasts, setTypeCasts
Methods inherited from interface spoon.reflect.declaration.CtNamedElement
getSimpleName, setSimpleName
Methods inherited from interface spoon.reflect.visitor.chain.CtQueryable
filterChildren, map, map
Methods inherited from interface spoon.reflect.declaration.CtTypedElement
getType, setType
Methods inherited from interface spoon.reflect.visitor.CtVisitable
accept
Methods inherited from interface spoon.processing.FactoryAccessor
getFactory, setFactory
Methods 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:CtElement
Clone 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:
clone
in interfaceCtCodeElement
- Specified by:
clone
in interfaceCtElement
- Specified by:
clone
in interfaceCtExecutable<T>
- Specified by:
clone
in interfaceCtExpression<T>
- Specified by:
clone
in interfaceCtNamedElement
-
setThrownTypes
<T1 extends CtExecutable<T>> T1 setThrownTypes(Set<CtTypeReference<? extends Throwable>> thrownTypes)Description copied from interface:CtExecutable
Sets the thrown types.- Specified by:
setThrownTypes
in interfaceCtExecutable<T>
-