本文整理汇总了Java中com.sun.codemodel.JExpr类的典型用法代码示例。如果您正苦于以下问题:Java JExpr类的具体用法?Java JExpr怎么用?Java JExpr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JExpr类属于com.sun.codemodel包,在下文中一共展示了JExpr类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: visitDecimal9Constant
import com.sun.codemodel.JExpr; //导入依赖的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
示例17: visitDecimal18Constant
import com.sun.codemodel.JExpr; //导入依赖的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
示例18: renderEnd
import com.sun.codemodel.JExpr; //导入依赖的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
示例19: 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.
*/
LogicalExpression hashExpression = HashPrelUtil.getHashExpression(Arrays.asList(keyExprs));
final LogicalExpression materializedExpr = producer.materialize(hashExpression, batch);
HoldingContainer hash = cg.addExpr(materializedExpr);
cg.getEvalBlock()._return(hash.getValue());
}
开发者ID:dremio,项目名称:dremio-oss,代码行数:22,代码来源:ChainedHashTable.java
示例20: visitDecimalConstant
import com.sun.codemodel.JExpr; //导入依赖的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
注:本文中的com.sun.codemodel.JExpr类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论