Package com.sun.codemodel

Examples of com.sun.codemodel.JConditional


      // next we wrap the two comparison sides and add the expression block for the comparison.
      LogicalExpression f = FunctionGenerationHelper.getComparator(left, right, context.getFunctionRegistry());
      HoldingContainer out = cg.addExpr(f, false);

      // check if two values are not equal (comparator result != 0)
      JConditional jc = cg.getEvalBlock()._if(out.getValue().ne(JExpr.lit(0)));
       
      jc._then()._return(JExpr.FALSE);
    }

    // All key expressions compared equal, so return TRUE
    cg.getEvalBlock()._return(JExpr.TRUE);
  }
View Full Code Here


      g.setMappingSet(MAIN_MAPPING);

      // next we wrap the two comparison sides and add the expression block for the comparison.
      LogicalExpression fh = FunctionGenerationHelper.getComparator(left, right, context.getFunctionRegistry());
      HoldingContainer out = g.addExpr(fh, false);
      JConditional jc = g.getEvalBlock()._if(out.getValue().ne(JExpr.lit(0)));

      if(od.getDirection() == Direction.ASCENDING){
        jc._then()._return(out.getValue());
      }else{
        jc._then()._return(out.getValue().minus());
      }
    }

    g.getEvalBlock()._return(JExpr.lit(0));
  }
View Full Code Here

        String name = variableManager.createId("value");

        JVar var;
        if (!cls.isPrimitive() && nillable) {
            var = this.method.body().decl(model._ref(cls), name, JExpr._null());
            JConditional cond = this.method.body()._if(xsrVar.invoke("isXsiNil").not());
           
            JInvocation invocation = xsrVar.invoke(method);
            cond._then().assign(var, invocation);
        } else {
            var = this.method.body().decl(model._ref(cls), name, xsrVar.invoke(method));
        }
       
        return var;
View Full Code Here

                JBlock loop = b._while(depthVar.gte(targetDepthVar.minus(JExpr.lit(1)))).body();

                b = loop._if(event.eq(JExpr.lit(XMLStreamConstants.START_ELEMENT)))._then();


                JConditional ifDepth = b._if(depthVar.eq(targetDepthVar));

                Map<QName, ExpectedElement> globalAndLocalEls = new HashMap<QName, ExpectedElement>();
                globalAndLocalEls.putAll(elements);
                globalAndLocalEls.putAll(buildContext.getGlobalElements());
               
                writeElementReader(globalAndLocalEls, ifDepth._then(), xsrVar, false);

                if (allowUnknown) {
                    writeElementReader(buildContext.getGlobalElements(), ifDepth._else(), xsrVar, true);
                }

                JConditional ifHasNext = loop._if(xsrVar.invoke("hasNext"));
                ifHasNext._then().assign(event, xsrVar.invoke("next"));
                ifHasNext._then().assign(depthVar, xsrVar.invoke("getDepth"));
                ifHasNext._else()._break();
            }
        }
        removeBraces(preElementBlock);
    }
View Full Code Here

        }

        b.add(new JBlankLine());
        b.add(new JLineComment("Check xsi:type"));
        JVar xsiType = b.decl(model._ref(QName.class), "xsiType", xsrVar.invoke("getXsiType"));
        JConditional cond = b._if(xsiType.ne(JExpr._null()));
       
        writeXsiChecks(cond._then(), xsiType);
    }
View Full Code Here

        } else if (cls.equals(boolean.class) || cls.equals(Boolean.class)) {
            JExpression var = JExpr.direct("_attValue");
            JBlock b = method.body();
            JVar retVar = method.body().decl(model._ref(boolean.class), "value");
           
            JConditional cond = b._if(JExpr.lit("1").invoke("equals").arg(var).cor(JExpr.lit("true").invoke("equals").arg(var)));
            JClass boolClass = (JClass) model._ref(Boolean.class);
           
            cond._then().assign(retVar, boolClass.staticRef("TRUE"));
            cond._else().assign(retVar, boolClass.staticRef("FALSE"));
           
            return retVar;
        }
        throw new UnsupportedOperationException();
    }
View Full Code Here

    public ElementWriterBuilder writeElement(QName name) {
        return writeElement(name, objectVar.type(), objectVar);
    }

    public ElementWriterBuilder writeElement(QName name, JExpression condition, JType type, JExpression var) {
        JConditional conditional = currentBlock._if(condition);
        JBlock block = conditional._then();
       
        return writeElement(name, type, var, block);
    }
View Full Code Here

        return builder;
    }

    public void writeNilIfNull() {
        JBlock ifBlock = currentBlock;
        JConditional cond2 = ifBlock._if(getObject().eq(JExpr._null()));
        JBlock nullBlock2 = cond2._then();
        nullBlock2.add(xswVar.invoke("writeXsiNil"));
        nullBlock2._return();
    }
View Full Code Here

    }

    public void writeAs(Class cls, boolean nillable) {
        if (!cls.isPrimitive()) {
            JBlock block = currentBlock;
            JConditional cond = block._if(getObject().ne(JExpr._null()));
            JBlock newBlock = cond._then();
            setCurrentBlock(newBlock);
           
            writeAs(cls);
           
            if (nillable) {
                newBlock = cond._else();
                newBlock.add(xswVar.invoke("writeXsiNil"));
                setCurrentBlock(newBlock);
            }
            setCurrentBlock(block);
        } else {
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

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.