JBlock lastBlock = propertyConditional == null ? body : propertyConditional._else();
private void addSetProperty(JDefinedClass jclass, JBlock callSite, String propertyName, JType propertyType, JVar valueVar, JsonNode node) { JMethod propertySetter = jclass.getMethod(getSetterName(propertyName, node), new JType[] { propertyType }); JConditional isInstance = callSite._if(valueVar._instanceof(propertyType.boxify().erasure())); isInstance._then() .invoke(propertySetter).arg(cast(propertyType.boxify(), valueVar)); isInstance._else() ._throw(illegalArgumentInvocation(jclass, propertyName, propertyType, valueVar)); }
JConditional jc = block._if(returnValue.eq(JExpr._null())); jc._then().assign(returnValueHolder.ref("isSet"), JExpr.lit(0)); jc._else().assign(returnValueHolder.ref("isSet"), JExpr.lit(1)); JVar castedOI = jc._else().decl( m.directClass(BooleanObjectInspector.class.getCanonicalName()), "castOI", JExpr._null()); jc._else().assign(castedOI, JExpr.cast(m.directClass(BooleanObjectInspector.class.getCanonicalName()), returnOI)); JConditional booleanJC = jc._else()._if(castedOI.invoke("get").arg(returnValue)); booleanJC._then().assign(returnValueHolder.ref("value"), JExpr.lit(1)); booleanJC._else().assign(returnValueHolder.ref("value"), JExpr.lit(0)); JConditional jc = block._if(returnValue.eq(JExpr._null())); jc._then().assign(returnValueHolder.ref("isSet"), JExpr.lit(0)); jc._else().assign(returnValueHolder.ref("isSet"), JExpr.lit(1)); JVar castedOI = jc._else().decl( m.directClass(ByteObjectInspector.class.getCanonicalName()), "castOI", JExpr._null()); jc._else().assign(castedOI, JExpr.cast(m.directClass(ByteObjectInspector.class.getCanonicalName()), returnOI)); jc._else().assign(returnValueHolder.ref("value"), castedOI.invoke("get").arg(returnValue)); return block; JConditional jc = block._if(returnValue.eq(JExpr._null())); jc._then().assign(returnValueHolder.ref("isSet"), JExpr.lit(0)); jc._else().assign(returnValueHolder.ref("isSet"), JExpr.lit(1)); JVar castedOI = jc._else().decl( m.directClass(ShortObjectInspector.class.getCanonicalName()), "castOI", JExpr._null());
JBlock lastBlock = propertyConditional == null ? body : propertyConditional._else(); if (extendsType != null && extendsType instanceof JDefinedClass) { JDefinedClass parentClass = (JDefinedClass) extendsType;
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(_enum, fromValue); }
JConditional jc = conditionalBlock._if(inputVariables[i].getIsSet().ne(JExpr.lit(0))); jc._then().assign(JExpr.ref(workspaceJVars[3].component(JExpr.lit(i)), "valueHolder"), inputVariables[i].getHolder()); jc._else().assign(JExpr.ref(workspaceJVars[3].component(JExpr.lit(i)), "valueHolder"), JExpr._null()); sub.add(conditionalBlock); } else {
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; }
/** * Creates <tt>... else if(...) ...</tt> code. */ public JConditional _elseif(JExpression boolExp) { return _else()._if(boolExp); }
JConditional condition = body._if(input.lt(JExpr.lit(42))); condition._then().add( codeModel.ref(System.class).staticRef("out").invoke("println").arg(JExpr.lit("hello"))); condition._else().add( codeModel.ref(System.class).staticRef("out").invoke("println").arg(JExpr.lit("world")));
/** * Creates {@code ... else if(...) ...} code. */ public JConditional _elseif(JExpression boolExp) { return _else()._if(boolExp); }
/** * Creates <tt>... else if(...) ...</tt> code. */ public JConditional _elseif(JExpression boolExp) { return _else()._if(boolExp); }
/** * Creates {@code ... else if(...) ...} code. */ public JConditional _elseif(JExpression boolExp) { return _else()._if(boolExp); }
public void toRawValue(JBlock block, JVar $var) { // [RESULT] // if([core.hasSetValue]) // $var = [core.toRawValue].getValue(); // else // $var = null; JConditional cond = block._if(acc.hasSetValue()); JVar $v = cond._then().decl(core.getRawType(), "v" + hashCode());// TODO: unique value control acc.toRawValue(cond._then(),$v); cond._then().assign($var,$v.invoke("getValue")); cond._else().assign($var, JExpr._null()); }
public void toRawValue(JBlock block, JVar $var) { // [RESULT] // if([core.hasSetValue]) // $var = [core.toRawValue].getValue(); // else // $var = null; JConditional cond = block._if(acc.hasSetValue()); JVar $v = cond._then().decl(core.getRawType(), "v" + hashCode());// TODO: unique value control acc.toRawValue(cond._then(),$v); cond._then().assign($var,$v.invoke("getValue")); cond._else().assign($var, JExpr._null()); }
public JStatement validate(final DatabindableDatatype datatype, final JCodeModel codeModel, final JDefinedClass theClass, final JExpression value, final JAssignmentTarget problem) { final JBlock block = newBlock(); final JConditional ifValueIsNmtoken = block._if(codeModel.ref(XmlNames.class).staticInvoke("isNmtoken").arg(value)); ifValueIsNmtoken._then().directStatement("// Value is a valid Nmtoken"); ifValueIsNmtoken._else(). assign(problem, JExpr._new(codeModel.ref(NmtokenProblem.class)).arg(value)); return block; } }
public JStatement validate(final DatabindableDatatype datatype, final JCodeModel codeModel, final JDefinedClass theClass, final JExpression value, final JAssignmentTarget problem) { final JBlock block = newBlock(); final JConditional ifValueIsName = block._if(codeModel.ref(XmlNames.class).staticInvoke("isName").arg(value)); ifValueIsName._then().directStatement("// Value is a valid Name"); ifValueIsName._else(). assign(problem, JExpr._new(codeModel.ref(NameProblem.class)).arg(value)); return block; } }
private void addSetProperty(JDefinedClass jclass, JBlock callSite, String propertyName, JType propertyType, JVar valueVar, JsonNode node) { JMethod propertySetter = jclass.getMethod(getSetterName(propertyName, node), new JType[] { propertyType }); JConditional isInstance = callSite._if(valueVar._instanceof(propertyType.boxify().erasure())); isInstance._then() .invoke(propertySetter).arg(cast(propertyType.boxify(), valueVar)); isInstance._else() ._throw(illegalArgumentInvocation(jclass, propertyName, propertyType, valueVar)); }
public JStatement diagnoseByFacet(final DataTypeWithFacet datatype, final JCodeModel codeModel, final JDefinedClass theClass, final JExpression value, final JAssignmentTarget problem) { final JBlock block = newBlock(); final Beholder vc = BeholderFactory.getBeholder(datatype.getConcreteType()); final JExpression length = ((DiscreteVC) vc).countLength(codeModel, value); final JExpression expectedLength = JExpr.lit(expectedLength(datatype)); final JConditional ifValueLengthIsCorrect = block._if(lengthValid(codeModel, length, expectedLength)); ifValueLengthIsCorrect._then().directStatement("// Value length is correct"); ifValueLengthIsCorrect._else(). assign(problem, JExpr._new(problemClass(codeModel)).arg(value).arg(length).arg(expectedLength)); return block; }
public JStatement validate(final DatabindableDatatype datatype, final JCodeModel codeModel, final JDefinedClass theClass, final JExpression value, final JAssignmentTarget problem) { final JBlock block = newBlock(); final JExpression intValue = value.invoke("intValue"); final JConditional ifNegative = block._if(JOp.lt(intValue, JExpr.lit(0))); ifNegative._then().assign(problem, JExpr._new(codeModel.ref(org.jvnet.jaxbvalidation.problem.datatype.NegativeProblem.class)).arg(value)); final JConditional ifTooBig = ifNegative._else()._if(JOp.gt(intValue, JExpr.lit(65535))); ifTooBig._then().assign(problem, JExpr._new(codeModel.ref(GreaterProblem.class)).arg(value).arg(JExpr._new(codeModel.ref(Integer.class)).arg(JExpr.lit(65535)))); return block; }