@JRubyMethod public IRubyObject clear(ThreadContext context) { this.storage.clear(); return this.storage; }
int actualRequired = calculateActualRequired(method, method.getParameters().size(), anno.optional(), anno.rest(), isStatic, info.hasContext, info.hasBlock); isStatic, actualRequired, anno.optional(), true, anno.frame()); String implClass = anno.meta() ? "singletonClass" : "cls"; String baseName = getBaseName(anno.name(), method); out.println(" javaMethod = new " + annotatedBindingName + "(" + implClass + ", Visibility." + anno.visibility() + ", \"" + baseName + "\");"); out.println(" populateMethod(javaMethod, " + join(-1, quote(method.getSimpleName()), isStatic, anno.notImplemented(), ((TypeElement) method.getEnclosingElement()).getQualifiedName() + ".class", quote(method.getSimpleName()),
hasMeta |= anno.meta(); hasModule |= anno.module(); hasCompat |= anno.compat() != CompatVersion.BOTH; CharSequence name = anno.name().length == 0 ? method.getSimpleName() : anno.name()[0]; if (anno.compat() == CompatVersion.RUBY1_8) { methodsHash = staticAnnotatedMethods1_8; } else if (anno.compat() == CompatVersion.RUBY1_9) { methodsHash = staticAnnotatedMethods1_9; } else if (anno.compat() == CompatVersion.RUBY2_0) { methodsHash = staticAnnotatedMethods2_0; } else { if (anno.compat() == CompatVersion.RUBY1_8) { methodsHash = annotatedMethods1_8; } else if (anno.compat() == CompatVersion.RUBY1_9) { methodsHash = annotatedMethods1_9; } else if (anno.compat() == CompatVersion.RUBY2_0) { methodsHash = annotatedMethods2_0; } else { if (anno.frame()) { if (DEBUG) System.out.println("Method has frame = true: " + methodDescs.get(0).getEnclosingElement() + ":" + methodDescs); frame = true; if (anno.scope()) { if (DEBUG)
if (jrubyMethod.frame()) { frame = true; if (jrubyMethod.scope()) { scope = true; for (FrameField field : jrubyMethod.reads()) { frame |= field.needsFrame(); scope |= field.needsScope(); for (FrameField field : jrubyMethod.writes()) { frame |= field.needsFrame(); scope |= field.needsScope(); if (jrubyMethod.meta()) { singletonClass = module.getSingletonClass(); dynamicMethod.setImplementationClass(singletonClass); 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);
hasMeta |= anno.meta(); hasModule |= anno.module(); if (anno.compat() == org.jruby.CompatVersion.RUBY1_8) continue; CharSequence name = anno.name().length == 0 ? method.getSimpleName() : anno.name()[0]; JRubyMethod anno = decl.getAnnotation(JRubyMethod.class); if (anno.omit()) continue; JRubyMethod anno = decl.getAnnotation(JRubyMethod.class); if (anno.omit()) continue; if (decl.getSimpleName().equals(rubyName) && decl.getAnnotation(JRubyMethod.class).name().length <= 1) { simpleNames.add(decl); continue;
false); int handleOffset = calculateHandleOffset(method.getParameters().size(), anno.required(), anno.optional(), anno.rest(), isStatic, hasContext, hasBlock); meta |= anno.meta(); mv.getstatic(p(Visibility.class), anno.visibility().name(), ci(Visibility.class)); mv.ldc(AnnotationBinder.getBaseName(anno.name(), methods.get(0))); mv.ldc(encodeSignature(0, 0, 0, 0, 0, true, false)); mv.ldc(true); mv.ldc(anno.notImplemented());
if (anno.frame() || (anno.reads() != null && anno.reads().length >= 1) || (anno.writes() != null && anno.writes().length >= 1)) { ASTInspector.addFrameAwareMethods(anno.name()); clsmod.defineAnnotatedMethod(entry.getKey(), entry.getValue(), methodFactory); for (JavaMethodDescriptor desc : entry.getValue()) { if (!desc.anno.omit()) runtime.addBoundMethod(desc.declaringClassName, desc.name, entry.getKey()); clsmod.defineAnnotatedMethod(entry.getKey(), entry.getValue(), methodFactory); for (JavaMethodDescriptor desc : entry.getValue()) { if (!desc.anno.omit()) runtime.addBoundMethod(desc.declaringClassName, desc.name, entry.getKey()); clsmod.defineAnnotatedMethod(entry.getKey(), entry.getValue(), methodFactory); for (JavaMethodDescriptor desc : entry.getValue()) { if (!desc.anno.omit()) runtime.addBoundMethod(desc.declaringClassName, desc.name, entry.getKey()); clsmod.defineAnnotatedMethod(entry.getKey(), entry.getValue(), methodFactory); for (JavaMethodDescriptor desc : entry.getValue()) { if (!desc.anno.omit()) runtime.addBoundMethod(desc.declaringClassName, desc.name, entry.getKey()); clsmod.defineAnnotatedMethod(entry.getKey(), entry.getValue(), methodFactory); for (JavaMethodDescriptor desc : entry.getValue()) { if (!desc.anno.omit()) runtime.addBoundMethod(desc.declaringClassName, desc.name, entry.getKey()); clsmod.defineAnnotatedMethod(entry.getKey(), entry.getValue(), methodFactory); for (JavaMethodDescriptor desc : entry.getValue()) { if (!desc.anno.omit()) runtime.addBoundMethod(desc.declaringClassName, desc.name, entry.getKey()); clsmod.defineAnnotatedMethod(entry.getKey(), entry.getValue(), methodFactory);
if (anno.compat() == org.jruby.CompatVersion.RUBY1_8) continue; final String[] names = anno.name(); String name = names.length == 0 ? method.getName() : names[0]; if (anno.reads().length > 0 && readGroups == Collections.EMPTY_MAP) readGroups = new HashMap<>(); if (anno.writes().length > 0 && writeGroups == Collections.EMPTY_MAP) writeGroups = new HashMap<>();
public static void addMethodNamesToSet(Set<String> set, JRubyMethod jrubyMethod, String simpleName) { if (jrubyMethod.name().length == 0) { set.add(simpleName); } else { set.addAll(Arrays.asList(jrubyMethod.name())); } if (jrubyMethod.alias().length > 0) { set.addAll(Arrays.asList(jrubyMethod.alias())); } }
public static void groupFrameFields(Map<Set<FrameField>, List<String>> readGroups, Map<Set<FrameField>, List<String>> writeGroups, JRubyMethod anno, String simpleName) { if (anno.reads().length > 0) { Set<FrameField> reads = new HashSet<>(Arrays.asList(anno.reads())); List<String> nameList = readGroups.get(reads); if (nameList == null) readGroups.put(reads, nameList = new ArrayList<>()); if (anno.name().length == 0) { nameList.add(simpleName); } else { nameList.addAll(Arrays.asList(anno.name())); } } if (anno.writes().length > 0) { Set<FrameField> writes = new HashSet<>(Arrays.asList(anno.writes())); List<String> nameList = writeGroups.get(writes); if (nameList == null) writeGroups.put(writes, nameList = new ArrayList<>()); if (anno.name().length == 0) { nameList.add(simpleName); } else { nameList.addAll(Arrays.asList(anno.name())); } } }
DescriptorInfo info = new DescriptorInfo(desc1); if (desc1.anno.frame()) { notImplemented = notImplemented || desc.anno.notImplemented(); desc1.anno.visibility(), desc1.name, (min == max) ?
/** * 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()); } }
/** * Produce a CallConfiguration name that represents what must be prepared around calls to * the method with this annotation. */ public static CallConfiguration getCallConfigByAnno(JRubyMethod anno) { return getCallConfig(anno.frame()); }
public void generateMethodAddCalls(ExecutableElement md, JRubyMethod jrubyMethod) { if (jrubyMethod.meta()) { defineMethodOnClass("javaMethod", "singletonClass", jrubyMethod, md); } else { defineMethodOnClass("javaMethod", "cls", jrubyMethod, md); if (jrubyMethod.module()) { out.println(" moduleMethod = populateModuleMethod(cls, javaMethod);"); defineMethodOnClass("moduleMethod", "singletonClass", jrubyMethod, md); } } // } }
@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); }
Modifier.isStatic(method0.getModifiers()), CallConfiguration.getCallConfigByAnno(anno0), anno0.notImplemented()); return ic; } catch (Exception e) {
String name = anno.name().length == 0 ? method.getName() : anno.name()[0]; 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 { 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 {
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; }