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).booleanChecks if the method is a default method.booleanisOverriding(CtMethod<?> superMethod)setDefaultMethod(boolean defaultMethod)Sets the default value state of a method.Methods inherited from interface spoon.reflect.code.CtBodyHolder
setBodyMethods 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, updateAllParentsBelowMethods inherited from interface spoon.reflect.declaration.CtExecutable
addParameter, addParameterAt, addThrownType, getBody, getParameters, getReference, getSignature, getThrownTypes, removeParameter, removeThrownType, setParameters, setThrownTypesMethods inherited from interface spoon.reflect.declaration.CtFormalTypeDeclarer
addFormalCtTypeParameter, addFormalCtTypeParameterAt, getFormalCtTypeParameters, removeFormalCtTypeParameter, setFormalCtTypeParametersMethods 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, setVisibilityMethods inherited from interface spoon.reflect.declaration.CtNamedElement
getSimpleName, setSimpleNameMethods inherited from interface spoon.reflect.visitor.chain.CtQueryable
filterChildren, map, mapMethods inherited from interface spoon.reflect.declaration.CtShadowable
isShadow, setShadowMethods inherited from interface spoon.reflect.declaration.CtTypedElement
getType, setTypeMethods inherited from interface spoon.reflect.declaration.CtTypeMember
getDeclaringType, getTopLevelTypeMethods inherited from interface spoon.reflect.visitor.CtVisitable
acceptMethods 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:CtElementClone 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:
clonein interfaceCtElement- Specified by:
clonein interfaceCtExecutable<T>- Specified by:
clonein 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)
-