Package com.sun.codemodel

Examples of com.sun.codemodel.JConditional


        method.javadoc().append(doc);

        JFieldRef fr = JExpr.ref(fieldName);
        if (dvExpr != null) {
            JExpression test = JOp.eq(JExpr._null(), fr);
            JConditional jc =  method.body()._if(test);
            jc._then()._return(dvExpr);
            jc._else()._return(fr);
        } else {
            method.body()._return(fr);
        }
    }
View Full Code Here


        method.javadoc().append(doc);

        JFieldRef fr = JExpr.ref(fieldName);
        if (dvExpr != null) {
            JExpression test = JOp.eq(JExpr._null(), fr);
            JConditional jc =  method.body()._if(test);
            jc._then()._return(dvExpr);
            jc._else()._return(fr);
        } else {
            method.body()._return(fr);
        }
    }
View Full Code Here

    startElement._throws(SAXException.class);
    final JVar uri = startElement.param(stringClass, "uri");
    final JVar localName = startElement.param(stringClass, "localName");
    final JVar qName = startElement.param(stringClass, "qName");
    final JVar atts = startElement.param(Attributes.class, "atts");
    final JConditional if1 = startElement.body()._if(uri.invoke("equals").arg(KML_20).cor(uri.invoke("equals").arg(KML_21)));
    if1._then().block().add(content.invoke("startElement").arg(KML_22).arg(localName).arg(qName).arg(atts));
    if1._else().block().add(content.invoke("startElement").arg(uri).arg(localName).arg(qName).arg(atts));
   
    final JMethod characters = namespaceFilterHandler.method(JMod.PUBLIC, cc.implClass.owner().VOID, "characters");
    final JVar charCh = characters.param(cc.implClass.owner().CHAR.array(), "ch");
    final JVar charStart = characters.param(cc.implClass.owner().INT, "start");
    final JVar charLength = characters.param(cc.implClass.owner().INT, "length");
View Full Code Here

    // }
    // return jc;
    // }
    getJAXBContex = cc.implClass.method(JMod.PRIVATE, jaxbContextClass, "getJaxbContext");
    getJAXBContex._throws(jaxbExceptionClass.boxify());
    final JConditional ifBlockOutstream = getJAXBContex.body()._if(jcVar.eq(JExpr._null()));
    ifBlockOutstream._then().assign(jcVar, jaxbContextClass.boxify().staticInvoke("newInstance").arg(JExpr.direct("Kml.class")));
    getJAXBContex.body()._return(jcVar);

    // private Marshaller createMarshaller() throws JAXBException {
    // if (m == null) {
    // m = getJAXBContext().createMarshaller();
    // }
    // return m;
    // }
    createMashaller = cc.implClass.method(JMod.PRIVATE, jaxbMarshallerClass, "createMarshaller");
    createMashaller._throws(jaxbExceptionClass.boxify());
    final JConditional ifBlockMarshaller = createMashaller.body()._if(mVar.eq(JExpr._null()));
    ifBlockMarshaller._then().assign(mVar, JExpr._this().invoke(getJAXBContex).invoke("createMarshaller"));
    ifBlockMarshaller._then().add(
        mVar.invoke("setProperty").arg(jaxbMarshallerClass.boxify().staticRef("JAXB_FORMATTED_OUTPUT")).arg(JExpr.TRUE));
    // m.setProperty("com.sun.xml.bind.namespacePrefixMapper", new PreferredMapper());

    createMashaller.body()._return(mVar);

    try {
      final JDefinedClass createNestedPrefixCustomizer = createNestedPrefixCustomizer(cc);
      ifBlockMarshaller._then().add(
          mVar.invoke("setProperty").arg("com.sun.xml.bind.namespacePrefixMapper").arg(JExpr._new(createNestedPrefixCustomizer)));
    } catch (final JClassAlreadyExistsException e) {
    }

    // private Unmarshaller createUnmarshaller() throws JAXBException {
View Full Code Here

    final JVar varKmzFile = createAddToKmzFile.param(kmlClass, "kmzFile");
    final JVar varOut = createAddToKmzFile.param(zipOutputStreamClass, "out");
    final JVar varMainFile = createAddToKmzFile.param(cc.implClass.owner().BOOLEAN, "mainfile");
    createAddToKmzFile.javadoc().add("Internal method");
    final JVar varFileName = createAddToKmzFile.body().decl(stringClass, "fileName", JExpr._null());
    final JConditional if1 = createAddToKmzFile.body()._if(
        varKmzFile.invoke("getFeature").eq(JExpr._null()).cor(varKmzFile.invoke("getFeature").invoke("getName").eq(JExpr._null())).cor(
            varKmzFile.invoke("getFeature").invoke("getName").invoke("length").eq(JExpr.lit(0))));
    if1._then().assign(varFileName, JExpr.lit("noFeatureNameSet").plus(varMissingNameCounter.incr()).plus(JExpr.lit(".kml")));
    if1._else().assign(varFileName, varKmzFile.invoke("getFeature").invoke("getName"));
    if1._else()._if(varFileName.invoke("endsWith").arg(".kml").not())._then().assignPlus(varFileName, JExpr.lit(".kml"));

    createAddToKmzFile.body()._if(varMainFile)._then().assign(varFileName, JExpr.lit("doc.kml"));
    createAddToKmzFile.body().add(
        varOut.invoke("putNextEntry").arg(
            JExpr._new(zipEntryClass).arg(UrlEncoderClass.boxify().staticInvoke("encode").arg(varFileName).arg(JExpr.lit("UTF-8")))));
View Full Code Here

    final JTryBlock tryBlock = generateUnMarshallerFileFile.body()._try();
    final JVar localUnmarshallerFile = tryBlock.body().decl(jaxbUnmarshallerClass, "unmarshaller",
        jaxbContextClass.boxify().staticInvoke("newInstance").arg(JExpr.direct("Kml.class")).invoke("createUnmarshaller"));

    final JConditional ifBlockFilename = tryBlock.body()._if(validateVar.eq(JExpr.TRUE));
    ifBlockFilename._then().add(kmlClass.boxify().staticInvoke(generateValidate).arg(localUnmarshallerFile));
   
    final JVar inputsource = tryBlock.body().decl(inputsourceClass, "input", JExpr._new(inputsourceClass).arg(JExpr._new(fileReaderClass).arg(fileunmarshallVar)));
    final JVar saxsource = tryBlock.body().decl(saxsourceClass, "saxSource", JExpr._new(saxsourceClass).arg(JExpr._new(namespaceFilterXMLReaderclass).arg(validateVar)).arg(inputsource));
    final JVar decl = tryBlock.body().decl(kmlClass, "jaxbRootElement", JExpr.cast(kmlClass, JExpr.invoke(localUnmarshallerFile, "unmarshal").arg(saxsource)));
    tryBlock.body()._return(decl);
View Full Code Here

    // 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

      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

    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

      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

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.