本文整理匯總了Java中com.sun.codemodel.JVar類的典型用法代碼示例。如果您正苦於以下問題:Java JVar類的具體用法?Java JVar怎麽用?Java JVar使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
JVar類屬於com.sun.codemodel包,在下文中一共展示了JVar類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addFactoryMethod
import com.sun.codemodel.JVar; //導入依賴的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);
}
示例2: addPublicGetMethod
import com.sun.codemodel.JVar; //導入依賴的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;
}
示例3: addPublicSetMethod
import com.sun.codemodel.JVar; //導入依賴的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;
}
示例4: addPublicWithMethod
import com.sun.codemodel.JVar; //導入依賴的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;
}
示例5: generateBeanNonStaticInitCode
import com.sun.codemodel.JVar; //導入依賴的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;
}
示例6: JavaBeanBasicField
import com.sun.codemodel.JVar; //導入依賴的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);
}
示例7: JavaBeanRefField
import com.sun.codemodel.JVar; //導入依賴的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);
}
示例8: generateCode
import com.sun.codemodel.JVar; //導入依賴的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);
}
示例9: visitFunctionHolderExpression
import com.sun.codemodel.JVar; //導入依賴的package包/類
@Override
public HoldingContainer visitFunctionHolderExpression(FunctionHolderExpression holderExpr,
ClassGenerator<?> generator) throws RuntimeException {
AbstractFuncHolder holder = (AbstractFuncHolder) holderExpr.getHolder();
JVar[] workspaceVars = holder.renderStart(generator, null);
if (holder.isNested()) {
generator.getMappingSet().enterChild();
}
HoldingContainer[] args = new HoldingContainer[holderExpr.args.size()];
for (int i = 0; i < holderExpr.args.size(); i++) {
args[i] = holderExpr.args.get(i).accept(this, generator);
}
holder.renderMiddle(generator, args, workspaceVars);
if (holder.isNested()) {
generator.getMappingSet().exitChild();
}
return holder.renderEnd(generator, args, workspaceVars);
}
示例10: visitDecimal9Constant
import com.sun.codemodel.JVar; //導入依賴的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);
}
示例11: visitDecimal18Constant
import com.sun.codemodel.JVar; //導入依賴的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);
}
示例12: renderEnd
import com.sun.codemodel.JVar; //導入依賴的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;
}
示例13: declareWorkspaceVectors
import com.sun.codemodel.JVar; //導入依賴的package包/類
private JVar[] declareWorkspaceVectors(ClassGenerator<?> g) {
JVar[] workspaceJVars = new JVar[workspaceVars.length];
for(int i =0 ; i < workspaceVars.length; i++){
if (workspaceVars[i].isInject() == true) {
workspaceJVars[i] = g.declareClassField("work", g.getModel()._ref(workspaceVars[i].type));
g.getBlock(BlockType.SETUP).assign(workspaceJVars[i], g.getMappingSet().getIncoming().invoke("getContext").invoke("getManagedBuffer"));
} else {
Preconditions.checkState(Types.isFixedWidthType(workspaceVars[i].majorType), String.format("Workspace variable '%s' in aggregation function '%s' is not allowed to have variable length type.", workspaceVars[i].name, registeredNames[0]));
Preconditions.checkState(workspaceVars[i].majorType.getMode()==DataMode.REQUIRED, String.format("Workspace variable '%s' in aggregation function '%s' is not allowed to have null or repeated type.", workspaceVars[i].name, registeredNames[0]));
//workspaceJVars[i] = g.declareClassField("work", g.getHolderType(workspaceVars[i].majorType), JExpr._new(g.getHolderType(workspaceVars[i].majorType)));
workspaceJVars[i] = g.declareClassField("work", g.getHolderType(workspaceVars[i].majorType));
//Declare a workspace vector for the workspace var.
TypedFieldId typedFieldId = new TypedFieldId(workspaceVars[i].majorType, g.getWorkspaceTypes().size());
JVar vv = g.declareVectorValueSetupAndMember(g.getMappingSet().getWorkspace(), typedFieldId);
g.getWorkspaceTypes().add(typedFieldId);
g.getWorkspaceVectors().put(workspaceVars[i], vv);
}
}
return workspaceJVars;
}
示例14: visitFunctionHolderExpression
import com.sun.codemodel.JVar; //導入依賴的package包/類
@Override
public HoldingContainer visitFunctionHolderExpression(FunctionHolderExpression holderExpr,
ClassGenerator<?> generator) throws RuntimeException {
CompleteType resolvedOutput = holderExpr.getCompleteType();
AbstractFunctionHolder holder = (AbstractFunctionHolder) holderExpr.getHolder();
JVar[] workspaceVars = holder.renderStart(generator, resolvedOutput, null);
if (holder.isNested()) {
generator.getMappingSet().enterChild();
}
HoldingContainer[] args = new HoldingContainer[holderExpr.args.size()];
for (int i = 0; i < holderExpr.args.size(); i++) {
args[i] = holderExpr.args.get(i).accept(this, generator);
}
holder.renderMiddle(generator, resolvedOutput, args, workspaceVars);
if (holder.isNested()) {
generator.getMappingSet().exitChild();
}
return holder.renderEnd(generator, resolvedOutput, args, workspaceVars);
}
示例15: visitDecimalConstant
import com.sun.codemodel.JVar; //導入依賴的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"));
}