Package spoon.reflect.declaration
Interface CtMethod<T>
- All Superinterfaces:
Cloneable
,CtBodyHolder
,CtElement
,CtExecutable<T>
,CtFormalTypeDeclarer
,CtModifiable
,CtNamedElement
,CtQueryable
,CtShadowable
,CtTypedElement<T>
,CtTypeMember
,CtVisitable
,FactoryAccessor
,Serializable
,SourcePositionHolder
- All Known Subinterfaces:
CtAnnotationMethod<T>
- All Known Implementing Classes:
CtAnnotationMethodImpl
,CtMethodImpl
This element defines a method declaration.
-
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.CtMethod<?>
Copy the method, where copy means cloning + porting all the references of the old method to the new method (important for recursive methods).Collection<CtMethod<?>>
Returns the top-most methods in the hierarchy defining this method (in super class and super interfaces).boolean
Checks if the method is a default method.boolean
isOverriding(CtMethod<?> superMethod)
setDefaultMethod(boolean defaultMethod)
Sets the default value state of a method.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.CtFormalTypeDeclarer
addFormalCtTypeParameter, addFormalCtTypeParameterAt, getFormalCtTypeParameters, removeFormalCtTypeParameter, setFormalCtTypeParameters
Methods inherited from interface spoon.reflect.declaration.CtModifiable
addModifier, getExtendedModifiers, getModifiers, getVisibility, hasModifier, isAbstract, isFinal, isNative, isPrivate, isProtected, isPublic, isStatic, isStrictfp, isSynchronized, isTransient, isVolatile, removeModifier, setExtendedModifiers, setModifiers, setVisibility
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.CtShadowable
isShadow, setShadow
Methods inherited from interface spoon.reflect.declaration.CtTypedElement
getType, setType
Methods inherited from interface spoon.reflect.declaration.CtTypeMember
getDeclaringType, getTopLevelType
Methods inherited from interface spoon.reflect.visitor.CtVisitable
accept
Methods inherited from interface spoon.processing.FactoryAccessor
getFactory, setFactory
-
Method Details
-
isOverriding
- Parameters:
superMethod
- to be checked method- Returns:
- true if this method overrides `superMethod`.
Returns true for itself too.assertTrue(this.isOverriding(this))
-
isDefaultMethod
boolean isDefaultMethod()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. -
setDefaultMethod
Sets the default value state of a method. -
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 interfaceCtNamedElement
-
getTopDefinitions
Collection<CtMethod<?>> getTopDefinitions()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. -
copyMethod
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). 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)
-