Package com.sun.codemodel

Examples of com.sun.codemodel.JExpression


  }

  @NotNull
  protected JFieldVar getConstant( @NotNull JDefinedClass serializerClass, @NotNull FieldInfo fieldInfo ) {
    String constantName = getConstantName( fieldInfo );
    JExpression value = JExpr.lit( fieldInfo.getSimpleName() );
    return getConstant( serializerClass, constantName, value );
  }
View Full Code Here


    //Add serializer to constructor
    generator.addDelegatingSerializerToConstructor( serializerClass, codeGenerator.ref( TypeUtils.getErasure( fieldInfo.getType() ).toString() ) );

    JFieldVar constant = getConstant( serializerClass, fieldInfo );

    JExpression getterInvocation = codeGenerator.createGetterInvocation( object, fieldInfo );

    return JExpr.invoke( METHOD_NAME_SERIALIZE )
      .arg( getterInvocation )
      .arg( JExpr.dotclass( codeGenerator.ref( TypeUtils.getErasure( fieldInfo.getType() ).toString() ) ) )
      .arg( constant )
View Full Code Here

  }

  @Nonnull
  protected JFieldVar getConstant( @Nonnull JDefinedClass serializerClass, @Nonnull FieldInfo fieldInfo ) {
    String constantName = getConstantName( fieldInfo );
    JExpression value = JExpr.lit( fieldInfo.getSimpleName() );
    return getConstant( serializerClass, constantName, value );
  }
View Full Code Here

    //Add serializer to constructor
    generator.addDelegatingSerializerToConstructor( serializerClass, codeGenerator.ref( TypeUtils.getErasure( fieldInfo.getType() ).toString() ) );

    JFieldVar constant = getConstant( serializerClass, fieldInfo );

    JExpression getterInvocation = codeGenerator.createGetterInvocation( object, fieldInfo );

    return JExpr.invoke( METHOD_NAME_SERIALIZE )
      .arg( getterInvocation )
      .arg( JExpr.dotclass( codeGenerator.ref( TypeUtils.getErasure( fieldInfo.getType() ).toString() ) ) )
      .arg( constant )
View Full Code Here

        }

        b.add(new JBlankLine());
        b.add(new JLineComment("Read attributes"));

        JExpression attName;
        JExpression attNs;
        JExpression attValue;
        if (forEachAttribute != null) {
            b.add(forEachAttribute);
            b = forEachAttribute.body();
            JVar attributeVar = forEachAttribute.var();
            attName = attributeVar.invoke("getLocalName");
            attNs = attributeVar.invoke("getNamespace");
            attValue = attributeVar.invoke("getValue");
        } else {
            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();
            attName = b.decl(model._ref(String.class), "attName", xsrVar.invoke("getAttributeLocalName").arg(var));
            attNs = b.decl(model._ref(String.class), "attNs", xsrVar.invoke("getAttributeNamespace").arg(var));
            attValue = b.decl(model._ref(String.class), "attValue", xsrVar.invoke("getAttributeValue").arg(var));
        }


        JIfElseBlock attributesBlock = new JIfElseBlock();
        b.add(attributesBlock);
        for (Map.Entry<QName, ExpectedAttribute> e : attributes.entrySet()) {
            QName name = e.getKey();
            ExpectedAttribute expectedAttribute = e.getValue();

            JExpression qnameCompare = buildQNameCompare(name, attName, attNs);
            JBlock block = attributesBlock.addCondition(qnameCompare);

            List<JExpression> vars = null;
            if (expectedAttribute.getParserBuilder() != null) {
                AttributeParserBuilderImpl builder = expectedAttribute.getParserBuilder();
View Full Code Here

        } else if (cls.equals(short.class) || cls.equals(Short.class)) {
            return createVar(short.class, Short.class);
        } else if (cls.equals(byte.class) || cls.equals(Byte.class)) {
            return createVar(byte.class, Byte.class);
        } else if (cls.equals(boolean.class) || cls.equals(Boolean.class)) {
            JExpression var = JExpr.direct("_attValue");
            JBlock b = method.body();
            JVar retVar = method.body().decl(model._ref(boolean.class), "value");
           
            JConditional cond = b._if(JExpr.lit("1").invoke("equals").arg(var).cor(JExpr.lit("true").invoke("equals").arg(var)));
            JClass boolClass = (JClass) model._ref(Boolean.class);
View Full Code Here

        block.add(xsiTypesBlock);
        for (Map.Entry<QName, ExpectedXsiType> entry : xsiTypes.entrySet()) {
            QName name = entry.getKey();
            ExpectedXsiType expectedXsiType = entry.getValue();

            JExpression qnameCompare = buildQNameCompare(name, xsiType.invoke("getLocalPart"), xsiType.invoke("getNamespaceURI"));
            JBlock xsiTypeBlock = xsiTypesBlock.addCondition(qnameCompare);

            // xsi:type elements are immediately returned to the caller
            writeReader(xsiTypeBlock, xsrVar, expectedXsiType, null);

            ElementParserBuilderImpl parserBuilder = expectedXsiType.getParserBuilder();
            if (parserBuilder != null && expectedXsiType.getParserBuilder().returnType == null) {
                xsiTypeBlock._return();
            }
        }

        if (unexpectedXsiType != null) {
            JBlock anyBlock = block;
            if (xmlType != null) {
                JExpression localInv = JExpr.lit(xmlType.getLocalPart()).ne(xsiType.invoke("getLocalPart"));
                JExpression nsInv = JExpr.lit(xmlType.getNamespaceURI()).ne(xsiType.invoke("getNamespaceURI"));
                if (xmlType.getNamespaceURI().equals("")) {
                    nsInv = nsInv.cand(xsiType.invoke("getNamespaceURI").ne(JExpr._null()));
                }
                JExpression qnameCompare = localInv.cor(nsInv);

                anyBlock = xsiTypesBlock.addCondition(qnameCompare);
            } else if (!xsiTypesBlock.ifConditions().isEmpty()) {
                anyBlock = xsiTypesBlock._else().block();
            }
View Full Code Here

        for (Map.Entry<QName, ExpectedElement> entry : elements.entrySet()) {
            QName name = entry.getKey();
            ExpectedElement expectedElement = entry.getValue();

            JExpression qnameCompare = buildQNameCompare(name, xsrVar.invoke("getLocalName"), xsrVar.invoke("getNamespaceURI"));
            JBlock elementBlock = elementsBlock.addCondition(qnameCompare);

            writeReader(elementBlock, xsrVar, expectedElement, expectedElement.getVars());
        }
View Full Code Here

            block.add(removeBraces(readBlock));
        }
    }

    private JExpression buildQNameCompare(QName name, JExpression localPart, JExpression namespaceUri) {
        JExpression localInv = JExpr.lit(name.getLocalPart()).eq(localPart);
        String ns = name.getNamespaceURI();
        JExpression nsInv = JExpr.lit(ns).eq(namespaceUri);
        if (ns.equals("")) {
            nsInv = nsInv.cor(namespaceUri.eq(JExpr._null()));
        }

        JExpression qnameCompare = localInv.cand(nsInv);
        return qnameCompare;
    }
View Full Code Here

                if (null == xmlDefaultValue || null == xmlDefaultValue.value) {
                    continue;
                }
               
                JExpression dvExpr =
                    getDefaultValueExpression(f, co, outline, xsType, isElement, xmlDefaultValue);
               
                if (null == dvExpr) {
                    continue;
                }
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.