Examples of Ruby


Examples of org.jruby.Ruby

    private static void appendFeaturesToModule(ThreadContext context, IRubyObject self, RubyModule module) {
        // assuming the user wants a collection of interfaces that can be
        // included together. make it so.
       
        Ruby runtime = context.getRuntime();

        // not allowed for existing Java interface modules
        if (module.getInstanceVariables().fastHasInstanceVariable("@java_class") &&
                module.getInstanceVariables().fastGetInstanceVariable("@java_class").isTrue()) {
            throw runtime.newTypeError("can not add Java interface to existing Java interface");
        }
       
        // To turn a module into an "interface collection" we add a class instance
        // variable to hold the list of interfaces, and modify append_features
        // for this module to call append_features on each of those interfaces as
View Full Code Here

Examples of org.jruby.Ruby

    public ConcreteJavaProxy(Ruby runtime, RubyClass klazz) {
        super(runtime, klazz);
    }
   
    public static RubyClass createConcreteJavaProxy(ThreadContext context) {
        Ruby runtime = context.getRuntime();
       
        RubyClass concreteJavaProxy = runtime.defineClass("ConcreteJavaProxy",
                runtime.getJavaSupport().getJavaProxyClass(),
                new ObjectAllocator() {
            public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
                return new ConcreteJavaProxy(runtime, klazz);
            }
        });
View Full Code Here

Examples of org.jruby.Ruby

    public InterfaceJavaProxy(Ruby runtime, RubyClass klazz) {
        super(runtime, klazz);
    }

    public static RubyClass createInterfaceJavaProxy(ThreadContext context) {
        Ruby runtime = context.getRuntime();
       
        RubyClass ifcJavaProxy = runtime.defineClass(
                "InterfaceJavaProxy",
                runtime.getJavaSupport().getJavaProxyClass(), new ObjectAllocator() {
            public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
                return new InterfaceJavaProxy(runtime, klazz);
            }
        });
View Full Code Here

Examples of org.jruby.Ruby

    public ArrayJavaProxy(Ruby runtime, RubyClass klazz) {
        super(runtime, klazz);
    }
   
    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

Examples of org.jruby.Ruby

            this.oldNew = oldNew;
        }
       
        @Override
        public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0) {
            Ruby runtime = context.getRuntime();
            IRubyObject proxy = oldNew.call(context, self, clazz, "new_proxy");
           
            if (arg0 instanceof JavaArray) {
                proxy.dataWrapStruct(arg0);
                return proxy;
            } else {
                throw runtime.newTypeError(arg0, runtime.getJavaSupport().getJavaArrayClass());
            }
        }
View Full Code Here

Examples of org.jruby.Ruby

        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
View Full Code Here

Examples of org.jruby.Ruby

        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
View Full Code Here

Examples of org.jruby.Ruby

            return rubyCls;
        }
    }

    protected static void populateMirrorForClass(RubyModule rubyMod, final Class cls) {
        Ruby ruby = rubyMod.getRuntime();

        // set the full name
        rubyMod.setBaseName(cls.getCanonicalName());

        // include all interfaces
View Full Code Here

Examples of org.jruby.Ruby

            }
        });
    }

    private static void populateConstructors(RubyModule rubySing, final Class cls) {
        final Ruby ruby = rubySing.getRuntime();
       
        // add all public constructors (note: getConstructors only returns public ones)
        Constructor[] constructors = cls.getConstructors();
        for (final Constructor constructor : constructors) {
            DynamicMethod dynMethod;
            if (constructor.getParameterTypes().length == 0) {
                dynMethod = new JavaMethod.JavaMethodZero(rubySing, Visibility.PUBLIC) {
                    @Override
                    public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name) {
                        try {
                            return javaToRuby(context.getRuntime(), constructor.newInstance());
                        } catch (InstantiationException ex) {
                            if (ruby.getDebug().isTrue()) ex.printStackTrace();
                            throw ruby.newTypeError("Could not instantiate " + cls.getCanonicalName() + " using " + prettyParams(constructor.getParameterTypes()));
                        } catch (IllegalAccessException ex) {
                            if (ruby.getDebug().isTrue()) ex.printStackTrace();
                            throw ruby.newTypeError("Could not instantiate " + cls.getCanonicalName() + " using " + prettyParams(constructor.getParameterTypes()));
                        } catch (IllegalArgumentException ex) {
                            if (ruby.getDebug().isTrue()) ex.printStackTrace();
                            throw ruby.newTypeError("Could not instantiate " + cls.getCanonicalName() + " using " + prettyParams(constructor.getParameterTypes()));
                        } catch (InvocationTargetException ex) {
                            if (ruby.getDebug().isTrue()) ex.printStackTrace();
                            throw ruby.newTypeError("Could not instantiate " + cls.getCanonicalName() + " using " + prettyParams(constructor.getParameterTypes()));
                        }
                    }
                };
            } else {
                dynMethod = new JavaMethod.JavaMethodNoBlock(rubySing, Visibility.PUBLIC) {
                    @Override
                    public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] rubyArgs) {
                        Object[] args = new Object[rubyArgs.length];

                        for (int i = 0; i < args.length; i++) {
                            args[i] = rubyToJava(rubyArgs[i]);
                        }
                        try {
                            return javaToRuby(ruby, constructor.newInstance(args));
                        } catch (InstantiationException ex) {
                            if (ruby.getDebug().isTrue()) ex.printStackTrace();
                            throw ruby.newTypeError("Could not instantiate " + cls.getCanonicalName() + " using " + prettyParams(constructor.getParameterTypes()));
                        } catch (IllegalAccessException ex) {
                            if (ruby.getDebug().isTrue()) ex.printStackTrace();
                            throw ruby.newTypeError("Could not instantiate " + cls.getCanonicalName() + " using " + prettyParams(constructor.getParameterTypes()));
                        } catch (IllegalArgumentException ex) {
                            if (ruby.getDebug().isTrue()) ex.printStackTrace();
                            throw ruby.newTypeError("Could not instantiate " + cls.getCanonicalName() + " using " + prettyParams(constructor.getParameterTypes()));
                        } catch (InvocationTargetException ex) {
                            if (ruby.getDebug().isTrue()) ex.printStackTrace();
                            throw ruby.newTypeError("Could not instantiate " + cls.getCanonicalName() + " using " + prettyParams(constructor.getParameterTypes()));
                        }
                    }
                };
            }
View Full Code Here

Examples of org.jruby.Ruby

            target.addMethod(name, dynMethod);
        }
    }
   
    private static void populateSpecialMethods(RubyModule rubyMod, RubyModule rubySing, final Class cls) {
        final Ruby ruby = rubyMod.getRuntime();
       
        // add a few type-specific special methods
        rubySing.addMethod("java_class", new JavaMethod.JavaMethodZero(rubySing, Visibility.PUBLIC) {
            @Override
            public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.