org.jruby.RubyClass.setAllocator()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(12.2k)|赞(0)|评价(0)|浏览(93)

本文整理了Java中org.jruby.RubyClass.setAllocator方法的一些代码示例,展示了RubyClass.setAllocator的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RubyClass.setAllocator方法的具体详情如下:
包路径:org.jruby.RubyClass
类名称:RubyClass
方法名:setAllocator

RubyClass.setAllocator介绍

暂无

代码示例

代码示例来源:origin: bazelbuild/bazel

private RubyModule buildClassFromDescriptor(ThreadContext context) {
  Ruby runtime = context.runtime;
  ObjectAllocator allocator = new ObjectAllocator() {
    @Override
    public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
      return new RubyMessage(runtime, klazz, descriptor);
    }
  };
  // rb_define_class_id
  RubyClass klass = RubyClass.newClass(runtime, runtime.getObject());
  klass.setAllocator(allocator);
  klass.makeMetaClass(runtime.getObject().getMetaClass());
  klass.inherit(runtime.getObject());
  RubyModule messageExts = runtime.getClassFromPath("Google::Protobuf::MessageExts");
  klass.include(new IRubyObject[] {messageExts});
  klass.instance_variable_set(runtime.newString(Utils.DESCRIPTOR_INSTANCE_VAR), this);
  klass.defineAnnotatedMethods(RubyMessage.class);
  return klass;
}

代码示例来源:origin: org.jruby/jruby-core

public static void addRealImplClassNew(final RubyClass clazz) {
  clazz.setAllocator(new ObjectAllocator() {
    private Constructor proxyConstructor;
    public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
      // if we haven't been here before, reify the class
      Class reifiedClass = klazz.getReifiedClass();
      if (proxyConstructor == null || proxyConstructor.getDeclaringClass() != reifiedClass) {
        if (reifiedClass == null) {
          reifiedClass = Java.generateRealClass(klazz);
        }
        proxyConstructor = Java.getRealClassConstructor(runtime, reifiedClass);
      }
      IRubyObject newObj = Java.constructProxy(runtime, proxyConstructor, klazz);
      return newObj;
    }
  });
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

public static void addRealImplClassNew(RubyClass clazz) {
  clazz.setAllocator(new ObjectAllocator() {
    private Constructor proxyConstructor;
    public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
      // if we haven't been here before, reify the class
      Class reifiedClass = klazz.getReifiedClass();
      if (proxyConstructor == null || proxyConstructor.getDeclaringClass() != reifiedClass) {
        if (reifiedClass == null) {
          reifiedClass = Java.generateRealClass(klazz);
        }
        proxyConstructor = Java.getRealClassConstructor(runtime, reifiedClass);
      }
      IRubyObject newObj = Java.constructProxy(runtime, proxyConstructor, klazz);
      return newObj;
    }
  });
}

代码示例来源:origin: org.jruby/jruby-complete

public static void addRealImplClassNew(final RubyClass clazz) {
  clazz.setAllocator(new ObjectAllocator() {
    private Constructor proxyConstructor;
    public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
      // if we haven't been here before, reify the class
      Class reifiedClass = klazz.getReifiedClass();
      if (proxyConstructor == null || proxyConstructor.getDeclaringClass() != reifiedClass) {
        if (reifiedClass == null) {
          reifiedClass = Java.generateRealClass(klazz);
        }
        proxyConstructor = Java.getRealClassConstructor(runtime, reifiedClass);
      }
      IRubyObject newObj = Java.constructProxy(runtime, proxyConstructor, klazz);
      return newObj;
    }
  });
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

/** boot_defclass
 * Create an initial Object meta class before Module and Kernel dependencies have
 * squirreled themselves together.
 * 
 * @param runtime we need it
 * @return a half-baked meta class for object
 */
public static RubyClass createBootstrapClass(Ruby runtime, String name, RubyClass superClass, ObjectAllocator allocator) {
  RubyClass obj;
  if (superClass == null ) {  // boot the Object class 
    obj = new RubyClass(runtime);
    obj.marshal = DEFAULT_OBJECT_MARSHAL;
  } else {                    // boot the Module and Class classes
    obj = new RubyClass(runtime, superClass);
  }
  obj.setAllocator(allocator);
  obj.setBaseName(name);
  return obj;
}

代码示例来源:origin: org.jruby/jruby-complete

private static RubyClass createProxyClass(final Ruby runtime,
  final RubyClass proxyClass, final Class<?> javaClass,
  final RubyClass superClass, boolean invokeInherited) {
  proxyClass.makeMetaClass( superClass.getMetaClass() );
  if ( Map.class.isAssignableFrom( javaClass ) ) {
    proxyClass.setAllocator( runtime.getJavaSupport().getMapJavaProxyClass().getAllocator() );
    proxyClass.defineAnnotatedMethods( MapJavaProxy.class );
    proxyClass.includeModule( runtime.getEnumerable() );
  }
  else {
    proxyClass.setAllocator( superClass.getAllocator() );
  }
  proxyClass.defineAnnotatedMethods( JavaProxy.ClassMethods.class );
  if ( invokeInherited ) proxyClass.inherit(superClass);
  Initializer.setupProxyClass(runtime, javaClass, proxyClass);
  return proxyClass;
}

