本文整理了Java中org.jruby.Ruby.getClassFromPath
方法的一些代码示例,展示了Ruby.getClassFromPath
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ruby.getClassFromPath
方法的具体详情如下:
包路径:org.jruby.Ruby
类名称:Ruby
方法名:getClassFromPath
暂无
代码示例来源:origin: bazelbuild/bazel
public RubyBuilder(Ruby runtime, RubyClass metaClass) {
super(runtime, metaClass);
this.cDescriptor = (RubyClass) runtime.getClassFromPath("Google::Protobuf::Descriptor");
this.cEnumDescriptor = (RubyClass) runtime.getClassFromPath("Google::Protobuf::EnumDescriptor");
this.cMessageBuilderContext = (RubyClass) runtime.getClassFromPath("Google::Protobuf::MessageBuilderContext");
this.cEnumBuilderContext = (RubyClass) runtime.getClassFromPath("Google::Protobuf::EnumBuilderContext");
}
代码示例来源:origin: bazelbuild/bazel
@JRubyMethod
public IRubyObject initialize(ThreadContext context, IRubyObject descriptor, IRubyObject rubyBuilder) {
this.cFieldDescriptor = (RubyClass) context.runtime.getClassFromPath("Google::Protobuf::FieldDescriptor");
this.cDescriptor = (RubyClass) context.runtime.getClassFromPath("Google::Protobuf::Descriptor");
this.cOneofDescriptor = (RubyClass) context.runtime.getClassFromPath("Google::Protobuf::OneofDescriptor");
this.cOneofBuilderContext = (RubyClass) context.runtime.getClassFromPath("Google::Protobuf::Internal::OneofBuilderContext");
this.descriptor = (RubyDescriptor) descriptor;
this.builder = (RubyBuilder) rubyBuilder;
return this;
}
代码示例来源:origin: bazelbuild/bazel
@JRubyMethod
public IRubyObject initialize(ThreadContext context, IRubyObject oneofdef) {
this.descriptor = (RubyOneofDescriptor) oneofdef;
this.cFieldDescriptor = (RubyClass) context.runtime.getClassFromPath("Google::Protobuf::FieldDescriptor");
return this;
}
代码示例来源:origin: bazelbuild/bazel
@JRubyMethod
public IRubyObject initialize(ThreadContext context) {
this.symtab = new HashMap<IRubyObject, IRubyObject>();
this.cBuilder = (RubyClass) context.runtime.getClassFromPath("Google::Protobuf::Builder");
this.builder = DescriptorProtos.FileDescriptorProto.newBuilder();
return this;
}
代码示例来源:origin: bazelbuild/bazel
public static void createRubyMessageBuilderContext(Ruby runtime) {
RubyModule protobuf = runtime.getClassFromPath("Google::Protobuf");
RubyClass cMessageBuilderContext = protobuf.defineClassUnder("MessageBuilderContext", runtime.getObject(), new ObjectAllocator() {
@Override
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
return new RubyMessageBuilderContext(runtime, klazz);
}
});
cMessageBuilderContext.defineAnnotatedMethods(RubyMessageBuilderContext.class);
}
代码示例来源:origin: bazelbuild/bazel
public static void createRubyBuilder(Ruby runtime) {
RubyModule protobuf = runtime.getClassFromPath("Google::Protobuf");
RubyClass cBuilder = protobuf.defineClassUnder("Builder", runtime.getObject(), new ObjectAllocator() {
@Override
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
return new RubyBuilder(runtime, klazz);
}
});
cBuilder.defineAnnotatedMethods(RubyBuilder.class);
}
代码示例来源:origin: bazelbuild/bazel
public static void createRubyFileDescriptor(Ruby runtime) {
RubyModule mProtobuf = runtime.getClassFromPath("Google::Protobuf");
RubyClass cFieldDescriptor = mProtobuf.defineClassUnder("FieldDescriptor", runtime.getObject(), new ObjectAllocator() {
@Override
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
return new RubyFieldDescriptor(runtime, klazz);
}
});
cFieldDescriptor.defineAnnotatedMethods(RubyFieldDescriptor.class);
}
代码示例来源:origin: bazelbuild/bazel
public static void createRubyEnumBuilderContext(Ruby runtime) {
RubyModule protobuf = runtime.getClassFromPath("Google::Protobuf");
RubyClass cMessageBuilderContext = protobuf.defineClassUnder("EnumBuilderContext", runtime.getObject(), new ObjectAllocator() {
@Override
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
return new RubyEnumBuilderContext(runtime, klazz);
}
});
cMessageBuilderContext.defineAnnotatedMethods(RubyEnumBuilderContext.class);
}
代码示例来源:origin: bazelbuild/bazel
@JRubyMethod(optional = 1)
public IRubyObject initialize(final ThreadContext context, IRubyObject[] args) {
final Ruby runtime = context.runtime;
this.cRepeatedField = (RubyClass) runtime.getClassFromPath("Google::Protobuf::RepeatedField");
this.cMap = (RubyClass) runtime.getClassFromPath("Google::Protobuf::Map");
this.builder = DynamicMessage.newBuilder(this.descriptor);
this.repeatedFields = new HashMap<Descriptors.FieldDescriptor, RubyRepeatedField>();
代码示例来源:origin: bazelbuild/bazel
public static void createRubyOneofBuilderContext(Ruby runtime) {
RubyModule protobuf = runtime.getClassFromPath("Google::Protobuf");
RubyModule internal = protobuf.defineModuleUnder("Internal");
RubyClass cRubyOneofBuidlerContext = internal.defineClassUnder("OneofBuilderContext", runtime.getObject(), new ObjectAllocator() {
@Override
public IRubyObject allocate(Ruby ruby, RubyClass rubyClass) {
return new RubyOneofBuilderContext(ruby, rubyClass);
}
});
cRubyOneofBuidlerContext.defineAnnotatedMethods(RubyOneofBuilderContext.class);
}
代码示例来源:origin: bazelbuild/bazel
public static void createRubyOneofDescriptor(Ruby runtime) {
RubyModule protobuf = runtime.getClassFromPath("Google::Protobuf");
RubyClass cRubyOneofDescriptor = protobuf.defineClassUnder("OneofDescriptor", runtime.getObject(), new ObjectAllocator() {
@Override
public IRubyObject allocate(Ruby ruby, RubyClass rubyClass) {
return new RubyOneofDescriptor(ruby, rubyClass);
}
});
cRubyOneofDescriptor.defineAnnotatedMethods(RubyOneofDescriptor.class);
cRubyOneofDescriptor.includeModule(runtime.getEnumerable());
}
代码示例来源:origin: bazelbuild/bazel
public static void createRubyDescriptorPool(Ruby runtime) {
RubyModule protobuf = runtime.getClassFromPath("Google::Protobuf");
RubyClass cDescriptorPool = protobuf.defineClassUnder("DescriptorPool", runtime.getObject(), new ObjectAllocator() {
@Override
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
return new RubyDescriptorPool(runtime, klazz);
}
});
cDescriptorPool.defineAnnotatedMethods(RubyDescriptorPool.class);
descriptorPool = (RubyDescriptorPool) cDescriptorPool.newInstance(runtime.getCurrentContext(), Block.NULL_BLOCK);
}
代码示例来源:origin: bazelbuild/bazel
public static void createRubyRepeatedField(Ruby runtime) {
RubyModule mProtobuf = runtime.getClassFromPath("Google::Protobuf");
RubyClass cRepeatedField = mProtobuf.defineClassUnder("RepeatedField", runtime.getObject(),
new ObjectAllocator() {
@Override
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
return new RubyRepeatedField(runtime, klazz);
}
});
cRepeatedField.defineAnnotatedMethods(RubyRepeatedField.class);
cRepeatedField.includeModule(runtime.getEnumerable());
}
代码示例来源:origin: bazelbuild/bazel
public static void createRubyMap(Ruby runtime) {
RubyModule protobuf = runtime.getClassFromPath("Google::Protobuf");
RubyClass cMap = protobuf.defineClassUnder("Map", runtime.getObject(), new ObjectAllocator() {
@Override
public IRubyObject allocate(Ruby ruby, RubyClass rubyClass) {
return new RubyMap(ruby, rubyClass);
}
});
cMap.includeModule(runtime.getEnumerable());
cMap.defineAnnotatedMethods(RubyMap.class);
}
代码示例来源:origin: bazelbuild/bazel
public static void createRubyDescriptor(Ruby runtime) {
RubyModule protobuf = runtime.getClassFromPath("Google::Protobuf");
RubyClass cDescriptor = protobuf.defineClassUnder("Descriptor", runtime.getObject(), new ObjectAllocator() {
@Override
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
return new RubyDescriptor(runtime, klazz);
}
});
cDescriptor.includeModule(runtime.getEnumerable());
cDescriptor.defineAnnotatedMethods(RubyDescriptor.class);
}
代码示例来源:origin: bazelbuild/bazel
public static void createRubyEnumDescriptor(Ruby runtime) {
RubyModule mProtobuf = runtime.getClassFromPath("Google::Protobuf");
RubyClass cEnumDescriptor = mProtobuf.defineClassUnder("EnumDescriptor", runtime.getObject(), new ObjectAllocator() {
@Override
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
return new RubyEnumDescriptor(runtime, klazz);
}
});
cEnumDescriptor.includeModule(runtime.getEnumerable());
cEnumDescriptor.defineAnnotatedMethods(RubyEnumDescriptor.class);
}
代码示例来源:origin: bazelbuild/bazel
@JRubyMethod(name = "decode_json", meta = true)
public static IRubyObject decodeJson(ThreadContext context, IRubyObject recv, IRubyObject json) {
Ruby runtime = context.runtime;
RubyMessage ret = (RubyMessage) ((RubyClass) recv).newInstance(context, Block.NULL_BLOCK);
RubyModule jsonModule = runtime.getClassFromPath("JSON");
RubyHash opts = RubyHash.newHash(runtime);
opts.fastASet(runtime.newSymbol("symbolize_names"), runtime.getTrue());
IRubyObject[] args = new IRubyObject[] { Helpers.invoke(context, jsonModule, "parse", json, opts) };
ret.initialize(context, args);
return ret;
}
代码示例来源: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.kill-bill.billing/killbill-osgi-bundles-jruby
public void run() {
if (latch.compareAndSet(false, true)) {
if (currentThread.alive_p().isTrue()) {
RubyClass anonException = (RubyClass)runtime.getClassFromPath("Timeout::AnonymousException");
IRubyObject anonExceptionObj = anonException.newInstance(runtime.getCurrentContext(), runtime.newString("execution expired"), Block.NULL_BLOCK);
anonExceptionObj.getInternalVariables().setInternalVariable("__identifier__", id);
currentThread.internalRaise(new IRubyObject[] {anonExceptionObj});
}
}
}
};
代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby
@JRubyMethod(visibility = PRIVATE)
public static IRubyObject path2class(ThreadContext context, IRubyObject self, IRubyObject path) {
try {
return context.runtime.getClassFromPath(path.asJavaString());
} catch (RaiseException re) {
if (re.getException().getMetaClass() == context.runtime.getNameError()) {
throw context.runtime.newArgumentError("undefined class/module " + path);
}
throw re;
}
}
}
内容来源于网络,如有侵权,请联系作者删除!