Package spoon.support.reflect.reference
Class CtExecutableReferenceImpl<T>
- java.lang.Object
-
- spoon.support.reflect.declaration.CtElementImpl
-
- spoon.support.reflect.reference.CtReferenceImpl
-
- spoon.support.reflect.reference.CtExecutableReferenceImpl<T>
-
- All Implemented Interfaces:
Serializable
,Cloneable
,FactoryAccessor
,SourcePositionHolder
,CtElement
,CtActualTypeContainer
,CtExecutableReference<T>
,CtReference
,CtQueryable
,CtVisitable
public class CtExecutableReferenceImpl<T> extends CtReferenceImpl implements CtExecutableReference<T>
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class spoon.support.reflect.reference.CtReferenceImpl
simplename
-
Fields inherited from class spoon.support.reflect.declaration.CtElementImpl
ERROR_MESSAGE_TO_STRING, factory, LOGGER, parent
-
Fields inherited from interface spoon.reflect.reference.CtExecutableReference
CONSTRUCTOR_NAME, LAMBDA_NAME_PREFIX, UNKNOWN_TYPE
-
-
Constructor Summary
Constructors Constructor Description CtExecutableReferenceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
accept(CtVisitor visitor)
Accepts a visitor<C extends CtActualTypeContainer>
CaddActualTypeArgument(CtTypeReference<?> actualTypeArgument)
Adds a type argument.CtExecutableReference<T>
clone()
Clone the element which calls this method in a new object.protected AnnotatedElement
getActualAnnotatedElement()
Constructor<?>
getActualConstructor()
Gets the runtime constructor that corresponds to an executable reference if any.Method
getActualMethod()
Gets the runtime method that corresponds to an executable reference if any.List<CtTypeReference<?>>
getActualTypeArguments()
Gets the type arguments.CtExecutable<T>
getDeclaration()
Returns the declaration that corresponds to the referenced element only if the declaration is in the analyzed source files.CtTypeReference<?>
getDeclaringType()
Gets the reference to the type that declares this executable.CtExecutable<T>
getExecutableDeclaration()
Returns a subtypeCtExecutable
that corresponds to the reference even if its declaring type isn't in the Spoon source path (in this case, the Spoon elements are built with runtime reflection).Set<ModifierKind>
getModifiers()
CtExecutableReference<?>
getOverridingExecutable()
Returns the method overridden by this one, if exists (null otherwise).<S extends T>
CtExecutableReference<S>getOverridingExecutable(CtTypeReference<?> subType)
Gets an overriding executable for this executable from a given subtype, if exists.List<CtTypeReference<?>>
getParameters()
Gets parameters of the executable.String
getSignature()
Gets the signature of this method or constructor, as explained inCtExecutable.getSignature()
.CtTypeReference<T>
getType()
For methods, gets the return type of the executable (may be null in noclasspath mode).boolean
isConstructor()
Tells if this is a reference to a constructor.boolean
isFinal()
Tells if the referenced executable is final.boolean
isOverriding(CtExecutableReference<?> executable)
Returnstrue
if this executable overrides the given executable.boolean
isStatic()
Tells if the referenced executable is static.boolean
removeActualTypeArgument(CtTypeReference<?> actualTypeArgument)
Removes a type argument.<C extends CtActualTypeContainer>
CsetActualTypeArguments(List<? extends CtTypeReference<?>> actualTypeArguments)
Sets the type arguments.<C extends CtExecutableReference<T>>
CsetDeclaringType(CtTypeReference<?> declaringType)
Sets the declaring type.<C extends CtExecutableReference<T>>
CsetParameters(List<CtTypeReference<?>> parameters)
Sets parameters of the executable.<C extends CtExecutableReference<T>>
CsetStatic(boolean stat)
Sets this executable reference to be static or not.<C extends CtExecutableReference<T>>
CsetType(CtTypeReference type)
Sets the type of the variable.-
Methods inherited from class spoon.support.reflect.reference.CtReferenceImpl
equals, getSimpleName, setComments, setSimpleName
-
Methods inherited from class spoon.support.reflect.declaration.CtElementImpl
addAnnotation, addComment, asIterable, comment, delete, descendantIterator, emptyList, emptySet, filterChildren, getAllMetadata, getAnnotatedChildren, getAnnotation, getAnnotation, getAnnotations, getComments, getDirectChildren, getDocComment, getElements, getFactory, getMetadata, getMetadataKeys, getOriginalSourceFragment, getParent, getParent, getParent, getPath, getPosition, getReferencedTypes, getRoleInParent, getShortRepresentation, getValueByRole, hasAnnotation, hashCode, hasParent, isImplicit, isParentInitialized, map, map, prettyprint, putMetadata, removeAnnotation, removeComment, replace, replace, setAllMetadata, setAnnotations, setDocComment, setFactory, setImplicit, setParent, setPosition, setPositions, setValueByRole, toString, toStringDebug, unmodifiableList, updateAllParentsBelow
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
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, setDocComment, setImplicit, setParent, setPosition, setPositions, setValueByRole, toString, toStringDebug, updateAllParentsBelow
-
Methods inherited from interface spoon.reflect.visitor.chain.CtQueryable
filterChildren, map, map
-
Methods inherited from interface spoon.reflect.reference.CtReference
getSimpleName, setComments, setSimpleName
-
Methods inherited from interface spoon.processing.FactoryAccessor
getFactory, setFactory
-
-
-
-
Method Detail
-
accept
public void accept(CtVisitor visitor)
Description copied from interface:CtVisitable
Accepts a visitor- Specified by:
accept
in interfaceCtVisitable
-
getActualTypeArguments
public List<CtTypeReference<?>> getActualTypeArguments()
Description copied from interface:CtActualTypeContainer
Gets the type arguments.- Specified by:
getActualTypeArguments
in interfaceCtActualTypeContainer
-
isConstructor
public boolean isConstructor()
Description copied from interface:CtExecutableReference
Tells if this is a reference to a constructor.- Specified by:
isConstructor
in interfaceCtExecutableReference<T>
-
getDeclaration
public CtExecutable<T> getDeclaration()
Description copied from interface:CtReference
Returns the declaration that corresponds to the referenced element only if the declaration is in the analyzed source files. It is strongly advised to use the more robustCtTypeReference.getTypeDeclaration()
andCtExecutableReference.getExecutableDeclaration()
that never return null.- Specified by:
getDeclaration
in interfaceCtExecutableReference<T>
- Specified by:
getDeclaration
in interfaceCtReference
- Returns:
- referenced element or null if element is not in the source path (aka input resource).
-
getExecutableDeclaration
public CtExecutable<T> getExecutableDeclaration()
Description copied from interface:CtExecutableReference
Returns a subtypeCtExecutable
that corresponds to the reference even if its declaring type isn't in the Spoon source path (in this case, the Spoon elements are built with runtime reflection).- Specified by:
getExecutableDeclaration
in interfaceCtExecutableReference<T>
- Returns:
- the executable declaration that corresponds to the reference.
-
getDeclaringType
public CtTypeReference<?> getDeclaringType()
Description copied from interface:CtExecutableReference
Gets the reference to the type that declares this executable.- Specified by:
getDeclaringType
in interfaceCtExecutableReference<T>
-
getType
public CtTypeReference<T> getType()
Description copied from interface:CtExecutableReference
For methods, gets the return type of the executable (may be null in noclasspath mode). For constructors, gets the constructor class (which is also the return type of the contructor calls).- Specified by:
getType
in interfaceCtExecutableReference<T>
-
getParameters
public List<CtTypeReference<?>> getParameters()
Description copied from interface:CtExecutableReference
Gets parameters of the executable.- Specified by:
getParameters
in interfaceCtExecutableReference<T>
-
setParameters
public <C extends CtExecutableReference<T>> C setParameters(List<CtTypeReference<?>> parameters)
Description copied from interface:CtExecutableReference
Sets parameters of the executable.- Specified by:
setParameters
in interfaceCtExecutableReference<T>
-
getOverridingExecutable
public <S extends T> CtExecutableReference<S> getOverridingExecutable(CtTypeReference<?> subType)
Description copied from interface:CtExecutableReference
Gets an overriding executable for this executable from a given subtype, if exists.- Specified by:
getOverridingExecutable
in interfaceCtExecutableReference<T>
- Type Parameters:
S
- subtype of T- Parameters:
subType
- starting bottom type to find an overriding executable (subtypes are not tested)- Returns:
- the first found (most concrete) executable that overrides this executable (null if none found)
-
isOverriding
public boolean isOverriding(CtExecutableReference<?> executable)
Description copied from interface:CtExecutableReference
Returnstrue
if this executable overrides the given executable.- Specified by:
isOverriding
in interfaceCtExecutableReference<T>
-
setActualTypeArguments
public <C extends CtActualTypeContainer> C setActualTypeArguments(List<? extends CtTypeReference<?>> actualTypeArguments)
Description copied from interface:CtActualTypeContainer
Sets the type arguments.- Specified by:
setActualTypeArguments
in interfaceCtActualTypeContainer
-
setDeclaringType
public <C extends CtExecutableReference<T>> C setDeclaringType(CtTypeReference<?> declaringType)
Description copied from interface:CtExecutableReference
Sets the declaring type.- Specified by:
setDeclaringType
in interfaceCtExecutableReference<T>
-
setType
public <C extends CtExecutableReference<T>> C setType(CtTypeReference type)
Description copied from interface:CtExecutableReference
Sets the type of the variable.- Specified by:
setType
in interfaceCtExecutableReference<T>
-
getActualAnnotatedElement
protected AnnotatedElement getActualAnnotatedElement()
- Specified by:
getActualAnnotatedElement
in classCtReferenceImpl
-
getActualMethod
public Method getActualMethod()
Description copied from interface:CtExecutableReference
Gets the runtime method that corresponds to an executable reference if any.- Specified by:
getActualMethod
in interfaceCtExecutableReference<T>
- Returns:
- the method (null if not found)
-
getActualConstructor
public Constructor<?> getActualConstructor()
Description copied from interface:CtExecutableReference
Gets the runtime constructor that corresponds to an executable reference if any.- Specified by:
getActualConstructor
in interfaceCtExecutableReference<T>
- Returns:
- the constructor (null if not found)
-
isStatic
public boolean isStatic()
Description copied from interface:CtExecutableReference
Tells if the referenced executable is static.- Specified by:
isStatic
in interfaceCtExecutableReference<T>
-
setStatic
public <C extends CtExecutableReference<T>> C setStatic(boolean stat)
Description copied from interface:CtExecutableReference
Sets this executable reference to be static or not.- Specified by:
setStatic
in interfaceCtExecutableReference<T>
-
isFinal
public boolean isFinal()
Description copied from interface:CtExecutableReference
Tells if the referenced executable is final.- Specified by:
isFinal
in interfaceCtExecutableReference<T>
-
getModifiers
public Set<ModifierKind> getModifiers()
-
getOverridingExecutable
public CtExecutableReference<?> getOverridingExecutable()
Description copied from interface:CtExecutableReference
Returns the method overridden by this one, if exists (null otherwise). The returned method is searched in the superclass hierarchy (and not in the super-interfaces). The returned method can be an abstract method from an abstract class, a super implementation, or even a method from Object.- Specified by:
getOverridingExecutable
in interfaceCtExecutableReference<T>
-
addActualTypeArgument
public <C extends CtActualTypeContainer> C addActualTypeArgument(CtTypeReference<?> actualTypeArgument)
Description copied from interface:CtActualTypeContainer
Adds a type argument.- Specified by:
addActualTypeArgument
in interfaceCtActualTypeContainer
-
removeActualTypeArgument
public boolean removeActualTypeArgument(CtTypeReference<?> actualTypeArgument)
Description copied from interface:CtActualTypeContainer
Removes a type argument.- Specified by:
removeActualTypeArgument
in interfaceCtActualTypeContainer
-
getSignature
public String getSignature()
Description copied from interface:CtExecutableReference
Gets the signature of this method or constructor, as explained inCtExecutable.getSignature()
.- Specified by:
getSignature
in interfaceCtExecutableReference<T>
-
clone
public CtExecutableReference<T> 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 interfaceCtExecutableReference<T>
- Specified by:
clone
in interfaceCtReference
- Overrides:
clone
in classCtReferenceImpl
-
-