Examples of JConditional


Examples of com.sun.codemodel.JConditional

    // add paramter for equals()-method
    final JVar vObj = equalsMethod.param(Object.class, "obj");

    // is it me? this==obj -> true
    final JConditional condMe = equalsMethod.body()._if(JExpr._this().eq(vObj));
    condMe._then()._return(JExpr.TRUE);

    // it's null? obj==null -> false
    final JConditional condNull = equalsMethod.body()._if(vObj.eq(JExpr._null()));
    condNull._then()._return(JExpr.FALSE);

    // paternity test (only add if equals in superclass isn't overridden)?
    // !super.equals(obj) -> false --> (super.equals(obj) == false)
    if (isSuperClass) {
      final JConditional condSuper = equalsMethod.body()._if(JExpr._super().invoke("equals").arg(vObj).eq(JExpr.FALSE));
      condSuper._then()._return(JExpr.FALSE);
    }

    // suit the class? !(obj instanceof TypeB) -> false --> if ((obj instanceof TypeB) == false)
    final JConditional condInstance = equalsMethod.body()._if(vObj._instanceof(implClass).eq(JExpr.FALSE));
    condInstance._then()._return(JExpr.FALSE);

    // cast: TYPE other = (TYPE) obj;
    final JVar vOther = equalsMethod.body().decl(implClass, "other", JExpr.cast(implClass, vObj));

    /*
     * check for each declared field distinguish between primitive types:
     *
     * <pre> if (field != other.field) { return false; } </pre>
     *
     * and reference types: <pre> if (field == null) { if (other.field != null) { return false; } } else if (!field.equals(other.field)) {
     * // --> if (field.equals(other.field) == false) return false; } </code>
     */
    JConditional condFieldCheck;
    boolean containsDouble = false;
    for (final JFieldVar jFieldVar : fields) {
      if (jFieldVar.type().fullName().equals("java.lang.Double") || jFieldVar.type().fullName().equals("double")) {
        jFieldVar.type(implClass.owner().DOUBLE);
        containsDouble = true;
      //  break;
      }
    }

    for (final JFieldVar jFieldVar : fields) {
      if (jFieldVar.type().isPrimitive()) {
        // LOG.info("JConditional: " + jFieldVar.name() +
        // " is PRIMITIVE");
        condFieldCheck = equalsMethod.body()._if(JExpr.ref(jFieldVar.name()).ne(vOther.ref(jFieldVar.name())));
        condFieldCheck._then()._return(JExpr.FALSE);
      } else {
        // LOG.info("JConditional: " + jFieldVar.name() +
        // " is REFERENCE");
        condFieldCheck = equalsMethod.body()._if(JExpr.ref(jFieldVar.name()).eq(JExpr._null()));
        condFieldCheck._then()._if(vOther.ref(jFieldVar.name()).ne(JExpr._null()))._then()._return(JExpr.FALSE);
        condFieldCheck._elseif(JExpr.ref(jFieldVar.name()).invoke("equals").arg(vOther.ref(jFieldVar.name())).eq(JExpr.FALSE))._then()
            ._return(JExpr.FALSE);
      }
    }

    // ir all works out, the objects are equal, return true
View Full Code Here

Examples of com.sun.codemodel.JConditional

      if(e != null){
        // if at least one expression must be checked, set up the conditional.
        returnValueType = returnValue.type.toBuilder().setMode(DataMode.OPTIONAL).build();
        out = g.declare(returnValueType);
        e = e.eq(JExpr.lit(0));
        JConditional jc = sub._if(e);
        jc._then().assign(out.getIsSet(), JExpr.lit(0));
        sub = jc._else();
      }
    }
   
    if(out == null) out = g.declare(returnValueType);
   
View Full Code Here

Examples of com.sun.codemodel.JConditional

    public HoldingContainer visitIfExpression(IfExpression ifExpr, CodeGenerator<?> generator) throws RuntimeException {
      JBlock local = generator.getEvalBlock();

      HoldingContainer output = generator.declare(ifExpr.getMajorType());

      JConditional jc = null;
      JBlock conditionalBlock = new JBlock(false, false);
      for (IfCondition c : ifExpr.conditions) {
        HoldingContainer HoldingContainer = c.condition.accept(this, generator);
        if (jc == null) {
          if (HoldingContainer.isOptional()) {
            jc = conditionalBlock._if(HoldingContainer.getIsSet().cand(HoldingContainer.getValue()));
          } else {
            jc = conditionalBlock._if(HoldingContainer.getValue());
          }
        } else {
          if (HoldingContainer.isOptional()) {
            jc = jc._else()._if(HoldingContainer.getIsSet().cand(HoldingContainer.getValue()));
          } else {
            jc = jc._else()._if(HoldingContainer.getValue());
          }
        }

        HoldingContainer thenExpr = c.expression.accept(this, generator);
        if (thenExpr.isOptional()) {
          JConditional newCond = jc._then()._if(thenExpr.getIsSet());
          JBlock b = newCond._then();
          b.assign(output.getValue(), thenExpr.getValue());
          b.assign(output.getIsSet(), thenExpr.getIsSet());
        } else {
          jc._then().assign(output.getValue(), thenExpr.getValue());
        }

      }

      HoldingContainer elseExpr = ifExpr.elseExpression.accept(this, generator);
      if (elseExpr.isOptional()) {
        JConditional newCond = jc._else()._if(elseExpr.getIsSet());
        JBlock b = newCond._then();
        b.assign(output.getValue(), elseExpr.getValue());
        b.assign(output.getIsSet(), elseExpr.getIsSet());
      } else {
        jc._else().assign(output.getValue(), elseExpr.getValue());
View Full Code Here

Examples of com.sun.codemodel.JConditional

      if(e.isSafe()){
        HoldingContainer outputContainer = generator.declare(Types.REQUIRED_BIT);
        block.assign(outputContainer.getValue(), JExpr.lit(1));
        if(inputContainer.isOptional()){
//          block._if(vv.invoke("getMutator").invoke(setMethod).arg(outIndex).not())._then().assign(outputContainer.getValue(), JExpr.lit(0));
          JConditional jc = block._if(inputContainer.getIsSet().eq(JExpr.lit(0)).not());
          block = jc._then();
        }
        block._if(setMeth.not())._then().assign(outputContainer.getValue(), JExpr.lit(0));
        return outputContainer;
      }else{
        if (inputContainer.isOptional()) {
//          block.add(vv.invoke("getMutator").invoke(setMethod).arg(outIndex));
          JConditional jc = block._if(inputContainer.getIsSet().eq(JExpr.lit(0)).not());
          block = jc._then();
        }
        block.add(setMeth);
      }
     
      return null;
View Full Code Here

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

Examples of com.sun.codemodel.JConditional

      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

Examples of com.sun.codemodel.JConditional

      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

Examples of com.sun.codemodel.JConditional

      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

Examples of com.sun.codemodel.JConditional

        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

Examples of com.sun.codemodel.JConditional

        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
Copyright © 2018 www.massapi.com. 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.