public final boolean defineAnnotatedMethod(Method method, MethodFactory methodFactory) { JRubyMethod jrubyMethod = method.getAnnotation(JRubyMethod.class); if (jrubyMethod == null) return false; JavaMethodDescriptor desc = new JavaMethodDescriptor(method); DynamicMethod dynamicMethod = methodFactory.getAnnotatedMethod(this, desc, method.getName()); define(this, desc, method.getName(), dynamicMethod); return true; }
private void addAnnotatedMethodInvoker(ClassWriter cw, String superClass, List<JavaMethodDescriptor> descs) { for (JavaMethodDescriptor desc: descs) { int specificArity = desc.calculateSpecificCallArity(); SkinnyMethodAdapter mv = beginMethod(cw, "call", specificArity, desc.hasBlock); mv.visitCode(); createAnnotatedMethodInvocation(desc, mv, superClass, specificArity, desc.hasBlock); mv.end(); } }
private static void loadArguments(SkinnyMethodAdapter mv, JavaMethodDescriptor desc, int specificArity) { Class[] argumentTypes; switch (specificArity) { default: case -1: mv.aload(ARGS_INDEX); break; case 0: // no args break; case 1: argumentTypes = desc.getArgumentTypes(); loadArgumentWithCast(mv, 1, argumentTypes[0]); break; case 2: argumentTypes = desc.getArgumentTypes(); loadArgumentWithCast(mv, 1, argumentTypes[0]); loadArgumentWithCast(mv, 2, argumentTypes[1]); break; case 3: argumentTypes = desc.getArgumentTypes(); loadArgumentWithCast(mv, 1, argumentTypes[0]); loadArgumentWithCast(mv, 2, argumentTypes[1]); loadArgumentWithCast(mv, 3, argumentTypes[2]); break; } }
/** * Use reflection to provide a method handle based on an annotated Java * method. * * @see org.jruby.internal.runtime.methods.MethodFactory#getAnnotatedMethod */ public DynamicMethod getAnnotatedMethod(RubyModule implementationClass, JavaMethodDescriptor desc) { try { if (!Modifier.isPublic(desc.getDeclaringClass().getModifiers())) { LOG.warn("warning: binding non-public class {}; reflected handles won't work", desc.declaringClassName); } Method method = desc.getDeclaringClass().getDeclaredMethod(desc.name, desc.getParameterClasses()); JavaMethod ic = new ReflectedJavaMethod(implementationClass, method, desc.anno); TypePopulator.populateMethod( ic, ic.getArity().getValue(), method.getName(), Modifier.isStatic(method.getModifiers()), CallConfiguration.getCallConfigByAnno(desc.anno), desc.anno.notImplemented()); return ic; } catch (Exception e) { throw new RuntimeException(e); } }
JavaMethodDescriptor desc1 = descs.get(0); if (!Modifier.isPublic(desc1.getDeclaringClass().getModifiers())) { LOG.warn("warning: binding non-public class {}; reflected handles won't work", desc1.declaringClassName); Class c = tryClass(generatedClassName, desc1.getDeclaringClass(), superclass); if (c == null) { synchronized (syncObject) { c = tryClass(generatedClassName, desc1.getDeclaringClass(), superclass); if (c == null) { if (DEBUG) out.println("Generating " + generatedClassName + ", min: " + info.getMin() + ", max: " + info.getMax() + ", hasBlock: " + info.isBlock() + ", rest: " + info.isRest());
if (desc.getReturnClass() == void.class) {
/** * Use reflection to provide a method handle based on an annotated Java * method. * * @see org.jruby.internal.runtime.methods.MethodFactory#getAnnotatedMethod */ public DynamicMethod getAnnotatedMethod(RubyModule implementationClass, JavaMethodDescriptor desc) { try { if (!Modifier.isPublic(desc.getDeclaringClass().getModifiers())) { LOG.warn("warning: binding non-public class {}; reflected handles won't work", desc.declaringClassName); } Method method = desc.getDeclaringClass().getDeclaredMethod(desc.name, desc.getParameterClasses()); JavaMethod ic = new ReflectedJavaMethod(implementationClass, method, desc.anno); TypePopulator.populateMethod( ic, ic.getArity().getValue(), method.getName(), Modifier.isStatic(method.getModifiers()), CallConfiguration.getCallConfigByAnno(desc.anno), desc.anno.notImplemented()); return ic; } catch (Exception e) { throw new RuntimeException(e); } }
JavaMethodDescriptor desc1 = descs.get(0); if (!Modifier.isPublic(desc1.getDeclaringClass().getModifiers())) { LOG.warn("warning: binding non-public class {}; reflected handles won't work", desc1.declaringClassName); Class c = tryClass(generatedClassName, desc1.getDeclaringClass(), superclass); if (c == null) { synchronized (syncObject) { c = tryClass(generatedClassName, desc1.getDeclaringClass(), superclass); if (c == null) { if (DEBUG) out.println("Generating " + generatedClassName + ", min: " + info.getMin() + ", max: " + info.getMax() + ", hasBlock: " + info.isBlock() + ", rest: " + info.isRest());
if (desc.getReturnClass() == void.class) {
public final boolean defineAnnotatedMethod(Method method, MethodFactory methodFactory) { JRubyMethod jrubyMethod = method.getAnnotation(JRubyMethod.class); if (jrubyMethod == null) return false; JavaMethodDescriptor desc = new JavaMethodDescriptor(method); DynamicMethod dynamicMethod = methodFactory.getAnnotatedMethod(this, desc, method.getName()); define(this, desc, method.getName(), dynamicMethod); return true; }
if (!Modifier.isPublic(descs.get(0).getDeclaringClass().getModifiers())) { LOG.warn("warning: binding non-public class {}; reflected handles won't work", descs.get(0).declaringClassName); methods.add(desc.getDeclaringClass().getDeclaredMethod(desc.name, desc.getParameterClasses())); annotations.add(desc.anno);
/** * Use code generation to provide a method handle based on an annotated Java * method. * * @see org.jruby.runtime.MethodFactory#getAnnotatedMethod */ public DynamicMethod getAnnotatedMethod(RubyModule implementationClass, JavaMethodDescriptor desc) { String javaMethodName = desc.name; try { Class c = getAnnotatedMethodClass(Arrays.asList(desc)); JavaMethod ic = (JavaMethod)c.getConstructor(new Class[]{RubyModule.class, Visibility.class}).newInstance(new Object[]{implementationClass, desc.anno.visibility()}); TypePopulator.populateMethod( ic, Arity.fromAnnotation(desc.anno, desc.actualRequired).getValue(), javaMethodName, desc.isStatic, CallConfiguration.getCallConfigByAnno(desc.anno), desc.anno.notImplemented(), desc.getDeclaringClass(), desc.name, desc.getReturnClass(), desc.getParameterClasses()); return ic; } catch(Exception e) { e.printStackTrace(); throw implementationClass.getRuntime().newLoadError(e.getMessage()); } }
private void addAnnotatedMethodInvoker(ClassWriter cw, String superClass, List<JavaMethodDescriptor> descs) { for (JavaMethodDescriptor desc: descs) { int specificArity = desc.calculateSpecificCallArity(); SkinnyMethodAdapter mv = beginMethod(cw, "call", specificArity, desc.hasBlock); mv.visitCode(); createAnnotatedMethodInvocation(desc, mv, superClass, specificArity, desc.hasBlock); mv.end(); } }
private static void loadArguments(SkinnyMethodAdapter mv, JavaMethodDescriptor desc, int specificArity) { Class[] argumentTypes; switch (specificArity) { default: case -1: mv.aload(ARGS_INDEX); break; case 0: // no args break; case 1: argumentTypes = desc.getArgumentTypes(); loadArgumentWithCast(mv, 1, argumentTypes[0]); break; case 2: argumentTypes = desc.getArgumentTypes(); loadArgumentWithCast(mv, 1, argumentTypes[0]); loadArgumentWithCast(mv, 2, argumentTypes[1]); break; case 3: argumentTypes = desc.getArgumentTypes(); loadArgumentWithCast(mv, 1, argumentTypes[0]); loadArgumentWithCast(mv, 2, argumentTypes[1]); loadArgumentWithCast(mv, 3, argumentTypes[2]); break; } }
JavaMethodDescriptor desc = new JavaMethodDescriptor(method);
if (!Modifier.isPublic(descs.get(0).getDeclaringClass().getModifiers())) { LOG.warn("warning: binding non-public class {}; reflected handles won't work", descs.get(0).declaringClassName); methods.add(desc.getDeclaringClass().getDeclaredMethod(desc.name, desc.getParameterClasses())); annotations.add(desc.anno);
/** * Use code generation to provide a method handle based on an annotated Java * method. * * @see org.jruby.runtime.MethodFactory#getAnnotatedMethod */ public DynamicMethod getAnnotatedMethod(RubyModule implementationClass, JavaMethodDescriptor desc) { String javaMethodName = desc.name; try { Class c = getAnnotatedMethodClass(Arrays.asList(desc)); JavaMethod ic = (JavaMethod)c.getConstructor(new Class[]{RubyModule.class, Visibility.class}).newInstance(new Object[]{implementationClass, desc.anno.visibility()}); TypePopulator.populateMethod( ic, Arity.fromAnnotation(desc.anno, desc.actualRequired).getValue(), javaMethodName, desc.isStatic, CallConfiguration.getCallConfigByAnno(desc.anno), desc.anno.notImplemented(), desc.getDeclaringClass(), desc.name, desc.getReturnClass(), desc.getParameterClasses()); return ic; } catch(Exception e) { e.printStackTrace(); throw implementationClass.getRuntime().newLoadError(e.getMessage()); } }
JavaMethodDescriptor desc = new JavaMethodDescriptor(method);
CallConfiguration.getCallConfig(info.isFrame(), info.isScope()), desc1.anno.notImplemented(), desc1.getDeclaringClass(), desc1.name, desc1.getReturnClass(),
public boolean defineAnnotatedMethod(Method method, MethodFactory methodFactory) { JRubyMethod jrubyMethod = method.getAnnotation(JRubyMethod.class); if (jrubyMethod == null) return false; CompatVersion compatVersion = getRuntime().getInstanceConfig().getCompatVersion(); if (shouldBindMethod(compatVersion, jrubyMethod.compat())) { JavaMethodDescriptor desc = new JavaMethodDescriptor(method); DynamicMethod dynamicMethod = methodFactory.getAnnotatedMethod(this, desc); define(this, desc, method.getName(), dynamicMethod); return true; } return false; }