Package com.sun.codemodel

Examples of com.sun.codemodel.JVar


      final String propertyName = fieldOutline.getPropertyInfo().getName(true);
      final JClass elementClass = fieldOutline.getRawType().boxify().getTypeParameters().get(0);
      final JPrimitiveType INT = fieldOutline.parent().parent().getCodeModel().INT;

      JMethod method = implClass.method(JMod.PUBLIC, elementClass, "with" + propertyName);
      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


      JMethod method = implClass.method(JMod.PUBLIC, elementClass, "withNew" + propertyName);

      JBlock body = method.body();

      JVar element = body.decl(elementClass, "value", JExpr._new(elementClass));

      body.invoke(JExpr._this().invoke("get" + propertyName), "add").arg(element);

      body._return(element);
   }
View Full Code Here

            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();
                JBlock block = builder.getBody().getBlock();
               
                xpathBuilder = builder.newState(block._if(var)._then());
            } else {
                xpathBuilder = (ParserBuilder) o;
            }
        } catch (SAXPathException e) {
            throw new XPathException(e);
        }
       
        CodeBody body = xpathBuilder.getBody();
       
        // grab the event handler out of the context
        JVar handlerVar = body.decl(eventHandlerType, varName,
                                    JExpr.cast(eventHandlerType,
                                               JExpr._super().ref("context").invoke("get").arg(varName)));

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

            throw new XPathException("Unknown expression type " + expr);
        }
    }

    private ExpressionState handle(ElementParserBuilder xpathBuilder, LiteralExpr expr) {
        JVar var = xpathBuilder.getBody().decl(stringType,
                                               "_literal" + varCount++,
                                               JExpr.lit(expr.getLiteral()));
        return new ExpressionState(xpathBuilder, var);
    }
View Full Code Here

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

   
    private ExpressionState handle(ElementParserBuilder xpathBuilder, FunctionCallExpr expr) {

        String name = "functValue" + varCount++;
        String functionName = expr.getFunctionName();
        JVar var;
        // See http://www.w3schools.com/xpath/xpath_functions.asp for a complete list
        if ("local-name".equals(functionName)) {
            var =  xpathBuilder.getBody().decl(stringType,
                                               name,
                                               xpathBuilder.getXSR().invoke("getLocalName"));
View Full Code Here

    private ExpressionState handle(ElementParserBuilder parent, EqualityExpr expr) {
        ExpressionState left = (ExpressionState) handleExpression(parent, expr.getLHS());
        ExpressionState right = (ExpressionState) handleExpression(parent, expr.getRHS());
       
        JVar var = parent.getBody().decl(boolType,
                              "b" + varCount++,
                     left.getVar().invoke("equals").arg(right.getVar()));
       
        return new ExpressionState(parent, var);
    }
View Full Code Here

       
        return returnObj;
    }

    private ExpressionState handleTextNodeStep(ParserBuilder returnBuilder, TextNodeStep step) {
        JVar var = returnBuilder.as(String.class);
        return new ExpressionState(returnBuilder, var);
    }
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

    for ( FieldInitializedInConstructorInfo fieldInfo : fieldsToSerialize ) {
      domainTypeInit.arg( fieldToVar.get( fieldInfo ) );
    }

    //Add the object type
    JVar domainObjectVar = deserializeMethod.body().decl( domainType, VAR_NAME_OBJECT, domainTypeInit );

    //Now call the setters
    for ( FieldInitializedInSetterInfo fieldInfo : domainObjectDescriptor.getFieldsInitializedInSetter() ) {
      deserializeMethod.body().add( domainObjectVar.invoke( fieldInfo.getSetterDeclaration().getSimpleName() ).arg( fieldToVar.get( fieldInfo ) ) );
    }

    deserializeMethod.body()._return( domainObjectVar );
  }
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.