if ("double".equals(fieldVar.type().name())) { JClass doubleClass = jclass.owner().ref(Double.class); fieldEquals = doubleClass.staticInvoke("doubleToLongBits").arg(thisFieldRef).eq( doubleClass.staticInvoke("doubleToLongBits").arg(otherFieldRef)); } else if ("float".equals(fieldVar.type().name())) { JClass floatClass = jclass.owner().ref(Float.class); fieldEquals = floatClass.staticInvoke("floatToIntBits").arg(thisFieldRef).eq( floatClass.staticInvoke("floatToIntBits").arg(otherFieldRef)); } else {
.eq(JExpr.lit(',')));
private void createFieldReferenceWillClear(JFieldVar field, JMethod method) { JBlock body = method.body(); JInvocation getObject = JExpr.invoke(method.listParams()[0], "getObject"); body._return(getObject.eq(JExpr._null())); }
public JMethod createCreateBeanMethod(final JDefinedClass bean) { final JMethod method = bean.method(JMod.PRIVATE | JMod.STATIC, bean, "_createBean"); final JVar classParameter = method.param( JMod.FINAL, _classByNames(java.lang.Class.class.getName(), MessageFormat.format("? extends {0}", bean.name())), "clazz"); final JBlock methodBody = method.body(); final JConditional ifBlock = methodBody ._if(_classByNames(System.class.getName()).staticInvoke("getSecurityManager").eq(JExpr._null())); add(bean, classParameter, ifBlock._then()._try()); final JDefinedClass anonymousClass = getCodeModel() .anonymousClass(_classByNames(PrivilegedAction.class.getName(), bean.name())); final JMethod anonymousClassMethod = anonymousClass.method(JMod.PUBLIC, bean, "run"); add(bean, classParameter, anonymousClassMethod.body()._try()); methodBody._return( _classByNames(AccessController.class.getName()).staticInvoke("doPrivileged").arg(JExpr._new(anonymousClass))); return method; }
.eq(JExpr._null())))._then(); then._return(JExpr._null());
private void createEqualsMethod(final JDefinedClass implClass, final List<JFieldVar> fields, final boolean isSuperClass) { final JMethod method = implClass.method(JMod.PUBLIC, implClass.owner().BOOLEAN, OPERATION_EQUALS); method.annotate(Override.class); final JVar vObj = method.param(Object.class, OBJ); final JConditional condMe = method.body()._if(JExpr._this().eq(vObj)); condMe._then()._return(JExpr.TRUE); final JConditional condNull = method.body()._if(vObj.eq(JExpr._null())); condNull._then()._return(JExpr.FALSE); if (isSuperClass) { final JConditional condSuper = method.body()._if(JExpr._super().invoke(OPERATION_EQUALS).arg(vObj).eq(JExpr.FALSE)); condSuper._then()._return(JExpr.FALSE); } final JVar vOther = method.body().decl(JMod.FINAL, implClass, OTHER, JExpr.cast(implClass, vObj)); final JClass objectsClass = implClass.owner().ref(Objects.class); final List<JFieldVar> clonedList = new ArrayList<JFieldVar>(fields.size()); clonedList.addAll(fields); final JFieldVar first = clonedList.remove(IDX_TO_REMOVE); final JBlock block = new JBlock(); JExpression invocation = block.staticInvoke(objectsClass, OPERATION_EQUALS).arg(JExpr.ref(first.name())).arg(vOther.ref(first.name())); for (final JFieldVar jFieldVar : clonedList) { invocation = JOp.cand(invocation, block.staticInvoke(objectsClass, OPERATION_EQUALS).arg(JExpr.ref(jFieldVar.name())).arg(vOther.ref(jFieldVar.name()))); } method.body()._return(invocation); }
if ("double".equals(fieldVar.type().name())) { JClass doubleClass = jclass.owner().ref(Double.class); fieldEquals = doubleClass.staticInvoke("doubleToLongBits").arg(thisFieldRef).eq( doubleClass.staticInvoke("doubleToLongBits").arg(otherFieldRef)); } else if ("float".equals(fieldVar.type().name())) { JClass floatClass = jclass.owner().ref(Float.class); fieldEquals = floatClass.staticInvoke("floatToIntBits").arg(thisFieldRef).eq( floatClass.staticInvoke("floatToIntBits").arg(otherFieldRef)); } else {
.cand(eventParam.invoke("getRepeatCount").eq(JExpr.lit(0)))) //
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"))); }
arrayNotNull._then()._if( arrayArg.invoke( "getClass" ).eq( primitiveArray.dotclass() ) );
.eq(JExpr.lit(',')));