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


Java JExpression类代码示例

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


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

示例1: addFactoryMethod

import com.sun.codemodel.JExpression; //导入依赖的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: getDefaultSet

import com.sun.codemodel.JExpression; //导入依赖的package包/类
/**
 * Creates a default value for a set property by:
 * <ol>
 * <li>Creating a new {@link LinkedHashSet} with the correct generic type
 * <li>Using {@link Arrays#asList(Object...)} to initialize the set with the
 * correct default values
 * </ol>
 *
 * @param fieldType
 *            the java type that applies for this field ({@link Set} with
 *            some generic type argument)
 * @param node
 *            the node containing default values for this set
 * @return an expression that creates a default value that can be assigned
 *         to this field
 */
private JExpression getDefaultSet(JType fieldType, JsonNode node) {

    JClass setGenericType = ((JClass) fieldType).getTypeParameters().get(0);

    JClass setImplClass = fieldType.owner().ref(LinkedHashSet.class);
    setImplClass = setImplClass.narrow(setGenericType);

    JInvocation newSetImpl = JExpr._new(setImplClass);

    if (node instanceof ArrayNode && node.size() > 0) {
        JInvocation invokeAsList = fieldType.owner().ref(Arrays.class).staticInvoke("asList");
        for (JsonNode defaultValue : node) {
            invokeAsList.arg(getDefaultValue(setGenericType, defaultValue));
        }
        newSetImpl.arg(invokeAsList);
    } else if (!ruleFactory.getGenerationConfig().isInitializeCollections()) {
        return JExpr._null();
    }

    return newSetImpl;

}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:39,代码来源:DefaultRule.java

示例3: getDefaultList

import com.sun.codemodel.JExpression; //导入依赖的package包/类
/**
 * Creates a default value for a list property by:
 * <ol>
 * <li>Creating a new {@link ArrayList} with the correct generic type
 * <li>Using {@link Arrays#asList(Object...)} to initialize the list with
 * the correct default values
 * </ol>
 *
 * @param fieldType
 *            the java type that applies for this field ({@link List} with
 *            some generic type argument)
 * @param node
 *            the node containing default values for this list
 * @return an expression that creates a default value that can be assigned
 *         to this field
 */
private JExpression getDefaultList(JType fieldType, JsonNode node) {

    JClass listGenericType = ((JClass) fieldType).getTypeParameters().get(0);

    JClass listImplClass = fieldType.owner().ref(ArrayList.class);
    listImplClass = listImplClass.narrow(listGenericType);

    JInvocation newListImpl = JExpr._new(listImplClass);

    if (node instanceof ArrayNode && node.size() > 0) {
        JInvocation invokeAsList = fieldType.owner().ref(Arrays.class).staticInvoke("asList");
        for (JsonNode defaultValue : node) {
            invokeAsList.arg(getDefaultValue(listGenericType, defaultValue));
        }
        newListImpl.arg(invokeAsList);
    } else if (!ruleFactory.getGenerationConfig().isInitializeCollections()) {
        return JExpr._null();
    }

    return newListImpl;

}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:39,代码来源:DefaultRule.java

示例4: generateCode

