Package com.sun.codemodel

Examples of com.sun.codemodel.JForEach


          }
        }

        clone.body().assign(copy.ref(jFieldVar),
            JExpr._new(arrayList.narrow(clazz)).arg(JExpr.direct("get" + Util.upperFirst(jFieldVar.name()) + "().size()")));
        final JForEach forEach = clone.body().forEach(clazz, "iter", jFieldVar);
        if (forEach.var().type().fullName().equals("java.lang.Object") || enums.contains(forEach.var().type().fullName()) || forEach.var().type().fullName().equals("java.lang.String") ){
          forEach.body().add(copy.ref(jFieldVar).invoke("add").arg(forEach.var()));
          LOG.info("444a>>>>>>>" + forEach.var().type().fullName());
        } else {
          forEach.body().add(copy.ref(jFieldVar).invoke("add").arg(forEach.var().invoke("clone")));
          LOG.info("444b>>>>>>>" + forEach.var().type().fullName()+".clone()");
        }
      } else {
        final JExpression cond = JOp.cond(jFieldVar.eq(JExpr._null()), JExpr._null(), JExpr.cast(jFieldVar.type(), jFieldVar.invoke("clone")));
        clone.body().assign(copy.ref(jFieldVar), cond);
        LOG.info(jFieldVar.type().fullName());
View Full Code Here


    final JMethod marshall = coordinateClassConverter.method(JMod.PUBLIC, String.class, "marshal");
    final JVar stringConstructorArg = marshall.param(JMod.FINAL, listGenericsCoordinates, "dt");
    marshall._throws(Exception.class);
    marshall.annotate(Override.class);
    final JVar sbVarMarshall = marshall.body().decl(stringBuilderClass, "sb", JExpr._new(stringBuilderClass));
    final JForEach forMarshall = marshall.body().forEach(coordinateClass, "coord", stringConstructorArg);
    // forMarshall.body().add(sbVarMarshall.invoke("append").arg(forMarshall.var().name() + " + \" \""));
    forMarshall.body().add(sbVarMarshall.invoke("append").arg(JExpr.direct("coord + \" \"")));
    marshall.body()._return(sbVarMarshall.invoke("toString").invoke("trim"));

    // toString
    final JMethod unmarshall = coordinateClassConverter.method(JMod.PUBLIC, listGenericsCoordinates, "unmarshal");
    final JVar unmarshallparam = unmarshall.param(JMod.FINAL, String.class, "s");
    unmarshall._throws(Exception.class);
    unmarshall.annotate(Override.class);

    //    http://code.google.com/p/javaapiforkml/issues/detail?id=10
    //    changed:
    //      String[] coords = s.replaceAll(",[ ]+?", ",").trim().split(" ");
    //      to:
    //      String[] coords = s.replaceAll(",\\s+", ",").trim().split("\\s+");
    final JVar varCoords1 = unmarshall.body().decl(stringClass.array(), "coords",
        unmarshallparam.invoke("replaceAll").arg(",[\\s]+").arg(",").invoke("trim").invoke("split").arg("\\s+"));

    final JVar coordinateslist = unmarshall.body().decl(listGenericsCoordinates, "coordinates", JExpr._new(arraylistGenericsCoordinates));
    unmarshall.body()._if(JExpr.ref(varCoords1.name()).ref("length").lte(JExpr.lit(0)))._then().block()._return(coordinateslist);

    final JForEach forUnMarshall = unmarshall.body().forEach(stringClass, "string", varCoords1);
    forUnMarshall.body().add(coordinateslist.invoke("add").arg(JExpr._new(coordinateClass).arg(forUnMarshall.var())));
    unmarshall.body()._return(coordinateslist);
  }
View Full Code Here

    final JVar varAdditionalFiles = generateMarshalKmz.varParam(kmlClass.boxify(), "additionalFiles");
    generateMarshalKmz._throws(IOException.class);
    final JVar varOut = generateMarshalKmz.body().decl(zipOutputStreamClass, "out", JExpr._new(zipOutputStreamClass).arg(JExpr._new(fileOutputStreamClass).arg(varName)));
    generateMarshalKmz.body().add(varOut.invoke("setComment").arg("KMZ-file created with Java API for KML. Visit us: http://code.google.com/p/javaapiforkml/"));
    generateMarshalKmz.body().add(JExpr._this().invoke(createAddToKmzFile).arg(JExpr._this()).arg(varOut).arg(JExpr.TRUE));
    final JForEach forEach = generateMarshalKmz.body().forEach(kmlClass, "kml", varAdditionalFiles);
    forEach.body().add(JExpr._this().invoke(createAddToKmzFile).arg(forEach.var()).arg(varOut).arg(JExpr.FALSE));
    generateMarshalKmz.body().add(varOut.invoke("close"));
    generateMarshalKmz.body().assign(varMissingNameCounter,JExpr.lit(1));
    generateMarshalKmz.body()._return(JExpr.FALSE);
  }
