Package com.helger.jcodemodel

Examples of com.helger.jcodemodel.JConditional


        void appendNullableValue(AbstractJType type, IJExpression value) {
            if (!type.isReference())
                throw new AssertionError("appendNullableValue called for non-reference type");
            else {
                JConditional _if = body._if(value.eq(JExpr._null()));
                Body thenBody = new Body(result, _if._then(), nameSource);
                thenBody.appendNotNullValue(types._int, JExpr.lit(0));
                Body elseBody = new Body(result, _if._else(), nameSource);
                elseBody.appendNotNullValue(type, value);
            }
        }
View Full Code Here


            this.nameSource = nameSource;
        }

        void appendNullableValue(AbstractJType paramType, IJExpression field1, IJExpression field2) {
            JBlock _then = body._if(field1.ne(JExpr._null()).cor(field2.ne(JExpr._null())))._then();
            JConditional _if = _then._if(field1.eq(JExpr._null()));
            _if._then()._return(JExpr.lit(-1));
            JConditional _elseif = _if._elseif(field2.eq(JExpr._null()));
            _elseif._then()._return(JExpr.lit(1));
            Body ifbody = new Body(resultVariable, _elseif._else(), nameSource);
            ifbody.appendNotNullValue(paramType, field1, field2);
        }
View Full Code Here

                appendNotNullValue(types._int, value1.ref("length"), value2.ref("length"));
            } else if (type.isPrimitive()) {
                IJExpression condition = JOp.cond(value1.lt(value2), JExpr.lit(-1),
                                                  JOp.cond(value1.eq(value2), JExpr.lit(0), JExpr.lit(1)));
                body.assign(resultVariable, condition);
                JConditional _if = body._if(resultVariable.ne(JExpr.lit(0)));
                _if._then()._return(resultVariable);
            } else {
                JInvocation invocation = value1.invoke("compareTo");
                invocation.arg(value2);
                body.assign(resultVariable, invocation);
                JConditional _if = body._if(resultVariable.ne(JExpr.lit(0)));
                _if._then()._return(resultVariable);
            }
        }
View Full Code Here

    void appendNullableValue(AbstractJType type, IJExpression value1, IJExpression value2) {
        if (!type.isReference()) {
            throw new AssertionError("appendNullableValue called for non-reference type");
        } else {
            JConditional _if = body._if(value1.ne(value2));
            IJExpression isNull = value1.eq(JExpr._null()).cor(value2.eq(JExpr._null()));
            JConditional _if1 = _if._then()._if(isNull);
            _if1._then()._return(JExpr.FALSE);
            EqualsMethod innerBody = new EqualsMethod(types, _if._then(), nameSource);
            innerBody.appendNotNullValue(type, value1, value2);
        }
    }
View Full Code Here

            if (type.elementType().isReference())
                forBody.appendNullableValue(type.elementType(), value1.component(i), value2.component(i));
            else
                forBody.appendNotNullValue(type.elementType(), value1.component(i), value2.component(i));
        } else if (type.isPrimitive()) {
            JConditional _if = body._if(value1.ne(value2));
            _if._then()._return(JExpr.FALSE);
        } else {
            JInvocation invocation = value1.invoke("equals");
            invocation.arg(value2);
            JConditional _if = body._if(invocation.not());
            _if._then()._return(JExpr.FALSE);
        }
    }
View Full Code Here

        JAnnotationUse annotation = constructor.annotate(SuppressWarnings.class);
        annotation.paramArray("value", "null");
        AbstractJClass usedValueClassType = valueClass.narrow(valueClass.typeParams());
        JVar param = constructor.param(JMod.FINAL, usedValueClassType, "implementation");
        param.annotate(Nonnull.class);
        JConditional nullCheck = constructor.body()._if(JExpr.ref("implementation").eq(JExpr._null()));
        JInvocation nullPointerExceptionConstruction = JExpr._new(types._NullPointerException);
        nullPointerExceptionConstruction.arg(JExpr.lit("Argument shouldn't be null: 'implementation' argument in class constructor invocation: " + valueClass.fullName()));
        nullCheck._then()._throw(nullPointerExceptionConstruction);

        JDefinedClass proxyClass = createProxyClass(serialization);
        AbstractJClass usedProxyClassType = proxyClass.narrow(valueClass.typeParams());
        JInvocation construction = JExpr._new(usedProxyClassType);
        construction.arg(JExpr.ref("implementation"));
View Full Code Here

            AbstractJClass usedCaseClassType = caseClasses.get(interfaceMethod.name()).narrow(constructorMethod.typeParams());
            if (!interfaceMethod.params().isEmpty() || interfaceMethod.hasVarArgs()) {
                boolean hasNullChecks = false;
                for (JVar param1: interfaceMethod.params()) {
                    if (param1.type().isReference() && !isNullable(param1)) {
                        JConditional nullCheck = constructorMethod.body()._if(JExpr.ref(param1.name()).eq(JExpr._null()));
                        JInvocation nullPointerExceptionConstruction = JExpr._new(types._NullPointerException);
                        nullPointerExceptionConstruction.arg(JExpr.lit("Argument shouldn't be null: '" + param1.name() + "' argument in static method invocation: '" + constructorMethod.name() + "' in class " + valueClass.fullName()));
                        nullCheck._then()._throw(nullPointerExceptionConstruction);
                        hasNullChecks = true;
                    }
                }
                JVar param1 = interfaceMethod.listVarParam();
                if (param1 != null) {
                    if (param1.type().isReference() && !isNullable(param1)) {
                        JConditional nullCheck = constructorMethod.body()._if(JExpr.ref(param1.name()).eq(JExpr._null()));
                        JInvocation nullPointerExceptionConstruction = JExpr._new(types._NullPointerException);
                        nullPointerExceptionConstruction.arg(JExpr.lit("Argument shouldn't be null: '" + param1.name() + "' argument in static method invocation: '" + constructorMethod.name() + "' in class " + valueClass.fullName()));
                        nullCheck._then()._throw(nullPointerExceptionConstruction);
                        hasNullChecks = true;
                    }
                }
                if (hasNullChecks) {
                    JAnnotationUse annotation = constructorMethod.annotate(SuppressWarnings.class);
View Full Code Here

        VariableNameSource nameSource = new VariableNameSource();
        equalsMethod.annotate(Override.class);
        JAnnotationUse annotationUse = equalsMethod.annotate(SuppressWarnings.class);
        annotationUse.param("value", "unchecked");
        JVar thatObject = equalsMethod.param(types._Object, nameSource.get("thatObject"));
        JConditional _if = equalsMethod.body()._if(JExpr._this().eq(thatObject));
        _if._then()._return(JExpr.TRUE);
        JConditional elseif = _if._elseif(thatObject._instanceof(valueClass).not());
        elseif._then()._return(JExpr.FALSE);
        JBlock _else = elseif._else();
        AbstractJClass usedValueClassType = valueClass.narrow(valueClass.typeParams());
        JVar that = _else.decl(JMod.FINAL, usedValueClassType, nameSource.get("that"), JExpr.cast(usedValueClassType, thatObject));
        AbstractJClass visitorType = visitorInterface.narrowed(usedValueClassType, types._Boolean, types._RuntimeException);

        JDefinedClass anonymousClass1 = valueClass.owner().anonymousClass(visitorType);
View Full Code Here

TOP

Related Classes of com.helger.jcodemodel.JConditional

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.