Package com.sun.codemodel

Examples of com.sun.codemodel.JVar


    private Object handle(ElementParserBuilder xpathBuilder, NumberExpr expr) {
//        xpathBuilder = xpathBuilder.newState();
       
  JBlock block = xpathBuilder.getBody().getBlock();
 
        JVar counterVar = parserBldr.getBody().field(JMod.PUBLIC, intType, "counter" + elementCounters++, JExpr.lit(0));
       
        block.assignPlus(counterVar, JExpr.lit(1));
   
  JBlock then = block._if(counterVar.eq(JExpr.lit((int) Double.valueOf(expr.getText()).doubleValue())))._then();
 
  return xpathBuilder.newState(then);
    }
View Full Code Here


        }
        throw new UnsupportedOperationException("Invalid type " + cls);
    }

    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);
View Full Code Here

   
    protected void writeReadAsType() {
        JMethod m = getReaderClass().method(JMod.PUBLIC, Object.class, "read");
        m.param(XoXMLStreamReader.class, "reader");
        m.param(buildContext.getStringToObjectMap(), "properties");
        JVar typeVar = m.param(QName.class, "type");
        m._throws(XMLStreamException.class);
       
        JBlock block = m.body();
        writeXsiChecks(block, typeVar);
       
View Full Code Here

       
        if (attributes.size() > 0) {
            writeAttributeReader(b);
        }
       
        JVar depthVar = b.decl(model._ref(int.class), "depth", xsrVar.invoke("getDepth"));
        JVar targetDepthVar;
        JVar event;
        if (depth == 1) {
            targetDepthVar = b.decl(model._ref(int.class), "targetDepth", JExpr.lit(depth));
            event = b.decl(model._ref(int.class), "event", xsrVar.invoke("getEventType"));
        } else {
            targetDepthVar = b.decl(model._ref(int.class), "targetDepth", depthVar.plus(JExpr.lit(1)));
            event = b.decl(model._ref(int.class), "event", xsrVar.invoke("nextTagIgnoreAll"));
        }
       
       
       
        b.assign(depthVar, xsrVar.invoke("getDepth"));
       
//        JClass sysType = (JClass) model._ref(System.class);
//        if (depth != 1)
//            b.add(sysType.staticRef("out").invoke("println").arg(JExpr.lit("TD ").plus(targetDepthVar)
//                     .plus(JExpr.lit(" Depth: ")).plus(depthVar)
//                     .plus(JExpr.lit(" Name: " + name).plus(JExpr.lit(" Current: "))
//                           .plus(xsrVar.invoke("getName")))));

        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);
View Full Code Here

     * Write out a loop which will read in a sequence of elements.
     *
     */
    private void writeAttributeReader(JBlock b) {
        JForLoop loop = b._for();
        JVar var = loop.init(model._ref(int.class), "i", JExpr.lit(0));
        loop.test(var.lt(xsrVar.invoke("getAttributeCount")));
        loop.update(var.assignPlus(JExpr.lit(1)));
       
        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();
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

    public ElementWriterBuilder newCondition(JExpression condition, JType type) {
        JConditional conditional = currentBlock._if(condition);
        JBlock block = conditional._then();
       
        JMethod m = buildContext.getNextWriteMethod(writerClass);
        JVar newObjectVar = addBasicArgs(m,
            type, "_" + type.name().replaceAll("\\[", "").replace("]", ""));

        block.invoke(m).arg(xswVar).arg(JExpr.cast(type, objectVar)).arg(rtContextVar);
       
        block._return();
View Full Code Here

            !getName().getNamespaceURI().equals(name.getNamespaceURI())) {
            block.add(xswVar.invoke("writeAndDeclareIfUndeclared").arg(JExpr.lit("")).arg(name.getNamespaceURI()));
        }
       
        JMethod m = buildContext.getNextWriteMethod(writerClass);
        JVar newObjectVar = addBasicArgs(m, type, "_" + type.name().replaceAll("\\[", "").replace("]", ""));
       
        block.invoke(m).arg(xswVar).arg(JExpr.cast(type, var)).arg(rtContextVar);

        block.add(xswVar.invoke("writeEndElement"));
       
View Full Code Here

        return writeAttribute(name, objectVar.type(), objectVar);
    }

    public WriterBuilder writeAttribute(QName name, JType type, JExpression var) {
        JMethod m = buildContext.getNextWriteMethod(writerClass);
        JVar newObjectVar = addBasicArgs(m, type, "_obj");

        JBlock block = attributeBlock;
        block.invoke(m).arg(xswVar).arg(JExpr.cast(type, var)).arg(rtContextVar);

        return new AttributeWriterBuilder(this, name, m, newObjectVar);
View Full Code Here

    method._throws(cls);
  }

  protected JVar addBasicArgs(JMethod method, JType sourceObjectType, String sourceVariableName) {
        xswVar = method.param(XoXMLStreamWriter.class, "writer");
        JVar var = method.param(sourceObjectType, sourceVariableName);

        rtContextVar = method.param(buildContext.getStringToObjectMap(), "properties");
   
        method._throws(XMLStreamException.class);
       
View Full Code Here

TOP

Related Classes of com.sun.codemodel.JVar

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.