代码示例来源:origin: org.jruby/jruby-core

private static RubyClass createProxyClass(final Ruby runtime,
  final RubyClass proxyClass, final Class<?> javaClass,
  final RubyClass superClass, boolean invokeInherited) {
  proxyClass.makeMetaClass( superClass.getMetaClass() );
  if ( Map.class.isAssignableFrom( javaClass ) ) {
    proxyClass.setAllocator( runtime.getJavaSupport().getMapJavaProxyClass().getAllocator() );
    proxyClass.defineAnnotatedMethods( MapJavaProxy.class );
    proxyClass.includeModule( runtime.getEnumerable() );
  }
  else {
    proxyClass.setAllocator( superClass.getAllocator() );
  }
  proxyClass.defineAnnotatedMethods( JavaProxy.ClassMethods.class );
  if ( invokeInherited ) proxyClass.inherit(superClass);
  Initializer.setupProxyClass(runtime, javaClass, proxyClass);
  return proxyClass;
}

代码示例来源:origin: org.jruby/jruby-complete

private static void reifyWithAncestors(RubyClass klazz) {
    
    RubyClass realSuper = klazz.getSuperClass().getRealClass();

    if (realSuper.getReifiedClass() == null) reifyWithAncestors(realSuper);
    synchronized (klazz) {
      klazz.reify();
      klazz.setAllocator(new ReifyingAllocator(klazz.getReifiedClass()));
    }
  }
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

private static void reifyWithAncestors(RubyClass klazz) {
    
    RubyClass realSuper = klazz.getSuperClass().getRealClass();

    if (realSuper.getReifiedClass() == null) reifyWithAncestors(realSuper);
    synchronized (klazz) {
      klazz.reify();
      klazz.setAllocator(new ReifyingAllocator(klazz.getReifiedClass()));
    }
  }
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

private static void reifyWithAncestors(RubyClass klazz) {
    
    RubyClass realSuper = klazz.getSuperClass().getRealClass();

    if (realSuper.getReifiedClass() == null) reifyWithAncestors(realSuper);
    synchronized (klazz) {
      klazz.reify();
      klazz.setAllocator(new ReifyingAllocator(klazz.getReifiedClass()));
    }
  }
}

代码示例来源:origin: org.jruby/jruby-core

private static void reifyWithAncestors(RubyClass klazz) {
    
    RubyClass realSuper = klazz.getSuperClass().getRealClass();

    if (realSuper.getReifiedClass() == null) reifyWithAncestors(realSuper);
    synchronized (klazz) {
      klazz.reify();
      klazz.setAllocator(new ReifyingAllocator(klazz.getReifiedClass()));
    }
  }
}

代码示例来源:origin: org.jruby/jruby-complete

/**
 * A variation on newClass that allows passing in an array of supplementary
 * call sites to improve dynamic invocation performance.
 */
public static RubyClass newClass(Ruby runtime, RubyClass superClass, String name, ObjectAllocator allocator, RubyModule parent, boolean setParent, CallSite[] extraCallSites) {
  RubyClass clazz = newClass(runtime, superClass, extraCallSites);
  clazz.setBaseName(name);
  clazz.setAllocator(allocator);
  clazz.makeMetaClass(superClass.getMetaClass());
  if (setParent) clazz.setParent(parent);
  parent.setConstant(name, clazz);
  clazz.inherit(superClass);
  return clazz;
}

代码示例来源:origin: org.jruby/jruby-core

/**
 * A variation on newClass that allows passing in an array of supplementary
 * call sites to improve dynamic invocation performance.
 */
