當前位置: 首頁>>代碼示例>>Java>>正文


Java JExpr類代碼示例

本文整理匯總了Java中com.sun.codemodel.JExpr的典型用法代碼示例。如果您正苦於以下問題:Java JExpr類的具體用法?Java JExpr怎麽用?Java JExpr使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


JExpr類屬於com.sun.codemodel包,在下文中一共展示了JExpr類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addFactoryMethod

import com.sun.codemodel.JExpr; //導入依賴的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: getUDFInstance

import com.sun.codemodel.JExpr; //導入依賴的package包/類
private JInvocation getUDFInstance(JCodeModel m) {
  if (isGenericUDF) {
    return JExpr._new(m.directClass(genericUdfClazz.getCanonicalName()));
  } else {
    return JExpr._new(m.directClass(GenericUDFBridge.class.getCanonicalName()))
      .arg(JExpr.lit(udfName))
      .arg(JExpr.lit(false))
      .arg(JExpr.lit(udfClazz.getCanonicalName().toString()));
  }
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:11,代碼來源:HiveFuncHolder.java

示例3: getDefaultList

import com.sun.codemodel.JExpr; //導入依賴的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: setupIsFunction

import com.sun.codemodel.JExpr; //導入依賴的package包/類
/**
 * setup comparison functions isSamePartition and isPeer
 */
private void setupIsFunction(final ClassGenerator<WindowFramer> cg, final Iterable<LogicalExpression> exprs,
                             final MappingSet leftMapping, final MappingSet rightMapping) {
  cg.setMappingSet(leftMapping);
  for (LogicalExpression expr : exprs) {
    if (expr == null) {
      continue;
    }

    cg.setMappingSet(leftMapping);
    ClassGenerator.HoldingContainer first = cg.addExpr(expr, ClassGenerator.BlockCreateMode.MERGE);
    cg.setMappingSet(rightMapping);
    ClassGenerator.HoldingContainer second = cg.addExpr(expr, ClassGenerator.BlockCreateMode.MERGE);

    final LogicalExpression fh =
      FunctionGenerationHelper
        .getOrderingComparatorNullsHigh(first, second, context.getClassProducer());
    final ClassGenerator.HoldingContainer out = cg.addExpr(fh, ClassGenerator.BlockCreateMode.MERGE);
    cg.getEvalBlock()._if(out.getValue().ne(JExpr.lit(0)))._then()._return(JExpr.FALSE);
  }
  cg.getEvalBlock()._return(JExpr.TRUE);
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:25,代碼來源:WindowFrameOperator.java

示例5: addToString

import com.sun.codemodel.JExpr; //導入依賴的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: buildClassAnnotations

import com.sun.codemodel.JExpr; //導入依賴的package包/類
/**
 * @return A list of the class level annotations that the annotator will
 *         use.
 */
private List<MetaAnnotation> buildClassAnnotations() {

    List<MetaAnnotation> anns = Lists.newArrayList();
    HashMap<String, Object> annotParams;

    // AlwaysValid
    JDefinedClass alwaysValid = buildTemplateConstraint("AlwaysValid");
    JDefinedClass alwaysValidValidator = buildTemplateConstraintValidator("AlwaysValidValidator", alwaysValid, Object.class);
    JMethod isValid = getIsValidMethod(alwaysValidValidator);
    isValid.body()._return(JExpr.TRUE);
    alwaysValid.annotate(Constraint.class).param("validatedBy", alwaysValidValidator);
    
    annotParams = Maps.newHashMap();
    anns.add(new MetaAnnotation(alwaysValid, AnnotationType.JSR_303, annotParams));
    
    return anns;
}
 
開發者ID:hibernate,項目名稱:beanvalidation-benchmark,代碼行數:22,代碼來源:Jsr303Annotator.java

示例7: generateBeanNonStaticInitCode

import com.sun.codemodel.JExpr; //導入依賴的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: JavaBeanBasicField

import com.sun.codemodel.JExpr; //導入依賴的package包/類
/**
 * Creates a random MetaField
 * 
 * @param owner
 *            The class that owns this field.
 * @param name
 *            The name of the meta field.
 */
public JavaBeanBasicField(MetaJavaBean owner, String name) {
    
    super(owner, name);
    
    this.basicType = BasicType.getRandom();

    // Generate the field declaration
    JDefinedClass ownerClass = owner.getGeneratedClass();
    this.generatedField = ownerClass.field(JMod.PRIVATE, basicType.getTypeClass(), name);
    
    // The getter
    getter = ownerClass.method(JMod.PUBLIC, basicType.getTypeClass(), "get" + name.substring(0, 1).toUpperCase() + name.substring(1));
    getter.body()._return(this.generatedField);
    
    // And the setter
    setter = ownerClass.method(JMod.PUBLIC, void.class, "set" + name.substring(0, 1).toUpperCase() + name.substring(1));
    JVar setterParam = setter.param(basicType.getTypeClass(), name);
    setter.body().assign(JExpr._this().ref(this.generatedField), setterParam);
}
 
開發者ID:hibernate,項目名稱:beanvalidation-benchmark,代碼行數:28,代碼來源:JavaBeanBasicField.java

示例9: JavaBeanRefField

import com.sun.codemodel.JExpr; //導入依賴的package包/類
public JavaBeanRefField(MetaJavaBean owner, String name, MetaJavaBean refBean) {
    super(owner, name);
    
    this.refBean = refBean;
    
    // Generate the field declaration
    JDefinedClass ownerClass = owner.getGeneratedClass();
    this.generatedField = ownerClass.field(JMod.PRIVATE, refBean.getGeneratedClass(), name);
    
    // The getter
    getter = ownerClass.method(JMod.PUBLIC, refBean.getGeneratedClass(), "get"+name.substring(0, 1).toUpperCase()+name.substring(1));
    getter.body()._return(this.generatedField);
    
    // The setter
    setter = ownerClass.method(JMod.PUBLIC, void.class, "set"+name.substring(0, 1).toUpperCase()+name.substring(1));
    JVar setterParam = setter.param(refBean.getGeneratedClass(), name);
    setter.body().assign(JExpr._this().ref(this.generatedField), setterParam);
}
 
開發者ID:hibernate,項目名稱:beanvalidation-benchmark,代碼行數:19,代碼來源:JavaBeanRefField.java

示例10: setupIsSame

import com.sun.codemodel.JExpr; //導入依賴的package包/類
private void setupIsSame(ClassGenerator<StreamingAggregator> cg, LogicalExpression[] keyExprs) {
  cg.setMappingSet(IS_SAME_I1);
  for (final LogicalExpression expr : keyExprs) {
    // first, we rewrite the evaluation stack for each side of the comparison.
    cg.setMappingSet(IS_SAME_I1);
    final HoldingContainer first = cg.addExpr(expr, false);
    cg.setMappingSet(IS_SAME_I2);
    final HoldingContainer second = cg.addExpr(expr, false);

    final LogicalExpression fh =
        FunctionGenerationHelper
        .getOrderingComparatorNullsHigh(first, second, context.getFunctionRegistry());
    final HoldingContainer out = cg.addExpr(fh, false);
    cg.getEvalBlock()._if(out.getValue().ne(JExpr.lit(0)))._then()._return(JExpr.FALSE);
  }
  cg.getEvalBlock()._return(JExpr.TRUE);
}
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:18,代碼來源:StreamingAggBatch.java

示例11: setupIsSameApart

import com.sun.codemodel.JExpr; //導入依賴的package包/類
private void setupIsSameApart(ClassGenerator<StreamingAggregator> cg, LogicalExpression[] keyExprs) {
  cg.setMappingSet(ISA_B1);
  for (final LogicalExpression expr : keyExprs) {
    // first, we rewrite the evaluation stack for each side of the comparison.
    cg.setMappingSet(ISA_B1);
    final HoldingContainer first = cg.addExpr(expr, false);
    cg.setMappingSet(ISA_B2);
    final HoldingContainer second = cg.addExpr(expr, false);

    final LogicalExpression fh =
        FunctionGenerationHelper
        .getOrderingComparatorNullsHigh(first, second, context.getFunctionRegistry());
    final HoldingContainer out = cg.addExpr(fh, false);
    cg.getEvalBlock()._if(out.getValue().ne(JExpr.lit(0)))._then()._return(JExpr.FALSE);
  }
  cg.getEvalBlock()._return(JExpr.TRUE);
}
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:18,代碼來源:StreamingAggBatch.java

示例12: generateCode

import com.sun.codemodel.JExpr; //導入依賴的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

示例13: setupIsFunction

import com.sun.codemodel.JExpr; //導入依賴的package包/類
/**
 * setup comparison functions isSamePartition and isPeer
 */
private void setupIsFunction(final ClassGenerator<WindowFramer> cg, final List<LogicalExpression> exprs,
                             final MappingSet leftMapping, final MappingSet rightMapping) {
  cg.setMappingSet(leftMapping);
  for (LogicalExpression expr : exprs) {
    if (expr == null) {
      continue;
    }

    cg.setMappingSet(leftMapping);
    ClassGenerator.HoldingContainer first = cg.addExpr(expr, false);
    cg.setMappingSet(rightMapping);
    ClassGenerator.HoldingContainer second = cg.addExpr(expr, false);

    final LogicalExpression fh =
      FunctionGenerationHelper
        .getOrderingComparatorNullsHigh(first, second, context.getFunctionRegistry());
    final ClassGenerator.HoldingContainer out = cg.addExpr(fh, false);
    cg.getEvalBlock()._if(out.getValue().ne(JExpr.lit(0)))._then()._return(JExpr.FALSE);
  }
  cg.getEvalBlock()._return(JExpr.TRUE);
}
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:25,代碼來源:WindowFrameRecordBatch.java

示例14: setupGetHash

import com.sun.codemodel.JExpr; //導入依賴的package包/類
private void setupGetHash(ClassGenerator<HashTable> cg, MappingSet incomingMapping, VectorAccessible batch, LogicalExpression[] keyExprs,
                          boolean isProbe) throws SchemaChangeException {

  cg.setMappingSet(incomingMapping);

  if (keyExprs == null || keyExprs.length == 0) {
    cg.getEvalBlock()._return(JExpr.lit(0));
    return;
  }

  /*
   * We use the same logic to generate run time code for the hash function both for hash join and hash
   * aggregate. For join we need to hash everything as double (both for distribution and for comparison) but
   * for aggregation we can avoid the penalty of casting to double
   */
  LogicalExpression hashExpression = HashPrelUtil.getHashExpression(Arrays.asList(keyExprs),
      incomingProbe != null ? true : false);
  final LogicalExpression materializedExpr = ExpressionTreeMaterializer.materializeAndCheckErrors(hashExpression, batch, context.getFunctionRegistry());
  HoldingContainer hash = cg.addExpr(materializedExpr);
  cg.getEvalBlock()._return(hash.getValue());


}
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:24,代碼來源:ChainedHashTable.java

示例15: codeGenGetVectorIndex

import com.sun.codemodel.JExpr; //導入依賴的package包/類
private void codeGenGetVectorIndex(ClassGenerator<StreamingAggregator> g) {
  switch (onDeckInput.getSchema().getSelectionVectorMode()) {
  case FOUR_BYTE: {
    throw new UnsupportedOperationException();
  }
  case NONE: {
    g.getBlock("getVectorIndex")._return(JExpr.direct("recordIndex"));;
    return;
  }
  case TWO_BYTE: {
    throw new UnsupportedOperationException();
    // this does't work since the we would need to move between ondeck and atbat
    // JVar var = g.declareClassField("sv2_", g.getModel()._ref(SelectionVector2.class));
    // g.getBlock("setup").assign(var, JExpr.direct("incoming").invoke("getSelectionVector2"));
    // g.getBlock("getVectorIndex")._return(var.invoke("getIndex").arg(JExpr.direct("recordIndex")));;
    // return;
  }

  default:
    throw new IllegalStateException();
  }
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:23,代碼來源:StreamingAggOperator.java


注:本文中的com.sun.codemodel.JExpr類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。