本文整理汇总了Java中org.codehaus.commons.compiler.CompilerFactoryFactory类的典型用法代码示例。如果您正苦于以下问题:Java CompilerFactoryFactory类的具体用法?Java CompilerFactoryFactory怎么用?Java CompilerFactoryFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CompilerFactoryFactory类属于org.codehaus.commons.compiler包,在下文中一共展示了CompilerFactoryFactory类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getBindable
import org.codehaus.commons.compiler.CompilerFactoryFactory; //导入依赖的package包/类
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));
}
开发者ID:apache,项目名称:calcite,代码行数:24,代码来源:EnumerableInterpretable.java
示例2: getScalar
import org.codehaus.commons.compiler.CompilerFactoryFactory; //导入依赖的package包/类
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 (CalcitePrepareImpl.DEBUG) {
// Add line numbers to the generated janino class
cbe.setDebuggingInformation(true, true, true);
}
return (Scalar) cbe.createInstance(new StringReader(s));
}
开发者ID:apache,项目名称:calcite,代码行数:20,代码来源:JaninoRexCompiler.java
示例3: generateCondition
import org.codehaus.commons.compiler.CompilerFactoryFactory; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
private WorkflowCondition generateCondition(String exp, WorkflowContext workflowContext) throws Exception {
Object request = workflowContext.getRequest();
String workflowContectClassName = workflowContext.getClass().getName();
String className = request.getClass().getName();
StringBuffer classBody = new StringBuffer();
classBody.append(" public boolean evaluate(WorkflowContext contextParam, Object requestParam) { ");
classBody.append(workflowContectClassName).append(" context = (").append(workflowContectClassName)
.append(") contextParam; ");
classBody.append(className).append(" request = (").append(className).append(") requestParam;");
classBody.append("return ").append(exp).append("; ");
classBody.append(" } ");
IClassBodyEvaluator evaluator = CompilerFactoryFactory.getDefaultCompilerFactory().newClassBodyEvaluator();
evaluator.setImplementedInterfaces(new Class[] { WorkflowCondition.class });
evaluator.setDefaultImports(new String[] { "com.datarpm.sigma.workflow.*" });
evaluator.setParentClassLoader(WorkflowEngine.class.getClassLoader());
Reader reader = new StringReader(classBody.toString());
return (WorkflowCondition) evaluator.createInstance(reader);
}
开发者ID:DataRPM-Labs,项目名称:sigma,代码行数:23,代码来源:WorkflowEngine.java
示例4: getExpression
import org.codehaus.commons.compiler.CompilerFactoryFactory; //导入依赖的package包/类
/**
* 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));
}
开发者ID:apache,项目名称:samza,代码行数:24,代码来源:RexToJavaCompiler.java
示例5: initJanino
import org.codehaus.commons.compiler.CompilerFactoryFactory; //导入依赖的package包/类
private static void initJanino() throws SQLException {
// For unknown reason, threadContextClassLoader.getResource("org.codehaus.commons.compiler.properties")
// returns null when accessed via BundleClassLoader
// We make a shortcut
// Some OSGi WA might probably exist
if (initCompilerDone) {
return;
}
initCompilerDone = true;
Thread currentThread = Thread.currentThread();
ClassLoader cl = currentThread.getContextClassLoader();
try{
currentThread.setContextClassLoader(CompilerFactoryFactory.class.getClassLoader());
if (CompilerFactoryFactory.getDefaultCompilerFactory() == null) {
throw new SQLException("Janino compiler is not initialized: CompilerFactoryFactory.getDefaultCompilerFactory() == null");
};
} catch (Exception e) {
throw new SQLException("Unable to load Janino compiler", e);
} finally {
currentThread.setContextClassLoader(cl);
}
}
开发者ID:vlsi,项目名称:mat-calcite-plugin,代码行数:23,代码来源:CalciteDataSource.java
示例6: testFactory
import org.codehaus.commons.compiler.CompilerFactoryFactory; //导入依赖的package包/类
@Test
public void testFactory() throws Exception {
assertEquals(CompilerFactory.class, CompilerFactoryFactory.getDefaultCompilerFactory().getClass());
}
开发者ID:dremio,项目名称:dremio-oss,代码行数:5,代码来源:CommonsCompilerTest.java
示例7: SqlPredicate
import org.codehaus.commons.compiler.CompilerFactoryFactory; //导入依赖的package包/类
SqlPredicate(final Expression filterExpression,
final Schema schema,
boolean isWindowedKey,
final FunctionRegistry functionRegistry) {
this.filterExpression = filterExpression;
this.schema = schema;
this.genericRowValueTypeEnforcer = new GenericRowValueTypeEnforcer(schema);
this.isWindowedKey = isWindowedKey;
this.functionRegistry = functionRegistry;
CodeGenRunner codeGenRunner = new CodeGenRunner(schema, functionRegistry);
Map<String, Class> parameterMap = codeGenRunner.getParameterInfo(filterExpression);
String[] parameterNames = new String[parameterMap.size()];
Class[] parameterTypes = new Class[parameterMap.size()];
columnIndexes = new int[parameterMap.size()];
int index = 0;
for (Map.Entry<String, Class> entry : parameterMap.entrySet()) {
parameterNames[index] = entry.getKey();
parameterTypes[index] = entry.getValue();
columnIndexes[index] = SchemaUtil.getFieldIndexByName(schema, entry.getKey());
index++;
}
try {
ee = CompilerFactoryFactory.getDefaultCompilerFactory().newExpressionEvaluator();
// The expression will have two "int" parameters: "a" and "b".
ee.setParameters(parameterNames, parameterTypes);
// And the expression (i.e. "result") type is also "int".
ee.setExpressionType(boolean.class);
String expressionStr = new SqlToJavaVisitor(schema, functionRegistry).process(filterExpression);
// And now we "cook" (scan, parse, compile and load) the fabulous expression.
ee.cook(expressionStr);
} catch (Exception e) {
throw new KsqlException("Failed to generate code for SqlPredicate."
+ "filterExpression: "
+ filterExpression
+ "schema:"
+ schema
+ "isWindowedKey:"
+ isWindowedKey,
e);
}
}
开发者ID:confluentinc,项目名称:ksql,代码行数:50,代码来源:SqlPredicate.java
示例8: buildCodeGenFromParseTree
import org.codehaus.commons.compiler.CompilerFactoryFactory; //导入依赖的package包/类
public ExpressionMetadata buildCodeGenFromParseTree(
final Expression expression) throws Exception {
CodeGenRunner codeGenRunner = new CodeGenRunner(schema, functionRegistry);
Map<String, Class> parameterMap = codeGenRunner.getParameterInfo(expression);
String[] parameterNames = new String[parameterMap.size()];
Class[] parameterTypes = new Class[parameterMap.size()];
int[] columnIndexes = new int[parameterMap.size()];
Kudf[] kudfObjects = new Kudf[parameterMap.size()];
int index = 0;
for (Map.Entry<String, Class> entry : parameterMap.entrySet()) {
parameterNames[index] = entry.getKey();
parameterTypes[index] = entry.getValue();
columnIndexes[index] = SchemaUtil.getFieldIndexByName(schema, entry.getKey());
if (columnIndexes[index] < 0) {
kudfObjects[index] = (Kudf) entry.getValue().newInstance();
} else {
kudfObjects[index] = null;
}
index++;
}
String javaCode = new SqlToJavaVisitor(schema, functionRegistry).process(expression);
IExpressionEvaluator ee = CompilerFactoryFactory.getDefaultCompilerFactory().newExpressionEvaluator();
// The expression will have two "int" parameters: "a" and "b".
ee.setParameters(parameterNames, parameterTypes);
// And the expression (i.e. "result") type is also "int".
ExpressionTypeManager expressionTypeManager = new ExpressionTypeManager(schema,
functionRegistry);
Schema expressionType = expressionTypeManager.getExpressionType(expression);
ee.setExpressionType(SchemaUtil.getJavaType(expressionType));
// And now we "cook" (scan, parse, compile and load) the fabulous expression.
ee.cook(javaCode);
return new ExpressionMetadata(ee, columnIndexes, kudfObjects, expressionType);
}
开发者ID:confluentinc,项目名称:ksql,代码行数:43,代码来源:CodeGenRunner.java
注:本文中的org.codehaus.commons.compiler.CompilerFactoryFactory类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论