import com.sun.codemodel.JExpression; //导入依赖的package包/类
@Override
void generateCode(ClassGenerator<WindowFramer> cg) {
  final GeneratorMapping mapping = GeneratorMapping.create("setupPartition", "outputRow", "resetValues", "cleanup");
  final MappingSet mappingSet = new MappingSet(null, "outIndex", mapping, mapping);

  cg.setMappingSet(mappingSet);
  final JVar vv = cg.declareVectorValueSetupAndMember(cg.getMappingSet().getOutgoing(), fieldId);
  final JExpression outIndex = cg.getMappingSet().getValueWriteIndex();
  JInvocation setMethod = vv.invoke("getMutator").invoke("setSafe").arg(outIndex)
    .arg(JExpr.direct("partition.ntile(" + numTiles + ")"));
  cg.getEvalBlock().add(setMethod);
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:13,代码来源:WindowFunction.java

示例5: visitDecimal9Constant

import com.sun.codemodel.JExpression; //导入依赖的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

示例6: visitDecimal18Constant

import com.sun.codemodel.JExpression; //导入依赖的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

示例7: visitDecimalConstant

import com.sun.codemodel.JExpression; //导入依赖的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

示例8: declareVectorValueSetupAndMember

import com.sun.codemodel.JExpression; //导入依赖的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

示例9: createClassInstances

import com.sun.codemodel.JExpression; //导入依赖的package包/类
private List<Partitioner> createClassInstances(int actualPartitions) throws SchemaChangeException {
  // set up partitioning function
  final LogicalExpression expr = config.getExpr();
  final ClassGenerator<Partitioner> cg = context.getClassProducer().createGenerator(Partitioner.TEMPLATE_DEFINITION).getRoot();
  ClassGenerator<Partitioner> cgInner = cg.getInnerGenerator("OutgoingRecordBatch");

  final LogicalExpression materializedExpr = context.getClassProducer().materialize(expr, incoming);

  // generate code to copy from an incoming value vector to the destination partition's outgoing value vector
  JExpression bucket = JExpr.direct("bucket");

  // generate evaluate expression to determine the hash
  ClassGenerator.HoldingContainer exprHolder = cg.addExpr(materializedExpr);
  cg.getEvalBlock().decl(JType.parse(cg.getModel(), "int"), "bucket", exprHolder.getValue().mod(JExpr.lit(outGoingBatchCount)));
  cg.getEvalBlock()._return(cg.getModel().ref(Math.class).staticInvoke("abs").arg(bucket));

  CopyUtil.generateCopies(cgInner, incoming, incoming.getSchema().getSelectionVectorMode() == SelectionVectorMode.FOUR_BYTE);

  // compile and setup generated code
  List<Partitioner> subPartitioners = cg.getCodeGenerator().getImplementationClass(actualPartitions);
  return subPartitioners;
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:23,代码来源:PartitionSenderOperator.java

示例10: addParameter

import com.sun.codemodel.JExpression; //导入依赖的package包/类
private JVar addParameter(
    final JMethod method,
    final JExpression returnValue,
    final JFieldVar field,
    final boolean isImutable,
    final boolean isNullable,
    final boolean isArrayNullable,
    final boolean isCollectionNullable) {
  if (isImutable) {
    return SourceFactoryUtilities.addParameter(method, field);
  }
  if (isInstanceOfMap(field.type())) {
    return mapSetter(method, returnValue, field, isNullable);
  }
  if (isInstanceOfList(field.type())) {
    return listSetter(method, returnValue, field, isNullable, isCollectionNullable);
  }
  return objectSetter(method, returnValue, field, isNullable, isArrayNullable);
}
 
开发者ID:AndreasWBartels,项目名称:libraries,代码行数:20,代码来源:SetterFactory.java

示例11: listSetter

import com.sun.codemodel.JExpression; //导入依赖的package包/类
private JVar listSetter(
    final JMethod method,
    final JExpression returnValue,
    final JFieldVar field,
    final boolean isNullable,
    final boolean isCollectionNullable) {
  if (isNullable) {
    if (!isCollectionNullable) {
      return addListParameter(method, field, true, createAddIfNullClearListAndReturnClosure(method, returnValue));
    }
    return addListParameter(method, field, true, createAddIfNullReturnClosure(method, returnValue));
  }
  return addListParameter(
      method,
      field,
      true,
      createEnsureArgumentNotNullClosure(this.ensurePredicateFactory, method));
}
 
开发者ID:AndreasWBartels,项目名称:libraries,代码行数:19,代码来源:SetterFactory.java

示例12: objectSetter

import com.sun.codemodel.JExpression; //导入依赖的package包/类
private JVar objectSetter(
    final JMethod method,
    final JExpression returnValue,
    final JFieldVar field,
    final boolean isNullable,
    final boolean isArrayNullable) {
  if (isNullable) {
    if (!isArrayNullable && field.type().isArray()) {
      return addObjectParameter(
          method,
          field,
          createAddIfNullSetEmptyArrayAndReturnClosure(this.codeModel, method, returnValue));
    }
    return addObjectParameter(method, field);
  }
  return addObjectParameter(method, field, createEnsureArgumentNotNullClosure(this.ensurePredicateFactory, method));
}
 
开发者ID:AndreasWBartels,项目名称:libraries,代码行数:18,代码来源:SetterFactory.java

示例13: createEquals

import com.sun.codemodel.JExpression; //导入依赖的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

示例14: createAddIfNullSetEmptyArrayAndReturnClosure

import com.sun.codemodel.JExpression; //导入依赖的package包/类
public static IProcedure<JVar, RuntimeException> createAddIfNullSetEmptyArrayAndReturnClosure(
    final JCodeModel codeModel,
    final JMethod method,
    final JExpression returnValue) {
  ensureThatArgument(method, notNull());
  return new IProcedure<JVar, RuntimeException>() {

    @Override
    public void execute(final JVar param) throws RuntimeException {
      ensureThatArgument(param, notNull());
      final ValueConverter valueConverter = new ValueConverter(codeModel);
      final JInvocation invocation = JExpr._new(param.type());
      method
          .body()
          ._if(param.eq(JExpr._null()))
          ._then()
          .block()
          .assign(JExpr.refthis(param.name()), valueConverter.convert(invocation))
          ._return(returnValue);
    }
  };
}
 
开发者ID:AndreasWBartels,项目名称:libraries,代码行数:23,代码来源:SourceFactoryUtilities.java

示例15: createAddIfNullClearMapAndReturnClosure

import com.sun.codemodel.JExpression; //导入依赖的package包/类
public static IProcedure<JVar, RuntimeException> createAddIfNullClearMapAndReturnClosure(
    final JMethod method,
    final JExpression returnValue) {
  ensureThatArgument(method, notNull());
  return new IProcedure<JVar, RuntimeException>() {

    @Override
    public void execute(final JVar param) throws RuntimeException {
      ensureThatArgument(param, notNull());
      method
          .body()
          ._if(param.eq(JExpr._null()))
          ._then()
          .block()
          .add(JExpr.refthis(param.name()).invoke("clear"))
          ._return(returnValue);
    }
  };
}
 
开发者ID:AndreasWBartels,项目名称:libraries,代码行数:20,代码来源:SourceFactoryUtilities.java


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