Class MethodFactory

java.lang.Object
org.jruby.runtime.MethodFactory
Direct Known Subclasses:
InvocationMethodFactory

public abstract class MethodFactory extends Object
MethodFactory is used to generate "invokers" or "method handles" given a target class, method name, and other characteristics. In order to bind methods into Ruby's reified class hierarchy, we need a way to treat individual methods as objects. Implementers of this class provide that functionality.
  • Constructor Details

    • MethodFactory

      public MethodFactory()
  • Method Details

    • createFactory

      public static MethodFactory createFactory(ClassLoader classLoader)
      Based on optional properties, create a new MethodFactory. By default, this will create a code-generation-based InvocationMethodFactory. If security restricts code generation, ReflectionMethodFactory will be used. If we are dumping class definitions, DumpingInvocationMethodFactory will be used. See MethodFactory's static initializer for more details.
      Parameters:
      classLoader - The classloader to use for searching for and dynamically loading code.
      Returns:
      A new MethodFactory.
    • getAnnotatedMethod

      public abstract DynamicMethod getAnnotatedMethod(RubyModule implementationClass, List<JavaMethodDescriptor> desc, String name)
      Based on a list of annotated Java methods, generate a method handle using the annotation and the target signatures. The annotation and signatures will be used to dynamically generate the appropriate call logic for the handle. This differs from the single-method version in that it will dispatch multiple specific-arity paths to different target methods.
      Parameters:
      implementationClass - The target class or module on which the method will be bound.
      Returns:
      A method handle for the target object.
    • getAnnotatedMethod

      public abstract DynamicMethod getAnnotatedMethod(RubyModule implementationClass, JavaMethodDescriptor desc, String name)
      Based on an annotated Java method object, generate a method handle using the annotation and the target signature. The annotation and signature will be used to dynamically generate the appropriate call logic for the handle.
      Parameters:
      implementationClass - The target class or module on which the method will be bound.
      desc - A JavaMethodDescriptor describing the target method
      Returns:
      A method handle for the target object.