Package org.jruby

Examples of org.jruby.RubyClass


    protected final NativeType[] parameterTypes;
    protected final NativeType returnType;
   
    public static RubyClass createCallbackClass(Ruby runtime) {
        RubyModule module = FFIProvider.getModule(runtime);
        RubyClass result = module.defineClassUnder(CLASS_NAME,
                runtime.getObject(),
                ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
        result.defineAnnotatedMethods(Callback.class);
        result.defineAnnotatedConstants(Callback.class);

        return result;
    }
View Full Code Here


abstract public class AbstractBuffer extends AbstractMemory {
    public final static String ABSTRACT_BUFFER_RUBY_CLASS = "AbstractBuffer";

    public static RubyClass createBufferClass(Ruby runtime) {
        RubyModule module = FFIProvider.getModule(runtime);
        RubyClass result = module.defineClassUnder(ABSTRACT_BUFFER_RUBY_CLASS,
                module.getClass(AbstractMemory.ABSTRACT_MEMORY_RUBY_CLASS),
                ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
       
        result.defineAnnotatedMethods(AbstractBuffer.class);
        result.defineAnnotatedConstants(AbstractBuffer.class);

        return result;
    }
View Full Code Here

    }
   
    public static RubyClass createArrayJavaProxy(ThreadContext context) {
        Ruby runtime = context.getRuntime();
       
        RubyClass arrayJavaProxy = runtime.defineClass("ArrayJavaProxy",
                runtime.getJavaSupport().getJavaProxyClass(),
                new ObjectAllocator() {
            public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
                return new ArrayJavaProxy(runtime, klazz);
            }
        });
       
        RubyClass singleton = arrayJavaProxy.getSingletonClass();
       
        final DynamicMethod oldNew = singleton.searchMethod("new");
       
        singleton.addMethod("new", new ArrayNewMethod(singleton, Visibility.PUBLIC, oldNew));
       
        arrayJavaProxy.defineAnnotatedMethods(ArrayJavaProxy.class);
        arrayJavaProxy.includeModule(runtime.getEnumerable());
       
        return arrayJavaProxy;
View Full Code Here

public class JNAMemoryPointer extends AbstractMemoryPointer implements JNAMemory {
    public static final String MEMORY_POINTER_NAME = "MemoryPointer";
   
    public static RubyClass createMemoryPointerClass(Ruby runtime) {
        RubyModule module = FFIProvider.getModule(runtime);
        RubyClass result = module.defineClassUnder(MEMORY_POINTER_NAME,
                module.getClass(AbstractMemoryPointer.className),
                ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
        result.defineAnnotatedMethods(JNAMemoryPointer.class);
        result.defineAnnotatedConstants(JNAMemoryPointer.class);

        return result;
    }
View Full Code Here

        public Class getReturnType() {
            return m.getReturnType();
        }
       
        public static RubyClass createJavaProxyMethodClass(Ruby runtime, RubyModule javaProxyModule) {
            RubyClass result = javaProxyModule.defineClassUnder("JavaProxyMethod",
                    runtime.getObject(), ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);

            JavaProxyReflectionObject.registerRubyMethods(runtime, result);

            result.defineAnnotatedMethods(ProxyMethodImpl.class);

            return result;
        }
View Full Code Here

                methods.add(method);
            }
        }
       
        Class newClass = defineImplClass(ruby, name, superTypeNames, simpleToAll);
        RubyClass rubyCls = populateImplClass(ruby, newClass, simpleToAll);
       
        return rubyCls;
    }
View Full Code Here

            mv.voidreturn();
        }
    }

    public static RubyClass populateImplClass(Ruby ruby, Class newClass, Map<String, List<Method>> simpleToAll) {
        RubyClass rubyCls = (RubyClass)getMirrorForClass(ruby, newClass);
       
        // setup the class
        try {
            newClass.getMethod("__setup__", new Class[]{RubyClass.class}).invoke(null, new Object[]{rubyCls});
        } catch (IllegalAccessException ex) {
            throw error(ruby, ex, "Could not setup class: " + newClass);
        } catch (IllegalArgumentException ex) {
            throw error(ruby, ex, "Could not setup class: " + newClass);
        } catch (InvocationTargetException ex) {
            throw error(ruby, ex, "Could not setup class: " + newClass);
        } catch (NoSuchMethodException ex) {
            throw error(ruby, ex, "Could not setup class: " + newClass);
        }

        // now, create a method_added that can replace the DynamicMethod fields as they're redefined
        final Map<String, Field> allFields = new HashMap<String, Field>();
        try {
            for (Map.Entry<String, List<Method>> entry : simpleToAll.entrySet()) {
                String simpleName = entry.getKey();

                Field simpleField = newClass.getField(simpleName);
                allFields.put(simpleName, simpleField);

                for (Method method : entry.getValue()) {
                    String complexName = simpleName + prettyParams(method.getParameterTypes());
                    String fieldName = mangleMethodFieldName(simpleName, method.getParameterTypes());
                    allFields.put(complexName, newClass.getField(fieldName));
                }
            }
        } catch (IllegalArgumentException ex) {
            throw error(ruby, ex, "Could not prepare method fields: " + newClass);
        } catch (NoSuchFieldException ex) {
            throw error(ruby, ex, "Could not prepare method fields: " + newClass);
        }

        DynamicMethod method_added = new JavaMethod(rubyCls.getSingletonClass(), Visibility.PUBLIC) {
            @Override
            public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
                RubyClass selfClass = (RubyClass)self;
                Ruby ruby = selfClass.getClassRuntime();
                String methodName = args[0].asJavaString();
                Field field = allFields.get(methodName);

                if (field == null) {
                    // do nothing, it's a non-impl method
                } else {
                    try {
                        field.set(null, selfClass.searchMethod(methodName));
                    } catch (IllegalAccessException iae) {
                        throw error(ruby, iae, "Could not set new method into field: " + selfClass + "." + methodName);
                    } catch (IllegalArgumentException iae) {
                        throw error(ruby, iae, "Could not set new method into field: " + selfClass + "." + methodName);
                    }
View Full Code Here

        }

        DynamicMethod method_added = new JavaMethod(rubyCls.getSingletonClass(), Visibility.PUBLIC) {
            @Override
            public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
                RubyClass selfClass = (RubyClass)self;
                Ruby ruby = selfClass.getClassRuntime();
                String methodName = args[0].asJavaString();
                Field field = allFields.get(methodName);

                if (field == null) {
                    // do nothing, it's a non-impl method
                } else {
                    try {
                        synchronized (self) {
                            DynamicMethod method = selfClass.searchMethod(methodName);
                            if (method != UndefinedMethod.INSTANCE) {
                                field.set(null, method);
                            }
                        }
                    } catch (IllegalAccessException iae) {
View Full Code Here

            // interfaces are handled as modules
            RubyModule rubyMod = RubyModule.newModule(ruby);
            return rubyMod;
        } else {
            // construct the mirror class and parent classes
            RubyClass rubyCls = RubyClass.newClass(ruby, (RubyClass) getMirrorForClass(ruby, cls.getSuperclass()));
            return rubyCls;
        }
    }
View Full Code Here

    public static final String MODULE_NAME = "JRuby::FFI";
    public static final String CLASS_NAME = "Provider";
   
    public static RubyClass createProviderClass(Ruby runtime) {
        RubyModule module = FFIProvider.getModule(runtime);
        RubyClass result = module.defineClassUnder(CLASS_NAME,
                runtime.getObject(),
                ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
        result.defineAnnotatedMethods(FFIProvider.class);
        result.defineAnnotatedConstants(FFIProvider.class);

        return result;
    }
View Full Code Here

TOP

Related Classes of org.jruby.RubyClass

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.