Package com.sun.codemodel

Examples of com.sun.codemodel.JConditional


      HoldingContainer out = generator.declare(e.getMajorType());

      if (out.isOptional()) {
        JBlock blk = generator.getEvalBlock();
        blk.assign(out.getIsSet(), getValueAccessor2.invoke("isSet").arg(indexVariable));
        JConditional jc = blk._if(out.getIsSet().eq(JExpr.lit(1)));
        if (Types.usesHolderForGet(e.getMajorType())) {
          jc._then().add(getValueAccessor.arg(indexVariable).arg(out.getHolder()));
        } else {
          jc._then().assign(out.getValue(), getValueAccessor.arg(indexVariable));
        }
      } else {
        if (Types.usesHolderForGet(e.getMajorType())) {
          generator.getEvalBlock().add(getValueAccessor.arg(indexVariable).arg(out.getHolder()));
        } else {
View Full Code Here


      g.setMappingSet(MAIN_MAPPING);
     
      // next we wrap the two comparison sides and add the expression block for the comparison.
      FunctionCall f = new FunctionCall(ComparatorFunctions.COMPARE_TO, ImmutableList.of((LogicalExpression) new HoldingContainerExpression(left), new HoldingContainerExpression(right)), ExpressionPosition.UNKNOWN);
      HoldingContainer out = g.addExpr(f, false);
      JConditional jc = g.getEvalBlock()._if(out.getValue().ne(JExpr.lit(0)));
     
      //TODO: is this the right order...
      if(od.getDirection() == Direction.ASC){
        jc._then()._return(out.getValue());
      }else{
        jc._then()._return(out.getValue().minus());
      }
    }
   
    g.getEvalBlock()._return(JExpr.lit(0));
   
View Full Code Here

      JMethod method = implClass.method(JMod.PUBLIC, fieldOutline.getRawType(), "with" + propertyName);

      JBlock body = method.body();

      JConditional _if = body._if(JExpr.refthis(fieldName).eq(JExpr._null()));
      JBlock _then = _if._then();
      _then.assign(JExpr.ref(fieldName), JExpr._new(fieldOutline.getRawType()));

      body._return(JExpr.ref(fieldName));
   }
View Full Code Here

      JVar index = method.param(INT, "index");

      JBlock body = method.body();

      JVar list = body.decl(fieldOutline.getRawType(), "list", JExpr._this().invoke("get" + propertyName));
      JConditional _ifListIsTooSmall = body._if(list.invoke("size").lte(index));
      JBlock _ifListIsTooSmallThen = _ifListIsTooSmall._then();
      JForLoop _for = _ifListIsTooSmallThen._for();
      JVar i = _for.init(INT, "i", list.invoke("size"));
      _for.test(i.lte(index));
      _for.update(i.incr());
      _for.body().invoke(list, "add").arg(JExpr._null());

      JVar element = body.decl(elementClass, "value", list.invoke("get").arg(index));
      JConditional _ifElementIsNull = body._if(element.eq(JExpr._null()));
      JBlock _ifElementIsNullThen = _ifElementIsNull._then();
      _ifElementIsNullThen.assign(element, JExpr._new(element.type()));
      _ifElementIsNullThen.invoke(list, "set").arg(index).arg(element);

      body._return(element);
   }
View Full Code Here

        createXMLGregorianCalendar.body().directStatement( "// " + getMessage( "title" ) );
        value = createXMLGregorianCalendar.param( JMod.FINAL, Calendar.class, "value" );

        final JTryBlock tryBlock = createXMLGregorianCalendar.body()._try();
        final JConditional notNull = tryBlock.body()._if( value.ne( JExpr._null() ) );

        final JVar calendar = notNull._then().decl( cm.ref( GregorianCalendar.class ), "calendar" );
        calendar.init( JExpr._new( cm.ref( GregorianCalendar.class ) ) );
        notNull._then().add( calendar.invoke( "setTimeZone" ).arg( value.invoke( "getTimeZone" ) ) );
        notNull._then().add( calendar.invoke( "setTimeInMillis" ).arg( value.invoke( "getTimeInMillis" ) ) );
        notNull._then()._return( cm.ref( DatatypeFactory.class ).staticInvoke( "newInstance" ).invoke(
            "newXMLGregorianCalendar" ).arg( calendar ) );

        tryBlock.body()._return( JExpr._null() );

        final JCatchBlock catchBlock = tryBlock._catch( cm.ref( DatatypeConfigurationException.class ) );
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

    private JVar createVar(String value, Class<?> cls, boolean nillable) {
        JVar var;
        if (nillable) {
            var = method.body().decl(model._ref(cls), "value" + varCount++, JExpr._null());
            JConditional cond = method.body()._if(xsrVar.invoke("isXsiNil").not());
           
            JInvocation invocation = xsrVar.invoke(value);
            cond._then().assign(var, invocation);
        } else {
            var = method.body().decl(model._ref(cls), "value" + varCount++, xsrVar.invoke(value));
        }
       
        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));
       
        writeElementReader(elements, ifDepth._then(), false);
       
        if (allowUnknown) {
            writeElementReader(buildContext.getGlobalElements(), ifDepth._else(), 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();
    }
View Full Code Here

        b = loop.body();
        JVar attName = b.decl(model._ref(String.class), "attName", xsrVar.invoke("getAttributeLocalName").arg(var));
        JVar attNs = b.decl(model._ref(String.class), "attNs", xsrVar.invoke("getAttributeNamespace").arg(var));
        JVar attValue = b.decl(model._ref(String.class), "attValue", xsrVar.invoke("getAttributeValue").arg(var));
       
        JConditional cond = null;
       
        for (Map.Entry<QName, AttributeParserBuilderImpl> e : attributes.entrySet()) {
            QName name = e.getKey();
            AttributeParserBuilderImpl builder = e.getValue();
           
            JExpression localInv = attName.eq(JExpr.lit(name.getLocalPart()));
            String ns = name.getNamespaceURI();
            JExpression nsInv = JExpr.lit(name.getNamespaceURI()).eq(attNs);
           
            if (ns.equals("")) {
                nsInv = nsInv.cor(attNs.eq(JExpr._null()));
            }
           
            JExpression qnameCompare = localInv.cand(nsInv);

            if (cond == null) {
                cond = b._if(qnameCompare);
            } else {
                cond = cond._else()._if(qnameCompare);
            }
           
            JMethod nextMethod = builder.getMethod();
           
            JInvocation invocation = JExpr.invoke(nextMethod).arg(xsrVar).arg(rtContextVar);
            for (JVar v : builder.variables) {
                invocation.arg(v);
            }
           
            nextMethod.param(model._ref(String.class), "_attValue");
            invocation.arg(attValue);
           
            nextMethod.body().add(builder.codeBlock);
           
            if (root && builder.returnType != null) {
                cond._then()._return(invocation);
            } else {
                cond._then().add(invocation);
            }
           
            // TODO: throw exception if unknown elements are encountered and allowUnknown == false
            builder.write();
        }
View Full Code Here

    private void writeXsiChecks(JBlock b) {
        if(getXsiTypes().isEmpty())
            return; // no @xsi:type to look for.

        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

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.