public TupleAllocatorGenerator(Class tupleClass) throws Exception { setParentClassLoader(tupleClass.getClassLoader()); String className = tupleClass.getName() + "Allocator"; setClassName(packageName + "." + className); Java.CompilationUnit cu = new Java.CompilationUnit(null); Location loc = new Location(null, (short)0, (short)0); cu.setPackageDeclaration(new Java.PackageDeclaration(loc, packageName)); cu.addPackageMemberTypeDeclaration(makeClassDefinition(loc, tupleClass, className)); allocatorClass = compileToClass(cu); }
protected Java.CompilationUnit makeCompilationUnit() throws CompileException { Java.CompilationUnit cu = new Java.CompilationUnit(null); Location loc = new Location("", ((short) 0), ((short) 0)); cu.setPackageDeclaration(new Java.PackageDeclaration(loc, "com.boundary.tuple")); cu.addImportDeclaration(new Java.CompilationUnit.SingleTypeImportDeclaration(loc, "com.boundary.tuple.unsafe.Coterie".split("\\."))); Class[] ifaces; if (iface != null) { classesToTypes(loc, ifaces) ); cu.addPackageMemberTypeDeclaration(cd); for (Java.FieldDeclaration dec : generateFields()) { cd.addFieldDeclaration(dec);
private void generateEvaluatorClass() throws Exception { Scanner scanner = new Scanner(null, new StringReader(expression)); Parser parser = new Parser(scanner); Location loc = parser.location(); String className = "TupleExpression" + counter.incrementAndGet(); setClassName(packageName + "." + className); Java.CompilationUnit cu = makeCompilationUnit(parser); cu.setPackageDeclaration(new Java.PackageDeclaration(loc, packageName)); Java.PackageMemberClassDeclaration cd = new Java.PackageMemberClassDeclaration(loc, null, new Java.Modifiers(Mod.PUBLIC), className, null, null, new Java.Type[] { classToType(loc, iface) } ); cu.addPackageMemberTypeDeclaration(cd); cd.addConstructor(nullConstructor(loc)); cd.addDeclaredMethod(generateFrontendMethod(loc)); cd.addDeclaredMethod(generateBackendMethod(parser)); this.evaluatorClass = compileToClass(cu); this.evaluator = evaluatorClass.getConstructor().newInstance(); }
/** * Creates a map with all method names and their modified bodies * from specified {@link Java.CompilationUnit}. * * @param compilationUnit the source of the methods to collect * @param clazz type of the class to handle * @return a map with all method names and their modified bodies. */ public static Map<String, String> getMethods(Java.CompilationUnit compilationUnit, Class<?> clazz) { MethodGrabbingVisitor visitor = new MethodGrabbingVisitor(clazz); visitor.classFinder.visitTypeDeclaration(compilationUnit.getPackageMemberTypeDeclarations()[0]); return visitor.methods; }
public static Map<String, String> getMethods(Java.CompilationUnit cu, Class<?> c){ MethodGrabbingVisitor visitor = new MethodGrabbingVisitor(c); cu.getPackageMemberTypeDeclarations()[0].accept(visitor.classFinder.comprehensiveVisitor()); return visitor.methods; }
public static List<String> getMethods(Java.CompilationUnit cu){ ImportGrabber visitor = new ImportGrabber(); cu.getPackageMemberTypeDeclarations()[0].accept(visitor.finder.comprehensiveVisitor()); return visitor.imports; }