Package com.helger.jcodemodel

Examples of com.helger.jcodemodel.JBlock


            this.body = body;
            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


        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);
        for (JMethod interfaceMethod1: visitorInterface.methods()) {
            JMethod visitorMethod1 = anonymousClass1.method(interfaceMethod1.mods().getValue() & ~JMod.ABSTRACT, types._Boolean, interfaceMethod1.name());
            visitorMethod1.annotate(Nonnull.class);
            visitorMethod1.annotate(Override.class);

            VariableNameSource nameSource1 = nameSource.forBlock();
            List<JVar> arguments1 = new ArrayList<JVar>();
            JVar varArgument1 = null;
            for (JVar param1: interfaceMethod1.params()) {
                AbstractJType argumentType = visitorInterface.substituteSpecialType(param1.type(), usedValueClassType, types._Boolean, types._RuntimeException);
                JVar argument1 = visitorMethod1.param(param1.mods().getValue() | JMod.FINAL, argumentType, nameSource1.get(param1.name()));
                arguments1.add(argument1);
            }
            JVar param1 = interfaceMethod1.listVarParam();
            if (param1 != null) {
                AbstractJType argumentType = visitorInterface.substituteSpecialType(param1.type().elementType(), usedValueClassType, types._Boolean, types._RuntimeException);
                JVar argument1 = visitorMethod1.varParam(param1.mods().getValue() | JMod.FINAL, argumentType, nameSource1.get(param1.name()));
                varArgument1 = argument1;
            }

            JDefinedClass anonymousClass2 = valueClass.owner().anonymousClass(visitorType);
            for (JMethod interfaceMethod2: visitorInterface.methods()) {
                JMethod visitorMethod2 = anonymousClass2.method(interfaceMethod1.mods().getValue() & ~JMod.ABSTRACT, types._Boolean, interfaceMethod2.name());
                visitorMethod2.annotate(Nonnull.class);
                visitorMethod2.annotate(Override.class);

                VariableNameSource nameSource2 = nameSource1.forBlock();
                List<JVar> arguments2 = new ArrayList<JVar>();
                JVar varArgument2 = null;
                for (JVar param2: interfaceMethod2.params()) {
                    AbstractJType argumentType = visitorInterface.substituteSpecialType(param2.type(), usedValueClassType, types._Boolean, types._RuntimeException);
                    JVar argument2 = visitorMethod2.param(param2.mods().getValue(), argumentType, nameSource2.get(param2.name()));
                    arguments2.add(argument2);
                }
                JVar param2 = interfaceMethod2.listVarParam();
                if (param2 != null) {
                    AbstractJType argumentType = visitorInterface.substituteSpecialType(param2.type().elementType(), usedValueClassType, types._Boolean, types._RuntimeException);
                    JVar argument2 = visitorMethod2.varParam(param2.mods().getValue(), argumentType, nameSource2.get(param2.name()));
                    varArgument2 = argument2;
                }
                if (!interfaceMethod1.name().equals(interfaceMethod2.name()))
                    visitorMethod2.body()._return(JExpr.FALSE);
                else {
                    EqualsMethod body = new EqualsMethod(types, visitorMethod2.body(), nameSource2);
                    for (int i = 0; i < arguments1.size(); i++) {
                        JVar field1 = arguments1.get(i);
                        JVar field2 = arguments2.get(i);
                        JVar param = interfaceMethod1.params().get(i);
                        if (isNullable(param))
                            body.appendNullableValue(field1.type(), field1, field2);
                        else
                            body.appendNotNullValue(field1.type(), field1, field2);
                    }
                    if (varArgument1 != null) {
                        JVar param = interfaceMethod1.listVarParam();
                        if (isNullable(param))
                            body.appendNullableValue(varArgument1.type(), varArgument1, varArgument2);
                        else
                            body.appendNotNullValue(varArgument1.type(), varArgument1, varArgument2);
                    }
                    visitorMethod2.body()._return(JExpr.TRUE);
                }
            }

            JInvocation invocation2 = that.invoke("accept");
            invocation2.arg(JExpr._new(anonymousClass2));
            visitorMethod1.body()._return(invocation2);
        }
        JInvocation invocation1 = JExpr._this().invoke("accept");
        invocation1.arg(JExpr._new(anonymousClass1));
        _else._return(invocation1);
    }
View Full Code Here

TOP

Related Classes of com.helger.jcodemodel.JBlock

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.