@Override public Class toJavaClass(RubyModule clazz) { if (clazz instanceof RubyClass) { RubyClass rc = (RubyClass) clazz; Class c = rc.getReifiedClass(); if (c!=null) return c; // is this right? } return RubyObject.class; }
public static Class<? extends IRubyObject> nearestReifiedClass(final RubyClass klass) { RubyClass current = klass; do { Class<? extends IRubyObject> reified = current.getReifiedClass(); if ( reified != null ) return reified; current = current.getSuperClass(); } while ( current != null ); return null; }
public static Class<? extends IRubyObject> nearestReifiedClass(final RubyClass klass) { RubyClass current = klass; do { Class<? extends IRubyObject> reified = current.getReifiedClass(); if ( reified != null ) return reified; current = current.getSuperClass(); } while ( current != null ); return null; }
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; } });
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; } });
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; } });
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; } });
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())); } } }
private static IRubyObject becomeJava(final ThreadContext context, final RubyClass klass, final String dumpDir, final boolean useChildLoader) { klass.reifyWithAncestors(dumpDir, useChildLoader); final Class<?> reifiedClass = klass.getReifiedClass(); generateFieldAccessors(context, klass, reifiedClass); return asJavaClass(context.runtime, reifiedClass); }
private static IRubyObject becomeJava(final ThreadContext context, final RubyClass klass, final String dumpDir, final boolean useChildLoader) { klass.reifyWithAncestors(dumpDir, useChildLoader); final Class<?> reifiedClass = klass.getReifiedClass(); generateFieldAccessors(context, klass, reifiedClass); return asJavaClass(context.runtime, reifiedClass); }
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())); } } }
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())); } } }
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())); } } }
public IRubyObject allocate(Ruby runtime, RubyClass klazz) { try { if (klazz.getReifiedClass() == this.klass) { return (IRubyObject) cons.newInstance(runtime, klazz); } reifyWithAncestors(klazz); return klazz.getAllocator().allocate(runtime, klazz); } catch (InstantiationException ie) { throw runtime.newTypeError("could not allocate " + this.klass + " with default constructor:\n" + ie); } catch (IllegalAccessException iae) { throw runtime.newSecurityError("could not allocate " + this.klass + " due to inaccessible default constructor:\n" + iae); } catch (InvocationTargetException ite) { throw runtime.newSecurityError("could not allocate " + this.klass + " due to inaccessible default constructor:\n" + ite); } }
public IRubyObject allocate(Ruby runtime, RubyClass klazz) { try { if (klazz.getReifiedClass() == this.klass) { return (IRubyObject) cons.newInstance(runtime, klazz); } reifyWithAncestors(klazz); return klazz.getAllocator().allocate(runtime, klazz); } catch (InstantiationException ie) { throw runtime.newTypeError("could not allocate " + this.klass + " with default constructor:\n" + ie); } catch (IllegalAccessException iae) { throw runtime.newSecurityError("could not allocate " + this.klass + " due to inaccessible default constructor:\n" + iae); } catch (InvocationTargetException ite) { throw runtime.newSecurityError("could not allocate " + this.klass + " due to inaccessible default constructor:\n" + ite); } }
@Override public Class<?> resolve(String backend) { RubyClass rubyClass = (RubyClass) getConverterFactory() .callMethod("resolve", rubyRuntime.newString(backend)); Class<?> clazz = rubyClass.getReifiedClass(); if (clazz != null) { return clazz; } else if (rubyClass.getAllocator() instanceof ConverterProxy.Allocator) { ConverterProxy.Allocator allocator = (ConverterProxy.Allocator) rubyClass.getAllocator(); return allocator.getConverterClass(); } return null; }
@Override public Class<?> resolve(String backend) { RubyClass rubyClass = (RubyClass) getConverterFactory() .callMethod("resolve", rubyRuntime.newString(backend)); Class<?> clazz = rubyClass.getReifiedClass(); if (clazz != null) { return clazz; } else if (rubyClass.getAllocator() instanceof ConverterProxy.Allocator) { ConverterProxy.Allocator allocator = (ConverterProxy.Allocator) rubyClass.getAllocator(); return allocator.getConverterClass(); } return null; }
private static void checkAlreadyReified(final RubyClass clazz, Ruby runtime) throws RaiseException { // not allowed for original (non-generated) Java classes // note: not allowing for any previously created class right now; // this restriction might be loosened later for generated classes if ( ( Java.NEW_STYLE_EXTENSION && clazz.getReifiedClass() != null ) || ( clazz.hasInstanceVariable("@java_class") && clazz.getInstanceVariable("@java_class").isTrue() && !clazz.getSingletonClass().isMethodBound("java_proxy_class", false) ) || ( clazz.hasInstanceVariable("@java_proxy_class") && clazz.getInstanceVariable("@java_proxy_class").isTrue() ) ) { throw runtime.newArgumentError("can not add Java interface to existing Java class"); } }
private static void checkAlreadyReified(final RubyClass clazz, Ruby runtime) throws RaiseException { // not allowed for original (non-generated) Java classes // note: not allowing for any previously created class right now; // this restriction might be loosened later for generated classes if ((Java.NEW_STYLE_EXTENSION && clazz.getReifiedClass() != null) || (clazz.hasInstanceVariable("@java_class") && clazz.getInstanceVariable("@java_class").isTrue() && !clazz.getSingletonClass().isMethodBound("java_proxy_class", false)) || (clazz.hasInstanceVariable("@java_proxy_class") && clazz.getInstanceVariable("@java_proxy_class").isTrue())) { throw runtime.newArgumentError("can not add Java interface to existing Java class"); } }
private static void checkAlreadyReified(final RubyClass clazz, Ruby runtime) throws RaiseException { // not allowed for original (non-generated) Java classes // note: not allowing for any previously created class right now; // this restriction might be loosened later for generated classes if ((Java.NEW_STYLE_EXTENSION && clazz.getReifiedClass() != null) || (clazz.hasInstanceVariable("@java_class") && clazz.getInstanceVariable("@java_class").isTrue() && !clazz.getSingletonClass().isMethodBound("java_proxy_class", false)) || (clazz.hasInstanceVariable("@java_proxy_class") && clazz.getInstanceVariable("@java_proxy_class").isTrue())) { throw runtime.newArgumentError("can not add Java interface to existing Java class"); } }