private void createFieldReferenceUseWillClear(JFieldVar field, JMethod method) { JBlock body = method.body(); JInvocation getObject = JExpr.invoke(method.listParams()[0], "getObject"); body._return(getObject.ne(JExpr._null())); }
JExpression nsInv = JExpr.lit(xmlType.getNamespaceURI()).ne(xsiType.invoke("getNamespaceURI")); if (xmlType.getNamespaceURI().equals("")) { nsInv = nsInv.cand(xsiType.invoke("getNamespaceURI").ne(JExpr._null()));
private void handleIdProperty(JCodeModel model, JBlock body, Shape shape, JVar sourceVar, JVar jsonVar) { if (shape.getNodeKind() == NodeKind.IRI) { URI targetClass = shape.getTargetClass(); JBlock then = body._if(sourceVar.invoke("getId").ne(JExpr._null()))._then(); String methodName = owlReasoner.isEnumerationClass(targetClass) ? "getLocalName" : "stringValue"; then.add( jsonVar.invoke("writeStringField").arg(JExpr.lit("id")).arg( sourceVar.invoke("getId").invoke(methodName)) ); } }
itemBlock._if(stringBuilder.invoke("length").ne(JExpr.lit(0)))._then().invoke(stringBuilder, "append").arg(" ");
itemBlock._if(stringBuilder.invoke("length").ne(JExpr.lit(0)))._then().invoke(stringBuilder, "append").arg(" ");
public void generateToString() { JMethod toString1 = cls().method(JMod.PUBLIC, cm.ref("java.lang.String"), "toString"); toString1.body()._return(ref("this").invoke("toString").arg(lit(""))); JMethod toString2 = cls().method(JMod.PUBLIC, cm.ref("java.lang.String"), "toString"); toString2.param(String.class, "indent"); toString2.body().decl(cm.ref("java.lang.String"), "rc", lit("")); for (int i = 0; i < amqpFields.size(); i++) { Attribute attr = amqpFields.get(i); if ( attr.attribute.type().isArray() ) { JBlock block = toString2.body()._if(_this().ref(attr.attribute).ne(_null()))._then().block(); block._if(ref("rc").invoke("length").ne(lit(0)))._then().assignPlus(ref("rc"), lit(",\n")); block.assignPlus(ref("rc"), ref("indent").plus(lit(" " + attr.attribute.name() + ":").plus(cm.ref("java.util.Arrays").staticInvoke("toString").arg(_this().ref(attr.attribute))))); } else { JExpression value = _this().ref(attr.attribute); if ( generator.getMapping().get(attr.type) == null ) { value = value.invoke("toString").arg(ref("indent").plus(lit(" "))); } JBlock block = toString2.body()._if(_this().ref(attr.attribute).ne(_null()))._then().block(); block._if(ref("rc").invoke("length").ne(lit(0)))._then().assignPlus(ref("rc"), lit(",\n")); block.assignPlus(ref("rc"), ref("indent").plus(lit(" " + attr.attribute.name() + ":").plus(value))); } } toString2.body()._if(ref("rc").invoke("length").ne(lit(0)))._then(). assign(ref("rc"), lit(", {\n").plus(ref("rc").plus(lit("}")))); toString2.body()._return(lit("[" + toJavaClassName(type.getName())).plus(ref("rc")).plus(lit("]"))); }
private JMethod getLocalClassName(EBeansHolder eBeansHolder, JDefinedClass helperClass, JCodeModel codeModel) { JClass stringClass = eBeansHolder.refClass(String.class); JMethod getLocalClassName = helperClass.method(PRIVATE | STATIC, stringClass, "getLocalClassName"); JClass contextClass = eBeansHolder.refClass("android.content.Context"); JVar contextParam = getLocalClassName.param(contextClass, "context"); JBlock body = getLocalClassName.body(); JVar packageName = body.decl(stringClass, "packageName", contextParam.invoke("getPackageName")); JVar className = body.decl(stringClass, "className", contextParam.invoke("getClass").invoke("getName")); JVar packageLen = body.decl(codeModel.INT, "packageLen", packageName.invoke("length")); JExpression condition = className.invoke("startsWith").arg(packageName).not() // .cor(className.invoke("length").lte(packageLen)) // .cor(className.invoke("charAt").arg(packageLen).ne(lit('.'))); body._if(condition)._then()._return(className); body._return(className.invoke("substring").arg(packageLen.plus(lit(1)))); return getLocalClassName; } }
private void withEquals() { JMethod equals = this.pojo.method(JMod.PUBLIC, boolean.class, "equals"); JVar otherObject = equals.param(Object.class, "other"); Class<?> equalsBuilderClass = org.apache.commons.lang3.builder.EqualsBuilder.class; if (!Config.getPojoConfig().isUseCommonsLang3()) { equalsBuilderClass = org.apache.commons.lang.builder.EqualsBuilder.class; } JBlock body = equals.body(); body._if(otherObject.eq(JExpr._null()))._then()._return(JExpr.FALSE); body._if(otherObject.eq(JExpr._this()))._then()._return(JExpr.TRUE); body._if(JExpr._this().invoke("getClass").ne(otherObject.invoke("getClass")))._then()._return(JExpr.FALSE); JVar otherObjectVar = body.decl(this.pojo, "otherObject").init(JExpr.cast(this.pojo, otherObject)); JClass equalsBuilderRef = this.pojo.owner().ref(equalsBuilderClass); JInvocation equalsBuilderInvocation = appendFieldsToEquals(getNonTransientAndNonStaticFields(), otherObjectVar, equalsBuilderRef); body._return(equalsBuilderInvocation.invoke("isEquals")); }
private void generateEquals() { equalsGeneric = cls().method(JMod.PUBLIC, cm.BOOLEAN, "equals"); equalsGeneric.param(cm.ref("java.lang.Object"), "other"); equalsGeneric.body().block()._if(_this().eq(ref("other"))) ._then() ._return(TRUE); equalsGeneric.body().block()._if( ref("other").eq(_null()) .cor((ref("other")._instanceof(cls()).not()))) ._then() ._return(FALSE); equalsGeneric.body().block()._return(_this().invoke("equals").arg(cast(cls(), ref("other")))); equalsTypeSpecific = cls().method(JMod.PUBLIC, cm.BOOLEAN, "equals"); equalsTypeSpecific.param(cls(), "other"); equalsTypeSpecific.body().block()._if(ref("other").eq(_null()))._then()._return(FALSE); JConditional test = equalsTypeSpecific.body().block()._if(_this().ref("value").eq(_null()).cand(ref("other").invoke("getValue").ne(_null()))); test._then().block()._return(FALSE); JConditional test2 = test._elseif(_this().ref("value").ne(_null()).cand(ref("other").invoke("getValue").eq(_null()))); test2._then().block()._return(FALSE); JConditional test3 = test2._elseif(_this().ref("value").eq(_null()).cand(ref("other").invoke("getValue").eq(_null()))); test3._then().block()._return(TRUE); test3._else().block()._return(_this().ref("value").invoke("equals").arg(ref("other").invoke("getValue"))); }