Examples of DynamicMethod


Examples of org.jruby.internal.runtime.methods.DynamicMethod

    private static void callSingletonMethodHook(IRubyObject receiver, ThreadContext context, RubySymbol name) {
        receiver.callMethod(context, "singleton_method_added", name);
    }

    private static DynamicMethod constructNormalMethod(String name, Visibility visibility, MethodFactory factory, RubyModule containingClass, String javaName, int arity, StaticScope scope, Object scriptObject, CallConfiguration callConfig) {
        DynamicMethod method;

        if (name.equals("initialize") || name.equals("initialize_copy") || visibility == Visibility.MODULE_FUNCTION) {
            visibility = Visibility.PRIVATE;
        }
       
View Full Code Here

Examples of org.jruby.internal.runtime.methods.DynamicMethod

    public String definition(Ruby runtime, ThreadContext context, IRubyObject self, Block aBlock) {
        if (receiverNode.definition(runtime, context, self, aBlock) != null) {
            try {
                IRubyObject receiver = receiverNode.interpret(runtime, context, self, aBlock);
                RubyClass metaClass = receiver.getMetaClass();
                DynamicMethod method = metaClass.searchMethod(name);
                Visibility visibility = method.getVisibility();

                if (visibility != Visibility.PRIVATE &&
                        (visibility != Visibility.PROTECTED || metaClass.getRealClass().isInstance(self))) {
                    if (metaClass.isMethodBound(name, false)) {
                        return ASTInterpreter.getArgumentDefinition(runtime, context, argsNode, "assignment", self, aBlock);
View Full Code Here

Examples of org.jruby.internal.runtime.methods.DynamicMethod

            haveLocalConstructor |= javaClass == ctor.getDeclaringClass();
        }
       
        void install(RubyModule proxy) {
            if (haveLocalConstructor) {
                DynamicMethod method = new ConstructorInvoker(proxy, constructors);
                proxy.addMethod(name, method);
            } else {
                // if there's no constructor, we must prevent construction
                proxy.addMethod(name, new org.jruby.internal.runtime.methods.JavaMethod() {
                    @Override
View Full Code Here

Examples of org.jruby.internal.runtime.methods.DynamicMethod

        }

        void install(RubyModule proxy) {
            if (hasLocalMethod()) {
                RubyClass singleton = proxy.getSingletonClass();
                DynamicMethod method = new StaticMethodInvoker(singleton, methods);
                singleton.addMethod(name, method);
                if (aliases != null && isPublic() ) {
                    singleton.defineAliases(aliases, this.name);
                    aliases = null;
                }
View Full Code Here

Examples of org.jruby.internal.runtime.methods.DynamicMethod

        InstanceMethodInvokerInstaller(String name) {
            super(name,INSTANCE_METHOD);
        }
        void install(RubyModule proxy) {
            if (hasLocalMethod()) {
                DynamicMethod method = new InstanceMethodInvoker(proxy, methods);
                proxy.addMethod(name, method);
                if (aliases != null && isPublic()) {
                    proxy.defineAliases(aliases, this.name);
                    aliases = null;
                }
View Full Code Here

Examples of org.jruby.internal.runtime.methods.DynamicMethod

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

Examples of org.jruby.internal.runtime.methods.DynamicMethod

            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 {
                        synchronized (self) {
                            DynamicMethod method = selfClass.searchMethod(methodName);
                            if (method != UndefinedMethod.INSTANCE) {
                                field.set(null, method);
                            }
                        }
                    } catch (IllegalAccessException iae) {
View Full Code Here

Examples of org.jruby.internal.runtime.methods.DynamicMethod

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

Examples of org.jruby.internal.runtime.methods.DynamicMethod

            } else {
                target = rubyMod;
            }

            JavaMethodFactory factory = getMethodFactory(method.getReturnType());
            DynamicMethod dynMethod = factory.createMethod(target, method);

            // if not overloaded, we add a method that guesses at which signature to use
            // TODO: just adding first one right now...add in signature-guessing logic
            if (target.getMethods().get(name) == null) {
                target.addMethod(name, dynMethod);
View Full Code Here

Examples of org.jruby.internal.runtime.methods.DynamicMethod

    public static DynamicMethod searchMethod(RubyClass clazz, String name1) {
        return clazz.searchMethod(name1);
    }
   
    public static DynamicMethod searchMethod(RubyClass clazz, String name1, String name2) {
        DynamicMethod method = clazz.searchMethod(name1);
        if (method == UndefinedMethod.INSTANCE) {
            return searchMethod(clazz, name2);
        }
        return method;
    }
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.