public RexExecutable(String code, Object reason) { try { //noinspection unchecked compiledFunction = (Function1) ClassBodyEvaluator.createFastClassBodyEvaluator( new Scanner(null, new StringReader(code)), GENERATED_CLASS_NAME, Utilities.class, new Class[] {Function1.class, Serializable.class}, getClass().getClassLoader()); } catch (CompileException e) { throw new RuntimeException("While compiling " + reason, e); } catch (IOException e) { throw new RuntimeException("While compiling " + reason, e); } this.code = code; }
/** * @param clazz * @param props * @return a compiled delegate * @see nuggets.IDelegateGenerator#generateDelegate(java.lang.Class, java.util.Map) */ public IDelegate generateDelegate(Class clazz, Map props, ClassLoader classloader) { String classbody = createDelegateClassBody(clazz, props); // System.out.println("BeanAnalyzer: generating delegate for class "+clazz.getName() +"\n"+classbody); // System.out.println("cl: "+Thread.currentThread().getContextClassLoader()); try { return (IDelegate)ClassBodyEvaluator.createFastClassBodyEvaluator(new Scanner( "<generated>", new StringReader(classbody)), "persistence.Delegate" + clazz.getName(), AGeneratedDelegate.class, new Class[]{IDelegate.class}, classloader); } catch(Exception e) { throw new PersistenceException(e); } }
public static Object evaluate(String classBody,Class extendedType,Class[] implementedTypes) { Object data = null; try { Scanner scanner = new Scanner(null, new StringReader(classBody)); data = ClassBodyEvaluator.createFastClassBodyEvaluator(scanner,extendedType.getName()+"$ClassBodyEvaluatorUtil$",extendedType,implementedTypes,null); } catch (CompileException e) { throw new CompileRuntimeException(e); } catch (ParseException e) { throw new ParseRuntimeException(e); } catch (ScanException e) { throw new ScanRuntimeException(e); } catch (IOException e) { throw new IORuntimeException(e); } return data; } }
try { bindable = (Bindable) ClassBodyEvaluator.createFastClassBodyEvaluator( new Scanner(null, new StringReader(s)), expr.name,
protected Object compileSrc(String src,BasicCompileInfo info) { Object data; try { if(logger.isDebugEnabled()) { logger.debug("compile "+info.getOutputClassName()+"\n"+src); } Scanner scanner = new Scanner(null, new StringReader(src)); Class baseClass = info.getBaseClass(); Class interfaceClass[] = info.getInterfaceClass(); data = ClassBodyEvaluator.createFastClassBodyEvaluator(scanner,info.getOutputClassName(),baseClass,interfaceClass,null); } catch (CompileException e) { compileProcessError(src,info.getBaseObject(),e.getLocation(),e.getMessage()); throw new CompileRuntimeException(e); } catch (ParseException e) { compileProcessError(src,info.getBaseObject(),e.getLocation(),e.getMessage()); throw new ParseRuntimeException(e); } catch (ScanException e) { compileProcessError(src,info.getBaseObject(),e.getLocation(),e.getMessage()); throw new ScanRuntimeException(e); } catch (IOException e) { throw new IORuntimeException(e); } return data; }