Examples of JRubyMethod


Examples of org.jruby.anno.JRubyMethod

    protected IRubyObject constantTableRemove(String name) {
        return getConstantMapForWrite().remove(name);
    }

    private static void define(RubyModule module, JavaMethodDescriptor desc, DynamicMethod dynamicMethod) {
        JRubyMethod jrubyMethod = desc.anno;
        if (jrubyMethod.frame()) {
            for (String name : jrubyMethod.name()) {
                ASTInspector.FRAME_AWARE_METHODS.add(name);
            }
        }
        if(jrubyMethod.compat() == BOTH ||
                module.getRuntime().getInstanceConfig().getCompatVersion() == jrubyMethod.compat()) {
            RubyModule singletonClass;

            if (jrubyMethod.meta()) {
                singletonClass = module.getSingletonClass();
                dynamicMethod.setImplementationClass(singletonClass);

                String baseName;
                if (jrubyMethod.name().length == 0) {
                    baseName = desc.name;
                    singletonClass.addMethod(baseName, dynamicMethod);
                } else {
                    baseName = jrubyMethod.name()[0];
                    for (String name : jrubyMethod.name()) {
                        singletonClass.addMethod(name, dynamicMethod);
                    }
                }

                if (jrubyMethod.alias().length > 0) {
                    for (String alias : jrubyMethod.alias()) {
                        singletonClass.defineAlias(alias, baseName);
                    }
                }
            } else {
                String baseName;
                if (jrubyMethod.name().length == 0) {
                    baseName = desc.name;
                    module.addMethod(baseName, dynamicMethod);
                } else {
                    baseName = jrubyMethod.name()[0];
                    for (String name : jrubyMethod.name()) {
                        module.addMethod(name, dynamicMethod);
                    }
                }

                if (jrubyMethod.alias().length > 0) {
                    for (String alias : jrubyMethod.alias()) {
                        module.defineAlias(alias, baseName);
                    }
                }

                if (jrubyMethod.module()) {
                    singletonClass = module.getSingletonClass();
                    // module/singleton methods are all defined public
                    DynamicMethod moduleMethod = dynamicMethod.dup();
                    moduleMethod.setVisibility(PUBLIC);

                    if (jrubyMethod.name().length == 0) {
                        baseName = desc.name;
                        singletonClass.addMethod(desc.name, moduleMethod);
                    } else {
                        baseName = jrubyMethod.name()[0];
                        for (String name : jrubyMethod.name()) {
                            singletonClass.addMethod(name, moduleMethod);
                        }
                    }

                    if (jrubyMethod.alias().length > 0) {
                        for (String alias : jrubyMethod.alias()) {
                            singletonClass.defineAlias(alias, baseName);
                        }
                    }
                }
            }
View Full Code Here

Examples of org.jruby.anno.JRubyMethod

            for (JavaMethodDescriptor desc: descs) {
                methods.add(desc.getDeclaringClass().getDeclaredMethod(desc.name, desc.getParameterClasses()));
                annotations.add(desc.anno);
            }
            Method method0 = methods.get(0);
            JRubyMethod anno0 = annotations.get(0);
           
            JavaMethod ic = new ReflectedJavaMultiMethod(implementationClass, methods, annotations);

            TypePopulator.populateMethod(
                    ic,
                    ic.getArity().getValue(),
                    method0.getName(),
                    Modifier.isStatic(method0.getModifiers()),
                    CallConfiguration.getCallConfigByAnno(anno0),
                    anno0.notImplemented());
            return ic;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
View Full Code Here

Examples of org.jruby.anno.JRubyMethod

            return true;
        }
    }
   
    public boolean defineAnnotatedMethod(Method method, MethodFactory methodFactory) {
        JRubyMethod jrubyMethod = method.getAnnotation(JRubyMethod.class);

        if (jrubyMethod == null) return false;

            if(jrubyMethod.compat() == BOTH ||
                    getRuntime().getInstanceConfig().getCompatVersion() == jrubyMethod.compat()) {
            JavaMethodDescriptor desc = new JavaMethodDescriptor(method);
            DynamicMethod dynamicMethod = methodFactory.getAnnotatedMethod(this, desc);
            define(this, desc, dynamicMethod);

            return true;
View Full Code Here

Examples of org.jruby.anno.JRubyMethod

        }
        return false;
    }
   
    public boolean defineAnnotatedMethod(JavaMethodDescriptor desc, MethodFactory methodFactory) {
        JRubyMethod jrubyMethod = desc.anno;

        if (jrubyMethod == null) return false;

            if(jrubyMethod.compat() == BOTH ||
                    getRuntime().getInstanceConfig().getCompatVersion() == jrubyMethod.compat()) {
            DynamicMethod dynamicMethod = methodFactory.getAnnotatedMethod(this, desc);
            define(this, desc, dynamicMethod);

            return true;
        }
View Full Code Here

Examples of org.jruby.anno.JRubyMethod

        }
        return null;
    }

    private static void define(RubyModule module, JavaMethodDescriptor desc, DynamicMethod dynamicMethod) {
        JRubyMethod jrubyMethod = desc.anno;
        if (jrubyMethod.frame()) {
            for (String name : jrubyMethod.name()) {
                ASTInspector.FRAME_AWARE_METHODS.add(name);
            }
        }
        if(jrubyMethod.compat() == BOTH ||
                module.getRuntime().getInstanceConfig().getCompatVersion() == jrubyMethod.compat()) {
            RubyModule singletonClass;

            if (jrubyMethod.meta()) {
                singletonClass = module.getSingletonClass();
                dynamicMethod.setImplementationClass(singletonClass);

                String baseName;
                if (jrubyMethod.name().length == 0) {
                    baseName = desc.name;
                    singletonClass.addMethod(baseName, dynamicMethod);
                } else {
                    baseName = jrubyMethod.name()[0];
                    for (String name : jrubyMethod.name()) {
                        singletonClass.addMethod(name, dynamicMethod);
                    }
                }

                if (jrubyMethod.alias().length > 0) {
                    for (String alias : jrubyMethod.alias()) {
                        singletonClass.defineAlias(alias, baseName);
                    }
                }
            } else {
                String baseName;
                if (jrubyMethod.name().length == 0) {
                    baseName = desc.name;
                    module.addMethod(baseName, dynamicMethod);
                } else {
                    baseName = jrubyMethod.name()[0];
                    for (String name : jrubyMethod.name()) {
                        module.addMethod(name, dynamicMethod);
                    }
                }

                if (jrubyMethod.alias().length > 0) {
                    for (String alias : jrubyMethod.alias()) {
                        module.defineAlias(alias, baseName);
                    }
                }

                if (jrubyMethod.module()) {
                    singletonClass = module.getSingletonClass();
                    // module/singleton methods are all defined public
                    DynamicMethod moduleMethod = dynamicMethod.dup();
                    moduleMethod.setVisibility(PUBLIC);

                    if (jrubyMethod.name().length == 0) {
                        baseName = desc.name;
                        singletonClass.addMethod(desc.name, moduleMethod);
                    } else {
                        baseName = jrubyMethod.name()[0];
                        for (String name : jrubyMethod.name()) {
                            singletonClass.addMethod(name, moduleMethod);
                        }
                    }

                    if (jrubyMethod.alias().length > 0) {
                        for (String alias : jrubyMethod.alias()) {
                            singletonClass.defineAlias(alias, baseName);
                        }
                    }
                }
            }
View Full Code Here

Examples of org.jruby.anno.JRubyMethod

        Map<String, List<JavaMethodDescriptor>> allAnnotatedMethods = new HashMap<String, List<JavaMethodDescriptor>>();
       
        public void clump(Class cls) {
            Method[] declaredMethods = cls.getDeclaredMethods();
            for (Method method: declaredMethods) {
                JRubyMethod anno = method.getAnnotation(JRubyMethod.class);
                if (anno == null) continue;
               
                JavaMethodDescriptor desc = new JavaMethodDescriptor(method);
               
                String name = anno.name().length == 0 ? method.getName() : anno.name()[0];
               
                List<JavaMethodDescriptor> methodDescs;
                Map<String, List<JavaMethodDescriptor>> methodsHash = null;
                if (desc.isStatic) {
                    if (anno.compat() == RUBY1_8) {
                        methodsHash = staticAnnotatedMethods1_8;
                    } else if (anno.compat() == RUBY1_9) {
                        methodsHash = staticAnnotatedMethods1_9;
                    } else if (anno.compat() == RUBY2_0) {
                        methodsHash = staticAnnotatedMethods2_0;
                    } else {
                        methodsHash = staticAnnotatedMethods;
                    }
                } else {
                    if (anno.compat() == RUBY1_8) {
                        methodsHash = annotatedMethods1_8;
                    } else if (anno.compat() == RUBY1_9) {
                        methodsHash = annotatedMethods1_9;
                    } else if (anno.compat() == RUBY2_0) {
                        methodsHash = annotatedMethods2_0;
                    } else {
                        methodsHash = annotatedMethods;
                    }
                }
View Full Code Here

Examples of org.jruby.anno.JRubyMethod

            for (JavaMethodDescriptor desc: descs) {
                methods.add(desc.getDeclaringClass().getDeclaredMethod(desc.name, desc.getParameterClasses()));
                annotations.add(desc.anno);
            }
            Method method0 = methods.get(0);
            JRubyMethod anno0 = annotations.get(0);
           
            JavaMethod ic = new ReflectedJavaMultiMethod(implementationClass, methods, annotations);

            TypePopulator.populateMethod(
                    ic,
                    ic.getArity().getValue(),
                    method0.getName(),
                    Modifier.isStatic(method0.getModifiers()),
                    CallConfiguration.getCallConfigByAnno(anno0),
                    anno0.notImplemented());
            return ic;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
View Full Code Here

Examples of org.jruby.anno.JRubyMethod

               
                if (nativeArgCount == 4 && site.arity() == 4) {
                    // Arity does not give us enough information about min/max
                    // so we must go to the annotation
                    Method reflected = method.getNativeCall().getMethod();
                    JRubyMethod annotation = reflected.getAnnotation(JRubyMethod.class);
                   
                    int required = annotation.required();
                    int optional = annotation.optional();
                    boolean rest = annotation.rest();
                   
                    if (required > 0 || !rest) {
                        MethodHandle arityCheck = Binder
                                .from(site.type().changeReturnType(void.class))
                                .insert(0, new Class[]{int.class, int.class, boolean.class}, required, optional, rest)
View Full Code Here

Examples of org.jruby.anno.JRubyMethod

     *
     * @see org.jruby.runtime.MethodFactory#getAnnotatedMethod
     */
    public DynamicMethod getAnnotatedMethod(RubyModule implementationClass, List<JavaMethodDescriptor> descs) {
        JavaMethodDescriptor desc1 = descs.get(0);
        JRubyMethod anno = desc1.anno;
        String javaMethodName = desc1.name;
       
        if (DEBUG) out.println("Binding multiple: " + desc1.declaringClassName + "." + javaMethodName);

        try {
View Full Code Here

Examples of org.jruby.anno.JRubyMethod

        Map<String, List<JavaMethodDescriptor>> allAnnotatedMethods = new HashMap<String, List<JavaMethodDescriptor>>();
       
        public void clump(Class cls) {
            Method[] declaredMethods = cls.getDeclaredMethods();
            for (Method method: declaredMethods) {
                JRubyMethod anno = method.getAnnotation(JRubyMethod.class);

                if (anno == null) continue;

                // skip bridge methods, as generated by JDK8 javac for e.g. return-value overloaded methods
                if (method.isBridge()) continue;
               
                JavaMethodDescriptor desc = new JavaMethodDescriptor(method);
               
                String name = anno.name().length == 0 ? method.getName() : anno.name()[0];
               
                List<JavaMethodDescriptor> methodDescs;
                Map<String, List<JavaMethodDescriptor>> methodsHash;
                if (desc.isStatic) {
                    methodsHash = staticAnnotatedMethods;
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.