当前位置: 首页>>代码示例>>Java>>正文


Java JCatchBlock.param方法代码示例

本文整理汇总了Java中com.sun.codemodel.JCatchBlock.param方法的典型用法代码示例。如果您正苦于以下问题:Java JCatchBlock.param方法的具体用法?Java JCatchBlock.param怎么用?Java JCatchBlock.param使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.codemodel.JCatchBlock的用法示例。


在下文中一共展示了JCatchBlock.param方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createCreateBeanMethod

import com.sun.codemodel.JCatchBlock; //导入方法依赖的package包/类
public JMethod createCreateBeanMethod(final JDefinedClass bean) {

    final JMethod method = bean.method(JMod.PRIVATE | JMod.STATIC, bean, "_createBean");
    final JVar param = method.param(
        _classByNames(java.lang.Class.class.getName(), MessageFormat.format("? extends {0}", bean.name())),
        "clazz");
    final JClass invokerClass = _classByNames(
        "net.anwiba.commons.reflection.ReflectionConstructorInvoker",
        bean.name());
    final JTryBlock _try = method.body()._try();
    final JVar invoker = _try.body().decl(invokerClass, "invoker", JExpr._new(invokerClass).arg(param)); //$NON-NLS-1$
    _try.body()._return(invoker.invoke("invoke"));
    final JCatchBlock _catch = _try._catch(_classByNames(java.lang.reflect.InvocationTargetException.class.getName()));
    final JVar exception = _catch.param("exception"); //$NON-NLS-1$
    _catch.body()._throw(JExpr._new(_classByNames(java.lang.RuntimeException.class.getName())).arg(exception));
    return method;
  }
 
开发者ID:AndreasWBartels,项目名称:libraries,代码行数:18,代码来源:CreatorFactory.java

示例2: catchCloneNotSupported

import com.sun.codemodel.JCatchBlock; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
JBlock catchCloneNotSupported(final JBlock body, final JClass elementType) {
	final Class<? extends Cloneable> elementRuntimeClass;
	try {
		elementRuntimeClass = (Class<? extends Cloneable>) Class.forName(elementType.binaryName());
	} catch (final ClassNotFoundException e) {
		return body;
	}
	if (!cloneThrows(elementRuntimeClass)) {
		return body;
	} else {
		final JTryBlock tryBlock = body._try();
		final JCatchBlock catchBlock = tryBlock._catch(this.codeModel.ref(CloneNotSupportedException.class));
		final JVar exceptionVar = catchBlock.param("e");
		catchBlock.body()._throw(JExpr._new(this.codeModel.ref(RuntimeException.class)).arg(exceptionVar));
		return tryBlock.body();
	}
}
 
开发者ID:mklemm,项目名称:jaxb2-rich-contract-plugin,代码行数:19,代码来源:PluginContext.java

示例3: generateSetup

import com.sun.codemodel.JCatchBlock; //导入方法依赖的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+")" : "")));
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:62,代码来源:HiveFuncHolder.java

示例4: generateEval

import com.sun.codemodel.JCatchBlock; //导入方法依赖的package包/类
private HoldingContainer generateEval(ClassGenerator<?> g, HoldingContainer[] inputVariables, JVar[] workspaceJVars) {

    HoldingContainer out = g.declare(returnType);

    JCodeModel m = g.getModel();
    JBlock sub = new JBlock(true, true);

    // initialize DeferredObject's. For an optional type, assign the value holder only if it is not null
    for(int i=0; i<argTypes.length; i++) {
      if (inputVariables[i].isOptional()) {
        sub.assign(workspaceJVars[3].component(JExpr.lit(i)), workspaceJVars[2].component(JExpr.lit(i)));
        JBlock conditionalBlock = new JBlock(false, false);
        JConditional jc = conditionalBlock._if(inputVariables[i].getIsSet().ne(JExpr.lit(0)));
        jc._then().assign(JExpr.ref(workspaceJVars[3].component(JExpr.lit(i)), "valueHolder"), inputVariables[i].getHolder());
        jc._else().assign(JExpr.ref(workspaceJVars[3].component(JExpr.lit(i)), "valueHolder"), JExpr._null());
        sub.add(conditionalBlock);
      } else {
        sub.assign(workspaceJVars[3].component(JExpr.lit(i)), workspaceJVars[2].component(JExpr.lit(i)));
        sub.assign(JExpr.ref(workspaceJVars[3].component(JExpr.lit(i)), "valueHolder"), inputVariables[i].getHolder());
      }
    }

    // declare generic object for storing return value from GenericUDF.evaluate
    JVar retVal = sub.decl(m._ref(Object.class), "ret");

    // create try..catch block to call the GenericUDF instance with given input
    JTryBlock udfEvalTry = sub._try();
    udfEvalTry.body().assign(retVal,
      workspaceJVars[1].invoke("evaluate").arg(workspaceJVars[3]));

    JCatchBlock udfEvalCatch = udfEvalTry._catch(m.directClass(Exception.class.getCanonicalName()));
    JVar exVar = udfEvalCatch.param("ex");
    udfEvalCatch.body()
      ._throw(JExpr._new(m.directClass(RuntimeException.class.getCanonicalName()))
        .arg(JExpr.lit(String.format("GenericUDF.evaluate method failed"))).arg(exVar));

    // get the ValueHolder from retVal and return ObjectInspector
    sub.add(ObjectInspectorHelper.getDrillObject(m, returnOI, workspaceJVars[0], workspaceJVars[4], retVal));
    sub.assign(out.getHolder(), workspaceJVars[4]);

    // now add it to the doEval block in Generated class
    JBlock setup = g.getBlock(ClassGenerator.BlockType.EVAL);
    setup.directStatement(String.format("/** start %s for function %s **/ ",
      ClassGenerator.BlockType.EVAL.name(), genericUdfClazz.getName() + (!isGenericUDF ? "("+udfName+")" : "")));
    setup.add(sub);
    setup.directStatement(String.format("/** end %s for function %s **/ ",
      ClassGenerator.BlockType.EVAL.name(), genericUdfClazz.getName() + (!isGenericUDF ? "("+udfName+")" : "")));

    return out;
  }
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:51,代码来源:HiveFuncHolder.java

