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


Java JBlock类代码示例

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


JBlock类属于com.sun.codemodel包,在下文中一共展示了JBlock类的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: addPublicSetMethod

import com.sun.codemodel.JBlock; //导入依赖的package包/类
private JMethod addPublicSetMethod(JDefinedClass jclass, JMethod internalSetMethod) {
    JMethod method = jclass.method(PUBLIC, jclass.owner().VOID, SETTER_NAME);
    JVar nameParam = method.param(String.class, "name");
    JVar valueParam = method.param(Object.class, "value");
    JBlock body = method.body();
    JBlock notFound = body._if(JOp.not(invoke(internalSetMethod).arg(nameParam).arg(valueParam)))._then();

    // if we have additional properties, then put value.
    JMethod getAdditionalProperties = jclass.getMethod("getAdditionalProperties", new JType[] {});
    if (getAdditionalProperties != null) {
        JType additionalPropertiesType = ((JClass) (getAdditionalProperties.type())).getTypeParameters().get(1);
        notFound.add(invoke(getAdditionalProperties).invoke("put").arg(nameParam)
                .arg(cast(additionalPropertiesType, valueParam)));
    }
    // else throw exception.
    else {
        notFound._throw(illegalArgumentInvocation(jclass, nameParam));
    }

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

示例4: addPublicWithMethod

import com.sun.codemodel.JBlock; //导入依赖的package包/类
private JMethod addPublicWithMethod(JDefinedClass jclass, JMethod internalSetMethod) {
    JMethod method = jclass.method(PUBLIC, jclass, BUILDER_NAME);
    JVar nameParam = method.param(String.class, "name");
    JVar valueParam = method.param(Object.class, "value");
    JBlock body = method.body();
    JBlock notFound = body._if(JOp.not(invoke(internalSetMethod).arg(nameParam).arg(valueParam)))._then();

    // if we have additional properties, then put value.
    JMethod getAdditionalProperties = jclass.getMethod("getAdditionalProperties", new JType[] {});
    if (getAdditionalProperties != null) {
        JType additionalPropertiesType = ((JClass) (getAdditionalProperties.type())).getTypeParameters().get(1);
        notFound.add(invoke(getAdditionalProperties).invoke("put").arg(nameParam)
                .arg(cast(additionalPropertiesType, valueParam)));
    }
    // else throw exception.
    else {
        notFound._throw(illegalArgumentInvocation(jclass, nameParam));
    }
    body._return(_this());

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

示例5: addToString

import com.sun.codemodel.JBlock; //导入依赖的package包/类
private void addToString(JDefinedClass jclass) {
    Map<String, JFieldVar> fields = jclass.fields();
    JMethod toString = jclass.method(JMod.PUBLIC, String.class, "toString");
    Set<String> excludes = new HashSet<String>(Arrays.asList(ruleFactory.getGenerationConfig().getToStringExcludes()));

    JBlock body = toString.body();
    Class<?> toStringBuilder = ruleFactory.getGenerationConfig().isUseCommonsLang3() ? org.apache.commons.lang3.builder.ToStringBuilder.class : org.apache.commons.lang.builder.ToStringBuilder.class;
    JClass toStringBuilderClass = jclass.owner().ref(toStringBuilder);
    JInvocation toStringBuilderInvocation = JExpr._new(toStringBuilderClass).arg(JExpr._this());

    if (!jclass._extends().fullName().equals(Object.class.getName())) {
        toStringBuilderInvocation = toStringBuilderInvocation.invoke("appendSuper").arg(JExpr._super().invoke("toString"));
    }

    for (JFieldVar fieldVar : fields.values()) {
        if (excludes.contains(fieldVar.name()) || (fieldVar.mods().getValue() & JMod.STATIC) == JMod.STATIC) {
            continue;
        }
        toStringBuilderInvocation = toStringBuilderInvocation.invoke("append").arg(fieldVar.name()).arg(fieldVar);
    }

    body._return(toStringBuilderInvocation.invoke("toString"));

    toString.annotate(Override.class);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:ObjectRule.java

示例6: addHashCode

import com.sun.codemodel.JBlock; //导入依赖的package包/类
private void addHashCode(JDefinedClass jclass, JsonNode node) {
    Map<String, JFieldVar> fields = removeFieldsExcludedFromEqualsAndHashCode(jclass.fields(), node);

    JMethod hashCode = jclass.method(JMod.PUBLIC, int.class, "hashCode");

    Class<?> hashCodeBuilder = ruleFactory.getGenerationConfig().isUseCommonsLang3() ? org.apache.commons.lang3.builder.HashCodeBuilder.class : org.apache.commons.lang.builder.HashCodeBuilder.class;

    JBlock body = hashCode.body();
    JClass hashCodeBuilderClass = jclass.owner().ref(hashCodeBuilder);
    JInvocation hashCodeBuilderInvocation = JExpr._new(hashCodeBuilderClass);

    if (!jclass._extends().fullName().equals(Object.class.getName())) {
        hashCodeBuilderInvocation = hashCodeBuilderInvocation.invoke("appendSuper").arg(JExpr._super().invoke("hashCode"));
    }

    for (JFieldVar fieldVar : fields.values()) {
        if ((fieldVar.mods().getValue() & JMod.STATIC) == JMod.STATIC) {
            continue;
        }
        hashCodeBuilderInvocation = hashCodeBuilderInvocation.invoke("append").arg(fieldVar);
    }

    body._return(hashCodeBuilderInvocation.invoke("toHashCode"));

    hashCode.annotate(Override.class);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:27,代码来源:ObjectRule.java

示例7: 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

示例8: visitDecimal9Constant

import com.sun.codemodel.JBlock; //导入依赖的package包/类
@Override
public HoldingContainer visitDecimal9Constant(Decimal9Expression e, ClassGenerator<?> generator)
    throws RuntimeException {
  MajorType majorType = e.getMajorType();
  JBlock setup = generator.getBlock(BlockType.SETUP);
  JType holderType = generator.getHolderType(majorType);
  JVar var = generator.declareClassField("dec9", holderType);
  JExpression valueLiteral = JExpr.lit(e.getIntFromDecimal());
  JExpression scaleLiteral = JExpr.lit(e.getScale());
  JExpression precisionLiteral = JExpr.lit(e.getPrecision());
  setup.assign(
      var,
      generator.getModel().ref(ValueHolderHelper.class).staticInvoke("getDecimal9Holder").arg(valueLiteral)
          .arg(scaleLiteral).arg(precisionLiteral));
  return new HoldingContainer(majorType, var, null, null);
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:17,代码来源:EvaluationVisitor.java

示例9: visitDecimal18Constant

import com.sun.codemodel.JBlock; //导入依赖的package包/类
@Override
public HoldingContainer visitDecimal18Constant(Decimal18Expression e, ClassGenerator<?> generator)
    throws RuntimeException {
  MajorType majorType = e.getMajorType();
  JBlock setup = generator.getBlock(BlockType.SETUP);
  JType holderType = generator.getHolderType(majorType);
  JVar var = generator.declareClassField("dec18", holderType);
  JExpression valueLiteral = JExpr.lit(e.getLongFromDecimal());
  JExpression scaleLiteral = JExpr.lit(e.getScale());
  JExpression precisionLiteral = JExpr.lit(e.getPrecision());
  setup.assign(
      var,
      generator.getModel().ref(ValueHolderHelper.class).staticInvoke("getDecimal18Holder").arg(valueLiteral)
          .arg(scaleLiteral).arg(precisionLiteral));
  return new HoldingContainer(majorType, var, null, null);
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:17,代码来源:EvaluationVisitor.java

示例10: ClassGenerator

import com.sun.codemodel.JBlock; //导入依赖的package包/类
@SuppressWarnings("unchecked")
ClassGenerator(CodeGenerator<T> codeGenerator, MappingSet mappingSet, SignatureHolder signature, EvaluationVisitor eval, JDefinedClass clazz, JCodeModel model) throws JClassAlreadyExistsException {
  this.codeGenerator = codeGenerator;
  this.clazz = clazz;
  this.mappings = mappingSet;
  this.sig = signature;
  this.evaluationVisitor = eval;
  this.model = model;
  blocks = (LinkedList<JBlock>[]) new LinkedList[sig.size()];
  for (int i =0; i < sig.size(); i++) {
    blocks[i] = Lists.newLinkedList();
  }
  rotateBlock();

  for (SignatureHolder child : signature.getChildHolders()) {
    String innerClassName = child.getSignatureClass().getSimpleName();
    JDefinedClass innerClazz = clazz._class(Modifier.FINAL + Modifier.PRIVATE, innerClassName);
    innerClasses.put(innerClassName, new ClassGenerator<>(codeGenerator, mappingSet, child, eval, innerClazz, model));
  }
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:21,代码来源:ClassGenerator.java

示例11: 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

示例12: visitDecimalConstant

import com.sun.codemodel.JBlock; //导入依赖的package包/类
@Override
public HoldingContainer visitDecimalConstant(DecimalExpression e, ClassGenerator<?> generator)
    throws RuntimeException {
  CompleteType majorType= e.getCompleteType();
  JBlock setup = generator.getBlock(BlockType.SETUP);
  JType holderType = majorType.getHolderType(generator.getModel());
  JVar var = generator.declareClassField("dec", holderType);
  JExpression valueLiteral = JExpr.lit(e.getIntFromDecimal());
  JExpression scaleLiteral = JExpr.lit(e.getScale());
  JExpression precisionLiteral = JExpr.lit(e.getPrecision());
  setup.assign(
      var,
      generator.getModel().ref(ValueHolderHelper.class).staticInvoke("getNullableDecimalHolder").arg(valueLiteral)
          .arg(scaleLiteral).arg(precisionLiteral));
  return new HoldingContainer(majorType, var, var.ref("value"), var.ref("isSet"));
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:17,代码来源:EvaluationVisitor.java

示例13: declareVectorValueSetupAndMember

import com.sun.codemodel.JBlock; //导入依赖的package包/类
public JVar declareVectorValueSetupAndMember(DirectExpression batchName, TypedFieldId fieldId) {
  final ValueVectorSetup setup = new ValueVectorSetup(batchName, fieldId);

  final Class<?> valueVectorClass = fieldId.getIntermediateClass();
  final JClass vvClass = model.ref(valueVectorClass);
  final JClass retClass = fieldId.isHyperReader() ? vvClass.array() : vvClass;

  final JVar vv = declareClassField("vv", retClass);
  final JBlock b = getSetupBlock();
  int[] fieldIndices = fieldId.getFieldIds();
  JInvocation invoke = model.ref(VectorResolver.class).staticInvoke(fieldId.isHyperReader() ? "hyper" : "simple")
      .arg(batchName)
      .arg(vvClass.dotclass());

  for(int i = 0; i < fieldIndices.length; i++){
    invoke.arg(JExpr.lit(fieldIndices[i]));
  }

  // we have to cast here since Janino doesn't handle generic inference well.
  JExpression casted = JExpr.cast(retClass, invoke);
  b.assign(vv, casted);
  vvDeclaration.put(setup, vv);

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

示例14: 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

示例15: 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


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