Class CtExecutableImpl<R>

All Implemented Interfaces:
Serializable, Cloneable, FactoryAccessor, CtBodyHolder, SourcePositionHolder, CtElement, CtExecutable<R>, CtNamedElement, CtTypedElement<R>, CtQueryable, CtVisitable
Direct Known Subclasses:
CtAnonymousExecutableImpl, CtConstructorImpl, CtMethodImpl

public abstract class CtExecutableImpl<R> extends CtNamedElementImpl implements CtExecutable<R>
The implementation for CtExecutable.
Author:
Renaud Pawlak
See Also:
Serialized Form
  • Constructor Details

    • CtExecutableImpl

      public CtExecutableImpl()
  • Method Details

    • getDeclaringType

      public CtType<?> getDeclaringType()
    • getTopLevelType

      public <T> CtType<T> getTopLevelType()
    • getBody

      public CtBlock<R> getBody()
      Description copied from interface: CtExecutable
      Gets the body expression.
      Specified by:
      getBody in interface CtBodyHolder
      Specified by:
      getBody in interface CtExecutable<R>
    • setBody

      public <T extends CtBodyHolder> T setBody(CtStatement statement)
      Description copied from interface: CtBodyHolder
      Sets the body of this element. If body is not a block, it is wrapped in a CtBlock which is semantically equivalent and eases transformation afterwards if required.
      Specified by:
      setBody in interface CtBodyHolder
    • getParameters

      public List<CtParameter<?>> getParameters()
      Description copied from interface: CtExecutable
      Gets the parameters list.
      Specified by:
      getParameters in interface CtExecutable<R>
    • setParameters

      public <T extends CtExecutable<R>> T setParameters(List<CtParameter<?>> parameters)
      Description copied from interface: CtExecutable
      Sets the parameters.
      Specified by:
      setParameters in interface CtExecutable<R>
    • addParameter

      public <T extends CtExecutable<R>> T addParameter(CtParameter<?> parameter)
      Description copied from interface: CtExecutable
      Add a parameter for this executable
      Specified by:
      addParameter in interface CtExecutable<R>
      Returns:
      true if this element changed as a result of the call
    • addParameterAt

      public <T extends CtExecutable<R>> T addParameterAt(int position, CtParameter<?> parameter)
      Description copied from interface: CtExecutable
      Add a parameter at a specific position in the executable.
      Specified by:
      addParameterAt in interface CtExecutable<R>
      Parameters:
      position - index where the `parameter` needs to be inserted
      parameter - parameter to be inserted
      Returns:
      an object or sub-type of CtExecutable
    • removeParameter

      public boolean removeParameter(CtParameter<?> parameter)
      Description copied from interface: CtExecutable
      Remove a parameter for this executable
      Specified by:
      removeParameter in interface CtExecutable<R>
      Returns:
      true if this element changed as a result of the call
    • getThrownTypes

      public Set<CtTypeReference<? extends Throwable>> getThrownTypes()
      Description copied from interface: CtExecutable
      Returns the exceptions and other throwables listed in this method or constructor's throws clause.
      Specified by:
      getThrownTypes in interface CtExecutable<R>
    • setThrownTypes

      public <T extends CtExecutable<R>> T setThrownTypes(Set<CtTypeReference<? extends Throwable>> thrownTypes)
      Description copied from interface: CtExecutable
      Sets the thrown types.
      Specified by:
      setThrownTypes in interface CtExecutable<R>
    • addThrownType

      public <T extends CtExecutable<R>> T addThrownType(CtTypeReference<? extends Throwable> throwType)
      Description copied from interface: CtExecutable
      add a thrown type.
      Specified by:
      addThrownType in interface CtExecutable<R>
      Returns:
      true if this element changed as a result of the call
    • removeThrownType

      public boolean removeThrownType(CtTypeReference<? extends Throwable> throwType)
      Description copied from interface: CtExecutable
      remove a thrown type.
      Specified by:
      removeThrownType in interface CtExecutable<R>
      Returns:
      true if this element changed as a result of the call
    • getSignature

      public String getSignature()
      Description copied from interface: CtExecutable
      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

      Specified by:
      getSignature in interface CtExecutable<R>
    • getReference

      public CtExecutableReference<R> getReference()
      Description copied from interface: CtNamedElement
      Returns the corresponding reference.
      Specified by:
      getReference in interface CtExecutable<R>
      Specified by:
      getReference in interface CtNamedElement
      Overrides:
      getReference in class CtNamedElementImpl
    • clone

      public 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 methods Refactoring.copyType(CtType) and Refactoring.copyMethod(CtMethod) instead which does additional work beyond cloning.
      Specified by:
      clone in interface CtElement
      Specified by:
      clone in interface CtExecutable<R>
      Specified by:
      clone in interface CtNamedElement
      Overrides:
      clone in class CtNamedElementImpl