Class CtMethodImpl<T>
- java.lang.Object
-
- spoon.support.reflect.declaration.CtElementImpl
-
- spoon.support.reflect.declaration.CtNamedElementImpl
-
- spoon.support.reflect.declaration.CtExecutableImpl<T>
-
- spoon.support.reflect.declaration.CtMethodImpl<T>
-
- All Implemented Interfaces:
Serializable
,Cloneable
,FactoryAccessor
,CtBodyHolder
,SourcePositionHolder
,CtElement
,CtExecutable<T>
,CtFormalTypeDeclarer
,CtMethod<T>
,CtModifiable
,CtNamedElement
,CtShadowable
,CtTypedElement<T>
,CtTypeMember
,CtQueryable
,CtVisitable
- Direct Known Subclasses:
CtAnnotationMethodImpl
public class CtMethodImpl<T> extends CtExecutableImpl<T> implements CtMethod<T>
The implementation forCtMethod
.- Author:
- Renaud Pawlak
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class spoon.support.reflect.declaration.CtElementImpl
ERROR_MESSAGE_TO_STRING, factory, LOGGER, parent
-
Fields inherited from interface spoon.reflect.declaration.CtExecutable
EXECUTABLE_SEPARATOR
-
-
Constructor Summary
Constructors Constructor Description CtMethodImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
accept(CtVisitor v)
Accepts a visitor<C extends CtFormalTypeDeclarer>
CaddFormalCtTypeParameter(CtTypeParameter formalTypeParameter)
Add a type parameter to this generic element.<C extends CtFormalTypeDeclarer>
CaddFormalCtTypeParameterAt(int position, CtTypeParameter formalTypeParameter)
Add a type parameter at a specific position.<C extends CtModifiable>
CaddModifier(ModifierKind modifier)
add a modifierCtMethod<T>
clone()
Clone the element which calls this method in a new object.CtMethod<?>
copyMethod()
Copy the method, where copy means cloning + porting all the references of the old method to the new method (important for recursive methods).Set<CtExtendedModifier>
getExtendedModifiers()
List<CtTypeParameter>
getFormalCtTypeParameters()
Returns the formal type parameters of this generic element.Set<ModifierKind>
getModifiers()
Returns the modifiers of this element, excluding annotations.Collection<CtMethod<?>>
getTopDefinitions()
Returns the top-most methods in the hierarchy defining this method (in super class and super interfaces).CtTypeReference<T>
getType()
Gets this element's type.ModifierKind
getVisibility()
Gets the visibility of this modifiable element.boolean
hasModifier(ModifierKind modifier)
Tells if this element contains the given modifier.boolean
isAbstract()
Returns true if it contains an abstract modifier (seeCtModifiable.hasModifier(ModifierKind)
)boolean
isDefaultMethod()
Checks if the method is a default method.boolean
isFinal()
Returns true if it contains a final modifier (seeCtModifiable.hasModifier(ModifierKind)
)boolean
isNative()
Returns true if it contains a native modifier (seeCtModifiable.hasModifier(ModifierKind)
)boolean
isOverriding(CtMethod<?> superMethod)
boolean
isPrivate()
Returns true if it contains a private modifier (seeCtModifiable.hasModifier(ModifierKind)
)boolean
isProtected()
Returns true if it contains a protected modifier (seeCtModifiable.hasModifier(ModifierKind)
)boolean
isPublic()
Returns true if it contains a public modifier (seeCtModifiable.hasModifier(ModifierKind)
)boolean
isShadow()
When an element isn't present in the factory (created in another factory), this element is considered as "shadow".boolean
isStatic()
Returns true if it contains a static modifier (seeCtModifiable.hasModifier(ModifierKind)
)boolean
isStrictfp()
Returns true if it contains a strictfp modifier (seeCtModifiable.hasModifier(ModifierKind)
)boolean
isSynchronized()
Returns true if it contains a synchronized modifier (seeCtModifiable.hasModifier(ModifierKind)
)boolean
isTransient()
Returns true if it contains a transient modifier (seeCtModifiable.hasModifier(ModifierKind)
)boolean
isVolatile()
Returns true if it contains a volatile modifier (seeCtModifiable.hasModifier(ModifierKind)
)boolean
removeFormalCtTypeParameter(CtTypeParameter formalTypeParameter)
Removes a type parameters from this generic element.<C extends CtModifiable>
CremoveModifier(ModifierKind modifier)
remove a modifier<C extends CtMethod<T>>
CsetDefaultMethod(boolean defaultMethod)
Sets the default value state of a method.<C extends CtModifiable>
CsetExtendedModifiers(Set<CtExtendedModifier> extendedModifiers)
<C extends CtFormalTypeDeclarer>
CsetFormalCtTypeParameters(List<CtTypeParameter> formalTypeParameters)
Sets the type parameters of this generic element.<C extends CtModifiable>
CsetModifiers(Set<ModifierKind> modifiers)
Sets the modifiers.<E extends CtShadowable>
EsetShadow(boolean isShadow)
Marks an element as shadow.<C extends CtTypedElement>
CsetType(CtTypeReference type)
Sets this element's type.<C extends CtModifiable>
CsetVisibility(ModifierKind visibility)
Sets the visibility of this modifiable element (replaces old visibility).-
Methods inherited from class spoon.support.reflect.declaration.CtExecutableImpl
addParameter, addParameterAt, addThrownType, getBody, getDeclaringType, getParameters, getReference, getSignature, getThrownTypes, getTopLevelType, removeParameter, removeThrownType, setBody, setParameters, setThrownTypes
-
Methods inherited from class spoon.support.reflect.declaration.CtNamedElementImpl
getSimpleName, setSimpleName
-
Methods inherited from class spoon.support.reflect.declaration.CtElementImpl
addAnnotation, addComment, asIterable, comment, delete, descendantIterator, emptyList, emptySet, equals, 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, setComments, 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.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.CtExecutable
addParameter, addParameterAt, addThrownType, getBody, getParameters, getReference, getSignature, getThrownTypes, removeParameter, removeThrownType, setParameters, setThrownTypes
-
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.CtTypeMember
getDeclaringType, getTopLevelType
-
Methods inherited from interface spoon.processing.FactoryAccessor
getFactory, setFactory
-
-
-
-
Method Detail
-
accept
public void accept(CtVisitor v)
Description copied from interface:CtVisitable
Accepts a visitor- Specified by:
accept
in interfaceCtVisitable
-
getType
public CtTypeReference<T> getType()
Description copied from interface:CtTypedElement
Gets this element's type.- Specified by:
getType
in interfaceCtTypedElement<T>
-
setType
public <C extends CtTypedElement> C setType(CtTypeReference type)
Description copied from interface:CtTypedElement
Sets this element's type.- Specified by:
setType
in interfaceCtTypedElement<T>
-
isDefaultMethod
public boolean isDefaultMethod()
Description copied from interface:CtMethod
Checks if the method is a default method. Default method can be in interfaces from Java 8: http://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html.- Specified by:
isDefaultMethod
in interfaceCtMethod<T>
-
setDefaultMethod
public <C extends CtMethod<T>> C setDefaultMethod(boolean defaultMethod)
Description copied from interface:CtMethod
Sets the default value state of a method.- Specified by:
setDefaultMethod
in interfaceCtMethod<T>
-
getFormalCtTypeParameters
public List<CtTypeParameter> getFormalCtTypeParameters()
Description copied from interface:CtFormalTypeDeclarer
Returns the formal type parameters of this generic element.- Specified by:
getFormalCtTypeParameters
in interfaceCtFormalTypeDeclarer
-
setFormalCtTypeParameters
public <C extends CtFormalTypeDeclarer> C setFormalCtTypeParameters(List<CtTypeParameter> formalTypeParameters)
Description copied from interface:CtFormalTypeDeclarer
Sets the type parameters of this generic element.- Specified by:
setFormalCtTypeParameters
in interfaceCtFormalTypeDeclarer
-
addFormalCtTypeParameterAt
public <C extends CtFormalTypeDeclarer> C addFormalCtTypeParameterAt(int position, CtTypeParameter formalTypeParameter)
Description copied from interface:CtFormalTypeDeclarer
Add a type parameter at a specific position.- Specified by:
addFormalCtTypeParameterAt
in interfaceCtFormalTypeDeclarer
- Parameters:
position
- Position to insert the type parameter atformalTypeParameter
- The type parameter to insert- Returns:
- The receiver
-
addFormalCtTypeParameter
public <C extends CtFormalTypeDeclarer> C addFormalCtTypeParameter(CtTypeParameter formalTypeParameter)
Description copied from interface:CtFormalTypeDeclarer
Add a type parameter to this generic element.- Specified by:
addFormalCtTypeParameter
in interfaceCtFormalTypeDeclarer
-
removeFormalCtTypeParameter
public boolean removeFormalCtTypeParameter(CtTypeParameter formalTypeParameter)
Description copied from interface:CtFormalTypeDeclarer
Removes a type parameters from this generic element.- Specified by:
removeFormalCtTypeParameter
in interfaceCtFormalTypeDeclarer
-
getModifiers
public Set<ModifierKind> getModifiers()
Description copied from interface:CtModifiable
Returns the modifiers of this element, excluding annotations. Implicit modifiers, such as thepublic
andstatic
modifiers of interface members, are included.- Specified by:
getModifiers
in interfaceCtModifiable
- Returns:
- the modifiers of this declaration in undefined order; an empty set if there are none
-
hasModifier
public boolean hasModifier(ModifierKind modifier)
Description copied from interface:CtModifiable
Tells if this element contains the given modifier.- Specified by:
hasModifier
in interfaceCtModifiable
- Parameters:
modifier
- to search- Returns:
true
if this element contain the modifier
-
setModifiers
public <C extends CtModifiable> C setModifiers(Set<ModifierKind> modifiers)
Description copied from interface:CtModifiable
Sets the modifiers.- Specified by:
setModifiers
in interfaceCtModifiable
-
addModifier
public <C extends CtModifiable> C addModifier(ModifierKind modifier)
Description copied from interface:CtModifiable
add a modifier- Specified by:
addModifier
in interfaceCtModifiable
-
removeModifier
public <C extends CtModifiable> C removeModifier(ModifierKind modifier)
Description copied from interface:CtModifiable
remove a modifier- Specified by:
removeModifier
in interfaceCtModifiable
-
setVisibility
public <C extends CtModifiable> C setVisibility(ModifierKind visibility)
Description copied from interface:CtModifiable
Sets the visibility of this modifiable element (replaces old visibility).- Specified by:
setVisibility
in interfaceCtModifiable
-
getVisibility
public ModifierKind getVisibility()
Description copied from interface:CtModifiable
Gets the visibility of this modifiable element.- Specified by:
getVisibility
in interfaceCtModifiable
-
getExtendedModifiers
public Set<CtExtendedModifier> getExtendedModifiers()
- Specified by:
getExtendedModifiers
in interfaceCtModifiable
- Returns:
- the set of extended modifiers (those incl. implicit).
-
setExtendedModifiers
public <C extends CtModifiable> C setExtendedModifiers(Set<CtExtendedModifier> extendedModifiers)
- Specified by:
setExtendedModifiers
in interfaceCtModifiable
-
isOverriding
public boolean isOverriding(CtMethod<?> superMethod)
- Specified by:
isOverriding
in interfaceCtMethod<T>
- Parameters:
superMethod
- to be checked method- Returns:
- true if this method overrides `superMethod`.
Returns true for itself too.assertTrue(this.isOverriding(this))
-
isShadow
public boolean isShadow()
Description copied from interface:CtShadowable
When an element isn't present in the factory (created in another factory), this element is considered as "shadow". e.g., a shadow element can be a CtType of java.lang.Class built when we callCtTypeReference.getTypeDeclaration()
on a reference of java.lang.Class.- Specified by:
isShadow
in interfaceCtShadowable
- Returns:
- true if the element is a shadow element, otherwise false.
-
setShadow
public <E extends CtShadowable> E setShadow(boolean isShadow)
Description copied from interface:CtShadowable
Marks an element as shadow. To know what is a shadow element, see the javadoc ofCtShadowable.isShadow()
.- Specified by:
setShadow
in interfaceCtShadowable
-
clone
public CtMethod<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 interfaceCtExecutable<T>
- Specified by:
clone
in interfaceCtMethod<T>
- Specified by:
clone
in interfaceCtNamedElement
- Overrides:
clone
in classCtExecutableImpl<T>
-
getTopDefinitions
public Collection<CtMethod<?>> getTopDefinitions()
Description copied from interface:CtMethod
Returns the top-most methods in the hierarchy defining this method (in super class and super interfaces). Returns the empty collection if defined here for the first time.- Specified by:
getTopDefinitions
in interfaceCtMethod<T>
-
isPublic
public boolean isPublic()
Description copied from interface:CtModifiable
Returns true if it contains a public modifier (seeCtModifiable.hasModifier(ModifierKind)
)- Specified by:
isPublic
in interfaceCtModifiable
-
isPrivate
public boolean isPrivate()
Description copied from interface:CtModifiable
Returns true if it contains a private modifier (seeCtModifiable.hasModifier(ModifierKind)
)- Specified by:
isPrivate
in interfaceCtModifiable
-
isProtected
public boolean isProtected()
Description copied from interface:CtModifiable
Returns true if it contains a protected modifier (seeCtModifiable.hasModifier(ModifierKind)
)- Specified by:
isProtected
in interfaceCtModifiable
-
isFinal
public boolean isFinal()
Description copied from interface:CtModifiable
Returns true if it contains a final modifier (seeCtModifiable.hasModifier(ModifierKind)
)- Specified by:
isFinal
in interfaceCtModifiable
-
isStatic
public boolean isStatic()
Description copied from interface:CtModifiable
Returns true if it contains a static modifier (seeCtModifiable.hasModifier(ModifierKind)
)- Specified by:
isStatic
in interfaceCtModifiable
-
isAbstract
public boolean isAbstract()
Description copied from interface:CtModifiable
Returns true if it contains an abstract modifier (seeCtModifiable.hasModifier(ModifierKind)
)- Specified by:
isAbstract
in interfaceCtModifiable
-
isTransient
public boolean isTransient()
Description copied from interface:CtModifiable
Returns true if it contains a transient modifier (seeCtModifiable.hasModifier(ModifierKind)
)- Specified by:
isTransient
in interfaceCtModifiable
-
isVolatile
public boolean isVolatile()
Description copied from interface:CtModifiable
Returns true if it contains a volatile modifier (seeCtModifiable.hasModifier(ModifierKind)
)- Specified by:
isVolatile
in interfaceCtModifiable
-
isSynchronized
public boolean isSynchronized()
Description copied from interface:CtModifiable
Returns true if it contains a synchronized modifier (seeCtModifiable.hasModifier(ModifierKind)
)- Specified by:
isSynchronized
in interfaceCtModifiable
-
isNative
public boolean isNative()
Description copied from interface:CtModifiable
Returns true if it contains a native modifier (seeCtModifiable.hasModifier(ModifierKind)
)- Specified by:
isNative
in interfaceCtModifiable
-
isStrictfp
public boolean isStrictfp()
Description copied from interface:CtModifiable
Returns true if it contains a strictfp modifier (seeCtModifiable.hasModifier(ModifierKind)
)- Specified by:
isStrictfp
in interfaceCtModifiable
-
copyMethod
public CtMethod<?> copyMethod()
Description copied from interface:CtMethod
Copy the method, where copy means cloning + porting all the references of the old method to the new method (important for recursive methods). The copied method is added to the type, with a suffix "Copy". A new unique method name is given for each copy, and this method can be called several times. If you want to rename the new method, useRefactoring.changeMethodName(CtMethod, String)
(and notCtNamedElement.setSimpleName(String)
, which does not update the references)- Specified by:
copyMethod
in interfaceCtMethod<T>
-
-