Package com.sun.codemodel

Examples of com.sun.codemodel.JFieldVar


      // * The candidate class should not extend any other model class (as the total number of properties in this case will be more than 1)
      if (!isHiddenClass(candidateClass._extends())) {
        continue;
      }

      JFieldVar field = null;

      // * The candidate class should have exactly one property
      for (JFieldVar f : candidateClass.fields().values()) {
        if ((f.mods().getValue() & JMod.STATIC) == JMod.STATIC) {
          continue;
        }

        // If there are at least two non-static fields, we discard this candidate:
        if (field != null) {
          field = null;
          break;
        }

        field = f;
      }

      // "field" is null if there are no fields (or all fields are static) or there are more then two fields.
      // The only property should be a collection, hence it should be class:
      if (field == null || !(field.type() instanceof JClass)) {
        continue;
      }

      JClass fieldType = (JClass) field.type();

      // * The property should be a collection
      if (!collectionModelClass.isAssignableFrom(fieldType)) {
        continue;
      }

      List<JClass> fieldParametrisations = fieldType.getTypeParameters();

      // FIXME: All known collections have exactly one parametrisation type.
      assert fieldParametrisations.size() == 1;

      JDefinedClass fieldParametrisationClass = null;
      JDefinedClass fieldParametrisationImpl = null;

      // Parametrisations like "List<String>" or "List<Serialazable>" are not considered.
      // They are substituted as is and do not require moving of classes.
      if (fieldParametrisations.get(0) instanceof JDefinedClass) {
        fieldParametrisationClass = (JDefinedClass) fieldParametrisations.get(0);

        ClassOutline fieldParametrisationClassOutline = interfaceImplementations.get(fieldParametrisationClass
                    .fullName());

        if (fieldParametrisationClassOutline != null) {
          assert fieldParametrisationClassOutline.ref == fieldParametrisationClass;

          fieldParametrisationImpl = fieldParametrisationClassOutline.implClass;
        }
        else {
          fieldParametrisationImpl = fieldParametrisationClass;
        }
      }

      JDefinedClass objectFactoryClass = null;

      // If class has a non-hidden interface, then there is object factory in another package.
      for (Iterator<JClass> iter = candidateClass._implements(); iter.hasNext();) {
        JClass interfaceClass = iter.next();

        if (!isHiddenClass(interfaceClass)) {
          objectFactoryClass = interfaceClass._package()._getClass(FACTORY_CLASS_NAME);

          if (objectFactoryClass != null) {
            break;
          }
        }
      }

      JDefinedClass valueObjectFactoryClass = candidateClass._package()._getClass(FACTORY_CLASS_NAME);

      assert objectFactoryClass != valueObjectFactoryClass;

      String fieldTargetNamespace = null;

      XSDeclaration xsdDeclaration = getXsdDeclaration(classOutline.target.getProperty(field.name()));

      if (xsdDeclaration != null && !xsdDeclaration.getTargetNamespace().isEmpty()) {
        fieldTargetNamespace = xsdDeclaration.getTargetNamespace();
      }
      else {
View Full Code Here


  }

  @Override
  @NotNull
  public JInvocation createAddToSerializeToExpression( @NotNull AbstractGenerator<?> generator, @NotNull JDefinedClass serializerClass, @NotNull JExpression serializeTo, @NotNull FieldDeclarationInfo fieldInfo, @NotNull JVar object, JVar formatVersion ) {
    JFieldVar constant = getConstant( serializerClass, fieldInfo );

    JExpression objectAsString = codeGenerator.getParseExpressionFactory().createToStringExpression( codeGenerator.createGetterInvocation( object, fieldInfo ), fieldInfo );
    return serializeTo.invoke( METHOD_NAME_ADD_ATTRIBUTE )
      .arg( constant )
      .arg( objectAsString );
View Full Code Here

  }

  @NotNull
  @Override
  public JExpression createReadExpression( @NotNull JDefinedClass serializerClass, @NotNull JExpression deserializeFrom, @NotNull JVar formatVersion, @NotNull FieldDeclarationInfo fieldInfo ) {
    JFieldVar constant = getConstant( serializerClass, fieldInfo );
    return deserializeFrom.invoke( METHOD_NAME_GET_ATTRIBUTE_VALUE ).arg( JExpr._null() ).arg( constant );
  }
