"org.pentaho.di.core.row.*", "org.pentaho.di.core.*", "org.pentaho.di.core.exception.*" } ); cbe.cook( new Scanner( null, sr ) ); rtn = cbe.getClazz(); UserDefinedJavaClassMeta.classCache.put( checksum, rtn );
protected String[] guessParameterNames() throws CompileException, IOException { return ExpressionEvaluator.guessParameterNames( new Scanner( "expressionEval", new StringReader( block ) ) ); }
protected String[] guessParameterNames() throws CompileException, IOException { return ExpressionEvaluator.guessParameterNames( new Scanner( "expressionEval", new StringReader( block ) ) ); }
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; }
return new Parser(new Scanner(null, new StringReader(body))).parseCompilationUnit(); } catch (CompileException e) { throw new IOException(String.format("Failure while loading class %s.", clazz.getName()), e);
@SuppressWarnings("unchecked") public <S> Class<S> compileClassBody(Reader classBody, Class<S> superClass, ClassLoader classLoader) throws CompileException { try { return new ClassBodyEvaluator(new Scanner(null, classBody), superClass, new Class[0], classLoader).getClazz(); } catch (Throwable t) { throw new CompileException(t); } finally { IOUtils.closeQuietly(classBody); } }
public ClassLoader compile(Reader javaSource, ClassLoader classLoader) throws CompileException { try { return new SimpleCompiler(new Scanner(null, javaSource), classLoader).getClassLoader(); } catch (Throwable t) { throw new CompileException(t); } finally { IOUtils.closeQuietly(javaSource); } } }
private CompilationUnit get(Class<?> c) throws IOException { URL u = getSourceURL(c); try (Reader reader = Resources.asCharSource(u, UTF_8).openStream()) { String body = CharStreams.toString(reader); // TODO: Hack to remove annotations so Janino doesn't choke. Need to reconsider this problem... body = body.replaceAll("@\\w+(?:\\([^\\\\]*?\\))?", ""); for(Replacement r : REPLACERS){ body = r.apply(body); } // System.out.println("original"); // System.out.println(body);; // System.out.println("decompiled"); // System.out.println(decompile(c)); try { return new Parser(new Scanner(null, new StringReader(body))).parseCompilationUnit(); } catch (CompileException e) { logger.warn("Failure while parsing function class:\n{}", body, e); return null; } } }
/** * @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); } }
private ClassFile[] doCompile(final String sourceCode) throws CompileException, IOException, ClassNotFoundException { StringReader reader = new StringReader(sourceCode); Scanner scanner = new Scanner((String) null, reader); Java.CompilationUnit compilationUnit = new Parser(scanner).parseCompilationUnit(); return new UnitCompiler(compilationUnit, compilationClassLoader) .compileUnit(this.debug, this.debug, this.debug); }
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; } }
ClassBodyEvaluator evaluator = new ClassBodyEvaluator( new Scanner( null, stringReader ), abstractClass, new Class[ 0 ], classLoader );
private static Function1<DataContext, Object[]> compile(String code, Object reason) { try { final ClassBodyEvaluator cbe = new ClassBodyEvaluator(); cbe.setClassName(GENERATED_CLASS_NAME); cbe.setExtendedClass(Utilities.class); cbe.setImplementedInterfaces(new Class[] {Function1.class, Serializable.class}); cbe.setParentClassLoader(RexExecutable.class.getClassLoader()); cbe.cook(new Scanner(null, new StringReader(code))); Class c = cbe.getClazz(); //noinspection unchecked final Constructor<Function1<DataContext, Object[]>> constructor = c.getConstructor(); return constructor.newInstance(); } catch (CompileException | IOException | InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new RuntimeException("While compiling " + reason, e); } }
private static Function1<DataContext, Object[]> compile(String code, Object reason) { try { final ClassBodyEvaluator cbe = new ClassBodyEvaluator(); cbe.setClassName(GENERATED_CLASS_NAME); cbe.setExtendedClass(Utilities.class); cbe.setImplementedInterfaces(new Class[] {Function1.class, Serializable.class}); cbe.setParentClassLoader(RexExecutable.class.getClassLoader()); cbe.cook(new Scanner(null, new StringReader(code))); Class c = cbe.getClazz(); //noinspection unchecked final Constructor<Function1<DataContext, Object[]>> constructor = c.getConstructor(); return constructor.newInstance(); } catch (CompileException | IOException | InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new RuntimeException("While compiling " + reason, e); } }
org.codehaus.janino.Scanner scanner = new Scanner(optionalFileName, new ByteArrayInputStream( code.getBytes("UTF-8")), "UTF-8");
org.codehaus.janino.Scanner scanner = new Scanner(optionalFileName, new ByteArrayInputStream( code.getBytes("UTF-8")), "UTF-8");
@Override public Class<?> compileClass(SourceCodeContext sourceCode) throws SourceCodeGenerationException { Scanner scanner; try { scanner = new Scanner(sourceCode.getClassName(), new StringReader(sourceCode.toSourceFile())); Java.CompilationUnit localCompilationUnit = new Parser(scanner).parseCompilationUnit(); UnitCompiler unitCompile = new UnitCompiler(localCompilationUnit, iClassLoader); ClassFile[] classes = unitCompile.compileUnit(false, false, false); return classLoader.findClass(classes[0].getThisClassName()); } catch (Exception e) { LOG.error("Can not compile {0}", sourceCode.getClassName(), e); throw new MappingException("Can not compile the generated mapper", e); } }
@Override protected ClassBytes[] getByteCode(final ClassNames className, final String sourcecode, boolean debug) throws CompileException, IOException, ClassNotFoundException, ClassTransformationException { StringReader reader = new StringReader(sourcecode); Scanner scanner = new Scanner((String) null, reader); Java.CompilationUnit compilationUnit = new Parser(scanner).parseCompilationUnit(); ClassFile[] classFiles = new UnitCompiler(compilationUnit, compilationClassLoader) .compileUnit(debug, debug, debug); ClassBytes[] byteCodes = new ClassBytes[classFiles.length]; for(int i = 0; i < classFiles.length; i++){ ClassFile file = classFiles[i]; byteCodes[i] = new ClassBytes(file.getThisClassName(), file.toByteArray()); } return byteCodes; }
bindable = (Bindable) ClassBodyEvaluator.createFastClassBodyEvaluator( new Scanner(null, new StringReader(s)), expr.name, Utilities.class,
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(); }