private void createEqualsMethod(ClassOutline classOutline, String baseMethod) { JDefinedClass definedClass = classOutline.implClass; JMethod equals = definedClass.getMethod(METHOD_EQUALS, new JType[]{CLASS_MAP.get(Object.class)}); if (equals != null) { // removeOldCustomGeneratedEquals(classOutline, hasParentAnnotation(classOutline, PRISM_OBJECT)); todo can this be removed? equals = recreateMethod(equals, definedClass); } else { equals = definedClass.method(JMod.PUBLIC, boolean.class, METHOD_EQUALS); } equals.annotate(CLASS_MAP.get(Override.class)); JBlock body = equals.body(); JVar obj = equals.listParams()[0]; JBlock ifNull = body._if(obj._instanceof(definedClass).not())._then(); ifNull._return(JExpr.lit(false)); JVar other = body.decl(definedClass, "other", JExpr.cast(definedClass, obj)); JInvocation invocation = JExpr.invoke(baseMethod).invoke(METHOD_EQUIVALENT); invocation.arg(other.invoke(baseMethod)); body._return(invocation); }
body._if(holder.contextRef._instanceof(classes.FRAGMENT_ACTIVITY).not())._then()._return(_null());
public void createEquals(final JDefinedClass bean, final Iterable<JFieldVar> fields) { final JMethod method = bean.method(JMod.PUBLIC, this.codeModel.BOOLEAN, "equals"); method.annotate(java.lang.Override.class); final JVar object = method.param(_type(java.lang.Object.class.getName()), "object"); final JBlock block = method.body(); block._if(JExpr._this().eq(object))._then()._return(JExpr.TRUE); block._if(object._instanceof(bean).not())._then()._return(JExpr.FALSE); JExpression result = JExpr.TRUE; final JExpression other = block.decl(bean, "other", JExpr.cast(bean, object)); final JClass objectUtilities = _classByNames(net.anwiba.commons.lang.object.ObjectUtilities.class.getName()); for (final JFieldVar field : fields) { result = result.cand(objectUtilities.staticInvoke("equals").arg(JExpr.refthis(field.name())).arg(other.ref(field))); } block._return(result); } }
body._if(holder.contextRef._instanceof(classes.FRAGMENT_ACTIVITY).not())._then()._return(_null());
afterSetContentViewBody._if(holder.contextRef._instanceof(classes.ACTIVITY).not())._then()._return();
JConditional jc = block._if(inputContainer.getIsSet().eq(JExpr.lit(0)).not()); block = jc._then();
JConditional jc = block._if(inputContainer.getIsSet().eq(JExpr.lit(0)).not()); block = jc._then(); block.add(setMeth);
String message = builder.toString(); body._if(dataVar._instanceof(targetClass).not())._then()._throw( JExpr._new(validationExceptionClass).arg(JExpr.lit(message)));
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"))); }