Package spoon.reflect.declaration
Interface CtExecutable<R>
-
- All Superinterfaces:
Cloneable
,CtBodyHolder
,CtElement
,CtNamedElement
,CtQueryable
,CtTypedElement<R>
,CtVisitable
,FactoryAccessor
,Serializable
,SourcePositionHolder
- All Known Subinterfaces:
CtAnnotationMethod<T>
,CtAnonymousExecutable
,CtConstructor<T>
,CtLambda<T>
,CtMethod<T>
- All Known Implementing Classes:
CtAnnotationMethodImpl
,CtAnonymousExecutableImpl
,CtConstructorImpl
,CtExecutableImpl
,CtLambdaImpl
,CtMethodImpl
,InvisibleArrayConstructorImpl
public interface CtExecutable<R> extends CtNamedElement, CtTypedElement<R>, CtBodyHolder
This element represents an executable element such as a method, a constructor, or an anonymous block.
-
-
Field Summary
Fields Modifier and Type Field Description static String
EXECUTABLE_SEPARATOR
The separator for a string representation of an executable.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description <T extends CtExecutable<R>>
TaddParameter(CtParameter<?> parameter)
Add a parameter for this executable<T extends CtExecutable<R>>
TaddParameterAt(int position, CtParameter<?> parameter)
Add a parameter at a specific position in the executable.<T extends CtExecutable<R>>
TaddThrownType(CtTypeReference<? extends Throwable> throwType)
add a thrown type.CtExecutable<R>
clone()
Clone the element which calls this method in a new object.CtBlock<R>
getBody()
Gets the body expression.List<CtParameter<?>>
getParameters()
Gets the parameters list.CtExecutableReference<R>
getReference()
Returns the corresponding reference.String
getSignature()
Gets the signature of this exectuable.Set<CtTypeReference<? extends Throwable>>
getThrownTypes()
Returns the exceptions and other throwables listed in this method or constructor's throws clause.boolean
removeParameter(CtParameter<?> parameter)
Remove a parameter for this executableboolean
removeThrownType(CtTypeReference<? extends Throwable> throwType)
remove a thrown type.<T extends CtExecutable<R>>
TsetParameters(List<CtParameter<?>> parameters)
Sets the parameters.<T extends CtExecutable<R>>
TsetThrownTypes(Set<CtTypeReference<? extends Throwable>> thrownTypes)
Sets the thrown types.-
Methods inherited from interface spoon.reflect.code.CtBodyHolder
setBody
-
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.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
-
-
-
-
Field Detail
-
EXECUTABLE_SEPARATOR
static final String EXECUTABLE_SEPARATOR
The separator for a string representation of an executable.- See Also:
- Constant Field Values
-
-
Method Detail
-
getReference
CtExecutableReference<R> getReference()
Description copied from interface:CtNamedElement
Returns the corresponding reference.- Specified by:
getReference
in interfaceCtNamedElement
-
getBody
CtBlock<R> getBody()
Gets the body expression.- Specified by:
getBody
in interfaceCtBodyHolder
-
getParameters
List<CtParameter<?>> getParameters()
Gets the parameters list.
-
setParameters
<T extends CtExecutable<R>> T setParameters(List<CtParameter<?>> parameters)
Sets the parameters.
-
addParameter
<T extends CtExecutable<R>> T addParameter(CtParameter<?> parameter)
Add a parameter for this executable- Parameters:
parameter
-- Returns:
- true if this element changed as a result of the call
-
addParameterAt
<T extends CtExecutable<R>> T addParameterAt(int position, CtParameter<?> parameter)
Add a parameter at a specific position in the executable.- Parameters:
position
- index where the `parameter` needs to be insertedparameter
- parameter to be inserted- Returns:
- an object or sub-type of
CtExecutable
-
removeParameter
boolean removeParameter(CtParameter<?> parameter)
Remove a parameter for this executable- Parameters:
parameter
-- Returns:
- true if this element changed as a result of the call
-
getThrownTypes
Set<CtTypeReference<? extends Throwable>> getThrownTypes()
Returns the exceptions and other throwables listed in this method or constructor's throws clause.
-
setThrownTypes
<T extends CtExecutable<R>> T setThrownTypes(Set<CtTypeReference<? extends Throwable>> thrownTypes)
Sets the thrown types.
-
addThrownType
<T extends CtExecutable<R>> T addThrownType(CtTypeReference<? extends Throwable> throwType)
add a thrown type.- Parameters:
throwType
-- Returns:
- true if this element changed as a result of the call
-
removeThrownType
boolean removeThrownType(CtTypeReference<? extends Throwable> throwType)
remove a thrown type.- Parameters:
throwType
-- Returns:
- true if this element changed as a result of the call
-
getSignature
String getSignature()
Gets the signature of this exectuable. The signature is composed of the method name and the parameter types, all fully-qualified, eg "foo(java.lang.String)
". The core contract is that in a type, there cannot be two methods with the same signature.Note that the concept of method signature in Java is not well defined (see chapter "8.4.2 Method Signature" of the Java specification, which defines what relations between signatures but not what a signature is exactly).
Note also that the signature of a method reference is the same as the signature of the corresponding method if and only if the method parameters does not involve generics in their types. Otherwise, one has eg m(String) (reference) and m(T) (declaration)
Reference: "In the Java programming language, a method signature is the method name and the number and type of its parameters. Return types and thrown exceptions are not considered to be a part of the method signature."
see Stackoverflow
see Wikipedia
-
clone
CtExecutable<R> 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 interfaceCtElement
- Specified by:
clone
in interfaceCtNamedElement
-
-