Package com.sun.codemodel

Examples of com.sun.codemodel.JConditional


            method.javadoc().append(doc);

            JFieldRef fr = JExpr.ref(fieldName);
           
            JExpression test;
            JConditional jc;
            JInvocation invocation;
                           
            invocation = JExpr.invoke("tryOverwrite");
            invocation.arg(JExpr.dotclass(type.boxify()));
            invocation.arg(JExpr.lit(fieldName));
            JVar tmp = method.body().decl(type.boxify(), "_" + fieldName,
                                          invocation);
            test = JOp.not(JOp.eq(JExpr._null(), tmp));
            jc = method.body()._if(test);
            jc._then()._return(tmp);
           
            test = JOp.not(JOp.eq(JExpr._null(), fr));
            jc = method.body()._if(test);
            jc._then()._return(fr);
           
            invocation = JExpr.invoke("tryFallback");
            invocation.arg(JExpr.dotclass(type.boxify()));
            invocation.arg(JExpr.lit(fieldName));
            // tmp = method.body().decl(type.boxify(), "_" + fieldName, invocation);
            method.body().assign(tmp, invocation);
            test = JOp.not(JOp.eq(JExpr._null(), tmp));
            jc = method.body()._if(test);
            jc._then()._return(tmp);
           
            // add the original block
           
            method.body().add(block);
View Full Code Here


        method.javadoc().append(doc);

        JFieldRef fr = JExpr.ref(fieldName);

        JExpression test = JOp.eq(JExpr._null(), fr);
        JConditional jc =  method.body()._if(test);
        jc._then()._return(dvExpr);
        jc._else()._return(fr);
    }
View Full Code Here


        if(defaultValue==null) {
            $get.body()._return(ref());
        } else {
            JConditional cond = $get.body()._if(ref().eq(JExpr._null()));
            cond._then()._return(defaultValue);
            cond._else()._return(ref());
        }

        List<Object> possibleTypes = listPossibleTypes(prop);
        writer.javadoc().addReturn()
            .append("possible object is\n")
View Full Code Here

                // RESULT: <value>.<method>()
                inv = $value.invoke(printMethod);
               
                // check value is not null ... if(value == null) return null;
                JConditional jcon = marshal.body()._if($value.eq(JExpr._null()));
                jcon._then()._return(JExpr._null());
            } else {
                // RESULT: <className>.<method>(<value>)
                if(this.printMethod==null) {
                    // HACK HACK HACK
                    JType t = inMemoryType.unboxify();
View Full Code Here

            block.assign($var,JExpr._new(cm.ref(ArrayList.class).narrow(itemType().boxify())));
            JVar $col = block.decl(core.getRawType(), "col" + hashCode());
            acc.toRawValue(block,$col);
            JForEach loop = block.forEach(elementType, "v" + hashCode()/*unique string handling*/, $col);

            JConditional cond = loop.body()._if(loop.var().eq(JExpr._null()));
            cond._then().invoke($var,"add").arg(JExpr._null());
            cond._else().invoke($var,"add").arg(loop.var().invoke("getValue"));
        }
View Full Code Here

            // if([core.hasSetValue])
            //   $var = [core.toRawValue].getValue();
            // else
            //   $var = null;

            JConditional cond = block._if(acc.hasSetValue());
            JVar $v = cond._then().decl(core.getRawType(), "v" + hashCode());// TODO: unique value control
            acc.toRawValue(cond._then(),$v);
            cond._then().assign($var,$v.invoke("getValue"));
            cond._else().assign($var, JExpr._null());
        }
View Full Code Here

      // method that expresses the following logic
      //   (requestOptions == null) ? return RestliRequestOptions.DEFAULT_OPTIONS : requestOptions;
      JMethod requestOptionsAssigner = facadeClass.method(JMod.PRIVATE | JMod.STATIC, RestliRequestOptions.class, "assignRequestOptions");
      JVar requestOptionsAssignerParam = requestOptionsAssigner.param(RestliRequestOptions.class, "requestOptions");
      JConditional requestNullCheck = requestOptionsAssigner.body()._if(requestOptionsAssignerParam.eq(JExpr._null()));
      requestNullCheck._then().block()._return(defaultOptionsField);
      requestNullCheck._else().block()._return(requestOptionsAssignerParam);
    }

    /*
    There will be 4 constructors:
      ()
View Full Code Here

    // initialize DeferredObject's. For an optional type, assign the value holder only if it is not null
    for(int i=0; i<argTypes.length; i++) {
      if (inputVariables[i].isOptional()) {
        JBlock conditionalBlock = new JBlock(false, false);
        JConditional jc = conditionalBlock._if(inputVariables[i].getIsSet().ne(JExpr.lit(0)));
        jc._then().assign(workspaceJVars[3].component(JExpr.lit(i)), workspaceJVars[2].component(JExpr.lit(i)));
        jc._then().assign(JExpr.ref(workspaceJVars[3].component(JExpr.lit(i)), "valueHolder"), inputVariables[i].getHolder());
        jc._else().assign(workspaceJVars[3].component(JExpr.lit(i)), JExpr._null());
        sub.add(conditionalBlock);
      } else {
        sub.assign(workspaceJVars[3].component(JExpr.lit(i)), workspaceJVars[2].component(JExpr.lit(i)));
        sub.assign(JExpr.ref(workspaceJVars[3].component(JExpr.lit(i)), "valueHolder"), inputVariables[i].getHolder());
      }
View Full Code Here

                              propEl.getName() + "_" + javify(name.getLocalPart()),
                              b.getObject().invoke(propName));

       
        if (!propEl.isRequired()) {
            JConditional nullCond = block._if(var.ne(JExpr._null()));
            block = nullCond._then();
            b.setCurrentBlock(block);
           
            if (typeRef.isNillable()) {
                nullCond._else().add(b.getXSW().invoke("writeXsiNil"));
            } else if (propEl.isCollection() && propEl.isCollectionNillable()) {
                nullCond._else().add(b.getXSW().invoke("writeXsiNil"));
            }
        }
       
        if (propEl.isCollection()) {
            JForEach each = block.forEach(getGenericType(rawType), "_o", var);
View Full Code Here

                                               JType t,
                                               String method,
                                               boolean nillable) {
        JBlock block = b.getCurrentBlock();

        JConditional cond = block._if(object.ne(JExpr._null()));
        JBlock nullBlock = cond._then();
        b.setCurrentBlock(nullBlock);
        JVar var = nullBlock.decl(model._ref(String.class), "_o",
                                  object.invoke(method));
       
        if (nillable) {
            JConditional cond2 = cond._then()._if(var.ne(JExpr._null()));
           
            JBlock elseblock = cond._else();
            JBlock elseblock2 = cond2._else();
           
            b.setCurrentBlock(cond2._then());
           
            elseblock.add(b.getXSW().invoke("writeXsiNil"));
            elseblock2.add(b.getXSW().invoke("writeXsiNil"));
        }
View Full Code Here

TOP

Related Classes of com.sun.codemodel.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.