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


Java JBlock.decl方法代码示例

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


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

示例1: addFactoryMethod

import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
private void addFactoryMethod(JDefinedClass _enum, JType backingType) {
    JFieldVar quickLookupMap = addQuickLookupMap(_enum, backingType);

    JMethod fromValue = _enum.method(JMod.PUBLIC | JMod.STATIC, _enum, "fromValue");
    JVar valueParam = fromValue.param(backingType, "value");

    JBlock body = fromValue.body();
    JVar constant = body.decl(_enum, "constant");
    constant.init(quickLookupMap.invoke("get").arg(valueParam));

    JConditional _if = body._if(constant.eq(JExpr._null()));

    JInvocation illegalArgumentException = JExpr._new(_enum.owner().ref(IllegalArgumentException.class));
    JExpression expr = valueParam;

    // if string no need to add ""
    if(!isString(backingType)){
        expr = expr.plus(JExpr.lit(""));
    }

    illegalArgumentException.arg(expr);
    _if._then()._throw(illegalArgumentException);
    _if._else()._return(constant);

    ruleFactory.getAnnotator().enumCreatorMethod(fromValue);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:27,代码来源:EnumRule.java

示例2: addPublicGetMethod

import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
private JMethod addPublicGetMethod(JDefinedClass jclass, JMethod internalGetMethod, JFieldRef notFoundValue) {
    JMethod method = jclass.method(PUBLIC, jclass.owner()._ref(Object.class), GETTER_NAME);
    JTypeVar returnType = method.generify("T");
    method.type(returnType);
    Models.suppressWarnings(method, "unchecked");
    JVar nameParam = method.param(String.class, "name");
    JBlock body = method.body();
    JVar valueVar = body.decl(jclass.owner()._ref(Object.class), "value",
            invoke(internalGetMethod).arg(nameParam).arg(notFoundValue));
    JConditional found = method.body()._if(notFoundValue.ne(valueVar));
    found._then()._return(cast(returnType, valueVar));
    JBlock notFound = found._else();

    JMethod getAdditionalProperties = jclass.getMethod("getAdditionalProperties", new JType[] {});
    if (getAdditionalProperties != null) {
        notFound._return(cast(returnType, invoke(getAdditionalProperties).invoke("get").arg(nameParam)));
    } else {
        notFound._throw(illegalArgumentInvocation(jclass, nameParam));
    }

    return method;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:DynamicPropertiesRule.java

示例3: generateBeanNonStaticInitCode

import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
/**
 * Recursive method that handles the creation of reference beans at
 * different depth levels.
 * 
 * @param mjb
 *            The target bean to create an instance of.
 * @param body
 *            The current block of code.
 * @param level
 *            The current depth level.
 * @return A generated variable referencing the created bean.
 */
private JVar generateBeanNonStaticInitCode(MetaJavaBean mjb, JBlock body, int level) {

    JVar beanDecl = body.decl(mjb.getGeneratedClass(), "lvl" + level + mjb.getName() + "_" + Config.CFG.nextUniqueNum());
    body.assign(beanDecl, JExpr._new(mjb.getGeneratedClass()));

    for (AbstractMetaField amf : mjb.getFields()) {
        if (amf instanceof JavaBeanRefField) {

            JavaBeanRefField jbrf = (JavaBeanRefField) amf;

            // Should a nested bean be created?
            if (Config.CFG.shouldAddNestedBean(level)) {
                JVar nestedBeanDecl = generateBeanNonStaticInitCode(jbrf.getRefBean(), body, level + 1);
                jbrf.generateAssignCode(body, beanDecl, nestedBeanDecl);
            }
        }

    }

    return beanDecl;
}
 
开发者ID:hibernate,项目名称:beanvalidation-benchmark,代码行数:34,代码来源:Generator.java

示例4: renderEnd

import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
@Override
public HoldingContainer renderEnd(ClassGenerator<?> g, HoldingContainer[] inputVariables, JVar[]  workspaceJVars) {
  HoldingContainer out = g.declare(returnValue.type, false);
  JBlock sub = new JBlock();
  g.getEvalBlock().add(sub);
  JVar internalOutput = sub.decl(JMod.FINAL, g.getHolderType(returnValue.type), returnValue.name, JExpr._new(g.getHolderType(returnValue.type)));
  addProtectedBlock(g, sub, output, null, workspaceJVars, false);
  sub.assign(out.getHolder(), internalOutput);
      //hash aggregate uses workspace vectors. Initialization is done in "setup" and does not require "reset" block.
      if (!g.getMappingSet().isHashAggMapping()) {
        generateBody(g, BlockType.RESET, reset, null, workspaceJVars, false);
      }
     generateBody(g, BlockType.CLEANUP, cleanup, null, workspaceJVars, false);

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

示例5: renderEnd

import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
@Override
public HoldingContainer renderEnd(ClassGenerator<?> g, CompleteType resolvedOutput, HoldingContainer[] inputVariables, JVar[]  workspaceJVars) {
  HoldingContainer out = g.declare(resolvedOutput, false);
  JBlock sub = new JBlock();
  g.getEvalBlock().add(sub);
  JVar internalOutput = sub.decl(JMod.FINAL, resolvedOutput.getHolderType(g.getModel()), getReturnName(), JExpr._new(resolvedOutput.getHolderType(g.getModel())));
  addProtectedBlock(g, sub, output(), null, workspaceJVars, false);
  sub.assign(out.getHolder(), internalOutput);
      //hash aggregate uses workspace vectors. Initialization is done in "setup" and does not require "reset" block.
      if (!g.getMappingSet().isHashAggMapping()) {
        generateBody(g, BlockType.RESET, reset(), null, workspaceJVars, false);
      }
     generateBody(g, BlockType.CLEANUP, cleanup(), null, workspaceJVars, false);

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

示例6: createEquals

import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
public void createEquals(final JDefinedClass bean, final Iterable<JFieldVar> fields) {
  final JMethod method = bean.method(JMod.PUBLIC, this.codeModel.BOOLEAN, "equals");
  method.annotate(java.lang.Override.class);
  final JVar object = method.param(_type(java.lang.Object.class.getName()), "object");
  final JBlock block = method.body();
  block._if(JExpr._this().eq(object))._then()._return(JExpr.TRUE);
  block._if(object._instanceof(bean).not())._then()._return(JExpr.FALSE);
  JExpression result = JExpr.TRUE;
  final JExpression other = block.decl(bean, "other", JExpr.cast(bean, object));
  final JClass objectUtilities = _classByNames(net.anwiba.commons.lang.object.ObjectUtilities.class.getName());
  for (final JFieldVar field : fields) {
    result =
        result.cand(objectUtilities.staticInvoke("equals").arg(JExpr.refthis(field.name())).arg(other.ref(field)));
  }
  block._return(result);
}
 
开发者ID:AndreasWBartels,项目名称:libraries,代码行数:17,代码来源:EqualsFactory.java

示例7: renderEnd

import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
@Override
public HoldingContainer renderEnd(ClassGenerator<?> classGenerator, HoldingContainer[] inputVariables,
                                  JVar[] workspaceJVars, FieldReference fieldReference) {
  HoldingContainer out = classGenerator.declare(getReturnType(), false);
  JBlock sub = new JBlock();
  classGenerator.getEvalBlock().add(sub);
  JVar internalOutput = sub.decl(JMod.FINAL, classGenerator.getHolderType(getReturnType()), getReturnValue().getName(), JExpr._new(classGenerator.getHolderType(getReturnType())));
  addProtectedBlock(classGenerator, sub, output(), null, workspaceJVars, false);
  sub.assign(out.getHolder(), internalOutput);
  //hash aggregate uses workspace vectors. Initialization is done in "setup" and does not require "reset" block.
  if (!classGenerator.getMappingSet().isHashAggMapping()) {
    generateBody(classGenerator, BlockType.RESET, reset(), null, workspaceJVars, false);
  }
  generateBody(classGenerator, BlockType.CLEANUP, cleanup(), null, workspaceJVars, false);

  return out;
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:18,代码来源:DrillAggFuncHolder.java

示例8: generateForDirectClass

import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
private void generateForDirectClass(JDefinedClass traversingVisitor, JTypeVar returnType, JTypeVar exceptionType, JClass implClass) {
    // add method impl to traversing visitor
    JMethod travViz;
    String visitMethodName = visitMethodNamer.apply(implClass.name());
    travViz = traversingVisitor.method(JMod.PUBLIC, returnType, visitMethodName);
    travViz._throws(exceptionType);
    JVar beanVar = travViz.param(implClass, "aBean");
    travViz.annotate(Override.class);
    JBlock travVizBloc = travViz.body();

    addTraverseBlock(travViz, beanVar, true);

    JVar retVal = travVizBloc.decl(returnType, "returnVal");

    travVizBloc.assign(retVal, JExpr.invoke(JExpr.invoke("getVisitor"), visitMethodName).arg(beanVar));

    travVizBloc._if(JExpr.ref("progressMonitor").ne(JExpr._null()))._then().invoke(JExpr.ref("progressMonitor"), "visited").arg(beanVar);

    addTraverseBlock(travViz, beanVar, false);

    travVizBloc._return(retVal);
}
 
开发者ID:massfords,项目名称:jaxb-visitor,代码行数:23,代码来源:CreateTraversingVisitorClass.java

示例9: getFormatIDMethod

import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
public JMethod getFormatIDMethod(JDefinedClass klass)
{
	final JMethod method = klass.method(JMod.PUBLIC, String_t,
					    "getFormatID");
	final JBlock body = method.body();
	comment_stamp(body);

	final JVar value = body.decl(Type_t, "value",
				     JExpr._this()
				     .invoke(makeGetter("header"))
				     .invoke(makeGetter("format_id"))
				     .invoke("get"));
	final JVar cast = body.decl(TypeString_t, "cast",
				    JExpr.cast(TypeString_t, value));
	body._return(cast.invoke("getValue"));

	return method;
}
 
开发者ID:BrainTech,项目名称:jsignalml,代码行数:19,代码来源:JavaClassGen.java

示例10: headerFieldMethod

import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
public JMethod headerFieldMethod(JDefinedClass klass,
				 String method_name,
				 String header_section,
				 String field_name)
{
	final JMethod method = klass.method(JMod.PUBLIC, String_t,
					    method_name);
	final JBlock body = method.body();
	comment_stamp(body);

	final JVar value = body.decl(Type_t, "value",
				     JExpr._this()
				     .invoke(makeGetter("header"))
				     .invoke(makeGetter(header_section))
				     .ref(field_name).invoke("get"));
	// XXX: this implementation is horrible. There's no reason
	// not to export individual header fields.

	final JVar cast = body.decl(TypeString_t, "cast",
				    JExpr.cast(TypeString_t, value));
	body._return(cast.invoke("getValue"));

	return method;
}
 
开发者ID:BrainTech,项目名称:jsignalml,代码行数:25,代码来源:JavaClassGen.java

示例11: element

import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
public EqualsArguments element(JBlock subBlock, JType elementType) {
	final JVar leftElementValue = subBlock.decl(JMod.FINAL, elementType,
			leftValue().name() + "Element", leftValue().invoke("next"));
	final JVar rightElementValue = subBlock.decl(JMod.FINAL, elementType,
			rightValue().name() + "Element", rightValue().invoke("next"));
	// if (!(o1==null ? o2==null : o1.equals(o2)))
	// return false;
	final boolean isElementAlwaysSet = elementType.isPrimitive();
	final JExpression leftElementHasSetValue = isElementAlwaysSet ? JExpr.TRUE
			: leftElementValue.ne(JExpr._null());
	final JExpression rightElementHasSetValue = isElementAlwaysSet ? JExpr.TRUE
			: rightElementValue.ne(JExpr._null());
	return spawn(leftElementValue, leftElementHasSetValue,
			rightElementValue, rightElementHasSetValue);

}
 
开发者ID:highsource,项目名称:jaxb2-basics,代码行数:17,代码来源:EqualsArguments.java

示例12: sampleFormatMethod

import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
public JMethod sampleFormatMethod(JDefinedClass klass, ASTNode.Channel node)
{
	final JMethod method = klass.method(JMod.PUBLIC, TypeString_t,
					    "getSampleFormat");
	final Type expected = node.format.getType();
	final JType expected_t = this.model.ref(expected.getClass());
	final JBlock body = method.body();
	comment_stamp(body);
	comment(body, "node.format.type=%s", typename(expected));

	final JavaExprGen javagen = createExprGen(node, null);
	final JVar value = body.decl(expected_t, "value",
				     node.format.accept(javagen));
	return_make_or_cast(body, TypeString.I, value, expected);
	return method;
}
 
开发者ID:BrainTech,项目名称:jsignalml,代码行数:17,代码来源:JavaClassGen.java

示例13:

import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
protected JMethod generateCopyTo$copyTo(final ClassOutline classOutline,
		final JDefinedClass theClass) {

	final JCodeModel codeModel = theClass.owner();
	final JMethod copyTo$copyTo = theClass.method(JMod.PUBLIC,
			codeModel.ref(Object.class), "copyTo");
	{
		final JVar target = copyTo$copyTo.param(Object.class, "target");

		final JBlock body = copyTo$copyTo.body();
		final JVar copyStrategy = body.decl(JMod.FINAL,
				codeModel.ref(CopyStrategy2.class), "strategy",
				createCopyStrategy(codeModel));

		body._return(JExpr.invoke("copyTo").arg(JExpr._null()).arg(target)
				.arg(copyStrategy));
	}
	return copyTo$copyTo;
}
 
开发者ID:highsource,项目名称:jaxb2-basics,代码行数:20,代码来源:CopyablePlugin.java

示例14: createToStringStrategy

import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
protected JMethod generateObject$toString(final ClassOutline classOutline,
		final JDefinedClass theClass) {
	final JCodeModel codeModel = theClass.owner();
	final JMethod object$toString = theClass.method(JMod.PUBLIC,
			codeModel.ref(String.class), "toString");
	{
		final JBlock body = object$toString.body();

		final JVar toStringStrategy =

		body.decl(JMod.FINAL, codeModel.ref(ToStringStrategy2.class),
				"strategy", createToStringStrategy(codeModel));

		final JVar buffer = body.decl(JMod.FINAL,
				codeModel.ref(StringBuilder.class), "buffer",
				JExpr._new(codeModel.ref(StringBuilder.class)));
		body.invoke("append").arg(JExpr._null()).arg(buffer)
				.arg(toStringStrategy);
		body._return(buffer.invoke("toString"));
	}
	return object$toString;
}
 
开发者ID:highsource,项目名称:jaxb2-basics,代码行数:23,代码来源:SimpleToStringPlugin.java

示例15: addProtectedBlock

import com.sun.codemodel.JBlock; //导入方法依赖的package包/类
protected void addProtectedBlock(ClassGenerator<?> g, JBlock sub, String body, HoldingContainer[] inputVariables,
    JVar[] workspaceJVars, boolean decConstInputOnly) {
  if (inputVariables != null) {
    for (int i = 0; i < inputVariables.length; i++) {
      if (decConstInputOnly && !inputVariables[i].isConstant()) {
        continue;
      }

      ValueReference parameter = parameters[i];
      HoldingContainer inputVariable = inputVariables[i];
      if (parameter.isFieldReader && ! inputVariable.isReader() && ! Types.isComplex(inputVariable.getMajorType())) {
        JType singularReaderClass = g.getModel()._ref(TypeHelper.getHolderReaderImpl(inputVariable.getMajorType().getMinorType(),
            inputVariable.getMajorType().getMode()));
        JType fieldReadClass = g.getModel()._ref(FieldReader.class);
        sub.decl(fieldReadClass, parameter.name, JExpr._new(singularReaderClass).arg(inputVariable.getHolder()));
      } else {
        sub.decl(inputVariable.getHolder().type(), parameter.name, inputVariable.getHolder());
      }
    }
  }

  JVar[] internalVars = new JVar[workspaceJVars.length];
  for (int i = 0; i < workspaceJVars.length; i++) {
    if (decConstInputOnly) {
      internalVars[i] = sub.decl(g.getModel()._ref(workspaceVars[i].type), workspaceVars[i].name, workspaceJVars[i]);
    } else {
      internalVars[i] = sub.decl(g.getModel()._ref(workspaceVars[i].type), workspaceVars[i].name, workspaceJVars[i]);
    }

  }

  Preconditions.checkNotNull(body);
  sub.directStatement(body);

  // reassign workspace variables back to global space.
  for (int i = 0; i < workspaceJVars.length; i++) {
    sub.assign(workspaceJVars[i], internalVars[i]);
  }
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:40,代码来源:DrillFuncHolder.java


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