/** * Transforms a single class. */ public void translate(String fqcn, String outfqcn, String sourceJarName) throws JClassAlreadyExistsException { final JDefinedClass $output = codeModel._class(outfqcn); $output.annotate(Generated.class).param("value", Translator.class.getName()).param("date", new Date().toString()).param("comments", "based on " + sourceJarName); $output.annotate(SuppressWarnings.class).param("value", "rawtypes"); $output.constructor(JMod.PRIVATE); CompilationUnitTree dgmCut = getDefaultGroovyMethodCompilationUnitTree(parsed, fqcn); overloadsResolved.clear(); ClassSymbol dgm = (ClassSymbol) elements.getTypeElement(fqcn); dgm.accept(new ElementScanner7<Void,Void>() { @Override public Void visitExecutable(ExecutableElement e, Void __) { if (translatable.contains(fqcn + "." + e)) { overloadsResolved.put(mangledName(e), e); } // System.err.println("Not translating " + e.getAnnotationMirrors() + " " + e.getModifiers() + " " + fqcn + "." + e); // TODO else if it is public and has a Closure argument, translate to a form that just throws UnsupportedOperationException when called in CPS mode return null; } },null); // TODO verify that we actually found everything listed in translatables overloadsResolved.forEach((overloadResolved, e) -> { try { translateMethod(dgmCut, e, $output, fqcn, overloadResolved); } catch (Exception x) { throw new RuntimeException("Unable to transform " + fqcn + "." + e, x); } }); /* private static MethodLocation loc(String methodName) { return new MethodLocation(CpsDefaultGroovyMethods.class,methodName); } */ JClass $MethodLocation = codeModel.ref("com.cloudbees.groovy.cps.MethodLocation"); $output.method(JMod.PRIVATE|JMod.STATIC, $MethodLocation, "loc").tap( m -> { JVar $methodName = m.param(String.class, "methodName"); m.body()._return(JExpr._new($MethodLocation).arg($output.dotclass()).arg($methodName)); }); // Record the fqcn we've already translated for possible use later. otherTranslated.put(fqcn, $output); }