Package com.sun.codemodel

Examples of com.sun.codemodel.JBlock


   
    private ParserBuilder handle(ElementParserBuilder parent, LogicalExpr expr) {
        Object left = handleExpression(parent, expr.getLHS());
        Object right = handleExpression(parent, expr.getRHS());
       
        JBlock block = parent.getBody().getBlock();
       
        JVar b1 = ((ExpressionState) left).getVar();
        JVar b2 = ((ExpressionState) right).getVar();
       
        String op = expr.getOperator();
       
        JBlock newBlock;
        if (op.equals("and")) {
            newBlock = block._if(b1.cand(b2))._then();
        } else if (op.equals("or")) {
            newBlock = block._if(b1.cor(b2))._then();
        } else {
View Full Code Here


       
        return handlePredicates(returnBuilder, step.getPredicateSet().getPredicates());
    }

    private Object handle(ElementParserBuilder xpathBuilder, NumberExpr expr) {
  JBlock block = xpathBuilder.getBody().getBlock();
  JVar xsrVar = xpathBuilder.getXSR();
 
  JInvocation result = JExpr._this().invoke("incrementElementCount")
          .arg(xsrVar.invoke("getName"))
          .arg(xsrVar.invoke("getDepth"));
  JVar countVar = block.decl(intType, "count", result);
   
  JBlock then = block._if(countVar.eq(JExpr.lit((int) Double.valueOf(expr.getText()).doubleValue())))._then();
 
  return xpathBuilder.newState(then);
    }
View Full Code Here

    private void generateCollectionSetter( final JCodeModel cm, final ClassOutline c, final CPropertyInfo p )
    {
        final JFieldVar field = c.implClass.fields().get( p.getName( false ) );
        final JMethod setter = c.implClass.method( JMod.PUBLIC, cm.VOID, "set" + p.getName( true ) );
        final JVar valueParam = setter.param( JMod.FINAL, field.type(), "value" );
        final JBlock body = setter.body();
        body.directStatement( "// " + getMessage( "title" ) );
        body.assign( JExpr._this().ref( field ), valueParam );

        setter.javadoc().append( "Sets the value of the " + p.getName( false ) + " property." );
        setter.javadoc().addParam( valueParam ).append( "The new value of the " + p.getName( false ) + " property." );
    }
View Full Code Here

    public void compileEventHandler(String expr, XPathEventHandler eventHandler) {
        String varName = "obj" + vars.size();
        vars.put(varName, eventHandler);
       
        ParserBuilder xpathBuilder = parserBldr;
        JBlock block;
        try {
            org.jaxen.saxpath.XPathReader reader = XPathReaderFactory.createReader();
           
            JaxenHandler handler = new JaxenHandler();
            reader.setXPathHandler(handler);
            reader.parse(expr);
           
            XPathExpr path = handler.getXPathExpr(true);
           
            Object o = handleExpression(parserBldr, path.getRootExpr());
            if (o instanceof ExpressionState) {
                ExpressionState exp = (ExpressionState) o;
                JVar var = exp.getVar();
                ParserBuilder builder = exp.getBuilder();
                block = builder.getBody().getBlock();
               
                block = block._if(var)._then();
            } else {
                xpathBuilder = (ParserBuilder) o;
                block = xpathBuilder.getBody().getBlock();
            }
        } catch (SAXPathException e) {
            throw new XPathException(e);
        }
       
        CodeBody body = xpathBuilder.getBody();
       
        // grab the event handler out of the context
        JVar handlerVar = block.decl(eventHandlerType, varName,
                                    JExpr.cast(eventHandlerType,
                                               JExpr._super().ref("context").invoke("get").arg(varName)));

        block.add(handlerVar.invoke("onMatch").arg(JExpr._new(eventType).arg(JExpr.lit(expr)).arg(xpathBuilder.getXSR())));
    }
View Full Code Here

   
    private ParserBuilder handle(ElementParserBuilder parent, LogicalExpr expr) {
        Object left = handleExpression(parent, expr.getLHS());
        Object right = handleExpression(parent, expr.getRHS());
       
        JBlock block = parent.getBody().getBlock();
       
        JVar b1 = ((ExpressionState) left).getVar();
        JVar b2 = ((ExpressionState) right).getVar();
       
        String op = expr.getOperator();
       
        JBlock newBlock;
        if (op.equals("and")) {
            newBlock = block._if(b1.cand(b2))._then();
        } else if (op.equals("or")) {
            newBlock = block._if(b1.cor(b2))._then();
        } else {
View Full Code Here

    }

    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

       
        return super.passParentVariable(parentVar);
    }

    public JVar call(JType type, String varName, ElementParserBuilder builder) {
        JBlock block = codeBlock;
       
        ElementParserBuilderImpl b = (ElementParserBuilderImpl) builder;
        JMethod nextMethod = b.getMethod();
       
        JInvocation invocation = JExpr.invoke(nextMethod).arg(xsrVar).arg(rtContextVar);
        for (JVar v : b.variables) {
            invocation.arg(v);
        }
       
        return block.decl(type, varName, invocation);
    }
View Full Code Here

    protected void write() {
        if (written) return;
       
        written = true;
       
        JBlock b = method.body();
       
        if (!valueType &&
            (elements.size() > 0
            || elementCalls.size() > 0
            || buildContext.getGlobalElements().size() > 0
            || getXsiTypes().size() > 0
            || attributes.size() > 0
            || anyElement != null)){
            writeMainLoop();
        } else {
            b.add(codeBlock);
        }
       
        for (ElementParserBuilderImpl e : states) {
            e.write();
        }
       
        // Add return statement to the end of the block
        if (returnType != null) {
            if(root)
                throw new IllegalStateException("root builder is not allowed to have the return type");
            setReturnType(returnType);
            codeBlock._return(_return);
        }
       
        if (root) {
            b._return(JExpr._null());
        }

        if (root) {
            writeReadAsType();
            readerClass._extends(baseClass);
View Full Code Here

        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);
       
        block._return(JExpr._null());
    }
View Full Code Here

    /**
     * Write out a loop which will read in a sequence of elements.
     *
     */
    private void writeMainLoop() {
        JBlock b = method.body();
       
        // Add XSI checks
        if (!valueType && depth > 1) {
            writeXsiChecks(b);
        }
       
        // Add the user constructed codeblock and continue from there
        b.add(codeBlock);
        b = codeBlock;
       
        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);
       
        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

TOP

Related Classes of com.sun.codemodel.JBlock

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.