View Full Code Here

        if (depth == 1) {
            root = true;
        }
        addReadAsType = false;

        forEachAttribute = new JForEach(model.ref(Attribute.class), variableManager.createId("attribute"), getXSR().invoke("getAttributes"));
        if (!mixed) {
            forEachChildElement = new JForEach(model.ref(XoXMLStreamReader.class), variableManager.createId("elementReader"), getXSR().invoke("getChildElements"));
        } else {
            forEachChildElement = new JForEach(model.ref(XoXMLStreamReader.class), variableManager.createId("elementReader"), getXSR().invoke("getMixedChildElements"));
        }

        reserveVariables();
    }
View Full Code Here

            //   throw new IllegalArgumentException(...);
            // }
            {
                JMethod m = type.method(JMod.PUBLIC|JMod.STATIC , type, "fromValue" );
                JVar $v = m.param(baseExposedType,"v");
                JForEach fe = m.body().forEach(type,"c", type.staticInvoke("values") );
                JExpression eq;
                if(baseExposedType.isPrimitive())
                    eq = fe.var().ref($value).eq($v);
                else
                    eq = fe.var().ref($value).invoke("equals").arg($v);

                fe.body()._if(eq)._then()._return(fe.var());

                JInvocation ex = JExpr._new(codeModel.ref(IllegalArgumentException.class));

                JExpression strForm;
                if(baseExposedType.isPrimitive()) {
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

            // [core.fromRawValue]

            JClass col = cm.ref(ArrayList.class).narrow(elementType);
            JVar $t = block.decl(col,uniqueName+"_col",JExpr._new(col));

            JForEach loop = block.forEach(itemType(), uniqueName+"_i", $t);
            loop.body().invoke($var,"add").arg(createJAXBElement(loop.var()));

            acc.fromRawValue(block, uniqueName, $t);
        }
View Full Code Here

                JVar marshaller = block.decl(mtype, "marsh",
                    JExpr.cast(mtype, JExpr.direct("context").invoke("get").arg(JExpr.lit(MarshallerImpl.MARSHALLER))));
               
                JExpression propValue = classBuilder.getObject().invoke(propName);
                if (prop.isCollection()) {
                        JForEach each = block.forEach(getGenericType(rawType), "_o", propValue);
                        JBlock newBody = each.body();
                        block = newBody;
                        propValue = each.var();
                    }
               
                block.add(marshaller.invoke("marshal").arg(propValue).arg(classBuilder.getXSW()));
//              }
            } else {
View Full Code Here

                nullCond._else().add(b.getXSW().invoke("writeXsiNil"));
            }
        }
       
        if (propEl.isCollection()) {
            JForEach each = block.forEach(getGenericType(rawType), "_o", var);
            JBlock newBody = each.body();
            b.setCurrentBlock(newBody);
            var = each.var();
           
            rawType = c;
            rawJT = jt;
        }
View Full Code Here

            //   throw new IllegalArgumentException(...);
            // }
            {
                JMethod m = type.method(JMod.PUBLIC|JMod.STATIC , type, "fromValue" );
                JVar $v = m.param(baseExposedType,"v");
                JForEach fe = m.body().forEach(type,"c", type.staticInvoke("values") );
                JExpression eq;
                if(baseExposedType.isPrimitive())
                    eq = fe.var().ref($value).eq($v);
                else
                    eq = fe.var().ref($value).invoke("equals").arg($v);

                fe.body()._if(eq)._then()._return(fe.var());

                JInvocation ex = JExpr._new(codeModel.ref(IllegalArgumentException.class));

                JExpression strForm;
                if(baseExposedType.isPrimitive()) {
View Full Code Here

TOP

Related Classes of com.sun.codemodel.JForEach

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.