Class MethodFactory


public class MethodFactory extends ExecutableFactory
The CtMethod sub-factory.
  • Field Details

    • OBJECT_METHODS

      public final Set<CtMethod<?>> OBJECT_METHODS
  • Constructor Details

    • MethodFactory

      public MethodFactory(Factory factory)
      Creates a new method sub-factory.
      Parameters:
      factory - the parent factory
  • Method Details

    • create

      public <R,​ B extends R> CtMethod<R> create(CtClass<?> target, Set<ModifierKind> modifiers, CtTypeReference<R> returnType, String name, List<CtParameter<?>> parameters, Set<CtTypeReference<? extends Throwable>> thrownTypes, CtBlock<B> body)
      Creates a method.
      Parameters:
      target - the class where the method is inserted
      modifiers - the modifiers
      returnType - the method's return type
      name - the method's name
      parameters - the parameters
      thrownTypes - the thrown types
      body - the method's body
    • create

      public <T> CtMethod<T> create(CtType<?> target, CtMethod<T> source, boolean redirectReferences)
      Creates a method by copying an existing method.
      Type Parameters:
      T - the type of the method
      Parameters:
      target - the target type where the new method has to be inserted to
      source - the source method to be copied
      redirectReferences - tells if all the references to the owning type of the source method should be redirected to the target type (true is recommended for most uses)
      Returns:
      the newly created method
    • create

      public <T> CtMethod<T> create(CtType<?> target, Set<ModifierKind> modifiers, CtTypeReference<T> returnType, String name, List<CtParameter<?>> parameters, Set<CtTypeReference<? extends Throwable>> thrownTypes)
      Creates an empty method.
      Parameters:
      target - the class where the method is inserted
      modifiers - the modifiers
      returnType - the method's return type
      name - the method's name
      parameters - the parameters
      thrownTypes - the thrown types
    • createReference

      public <T> CtExecutableReference<T> createReference(CtMethod<T> m)
      Creates a method reference.
    • createReference

      public <T> CtExecutableReference<T> createReference(Method method)
      Creates a method reference from an actual method.
    • getMainMethods

      public Collection<CtMethod<Void>> getMainMethods()
      Gets all the main methods stored in this factory.