本文整理汇总了Java中com.sun.codemodel.JConditional._then方法的典型用法代码示例。如果您正苦于以下问题:Java JConditional._then方法的具体用法?Java JConditional._then怎么用?Java JConditional._then使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.codemodel.JConditional
的用法示例。
在下文中一共展示了JConditional._then方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addParameter
import com.sun.codemodel.JConditional; //导入方法依赖的package包/类
private void addParameter(JBlock methodBody, JVar queryParams, String valueName, Boolean encode, Boolean simple, boolean isList) {
JBlock b = methodBody;
if (!simple) {
JConditional _if = methodBody._if(JExpr.ref(valueName).ne(JExpr._null()));
b = _if._then();
}
b.invoke(queryParams, "append").arg(JExpr.lit(valueName + "="));
if (encode) {
JExpression expr = jCodeModel.ref(java.net.URLEncoder.class).staticInvoke("encode").arg(JExpr.ref(valueName)).arg("UTF-8");
b.invoke(queryParams, "append").arg(expr);
} else {
if(isList){
b.directStatement("if("+valueName+".getClass().isArray())"
+"{queryParams.append(String.join(\"&"+valueName+"=\"," +valueName+"));}");
} else{
b.invoke(queryParams, "append").arg(JExpr.ref(valueName));
}
}
b.invoke(queryParams, "append").arg(JExpr.lit("&"));
}
示例2: ifHasSetValue
import com.sun.codemodel.JConditional; //导入方法依赖的package包/类
public JBlock ifHasSetValue(JBlock block, boolean isAlwaysSet,
boolean checkForNullRequired) {
if (isAlwaysSet || !checkForNullRequired) {
return block;
} else {
final JConditional ifLeftHasSetValue = block._if(leftHasSetValue());
final JConditional ifLeftHasSetValueAndRightHasSetValue = ifLeftHasSetValue
._then()._if(rightHasSetValue());
final JBlock subBlock = ifLeftHasSetValueAndRightHasSetValue
._then();
ifLeftHasSetValueAndRightHasSetValue._else()._return(JExpr.FALSE);
ifLeftHasSetValue._elseif(rightHasSetValue())._then()
._return(JExpr.FALSE);
return subBlock;
}
}
示例3: addInternalSetMethodJava6
import com.sun.codemodel.JConditional; //导入方法依赖的package包/类
private JMethod addInternalSetMethodJava6(JDefinedClass jclass, JsonNode propertiesNode) {
JMethod method = jclass.method(PROTECTED, jclass.owner().BOOLEAN, DEFINED_SETTER_NAME);
JVar nameParam = method.param(String.class, "name");
JVar valueParam = method.param(Object.class, "value");
JBlock body = method.body();
JConditional propertyConditional = null;
if (propertiesNode != null) {
for (Iterator<Map.Entry<String, JsonNode>> properties = propertiesNode.fields(); properties.hasNext();) {
Map.Entry<String, JsonNode> property = properties.next();
String propertyName = property.getKey();
JsonNode node = property.getValue();
String fieldName = ruleFactory.getNameHelper().getPropertyName(propertyName, node);
JType propertyType = jclass.fields().get(fieldName).type();
JExpression condition = lit(propertyName).invoke("equals").arg(nameParam);
propertyConditional = propertyConditional == null ? propertyConditional = body._if(condition)
: propertyConditional._elseif(condition);
JBlock callSite = propertyConditional._then();
addSetProperty(jclass, callSite, propertyName, propertyType, valueParam, node);
callSite._return(TRUE);
}
}
JClass extendsType = jclass._extends();
JBlock lastBlock = propertyConditional == null ? body : propertyConditional._else();
if (extendsType != null && extendsType instanceof JDefinedClass) {
JDefinedClass parentClass = (JDefinedClass) extendsType;
JMethod parentMethod = parentClass.getMethod(DEFINED_SETTER_NAME,
new JType[] { parentClass.owner()._ref(String.class), parentClass.owner()._ref(Object.class) });
lastBlock._return(_super().invoke(parentMethod).arg(nameParam).arg(valueParam));
} else {
lastBlock._return(FALSE);
}
return method;
}
示例4: visitValueVectorWriteExpression
import com.sun.codemodel.JConditional; //导入方法依赖的package包/类
private HoldingContainer visitValueVectorWriteExpression(ValueVectorWriteExpression e, ClassGenerator<?> generator) {
final LogicalExpression child = e.getChild();
final HoldingContainer inputContainer = child.accept(this, generator);
JBlock block = generator.getEvalBlock();
JExpression outIndex = generator.getMappingSet().getValueWriteIndex();
JVar vv = generator.declareVectorValueSetupAndMember(generator.getMappingSet().getOutgoing(), e.getFieldId());
// Only when the input is a reader, use writer interface to copy value.
// Otherwise, input is a holder and we use vv mutator to set value.
if (inputContainer.isReader()) {
JType writerImpl = generator.getModel()._ref(
TypeHelper.getWriterImpl(inputContainer.getMinorType(), inputContainer.getMajorType().getMode()));
JType writerIFace = generator.getModel()._ref(
TypeHelper.getWriterInterface(inputContainer.getMinorType(), inputContainer.getMajorType().getMode()));
JVar writer = generator.declareClassField("writer", writerIFace);
generator.getSetupBlock().assign(writer, JExpr._new(writerImpl).arg(vv).arg(JExpr._null()));
generator.getEvalBlock().add(writer.invoke("setPosition").arg(outIndex));
String copyMethod = inputContainer.isSingularRepeated() ? "copyAsValueSingle" : "copyAsValue";
generator.getEvalBlock().add(inputContainer.getHolder().invoke(copyMethod).arg(writer));
if (e.isSafe()) {
HoldingContainer outputContainer = generator.declare(Types.REQUIRED_BIT);
generator.getEvalBlock().assign(outputContainer.getValue(), JExpr.lit(1));
return outputContainer;
}
} else {
final JInvocation setMeth = GetSetVectorHelper.write(e.getChild().getMajorType(), vv, inputContainer, outIndex, e.isSafe() ? "setSafe" : "set");
if (inputContainer.isOptional()) {
JConditional jc = block._if(inputContainer.getIsSet().eq(JExpr.lit(0)).not());
block = jc._then();
}
block.add(setMeth);
}
return null;
}
示例5: visitIfExpression
import com.sun.codemodel.JConditional; //导入方法依赖的package包/类
@Override
public HoldingContainer visitIfExpression(IfExpression ifExpr, ClassGenerator<?> generator) throws RuntimeException {
JBlock local = generator.getEvalBlock();
HoldingContainer output = generator.declare(ifExpr.getCompleteType());
JBlock conditionalBlock = new JBlock(false, false);
IfCondition c = ifExpr.ifCondition;
HoldingContainer holdingContainer = c.condition.accept(this, generator);
final JConditional jc = conditionalBlock._if(holdingContainer.getIsSet().eq(JExpr.lit(1)).cand(holdingContainer.getValue().eq(JExpr.lit(1))));
generator.nestEvalBlock(jc._then());
HoldingContainer thenExpr = c.expression.accept(this, generator);
generator.unNestEvalBlock();
JConditional newCond = jc._then()._if(thenExpr.getIsSet().ne(JExpr.lit(0)));
JBlock b = newCond._then();
b.assign(output.getHolder(), thenExpr.getHolder());
// b.assign(output.getIsSet(), thenExpr.getIsSet());
// b.assign(output.getValue(), thenExpr.getValue());
generator.nestEvalBlock(jc._else());
HoldingContainer elseExpr = ifExpr.elseExpression.accept(this, generator);
generator.unNestEvalBlock();
JConditional newCond2 = jc._else()._if(elseExpr.getIsSet().ne(JExpr.lit(0)));
JBlock b2 = newCond2._then();
b2.assign(output.getHolder(), elseExpr.getHolder());
//b.assign(output.getIsSet(), elseExpr.getIsSet());
local.add(conditionalBlock);
return output;
}
示例6: visitValueVectorWriteExpression
import com.sun.codemodel.JConditional; //导入方法依赖的package包/类
private HoldingContainer visitValueVectorWriteExpression(ValueVectorWriteExpression e, ClassGenerator<?> generator) {
final LogicalExpression child = e.getChild();
final HoldingContainer inputContainer = child.accept(this, generator);
JBlock block = generator.getEvalBlock();
JExpression outIndex = generator.getMappingSet().getValueWriteIndex();
JVar vv = generator.declareVectorValueSetupAndMember(generator.getMappingSet().getOutgoing(), e.getFieldId());
// Only when the input is a reader, use writer interface to copy value.
// Otherwise, input is a holder and we use vv mutator to set value.
if (inputContainer.isReader()) {
JType writerImpl = generator.getModel()._ref(
TypeHelper.getWriterImpl(getArrowMinorType(inputContainer.getCompleteType().toMinorType())));
JType writerIFace = generator.getModel()._ref(
TypeHelper.getWriterInterface(getArrowMinorType(inputContainer.getCompleteType().toMinorType())));
JVar writer = generator.declareClassField("writer", writerIFace);
generator.getSetupBlock().assign(writer, JExpr._new(writerImpl).arg(vv));
generator.getEvalBlock().add(writer.invoke("setPosition").arg(outIndex));
String copyMethod = inputContainer.isSingularRepeated() ? "copyAsValueSingle" : "copyAsValue";
generator.getEvalBlock().add(inputContainer.getHolder().invoke(copyMethod).arg(writer));
if (e.isSafe()) {
HoldingContainer outputContainer = generator.declare(CompleteType.BIT);
generator.getEvalBlock().assign(outputContainer.getValue(), JExpr.lit(1));
return outputContainer;
}
} else {
final JInvocation setMeth = GetSetVectorHelper.write(e.getChild().getCompleteType().toMinorType(), vv, inputContainer, outIndex, e.isSafe() ? "setSafe" : "set");
JConditional jc = block._if(inputContainer.getIsSet().eq(JExpr.lit(0)).not());
block = jc._then();
block.add(setMeth);
}
return null;
}
示例7: buildAdditionalMethods
import com.sun.codemodel.JConditional; //导入方法依赖的package包/类
public void buildAdditionalMethods(JDefinedClass jc) {
// getCurrentResidency
JMethod jmgCurrentResidency = jc.method(JMod.PUBLIC, org.openhds.domain.model.Residency.class, "getCurrentResidency");
// if statement
JBlock jBlock = jmgCurrentResidency.body();
JConditional condition = jBlock._if(JExpr.ref(jfResidencies, "size()").eq(JExpr.lit(0)));
condition._then()._return(JExpr._null());
// iterator
JClass iterator = jCodeModel.ref(java.util.Iterator.class);
iterator = iterator.narrow(org.openhds.domain.model.Residency.class);
JVar jvIterator = jBlock.decl(iterator, "itr");
jvIterator.init(JExpr.ref(jfResidencies, "iterator()"));
// residency
JClass residencies = jCodeModel.ref(org.openhds.domain.model.Residency.class);
JVar jvResidencies = jBlock.decl(residencies, "residency");
jvResidencies.init(JExpr._null());
// while loop
JWhileLoop whileLoop = jBlock._while(JExpr.ref(jvIterator, "hasNext()"));
JBlock whileLoopBody = whileLoop.body();
whileLoopBody.assign(jvResidencies, JExpr.ref(jvIterator, "next()"));
jBlock._return(jvResidencies);
//-------------- getCurrentMembership ------------------
JMethod jmgCurrentMembership = jc.method(JMod.PUBLIC, org.openhds.domain.model.Membership.class, "getCurrentMembership");
//Init method
JBlock jBlockCurrentMembership = jmgCurrentMembership.body();
// Membership m1
JClass memberShipClass = jCodeModel.ref(org.openhds.domain.model.Membership.class);
JVar jvM1 = jBlockCurrentMembership.decl(memberShipClass, "m1");
jvM1.init(JExpr._new(memberShipClass));
// if statement
JConditional conditionMembership = jBlockCurrentMembership._if(JExpr.ref(jfMemberships, "size()").eq(JExpr.lit(0)));
conditionMembership._then()._return(JExpr._null());
// iterator
JClass membershipIterator = jCodeModel.ref(java.util.Iterator.class);
membershipIterator = membershipIterator.narrow(org.openhds.domain.model.Membership.class);
JVar jvMembershipIterator = jBlockCurrentMembership.decl(membershipIterator, "itr");
jvMembershipIterator.init(JExpr.ref(jfMemberships, "iterator()"));
//Membership membership
JVar jvMembership = jBlockCurrentMembership.decl(memberShipClass, "membership");
jvMembership.init(JExpr._null());
// while loop
JWhileLoop membershipWhileLoop = jBlockCurrentMembership._while(JExpr.ref(jvMembershipIterator, "hasNext()"));
JBlock membershipWhileLoopBody = membershipWhileLoop.body();
membershipWhileLoopBody.assign(jvM1, JExpr.ref(jvMembershipIterator, "next()"));
// if statement
JConditional conditionEndDate = membershipWhileLoopBody._if(JExpr.ref(jvM1, "endDate").eq(JExpr._null()));
JBlock assignBlock = conditionEndDate._then();
assignBlock.assign(jvMembership, jvM1);
jBlockCurrentMembership._return(jvMembership);
}
示例8: createReportingMethod
import com.sun.codemodel.JConditional; //导入方法依赖的package包/类
static
private void createReportingMethod(JDefinedClass clazz, ExecutableElement executableElement, String operation, String initialOperation, JPrimitiveType type){
JCodeModel codeModel = clazz.owner();
JMethod method = clazz.method(JMod.PUBLIC, clazz, String.valueOf(executableElement.getSimpleName()));
method.annotate(Override.class);
List<? extends VariableElement> parameterElements = executableElement.getParameters();
for(VariableElement parameterElement : parameterElements){
method.param(toType(codeModel, parameterElement.asType()), String.valueOf(parameterElement.getSimpleName()));
}
JBlock body = method.body();
JVar resultVariable = body.decl(clazz, "result", JExpr.cast(clazz, createSuperInvocation(clazz, method)));
if(initialOperation != null){
JConditional ifStatement = body._if(JExpr.invoke("hasExpression"));
JBlock trueBlock = ifStatement._then();
trueBlock.add(JExpr.invoke("report").arg(createReportInvocation(clazz, operation, method.params(), type)));
JBlock falseBlock = ifStatement._else();
falseBlock.add(JExpr.invoke("report").arg(createReportInvocation(clazz, initialOperation, method.params(), type)));
} else
{
body.add(JExpr.invoke("report").arg(createReportInvocation(clazz, operation, method.params(), type)));
}
body._return(resultVariable);
}