示例5: generateSetup

import com.sun.codemodel.JCatchBlock; //导入方法依赖的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+")" : "")));
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:64,代码来源:HiveFuncHolder.java

示例6: generateEval

import com.sun.codemodel.JCatchBlock; //导入方法依赖的package包/类
private HoldingContainer generateEval(ClassGenerator<?> g, HoldingContainer[] inputVariables, JVar[] workspaceJVars) {

    HoldingContainer out = g.declare(returnType);

    JCodeModel m = g.getModel();
    JBlock sub = new JBlock(true, true);

    // initialize DeferredObject's. For an optional type, assign the value holder only if it is not null
    for(int i=0; i<argTypes.length; i++) {
      sub.assign(workspaceJVars[3].component(JExpr.lit(i)), workspaceJVars[2].component(JExpr.lit(i)));
      JBlock conditionalBlock = new JBlock(false, false);
      JConditional jc = conditionalBlock._if(inputVariables[i].getIsSet().ne(JExpr.lit(0)));
      jc._then().assign(JExpr.ref(workspaceJVars[3].component(JExpr.lit(i)), "valueHolder"), inputVariables[i].getHolder());
      jc._else().assign(JExpr.ref(workspaceJVars[3].component(JExpr.lit(i)), "valueHolder"), JExpr._null());
      sub.add(conditionalBlock);
    }

    // declare generic object for storing return value from GenericUDF.evaluate
    JVar retVal = sub.decl(m._ref(Object.class), "ret");

    // create try..catch block to call the GenericUDF instance with given input
    JTryBlock udfEvalTry = sub._try();
    udfEvalTry.body().assign(retVal,
      workspaceJVars[1].invoke("evaluate").arg(workspaceJVars[3]));

    JCatchBlock udfEvalCatch = udfEvalTry._catch(m.directClass(Exception.class.getCanonicalName()));
    JVar exVar = udfEvalCatch.param("ex");
    udfEvalCatch.body()
      ._throw(JExpr._new(m.directClass(RuntimeException.class.getCanonicalName()))
        .arg(JExpr.lit(String.format("GenericUDF.evaluate method failed"))).arg(exVar));

    // get the ValueHolder from retVal and return ObjectInspector
    sub.add(ObjectInspectorHelper.getObject(m, returnOI, workspaceJVars[0], workspaceJVars[4], retVal));
    sub.assign(out.getHolder(), workspaceJVars[4]);

    // now add it to the doEval block in Generated class
    JBlock setup = g.getBlock(ClassGenerator.BlockType.EVAL);
    setup.directStatement(String.format("/** start %s for function %s **/ ",
      ClassGenerator.BlockType.EVAL.name(), genericUdfClazz.getName() + (!isGenericUDF ? "("+udfName+")" : "")));
    setup.add(sub);
    setup.directStatement(String.format("/** end %s for function %s **/ ",
      ClassGenerator.BlockType.EVAL.name(), genericUdfClazz.getName() + (!isGenericUDF ? "("+udfName+")" : "")));

    return out;
  }
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:46,代码来源:HiveFuncHolder.java

示例7: generateSetup

import com.sun.codemodel.JCatchBlock; //导入方法依赖的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+")" : "")));
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:64,代码来源:HiveFuncHolder.java


注:本文中的com.sun.codemodel.JCatchBlock.param方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。