public static RubyClass newClass(Ruby runtime, RubyClass superClass, String name, ObjectAllocator allocator, RubyModule parent, boolean setParent, CallSite[] extraCallSites) {
  RubyClass clazz = newClass(runtime, superClass, extraCallSites);
  clazz.setBaseName(name);
  clazz.setAllocator(allocator);
  clazz.makeMetaClass(superClass.getMetaClass());
  if (setParent) clazz.setParent(parent);
  parent.setConstant(name, clazz);
  clazz.inherit(superClass);
  return clazz;
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

/** 
 * A variation on newClass that allows passing in an array of supplementary
 * call sites to improve dynamic invocation performance.
 */
public static RubyClass newClass(Ruby runtime, RubyClass superClass, String name, ObjectAllocator allocator, RubyModule parent, boolean setParent, CallSite[] extraCallSites) {
  RubyClass clazz = newClass(runtime, superClass, extraCallSites);
  clazz.setBaseName(name);
  clazz.setAllocator(allocator);
  clazz.makeMetaClass(superClass.getMetaClass());
  if (setParent) clazz.setParent(parent);
  parent.setConstant(name, clazz);
  clazz.inherit(superClass);
  return clazz;
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

/** 
 * A variation on newClass that allows passing in an array of supplementary
 * call sites to improve dynamic invocation performance.
 */
public static RubyClass newClass(Ruby runtime, RubyClass superClass, String name, ObjectAllocator allocator, RubyModule parent, boolean setParent, CallSite[] extraCallSites) {
  RubyClass clazz = newClass(runtime, superClass, extraCallSites);
  clazz.setBaseName(name);
  clazz.setAllocator(allocator);
  clazz.makeMetaClass(superClass.getMetaClass());
  if (setParent) clazz.setParent(parent);
  parent.setConstant(name, clazz);
  clazz.inherit(superClass);
  return clazz;
}

代码示例来源:origin: org.jruby/jruby-core

/**
 * Construct a new class with the given name, allocator, parent class,
 * and containing class. If setParent is true, the class's parent will be
 * explicitly set to the provided parent (rather than the new class just
 * being assigned to a constant in that parent).
 * Corresponds to rb_class_new/rb_define_class_id/rb_name_class/rb_set_class_path
 * in MRI.
 */
public static RubyClass newClass(Ruby runtime, RubyClass superClass, String name, ObjectAllocator allocator, RubyModule parent, boolean setParent) {
  RubyClass clazz = newClass(runtime, superClass);
  clazz.setBaseName(name);
  clazz.setAllocator(allocator);
  clazz.makeMetaClass(superClass.getMetaClass());
  if (setParent) clazz.setParent(parent);
  parent.setConstant(name, clazz);
  clazz.inherit(superClass);
  return clazz;
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

/** 
 * Construct a new class with the given name, allocator, parent class,
 * and containing class. If setParent is true, the class's parent will be
 * explicitly set to the provided parent (rather than the new class just
 * being assigned to a constant in that parent).
 * Corresponds to rb_class_new/rb_define_class_id/rb_name_class/rb_set_class_path
 * in MRI.
 */
public static RubyClass newClass(Ruby runtime, RubyClass superClass, String name, ObjectAllocator allocator, RubyModule parent, boolean setParent) {
  RubyClass clazz = newClass(runtime, superClass);
  clazz.setBaseName(name);
  clazz.setAllocator(allocator);
  clazz.makeMetaClass(superClass.getMetaClass());
  if (setParent) clazz.setParent(parent);
  parent.setConstant(name, clazz);
  clazz.inherit(superClass);
  return clazz;
}

代码示例来源:origin: org.jruby/jruby-complete

/**
 * Construct a new class with the given name, allocator, parent class,
 * and containing class. If setParent is true, the class's parent will be
 * explicitly set to the provided parent (rather than the new class just
 * being assigned to a constant in that parent).
 * Corresponds to rb_class_new/rb_define_class_id/rb_name_class/rb_set_class_path
 * in MRI.
 */
public static RubyClass newClass(Ruby runtime, RubyClass superClass, String name, ObjectAllocator allocator, RubyModule parent, boolean setParent) {
  RubyClass clazz = newClass(runtime, superClass);
  clazz.setBaseName(name);
  clazz.setAllocator(allocator);
  clazz.makeMetaClass(superClass.getMetaClass());
  if (setParent) clazz.setParent(parent);
  parent.setConstant(name, clazz);
  clazz.inherit(superClass);
  return clazz;
}

代码示例来源:origin: org.jruby/jruby-complete

static RubyModule createJavaPackageClass(final Ruby runtime, final RubyModule Java) {
  RubyClass superClass = new BlankSlateWrapper(runtime, runtime.getModule(), runtime.getKernel());
  RubyClass JavaPackage = RubyClass.newClass(runtime, superClass);
  JavaPackage.setMetaClass(runtime.getModule());
  JavaPackage.setAllocator(ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
  ((MetaClass) JavaPackage.makeMetaClass(superClass)).setAttached(JavaPackage);
  JavaPackage.setBaseName("JavaPackage");
  JavaPackage.setParent(Java);
  Java.setConstant("JavaPackage", JavaPackage); // Java::JavaPackage
  // JavaPackage.setReifiedClass(JavaPackage.class);
  JavaPackage.defineAnnotatedMethods(JavaPackage.class);
  return JavaPackage;
}

代码示例来源:origin: org.jruby/jruby-core

static RubyModule createJavaPackageClass(final Ruby runtime, final RubyModule Java) {
  RubyClass superClass = new BlankSlateWrapper(runtime, runtime.getModule(), runtime.getKernel());
  RubyClass JavaPackage = RubyClass.newClass(runtime, superClass);
  JavaPackage.setMetaClass(runtime.getModule());
  JavaPackage.setAllocator(ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
  ((MetaClass) JavaPackage.makeMetaClass(superClass)).setAttached(JavaPackage);
  JavaPackage.setBaseName("JavaPackage");
  JavaPackage.setParent(Java);
  Java.setConstant("JavaPackage", JavaPackage); // Java::JavaPackage
  // JavaPackage.setReifiedClass(JavaPackage.class);
  JavaPackage.defineAnnotatedMethods(JavaPackage.class);
  return JavaPackage;
}

相关文章

微信公众号

最新文章

更多

RubyClass类方法