Package com.sun.codemodel

Examples of com.sun.codemodel.JExpression


            if (info.isElement()) {
                enumBuilder = rootReader.expectElement(info.getElementName());
            } else {
                enumBuilder = rootReader.expectXsiType(info.getTypeName());
            }
            JExpression toSet = handleElement(enumBuilder, info, null, cls, true);
           
            CodeBody cb = enumBuilder.getBody();
           
            JType type = model._ref(cls);
            JType jaxbElementType = model._ref(JAXBElement.class);
View Full Code Here


    private void createRefParser(ElementParserBuilder builder, QName q, RuntimeElementInfo rei) {
        ElementParserBuilder elBuilder = builder.expectElement(q);
        ref2Parser.put(rei, elBuilder);

        Class<?> c = (Class<?>) rei.getContentType().getType();
        JExpression expression = handleElement(elBuilder, rei.getContentType(), null, c, !c.isPrimitive());
       
        CodeBody cb = elBuilder.getBody();
       
        JType type = model._ref(c);
        JType jaxbElementType = model._ref(JAXBElement.class);
View Full Code Here

                c = (Class) type;
            }
           
            // type to create for this property
            JBlock block = builder.getBody().getBlock();
            JExpression toSet = handleElement(builder, target, adapter, c, nillable);

            if (toSet != null)
                doSet(block, bean, beanClass, propEl, toSet);
        } else if (target instanceof RuntimeClassInfo) {
            RuntimeClassInfo rci = (RuntimeClassInfo) target;
           
            BuilderKey key = new BuilderKey();
            key.parentClass = beanClass;
            key.type = name;
           
            ElementParserBuilder propBuilder = add(builder, name, c, beanClass, rci, false);
            if (propBuilder != null) {
                JExpression exp = JExpr.direct(c.getSimpleName());
                doSet(propBuilder.getBody().getBlock(), bean, beanClass, propEl, exp);
            }
        } else {
          logger.info("(JAXB Reader) Cannot map type " + c + " yet on " + beanClass);
        }
View Full Code Here

    private JExpression handleElement(ElementParserBuilder builder,
                                      RuntimeNonElement target,
                                      Adapter<Type, Class> adapter,
                                      Class c,
                                      boolean nillable) {
        JExpression toSet;
        if (adapter != null) {
             JVar adapterVar = getAdapter(adapter);
             toSet = adapterVar.invoke("unmarshal").arg(builder.getXSR().invoke("getElementText"));
        } else if ((c.equals(String.class)
            || c.equals(Integer.class)
            || c.equals(Double.class)
            || c.equals(Float.class)
            || c.equals(Short.class)
            || c.equals(Long.class)
            || c.equals(Boolean.class)
            || c.equals(Byte.class)
            || c.isPrimitive())
            && c != byte.class) {
            toSet = builder.as(c, nillable);
        } else if (c.equals(XMLGregorianCalendar.class)) {
            toSet = handleXMLGregorianCalendar(builder, builder.as(String.class, nillable));
        } else if (c.equals(Duration.class)) {
            toSet = handleDuration(builder, builder.as(String.class, nillable));
        } else if (c.isEnum()) {
            try {
                Method method = c.getMethod("value", new Class[0]);
               
                Class<?> readAs = method.getReturnType();
                JExpression val = handleElement(builder, target, adapter, readAs, nillable);
               
                toSet = handleEnum(builder, val, c);
            } catch (Exception e) {
                throw new BuildException(e);
            }
View Full Code Here

        Class<?> c = (Class<?>)propEl.getRawType();
       
        if (target.isSimpleType()) {
            // type to create for this property
            JBlock block = builder.getBody().getBlock();
            JExpression toSet = handleAttribute(builder, target, propEl.getAdapter(), c);

            if (toSet != null)
                doSet(block, bean, beanClass, propEl, toSet);
        } else {
            System.err.println("Unknown type " + c + " - " + target.getClass());
View Full Code Here

   
    private JExpression handleAttribute(ParserBuilder builder,
                                        RuntimeNonElement target,
                                        Adapter<Type, Class> adapter,
                                        Class c) {
        JExpression toSet;
        if (adapter != null) {
            JVar adapterVar = getAdapter(adapter);
            toSet = adapterVar.invoke("unmarshal").arg(JExpr.direct("_attValue"));
       } else if ((c.equals(String.class)
            || c.equals(Integer.class)
View Full Code Here

    }
  }

  @NotNull
  public JExpression createCollectionInvocation( @NotNull JType collectionParamType, @NotNull @NonNls String simpleName, boolean isSet ) {
    JExpression expression = create( collectionParamType.erasure(), simpleName );

    JInvocation listInvocation = classRefSupport.ref( Arrays.class ).staticInvoke( METHOD_NAME_AS_LIST ).arg( expression );
    if ( isSet ) {
      return JExpr._new( classRefSupport.ref( HashSet.class ) ).arg( listInvocation );
    } else {
View Full Code Here

    }
  }

  @NotNull
  public JExpression createCollectionInvocation( @NotNull TypeMirror collectionParamType, @NotNull @NonNls String simpleName, boolean isSet ) {
    JExpression expression = create( TypeUtils.getErasure( collectionParamType ), simpleName );

    JInvocation listInvocation = classRefSupport.ref( Arrays.class ).staticInvoke( METHOD_NAME_AS_LIST ).arg( expression );
    if ( isSet ) {
      return JExpr._new( classRefSupport.ref( HashSet.class ) ).arg( listInvocation );
    } else {
View Full Code Here

                JBlock block = classBuilder.getCurrentBlock().block();
                JType mtype = model._ref(MarshallerImpl.class);
                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();
View Full Code Here

            if (info.isElement()) {
                enumBuilder = rootReader.expectElement(info.getElementName());
            } else {
                enumBuilder = rootReader.expectXsiType(info.getTypeName());
            }
            JExpression toSet = handleElement(enumBuilder, info, null, cls, true);
           
            CodeBody cb = enumBuilder.getBody();
           
            JType type = model._ref(cls);
            JType jaxbElementType = model._ref(JAXBElement.class);
View Full Code Here

TOP

Related Classes of com.sun.codemodel.JExpression

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.