Refine search
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)); }
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);
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; }
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; }
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); }
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; }
sub.assign(workspaceJVars[3].component(JExpr.lit(i)), workspaceJVars[2].component(JExpr.lit(i))); JBlock conditionalBlock = new JBlock(false, false); 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);
switch(poi.getPrimitiveCategory()) { case BOOLEAN:{ 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( 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( JConditional jc = block._if(returnValue.eq(JExpr._null())); JConditional jc = block._if(returnValue.eq(JExpr._null())); JConditional jc = block._if(returnValue.eq(JExpr._null())); JConditional jc = block._if(returnValue.eq(JExpr._null())); JConditional jc = block._if(returnValue.eq(JExpr._null())); JConditional jc = block._if(returnValue.eq(JExpr._null())); JConditional jnullif = jc._else()._if(data.eq(JExpr._null()));
JVar superString = body.decl(jclass.owner().ref(String.class), "superString", JExpr._super().invoke("toString")); JBlock superToStringBlock = body._if(superString.ne(JExpr._null()))._then(); superString.invoke("lastIndexOf").arg(JExpr.lit(']'))); JConditional superToStringInnerConditional = superToStringBlock._if( contentStart.gte(JExpr.lit(0)).cand(contentEnd.gt(contentStart))); superToStringInnerConditional._then().add( sb.invoke("append") .arg(superString) body._if(sb.invoke("length").gt(baseLength)) ._then().add(sb.invoke("append").arg(JExpr.lit(','))); JConditional trailerConditional = body._if( sb.invoke("charAt").arg(sb.invoke("length").minus(JExpr.lit(1))) .eq(JExpr.lit(',')));
protected void generate() { conv = createConverter(itemType); conv.addMetadata(xmlTokenName(),itemType); if(!isVariableExpansion() && toJtype.visit(itemType,null)!=cm.ref(String.class)) printError("variableExpansion=false is only allowed on String", p.decl()); if(!generateNoopConfigInjector) { JVar value = var( packer!=null ? cm.ref(List.class).narrow(conv.sourceType()) : conv.sourceType(),getXmlValue()); if(!isRequired()) body._if(value.eq(JExpr._null()))._then()._return(); if(packer!=null) handleMultiValue(value); else assign(conv.as(value,itemType)); } if(p.isKey()) addKey(); }
MethodGenerator(String methodNamePrefix, JMethod reinjectionMethod, Property p, String xmlName) { this.xmlName = p.inferName(xmlName); this.p = p; if(generateNoopConfigInjector) { body = null; $dom = null; $target = null; } else { JMethod m = injector.method(JMod.PUBLIC,void.class, methodNamePrefix+p.seedName()); $dom = m.param(Dom.class,"dom"); $target = m.param(targetType,"target"); body = m.body(); injectMethod.body().invoke(m).arg($dom).arg($target); reinjectionMethod.body()._if(JExpr.lit(this.xmlName).invoke("equals").arg(JExpr.ref("name"))) ._then().invoke(m).arg($dom).arg($target); } erasure = erasure(p.type()); packer = createPacker(p.type(),erasure); itemType = packer==null ? erasure : erasure(packer.itemType()); }
/** * Generates statement(s) so that the successive {@link Accessor#ref(boolean)} with * true will always return a non-null list. * * This is useful to avoid generating redundant internal getter. */ protected final void fixNullRef(JBlock block) { block._if(field.eq(JExpr._null()))._then() .assign(field,newCoreList()); }
/** * Generates statement(s) so that the successive {@link Accessor#ref(boolean)} with * true will always return a non-null list. * * This is useful to avoid generating redundant internal getter. */ protected final void fixNullRef(JBlock block) { block._if(field.eq(JExpr._null()))._then() .assign(field,newCoreList()); }
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()); }
private void writeGetWsdlLocation(JType retType, JDefinedClass cls, JFieldVar urlField, JFieldVar exField) { JMethod m = cls.method(JMod.PRIVATE|JMod.STATIC , retType, "__getWsdlLocation"); JConditional ifBlock = m.body()._if(exField.ne(JExpr._null())); ifBlock._then()._throw(exField); m.body()._return(urlField); }