@JRubyMethod(meta = true, name = "descriptor") public static IRubyObject getDescriptor(ThreadContext context, IRubyObject recv) { return ((RubyModule) recv).getInstanceVariable(Utils.DESCRIPTOR_INSTANCE_VAR); } }
protected static void validateTypeClass(ThreadContext context, Descriptors.FieldDescriptor.Type type, IRubyObject value) { Ruby runtime = context.runtime; if (!(value instanceof RubyModule)) { throw runtime.newArgumentError("TypeClass has incorrect type"); } RubyModule klass = (RubyModule) value; IRubyObject descriptor = klass.getInstanceVariable(DESCRIPTOR_INSTANCE_VAR); if (descriptor.isNil()) { throw runtime.newArgumentError("Type class has no descriptor. Please pass a " + "class or enum as returned by the DescriptorPool."); } if (type == Descriptors.FieldDescriptor.Type.MESSAGE) { if (! (descriptor instanceof RubyDescriptor)) { throw runtime.newArgumentError("Descriptor has an incorrect type"); } } else if (type == Descriptors.FieldDescriptor.Type.ENUM) { if (! (descriptor instanceof RubyEnumDescriptor)) { throw runtime.newArgumentError("Descriptor has an incorrect type"); } } }
if (value instanceof RubySymbol) { Descriptors.EnumDescriptor enumDescriptor = ((RubyEnumDescriptor) typeClass.getInstanceVariable(DESCRIPTOR_INSTANCE_VAR)).getDescriptor(); val = enumDescriptor.findValueByName(value.asJavaString()); if (val == null)
/** * Returns the (reified or proxied) Java class if the passed Ruby module/class has one. * @param context * @param type * @return Java proxy class, Java reified class or nil */ public static IRubyObject java_class(final ThreadContext context, final RubyModule type) { IRubyObject java_class = type.getInstanceVariable("@java_class"); if ( java_class == null ) { // || java_class.isNil() if ( type.respondsTo("java_class") ) { // NOTE: quite bad since built-in Ruby classes will return // a Ruby Java proxy for java.lang.Class while Java proxies will return a JavaClass instance ! java_class = Helpers.invoke(context, type, "java_class"); } else java_class = context.nil; // we return != null (just like callMethod would) } return java_class; }
/** * Returns the (reified or proxied) Java class if the passed Ruby module/class has one. * @param context * @param type * @return Java proxy class, Java reified class or nil */ public static IRubyObject java_class(final ThreadContext context, final RubyModule type) { IRubyObject java_class = type.getInstanceVariable("@java_class"); if ( java_class == null ) { // || java_class.isNil() if ( type.respondsTo("java_class") ) { // NOTE: quite bad since built-in Ruby classes will return // a Ruby Java proxy for java.lang.Class while Java proxies will return a JavaClass instance ! java_class = Helpers.invoke(context, type, "java_class"); } else java_class = context.nil; // we return != null (just like callMethod would) } return java_class; }
private static RubyModule getProxyOrPackageUnderPackage(ThreadContext context, final Ruby runtime, RubyModule parentPackage, String sym) { IRubyObject packageNameObj = parentPackage.getInstanceVariable("@package_name"); if (packageNameObj == null) { throw runtime.newArgumentError("invalid package module");
private static RubyModule getProxyOrPackageUnderPackage(ThreadContext context, final Ruby runtime, RubyModule parentPackage, String sym) { IRubyObject packageNameObj = parentPackage.getInstanceVariable("@package_name"); if (packageNameObj == null) { throw runtime.newArgumentError("invalid package module");