@SuppressWarnings("deprecation") public JavaMethod constructJavaMethod(RubyModule implementationClass, JavaMethodDescriptor desc, String name, Class c) throws InstantiationException, IllegalAccessException, java.lang.reflect.InvocationTargetException, NoSuchMethodException { // In order to support older versions of generated JavaMethod invokers, we check for the Version // annotation to be present and > 0. If absent, we use a thread local to allow the deprecated constructor // to still provide a final method name. DynamicMethod.Version version = (DynamicMethod.Version) c.getAnnotation(DynamicMethod.Version.class); JavaMethod ic; if (version == null) { // Old constructor with no name, use thread-local to pass it. JavaMethod.NAME_PASSER.set(name); try { ic = (JavaMethod) c.getConstructor(RubyModule_and_Visibility).newInstance(implementationClass, desc.anno.visibility()); } finally { JavaMethod.NAME_PASSER.remove(); } } else { // New constructor with name. ic = (JavaMethod) c.getConstructor(RubyModule_and_Visibility_and_Name).newInstance(implementationClass, desc.anno.visibility(), name); } return ic; }
@SuppressWarnings("deprecation") public JavaMethod constructJavaMethod(RubyModule implementationClass, JavaMethodDescriptor desc, String name, Class c) throws InstantiationException, IllegalAccessException, java.lang.reflect.InvocationTargetException, NoSuchMethodException { // In order to support older versions of generated JavaMethod invokers, we check for the Version // annotation to be present and > 0. If absent, we use a thread local to allow the deprecated constructor // to still provide a final method name. DynamicMethod.Version version = (DynamicMethod.Version) c.getAnnotation(DynamicMethod.Version.class); JavaMethod ic; if (version == null) { // Old constructor with no name, use thread-local to pass it. JavaMethod.NAME_PASSER.set(name); try { ic = (JavaMethod) c.getConstructor(RubyModule_and_Visibility).newInstance(implementationClass, desc.anno.visibility()); } finally { JavaMethod.NAME_PASSER.remove(); } } else { // New constructor with name. ic = (JavaMethod) c.getConstructor(RubyModule_and_Visibility_and_Name).newInstance(implementationClass, desc.anno.visibility(), name); } return ic; }
public ReflectedJavaMultiMethod( RubyModule implementationClass, List<Method> methods, List<JRubyMethod> annotations) { super(implementationClass, annotations.get(1).visibility());
public ReflectedJavaMultiMethod( RubyModule implementationClass, List<Method> methods, List<JRubyMethod> annotations) { super(implementationClass, annotations.get(1).visibility());
String implClass = anno.meta() ? "singletonClass" : "cls"; out.println(" javaMethod = new " + annotatedBindingName + "(" + implClass + ", Visibility." + anno.visibility() + ");"); out.println(" populateMethod(javaMethod, " + "-1, \"" +
String implClass = anno.meta() ? "singletonClass" : "cls"; out.println(" javaMethod = new " + annotatedBindingName + "(" + implClass + ", Visibility." + anno.visibility() + ");"); out.println(" populateMethod(javaMethod, " + "-1, \"" +
String implClass = anno.meta() ? "singletonClass" : "cls"; out.println(" javaMethod = new " + annotatedBindingName + "(" + implClass + ", Visibility." + anno.visibility() + ");"); out.println(" populateMethod(javaMethod, " + +AnnotationHelper.getArityValue(anno, actualRequired) + ", \""
String implClass = anno.meta() ? "singletonClass" : "cls"; out.println(" javaMethod = new " + annotatedBindingName + "(" + implClass + ", Visibility." + anno.visibility() + ");"); out.println(" populateMethod(javaMethod, " + +AnnotationHelper.getArityValue(anno, actualRequired) + ", \""
public ReflectedJavaMethod( RubyModule implementationClass, Method method, JRubyMethod annotation) { super(implementationClass, annotation.visibility()); this.method = method; Class<?>[] params = method.getParameterTypes(); this.needsBlock = params.length > 0 && params[params.length - 1] == Block.class; this.isStatic = Modifier.isStatic(method.getModifiers()); Arity arity = Arity.fromAnnotation(annotation, params, this.isStatic); setArity(arity); this.required = arity.getValue() >= 0 ? arity.getValue() : Math.abs(arity.getValue())-1; this.optional = annotation.optional(); this.rest = annotation.rest(); this.needsThreadContext = params.length > 0 && params[0] == ThreadContext.class; this.argsAsIs = ! isStatic && optional == 0 && !rest && !needsBlock && !needsThreadContext; if (rest) { max = -1; } else { max = required + optional; } }
public ReflectedJavaMethod( RubyModule implementationClass, Method method, JRubyMethod annotation) { super(implementationClass, annotation.visibility()); this.method = method; Class<?>[] params = method.getParameterTypes(); this.needsBlock = params.length > 0 && params[params.length - 1] == Block.class; this.isStatic = Modifier.isStatic(method.getModifiers()); Arity arity = Arity.fromAnnotation(annotation, params, this.isStatic); setArity(arity); this.required = arity.getValue() >= 0 ? arity.getValue() : Math.abs(arity.getValue())-1; this.optional = annotation.optional(); this.rest = annotation.rest(); this.needsThreadContext = params.length > 0 && params[0] == ThreadContext.class; this.argsAsIs = ! isStatic && optional == 0 && !rest && !needsBlock && !needsThreadContext; if (rest) { max = -1; } else { max = required + optional; } }
/** * 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()); } }
out.println(" javaMethod = new " + annotatedBindingName + "(" + implClass + ", Visibility." + anno.visibility() + ", \"" + baseName + "\");"); out.println(" populateMethod(javaMethod, " + join(-1,
out.println(" javaMethod = new " + annotatedBindingName + "(" + implClass + ", Visibility." + anno.visibility() + ", \"" + baseName + "\");"); out.println(" populateMethod(javaMethod, " + join(-1,
out.println(" javaMethod = new " + annotatedBindingName + "(" + implClass + ", Visibility." + anno.visibility() + ", \"" + baseName + "\");"); out.println(" populateMethod(javaMethod, " + join(AnnotationHelper.getArityValue(anno, actualRequired),
out.println(" javaMethod = new " + annotatedBindingName + "(" + implClass + ", Visibility." + anno.visibility() + ", \"" + baseName + "\");"); out.println(" populateMethod(javaMethod, " + join(AnnotationHelper.getArityValue(anno, actualRequired),
/** * 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()); } }
@Override public DynamicMethod getAnnotatedMethod(RubyModule implementationClass, List<JavaMethodDescriptor> descs) { JavaMethodDescriptor desc1 = descs.get(0); if (desc1.anno.frame()) { // super logic does not work yet because we need to take impl class // and method name from the DynamicMethod#call call, so punt to // generated class for now return super.getAnnotatedMethod(implementationClass, descs); } if (!Modifier.isPublic(desc1.getDeclaringClass().getModifiers())) { LOG.warn("warning: binding non-public class {}; reflected handles won't work", desc1.declaringClassName); } DescriptorInfo info = new DescriptorInfo(descs); MethodHandle[] targets = buildAnnotatedMethodHandles(implementationClass.getRuntime(), descs, implementationClass); return new HandleMethod(implementationClass, desc1.anno.visibility(), CallConfiguration.getCallConfig(info.isFrame(), info.isScope()), targets, null); }
if (DEBUG) out.println(" min: " + info.getMin() + ", max: " + info.getMax()); JavaMethod ic = (JavaMethod)c.getConstructor(new Class[]{RubyModule.class, Visibility.class}).newInstance(new Object[]{implementationClass, desc1.anno.visibility()});
if (DEBUG) out.println(" min: " + info.getMin() + ", max: " + info.getMax()); JavaMethod ic = (JavaMethod)c.getConstructor(new Class[]{RubyModule.class, Visibility.class}).newInstance(new Object[]{implementationClass, desc1.anno.visibility()});
@Override public DynamicMethod getAnnotatedMethod(RubyModule implementationClass, List<JavaMethodDescriptor> descs) { JavaMethodDescriptor desc1 = descs.get(0); if (desc1.anno.frame()) { // super logic does not work yet because we need to take impl class // and method name from the DynamicMethod#call call, so punt to // generated class for now return super.getAnnotatedMethod(implementationClass, descs); } if (!Modifier.isPublic(desc1.getDeclaringClass().getModifiers())) { LOG.warn("warning: binding non-public class {}; reflected handles won't work", desc1.declaringClassName); } DescriptorInfo info = new DescriptorInfo(descs); MethodHandle[] targets = buildAnnotatedMethodHandles(implementationClass.getRuntime(), descs, implementationClass); return new HandleMethod(implementationClass, desc1.anno.visibility(), CallConfiguration.getCallConfig(info.isFrame(), info.isScope()), targets, null); }