private void generateMethodAddCalls(ExecutableElement md, final boolean meta, final boolean module, String[] names, String[] aliases) { if (meta) { defineMethodOnClass("javaMethod", "singletonClass", names, aliases, md); } else { defineMethodOnClass("javaMethod", "cls", names, aliases, md); if (module) { out.println(" moduleMethod = populateModuleMethod(cls, javaMethod);"); defineMethodOnClass("moduleMethod", "singletonClass", names, aliases, md); } } }
private CharSequence getActualQualifiedName(TypeElement td) { if (td.getNestingKind() == NestingKind.MEMBER) { return getActualQualifiedName((TypeElement)td.getEnclosingElement()) + "$" + td.getSimpleName(); } return td.getQualifiedName().toString(); }
public void processMethodDeclarations(Map<CharSequence, List<ExecutableElement>> declarations) { for (Map.Entry<CharSequence, List<ExecutableElement>> entry : declarations.entrySet()) { List<ExecutableElement> list = entry.getValue(); if (list.size() == 1) { // single method, use normal logic processMethodDeclaration(list.get(0)); } else { // multimethod, new logic processMethodDeclarationMulti(list.get(0)); } } }
if (anno != null && out != null) { boolean isStatic = method.getModifiers().contains(Modifier.STATIC); CharSequence qualifiedName = getActualQualifiedName((TypeElement) method.getEnclosingElement()); ParametersInfo info = identifyParameters(method.getParameters()); int actualRequired = calculateActualRequired(method, method.getParameters().size(), anno.optional(), anno.rest(), isStatic, info.hasContext, info.hasBlock); 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(AnnotationHelper.getArityValue(anno, actualRequired), quote(method.getSimpleName()), isStatic, anno.notImplemented(), ((TypeElement) method.getEnclosingElement()).getQualifiedName() + ".class", quote(method.getSimpleName()), method.getReturnType() + ".class", info.typeDecl ) + ");"); generateMethodAddCalls(method, anno);
processType(innerType); checkForThrows(cd, method); classNames.add(getActualQualifiedName(cd)); processMethodDeclarations(staticAnnotatedMethods); for (Map.Entry<CharSequence, List<ExecutableElement>> entry : staticAnnotatedMethods.entrySet()) { ExecutableElement decl = entry.getValue().get(0); processMethodDeclarations(annotatedMethods); for (Map.Entry<CharSequence, List<ExecutableElement>> entry : annotatedMethods.entrySet()) { ExecutableElement decl = entry.getValue().get(0); args.addAll(getMethodMappings(cd, complexNames)); args.addAll(getSimpleMethodMappings(cd, simpleNames)); out.println(" runtime.addBoundMethods(" + join(args.stream().map((str) -> quote(str)).toArray()) + ");"); (bits, names) -> emitIndexCode(bits, names, " MethodIndex.addMethodReadFieldsPacked(%d, \"%s\");")); AnnotationHelper.populateMethodIndex(writeGroups, (bits, names) -> emitIndexCode(bits, names, " MethodIndex.addMethodWriteFieldsPacked(%d, \"%s\");"));
if (anno != null && out != null) { boolean isStatic = method.getModifiers().contains(Modifier.STATIC); CharSequence qualifiedName = getActualQualifiedName((TypeElement)method.getEnclosingElement()); int actualRequired = calculateActualRequired(method, method.getParameters().size(), anno.optional(), anno.rest(), isStatic, hasContext, hasBlock); + method.getReturnType().toString() + ".class, " + "new Class[] {" + buffer.toString() + "});"); generateMethodAddCalls(method, anno);
processType(innerType); classNames.add(getActualQualifiedName(cd)); processMethodDeclarations(staticAnnotatedMethods); for (Map.Entry<CharSequence, List<ExecutableElement>> entry : staticAnnotatedMethods.entrySet()) { ExecutableElement decl = entry.getValue().get(0); if (!decl.getAnnotation(JRubyMethod.class).omit()) addCoreMethodMapping(entry.getKey(), decl, out); processMethodDeclarations(staticAnnotatedMethods1_8); for (Map.Entry<CharSequence, List<ExecutableElement>> entry : staticAnnotatedMethods1_8.entrySet()) { ExecutableElement decl = entry.getValue().get(0); if (!decl.getAnnotation(JRubyMethod.class).omit()) addCoreMethodMapping(entry.getKey(), decl, out); processMethodDeclarations(staticAnnotatedMethods1_9); for (Map.Entry<CharSequence, List<ExecutableElement>> entry : staticAnnotatedMethods1_9.entrySet()) { ExecutableElement decl = entry.getValue().get(0); if (!decl.getAnnotation(JRubyMethod.class).omit()) addCoreMethodMapping(entry.getKey(), decl, out); processMethodDeclarations(staticAnnotatedMethods2_0); for (Map.Entry<CharSequence, List<ExecutableElement>> entry : staticAnnotatedMethods2_0.entrySet()) { ExecutableElement decl = entry.getValue().get(0); if (!decl.getAnnotation(JRubyMethod.class).omit()) addCoreMethodMapping(entry.getKey(), decl, out); processMethodDeclarations(annotatedMethods); for (Map.Entry<CharSequence, List<ExecutableElement>> entry : annotatedMethods.entrySet()) { ExecutableElement decl = entry.getValue().get(0); if (!decl.getAnnotation(JRubyMethod.class).omit()) addCoreMethodMapping(entry.getKey(), decl, out);
@Override public boolean process(Set<? extends TypeElement> typeElements, RoundEnvironment roundEnvironment) { for (TypeElement element : ElementFilter.typesIn(roundEnvironment.getRootElements())) { processType(element); } try { FileWriter fw = new FileWriter("target/generated-sources/annotated_classes.txt"); for (CharSequence name : classNames) { fw.write(name.toString()); fw.write('\n'); } fw.close(); } catch (Exception e) { throw new RuntimeException(e); } return true; }
public void generateMethodAddCalls(ExecutableElement md, JRubyMethod anno) { generateMethodAddCalls(md, anno.meta(), anno.module(), anno.name(), anno.alias()); }
AnnotationBinder.checkForThrows(cd, method);
if (anno != null && out != null) { boolean isStatic = method.getModifiers().contains(Modifier.STATIC); CharSequence qualifiedName = getActualQualifiedName((TypeElement)method.getEnclosingElement()); ParametersInfo info = identifyParameters(method.getParameters()); int actualRequired = calculateActualRequired(method, method.getParameters().size(), anno.optional(), anno.rest(), isStatic, info.hasContext, info.hasBlock); 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()), method.getReturnType() + ".class", info.typeDecl ) + ");"); generateMethodAddCalls(method, anno);
processType(innerType); checkForThrows(cd, method); classNames.add(getActualQualifiedName(cd)); processMethodDeclarations(staticAnnotatedMethods); for (Map.Entry<CharSequence, List<ExecutableElement>> entry : staticAnnotatedMethods.entrySet()) { ExecutableElement decl = entry.getValue().get(0); processMethodDeclarations(annotatedMethods); for (Map.Entry<CharSequence, List<ExecutableElement>> entry : annotatedMethods.entrySet()) { ExecutableElement decl = entry.getValue().get(0); args.addAll(getMethodMappings(cd, complexNames)); args.addAll(getSimpleMethodMappings(cd, simpleNames)); out.println(" runtime.addBoundMethods(" + join(args.stream().map((str) -> quote(str)).toArray()) + ");"); (bits, names) -> emitIndexCode(bits, names, " MethodIndex.addMethodReadFieldsPacked(%d, \"%s\");")); AnnotationHelper.populateMethodIndex(writeGroups, (bits, names) -> emitIndexCode(bits, names, " MethodIndex.addMethodWriteFieldsPacked(%d, \"%s\");"));
if (anno != null && out != null) { boolean isStatic = method.getModifiers().contains(Modifier.STATIC); CharSequence qualifiedName = getActualQualifiedName((TypeElement)method.getEnclosingElement()); int actualRequired = calculateActualRequired(method, method.getParameters().size(), anno.optional(), anno.rest(), isStatic, hasContext, hasBlock); + method.getReturnType().toString() + ".class, " + "new Class[] {" + buffer.toString() + "});"); generateMethodAddCalls(method, anno);
processType(innerType); classNames.add(getActualQualifiedName(cd)); processMethodDeclarations(staticAnnotatedMethods); for (Map.Entry<CharSequence, List<ExecutableElement>> entry : staticAnnotatedMethods.entrySet()) { ExecutableElement decl = entry.getValue().get(0); if (!decl.getAnnotation(JRubyMethod.class).omit()) addCoreMethodMapping(entry.getKey(), decl, out); processMethodDeclarations(staticAnnotatedMethods1_8); for (Map.Entry<CharSequence, List<ExecutableElement>> entry : staticAnnotatedMethods1_8.entrySet()) { ExecutableElement decl = entry.getValue().get(0); if (!decl.getAnnotation(JRubyMethod.class).omit()) addCoreMethodMapping(entry.getKey(), decl, out); processMethodDeclarations(staticAnnotatedMethods1_9); for (Map.Entry<CharSequence, List<ExecutableElement>> entry : staticAnnotatedMethods1_9.entrySet()) { ExecutableElement decl = entry.getValue().get(0); if (!decl.getAnnotation(JRubyMethod.class).omit()) addCoreMethodMapping(entry.getKey(), decl, out); processMethodDeclarations(staticAnnotatedMethods2_0); for (Map.Entry<CharSequence, List<ExecutableElement>> entry : staticAnnotatedMethods2_0.entrySet()) { ExecutableElement decl = entry.getValue().get(0); if (!decl.getAnnotation(JRubyMethod.class).omit()) addCoreMethodMapping(entry.getKey(), decl, out); processMethodDeclarations(annotatedMethods); for (Map.Entry<CharSequence, List<ExecutableElement>> entry : annotatedMethods.entrySet()) { ExecutableElement decl = entry.getValue().get(0); if (!decl.getAnnotation(JRubyMethod.class).omit()) addCoreMethodMapping(entry.getKey(), decl, out);
@Override public boolean process(Set<? extends TypeElement> typeElements, RoundEnvironment roundEnvironment) { for (TypeElement element : ElementFilter.typesIn(roundEnvironment.getRootElements())) { processType(element); } try { FileWriter fw = new FileWriter("target/generated-sources/annotated_classes.txt"); for (CharSequence name : classNames) { fw.write(name.toString()); fw.write('\n'); } fw.close(); } catch (Exception e) { if (e instanceof RuntimeException) throw (RuntimeException) e; throw new RuntimeException(e); } return true; }
public void generateMethodAddCalls(ExecutableElement md, JRubyMethod anno) { generateMethodAddCalls(md, anno.meta(), anno.module(), anno.name(), anno.alias()); }
AnnotationBinder.checkForThrows(cd, method);
if (anno != null && out != null) { boolean isStatic = method.getModifiers().contains(Modifier.STATIC); CharSequence qualifiedName = getActualQualifiedName((TypeElement)method.getEnclosingElement()); ParametersInfo info = identifyParameters(method.getParameters()); int actualRequired = calculateActualRequired(method, method.getParameters().size(), anno.optional(), anno.rest(), isStatic, info.hasContext, info.hasBlock); 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()), method.getReturnType() + ".class", info.typeDecl ) + ");"); generateMethodAddCalls(method, anno);
if (anno != null && out != null) { boolean isStatic = method.getModifiers().contains(Modifier.STATIC); CharSequence qualifiedName = getActualQualifiedName((TypeElement)method.getEnclosingElement()); int actualRequired = calculateActualRequired(method, method.getParameters().size(), anno.optional(), anno.rest(), isStatic, hasContext, hasBlock); + method.getReturnType().toString() + ".class, " + "new Class[] {" + buffer.toString() + "});"); generateMethodAddCalls(method, anno);
public void processMethodDeclarations(Map<CharSequence, List<ExecutableElement>> declarations) { for (Map.Entry<CharSequence, List<ExecutableElement>> entry : declarations.entrySet()) { List<ExecutableElement> list = entry.getValue(); if (list.size() == 1) { // single method, use normal logic processMethodDeclaration(list.get(0)); } else { // multimethod, new logic processMethodDeclarationMulti(list.get(0)); } } }