Java Code Examples for org.codehaus.commons.compiler.IClassBodyEvaluator#createInstance()
The following examples show how to use
org.codehaus.commons.compiler.IClassBodyEvaluator#createInstance() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HiveEnumerableInterpretable.java From marble with Apache License 2.0 | 6 votes |
static Bindable getBindable(ClassDeclaration expr, String s, int fieldCount) throws CompileException, IOException { ICompilerFactory compilerFactory; try { compilerFactory = CompilerFactoryFactory.getDefaultCompilerFactory(); } catch (Exception e) { throw new IllegalStateException( "Unable to instantiate java compiler", e); } IClassBodyEvaluator cbe = compilerFactory.newClassBodyEvaluator(); cbe.setClassName(expr.name); cbe.setExtendedClass(Utilities.class); cbe.setImplementedInterfaces( fieldCount == 1 ? new Class[]{Bindable.class, Typed.class} : new Class[]{ArrayBindable.class}); cbe.setParentClassLoader(EnumerableInterpretable.class.getClassLoader()); if (CalcitePrepareImpl.DEBUG) { // Add line numbers to the generated janino class cbe.setDebuggingInformation(true, true, true); } return (Bindable) cbe.createInstance(new StringReader(s)); }
Example 2
Source File: RexToJavaCompiler.java From samza with Apache License 2.0 | 6 votes |
/** * Creates the instance of the class defined in {@link ClassDeclaration} * @param expr Interface whose instance needs to be created. * @param s The java code that implements the interface which should be used to create the instance. * @return The object of the class which implements the interface {@link Expression} with the code that is passed as input. * @throws CompileException * @throws IOException */ static Expression getExpression(ClassDeclaration expr, String s) throws CompileException, IOException { ICompilerFactory compilerFactory; try { compilerFactory = CompilerFactoryFactory.getDefaultCompilerFactory(); } catch (Exception e) { throw new IllegalStateException("Unable to instantiate java compiler", e); } IClassBodyEvaluator cbe = compilerFactory.newClassBodyEvaluator(); cbe.setClassName(expr.name); cbe.setImplementedInterfaces(expr.implemented.toArray(new Class[expr.implemented.size()])); cbe.setParentClassLoader(RexToJavaCompiler.class.getClassLoader()); cbe.setDebuggingInformation(true, true, true); return (org.apache.samza.sql.data.Expression) cbe.createInstance(new StringReader(s)); }
Example 3
Source File: JaninoRexCompiler.java From calcite with Apache License 2.0 | 6 votes |
static Scalar getScalar(ClassDeclaration expr, String s) throws CompileException, IOException { ICompilerFactory compilerFactory; try { compilerFactory = CompilerFactoryFactory.getDefaultCompilerFactory(); } catch (Exception e) { throw new IllegalStateException( "Unable to instantiate java compiler", e); } IClassBodyEvaluator cbe = compilerFactory.newClassBodyEvaluator(); cbe.setClassName(expr.name); cbe.setImplementedInterfaces(new Class[]{Scalar.class}); cbe.setParentClassLoader(JaninoRexCompiler.class.getClassLoader()); if (CalciteSystemProperty.DEBUG.value()) { // Add line numbers to the generated janino class cbe.setDebuggingInformation(true, true, true); } return (Scalar) cbe.createInstance(new StringReader(s)); }
Example 4
Source File: EnumerableInterpretable.java From Quicksql with MIT License | 5 votes |
static Bindable getBindable(ClassDeclaration expr, String s, int fieldCount) throws CompileException, IOException, ExecutionException { ICompilerFactory compilerFactory; try { compilerFactory = CompilerFactoryFactory.getDefaultCompilerFactory(); } catch (Exception e) { throw new IllegalStateException( "Unable to instantiate java compiler", e); } final IClassBodyEvaluator cbe = compilerFactory.newClassBodyEvaluator(); cbe.setClassName(expr.name); cbe.setExtendedClass(Utilities.class); cbe.setImplementedInterfaces( fieldCount == 1 ? new Class[] {Bindable.class, Typed.class} : new Class[] {ArrayBindable.class}); cbe.setParentClassLoader(EnumerableInterpretable.class.getClassLoader()); if (CalciteSystemProperty.DEBUG.value()) { // Add line numbers to the generated janino class cbe.setDebuggingInformation(true, true, true); } if (CalciteSystemProperty.BINDABLE_CACHE_MAX_SIZE.value() != 0) { StaticFieldDetector detector = new StaticFieldDetector(); expr.accept(detector); if (!detector.containsStaticField) { return BINDABLE_CACHE.get(s, () -> (Bindable) cbe.createInstance(new StringReader(s))); } } return (Bindable) cbe.createInstance(new StringReader(s)); }
Example 5
Source File: JaninoRexCompiler.java From Quicksql with MIT License | 5 votes |
static Scalar getScalar(ClassDeclaration expr, String s) throws CompileException, IOException { ICompilerFactory compilerFactory; try { compilerFactory = CompilerFactoryFactory.getDefaultCompilerFactory(); } catch (Exception e) { throw new IllegalStateException( "Unable to instantiate java compiler", e); } IClassBodyEvaluator cbe = compilerFactory.newClassBodyEvaluator(); cbe.setClassName(expr.name); cbe.setImplementedInterfaces(new Class[]{Scalar.class}); cbe.setParentClassLoader(JaninoRexCompiler.class.getClassLoader()); if (CalciteSystemProperty.DEBUG.value()) { // Add line numbers to the generated janino class cbe.setDebuggingInformation(true, true, true); } return (Scalar) cbe.createInstance(new StringReader(s)); }
Example 6
Source File: EnumerableInterpretable.java From calcite with Apache License 2.0 | 5 votes |
static Bindable getBindable(ClassDeclaration expr, String s, int fieldCount) throws CompileException, IOException, ExecutionException { ICompilerFactory compilerFactory; try { compilerFactory = CompilerFactoryFactory.getDefaultCompilerFactory(); } catch (Exception e) { throw new IllegalStateException( "Unable to instantiate java compiler", e); } final IClassBodyEvaluator cbe = compilerFactory.newClassBodyEvaluator(); cbe.setClassName(expr.name); cbe.setExtendedClass(Utilities.class); cbe.setImplementedInterfaces( fieldCount == 1 ? new Class[] {Bindable.class, Typed.class} : new Class[] {ArrayBindable.class}); cbe.setParentClassLoader(EnumerableInterpretable.class.getClassLoader()); if (CalciteSystemProperty.DEBUG.value()) { // Add line numbers to the generated janino class cbe.setDebuggingInformation(true, true, true); } if (CalciteSystemProperty.BINDABLE_CACHE_MAX_SIZE.value() != 0) { StaticFieldDetector detector = new StaticFieldDetector(); expr.accept(detector); if (!detector.containsStaticField) { return BINDABLE_CACHE.get(s, () -> (Bindable) cbe.createInstance(new StringReader(s))); } } return (Bindable) cbe.createInstance(new StringReader(s)); }