本文整理匯總了Java中com.sun.codemodel.JCodeModel.directClass方法的典型用法代碼示例。如果您正苦於以下問題:Java JCodeModel.directClass方法的具體用法?Java JCodeModel.directClass怎麽用?Java JCodeModel.directClass使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.sun.codemodel.JCodeModel
的用法示例。
在下文中一共展示了JCodeModel.directClass方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: generateSetup
import com.sun.codemodel.JCodeModel; //導入方法依賴的package包/類
private void generateSetup(ClassGenerator<?> g, JVar[] workspaceJVars) {
JCodeModel m = g.getModel();
JBlock sub = new JBlock(true, true);
// declare and instantiate argument ObjectInspector's
JVar oiArray = sub.decl(
m._ref(ObjectInspector[].class),
"argOIs",
JExpr.newArray(m._ref(ObjectInspector.class), argTypes.length));
JClass oih = m.directClass(ObjectInspectorHelper.class.getCanonicalName());
JClass mt = m.directClass(TypeProtos.MinorType.class.getCanonicalName());
JClass mode = m.directClass(DataMode.class.getCanonicalName());
for(int i=0; i<argTypes.length; i++) {
sub.assign(
oiArray.component(JExpr.lit(i)),
oih.staticInvoke("getDrillObjectInspector")
.arg(mode.staticInvoke("valueOf").arg(JExpr.lit(argTypes[i].getMode().getNumber())))
.arg(mt.staticInvoke("valueOf").arg(JExpr.lit(argTypes[i].getMinorType().getNumber()))));
}
// declare and instantiate DeferredObject array
sub.assign(workspaceJVars[2], JExpr.newArray(m._ref(DrillDeferredObject.class), argTypes.length));
for(int i=0; i<argTypes.length; i++) {
sub.assign(
workspaceJVars[2].component(JExpr.lit(i)),
JExpr._new(m.directClass(DrillDeferredObject.class.getCanonicalName())));
}
// declare empty array for argument deferred objects
sub.assign(workspaceJVars[3], JExpr.newArray(m._ref(DrillDeferredObject.class), argTypes.length));
// create new instance of the UDF class
sub.assign(workspaceJVars[1], getUDFInstance(m));
// create try..catch block to initialize the UDF instance with argument OIs
JTryBlock udfInitTry = sub._try();
udfInitTry.body().assign(
workspaceJVars[0],
workspaceJVars[1].invoke("initialize")
.arg(oiArray));
JCatchBlock udfInitCatch = udfInitTry._catch(m.directClass(Exception.class.getCanonicalName()));
JVar exVar = udfInitCatch.param("ex");
udfInitCatch.body()
._throw(JExpr._new(m.directClass(RuntimeException.class.getCanonicalName()))
.arg(JExpr.lit(String.format("Failed to initialize GenericUDF"))).arg(exVar));
sub.add(ObjectInspectorHelper.initReturnValueHolder(g, m, workspaceJVars[4], returnOI, returnType.getMinorType()));
// now add it to the doSetup block in Generated class
JBlock setup = g.getBlock(ClassGenerator.BlockType.SETUP);
setup.directStatement(String.format("/** start %s for function %s **/ ",
ClassGenerator.BlockType.SETUP.name(), genericUdfClazz.getName() + (!isGenericUDF ? "("+udfName+")" : "")));
setup.add(sub);
setup.directStatement(String.format("/** end %s for function %s **/ ",
ClassGenerator.BlockType.SETUP.name(), genericUdfClazz.getName() + (!isGenericUDF ? "("+udfName+")" : "")));
}
示例2: generateSetup
import com.sun.codemodel.JCodeModel; //導入方法依賴的package包/類
private void generateSetup(ClassGenerator<?> g, JVar[] workspaceJVars) {
JCodeModel m = g.getModel();
JBlock sub = new JBlock(true, true);
// declare and instantiate argument ObjectInspector's
JVar oiArray = sub.decl(
m._ref(ObjectInspector[].class),
"argOIs",
JExpr.newArray(m._ref(ObjectInspector.class), argTypes.length));
JClass oih = m.directClass(ObjectInspectorHelper.class.getCanonicalName());
JClass mt = m.directClass(MinorType.class.getCanonicalName());
JClass mode = m.directClass(DataMode.class.getCanonicalName());
for(int i=0; i<argTypes.length; i++) {
sub.assign(
oiArray.component(JExpr.lit(i)),
oih.staticInvoke("getObjectInspector")
.arg(mode.staticInvoke("valueOf").arg(JExpr.lit("OPTIONAL")))
.arg(mt.staticInvoke("valueOf").arg(JExpr.lit(argTypes[i].toMinorType().name())))
.arg((((PrimitiveObjectInspector) returnOI).getPrimitiveCategory() ==
PrimitiveObjectInspector.PrimitiveCategory.STRING) ? JExpr.lit(true) : JExpr.lit(false)));
}
// declare and instantiate DeferredObject array
sub.assign(workspaceJVars[2], JExpr.newArray(m._ref(DeferredObject.class), argTypes.length));
for(int i=0; i<argTypes.length; i++) {
sub.assign(
workspaceJVars[2].component(JExpr.lit(i)),
JExpr._new(m.directClass(DeferredObject.class.getCanonicalName())));
}
// declare empty array for argument deferred objects
sub.assign(workspaceJVars[3], JExpr.newArray(m._ref(DeferredObject.class), argTypes.length));
// create new instance of the UDF class
sub.assign(workspaceJVars[1], getUDFInstance(m));
// create try..catch block to initialize the UDF instance with argument OIs
JTryBlock udfInitTry = sub._try();
udfInitTry.body().assign(
workspaceJVars[0],
workspaceJVars[1].invoke("initialize")
.arg(oiArray));
JCatchBlock udfInitCatch = udfInitTry._catch(m.directClass(Exception.class.getCanonicalName()));
JVar exVar = udfInitCatch.param("ex");
udfInitCatch.body()
._throw(JExpr._new(m.directClass(RuntimeException.class.getCanonicalName()))
.arg(JExpr.lit(String.format("Failed to initialize GenericUDF"))).arg(exVar));
sub.add(ObjectInspectorHelper.initReturnValueHolder(g, m, workspaceJVars[4], returnOI, returnType.toMinorType()));
// now add it to the doSetup block in Generated class
JBlock setup = g.getBlock(ClassGenerator.BlockType.SETUP);
setup.directStatement(String.format("/** start %s for function %s **/ ",
ClassGenerator.BlockType.SETUP.name(), genericUdfClazz.getName() + (!isGenericUDF ? "("+udfName+")" : "")));
setup.add(sub);
setup.directStatement(String.format("/** end %s for function %s **/ ",
ClassGenerator.BlockType.SETUP.name(), genericUdfClazz.getName() + (!isGenericUDF ? "("+udfName+")" : "")));
}
示例3: generateSetup
import com.sun.codemodel.JCodeModel; //導入方法依賴的package包/類
private void generateSetup(ClassGenerator<?> g, JVar[] workspaceJVars) {
JCodeModel m = g.getModel();
JBlock sub = new JBlock(true, true);
// declare and instantiate argument ObjectInspector's
JVar oiArray = sub.decl(
m._ref(ObjectInspector[].class),
"argOIs",
JExpr.newArray(m._ref(ObjectInspector.class), argTypes.length));
JClass oih = m.directClass(ObjectInspectorHelper.class.getCanonicalName());
JClass mt = m.directClass(TypeProtos.MinorType.class.getCanonicalName());
JClass mode = m.directClass(DataMode.class.getCanonicalName());
for(int i=0; i<argTypes.length; i++) {
sub.assign(
oiArray.component(JExpr.lit(i)),
oih.staticInvoke("getDrillObjectInspector")
.arg(mode.staticInvoke("valueOf").arg(JExpr.lit(argTypes[i].getMode().getNumber())))
.arg(mt.staticInvoke("valueOf").arg(JExpr.lit(argTypes[i].getMinorType().getNumber())))
.arg((((PrimitiveObjectInspector) returnOI).getPrimitiveCategory() ==
PrimitiveObjectInspector.PrimitiveCategory.STRING) ? JExpr.lit(true) : JExpr.lit(false)));
}
// declare and instantiate DeferredObject array
sub.assign(workspaceJVars[2], JExpr.newArray(m._ref(DrillDeferredObject.class), argTypes.length));
for(int i=0; i<argTypes.length; i++) {
sub.assign(
workspaceJVars[2].component(JExpr.lit(i)),
JExpr._new(m.directClass(DrillDeferredObject.class.getCanonicalName())));
}
// declare empty array for argument deferred objects
sub.assign(workspaceJVars[3], JExpr.newArray(m._ref(DrillDeferredObject.class), argTypes.length));
// create new instance of the UDF class
sub.assign(workspaceJVars[1], getUDFInstance(m));
// create try..catch block to initialize the UDF instance with argument OIs
JTryBlock udfInitTry = sub._try();
udfInitTry.body().assign(
workspaceJVars[0],
workspaceJVars[1].invoke("initialize")
.arg(oiArray));
JCatchBlock udfInitCatch = udfInitTry._catch(m.directClass(Exception.class.getCanonicalName()));
JVar exVar = udfInitCatch.param("ex");
udfInitCatch.body()
._throw(JExpr._new(m.directClass(RuntimeException.class.getCanonicalName()))
.arg(JExpr.lit(String.format("Failed to initialize GenericUDF"))).arg(exVar));
sub.add(ObjectInspectorHelper.initReturnValueHolder(g, m, workspaceJVars[4], returnOI, returnType.getMinorType()));
// now add it to the doSetup block in Generated class
JBlock setup = g.getBlock(ClassGenerator.BlockType.SETUP);
setup.directStatement(String.format("/** start %s for function %s **/ ",
ClassGenerator.BlockType.SETUP.name(), genericUdfClazz.getName() + (!isGenericUDF ? "("+udfName+")" : "")));
setup.add(sub);
setup.directStatement(String.format("/** end %s for function %s **/ ",
ClassGenerator.BlockType.SETUP.name(), genericUdfClazz.getName() + (!isGenericUDF ? "("+udfName+")" : "")));
}