View Full Code Here

  @Override
  @NotNull
  public JInvocation createAddToSerializeToExpression( @NotNull AbstractGenerator<?> generator, @NotNull JDefinedClass serializerClass, @NotNull JExpression serializeTo, @NotNull FieldDeclarationInfo fieldInfo, @NotNull JVar object, JVar formatVersion ) {
    generator.addDelegatingSerializerToConstructor( serializerClass, codeGenerator.ref( TypeUtils.getErasure( fieldInfo.getCollectionParam() ).toString() ) );

    JFieldVar constant = getConstant( serializerClass, fieldInfo );

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

    return JExpr.invoke( METHOD_NAME_SERIALIZE_COLLECTION )
      .arg( getterInvocation )
View Full Code Here

  @Override
  public JStatement createAddToSerializeToExpression( @NotNull AbstractGenerator<?> generator, @NotNull JDefinedClass serializerClass, @NotNull JExpression serializeTo, @NotNull FieldDeclarationInfo fieldInfo, @NotNull JVar object, JVar formatVersion ) {
    //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 )
View Full Code Here

  }

  @Override
  @NotNull
  public JInvocation createAddToSerializeToExpression( @NotNull AbstractGenerator<?> generator, @NotNull JDefinedClass serializerClass, @NotNull JExpression serializeTo, @NotNull FieldDeclarationInfo fieldInfo, @NotNull JVar object, JVar formatVersion ) {
    JFieldVar constant = getConstant( serializerClass, fieldInfo );

    JExpression objectAsString = codeGenerator.getParseExpressionFactory().createToStringExpression( codeGenerator.createGetterInvocation( object, fieldInfo ), fieldInfo );

    return serializeTo.invoke( METHOD_NAME_ADD_ELEMENT_WITH_CHARACTERS )
      .arg( serializeTo.invoke( METHOD_NAME_GET_NAMESPACE ) )
View Full Code Here

  }

  @NotNull
  @Override
  public JExpression createReadExpression( @NotNull JDefinedClass serializerClass, @NotNull JExpression deserializeFrom, @NotNull JVar formatVersion, @NotNull FieldDeclarationInfo fieldInfo ) {
    JFieldVar constant = getConstant( serializerClass, fieldInfo );
    return JExpr.invoke( METHOD_NAME_GET_CHILD_TEXT ).arg( deserializeFrom ).arg( constant );
  }
View Full Code Here

        JClass mapType = codeModel.ref(Map.class).narrow(QName.class,String.class);
        JClass mapImpl = codeModel.ref(HashMap.class).narrow(QName.class,String.class);

        // [RESULT]
        // Map<QName,String> m = new HashMap<QName,String>();
        JFieldVar $ref = cc.implClass.field(JMod.PRIVATE,
                mapType, FIELD_NAME, JExpr._new(mapImpl) );
        $ref.annotate2(XmlAnyAttributeWriter.class);

        MethodWriter writer = cc.createMethodWriter();

        JMethod $get = writer.declareMethod( mapType, "get"+METHOD_SEED );
        $get.javadoc().append(
View Full Code Here


        if(needsValue) {
            // [RESULT]
            // final <valueType> value;
            JFieldVar $value = type.field( JMod.PRIVATE|JMod.FINAL, baseExposedType, "value" );

            // [RESULT]
            // public <valuetype> value() { return value; }
            type.method(JMod.PUBLIC, baseExposedType, "value" ).body()._return($value);
View Full Code Here

        if (node.has("javaInterfaces")) {
            addInterfaces(_enum, node.get("javaInterfaces"));
        }
        addGeneratedAnnotation(_enum);

        JFieldVar valueField = addValueField(_enum);
        addToString(_enum, valueField);
        addEnumConstants(node.path("enum"), _enum);
        addFactoryMethod(_enum);

        return _enum;
View Full Code Here

TOP

Related Classes of com.sun.codemodel.JFieldVar

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.