Package com.sun.codemodel

Examples of com.sun.codemodel.JVar


  protected JMethod createSerializeMethodStub( @Nonnull JType domainType, @Nonnull JDefinedClass serializerClass ) {
    JMethod serializeMethod = serializerClass.method( JMod.PUBLIC, Void.TYPE, METHOD_NAME_SERIALIZE );
    serializeMethod.annotate( Override.class );
    serializeMethod.param( getSerializeToType(), PARAM_NAME_SERIALIZE_TO );
    serializeMethod.param( domainType, VAR_NAME_OBJECT );
    JVar formatVersion = serializeMethod.param( codeGenerator.ref( Version.class ), PARAM_NAME_FORMAT_VERSION );
    serializeMethod._throws( IOException.class )._throws( ( Class ) getExceptionType() );

    serializeMethod.body().invoke( "verifyVersionWritable" ).arg( formatVersion );

    for ( Decorator decorator : codeGenerator.getDecorators() ) {
View Full Code Here


  @Nonnull
  protected JMethod createDeserializeMethodStub( @Nonnull JType domainType, @Nonnull JDefinedClass serializerClass ) {
    JMethod deserializeMethod = serializerClass.method( JMod.PUBLIC, domainType, METHOD_NAME_DESERIALIZE );
    deserializeMethod.param( getSerializeFromType(), METHOD_NAME_DESERIALIZE_FROM );
    JVar formatVersion = deserializeMethod.param( codeGenerator.ref( Version.class ), PARAM_NAME_FORMAT_VERSION );
    deserializeMethod.annotate( Override.class );
    deserializeMethod._throws( IOException.class )._throws( VersionException.class )._throws( ( Class ) getExceptionType() );

    deserializeMethod.body().invoke( "verifyVersionReadable" ).arg( formatVersion );
View Full Code Here

  @Nonnull
  protected Map<FieldWithInitializationInfo, JVar> fillDeSerializationMethods( @Nonnull DomainObjectDescriptor domainObjectDescriptor, @Nonnull JDefinedClass serializerClass, @Nonnull JMethod serializeMethod, @Nonnull JMethod deserializeMethod ) {
    Map<FieldWithInitializationInfo, JVar> fieldToVar = Maps.newHashMap();

    //Extract the parameters for the serialize method
    JVar serializeTo = serializeMethod.listParams()[0];
    JVar object = serializeMethod.listParams()[1];
    JVar serializeFormatVersion = serializeMethod.listParams()[2];

    //Extract the parameters for the deserialize method
    JVar deserializeFrom = deserializeMethod.listParams()[0];
    JVar deserializeFormatVersion = deserializeMethod.listParams()[1];

    @Nullable JVar wrapper = createDeserializeWrapper( deserializeMethod, deserializeFrom );

    //Generate the serialization and deserialization for every field. We use the ordering of the fields used within the class
    for ( FieldWithInitializationInfo fieldInfo : domainObjectDescriptor.getFieldInfos() ) {
      appendSerializeStatement( serializerClass, serializeMethod, serializeTo, object, serializeFormatVersion, fieldInfo );
View Full Code Here

        return;
      }
    }

    //It does not exist, therefore let us add the serializer and map it
    JVar param = constructor.param( fieldSerializerType, paramName );

    constructor.body().add( JExpr.invoke( "add" ).arg( param ).invoke( "responsibleFor" ).arg( JExpr.dotclass( fieldType ) )
                              .invoke( "map" )
                              .arg( JExpr.lit( 1 ) ).arg( JExpr.lit( 0 ) ).arg( JExpr.lit( 0 ) )
                              .invoke( "toDelegateVersion" )
View Full Code Here

  protected void createVersionVerifyMethod( @Nonnull JDefinedClass testClass, @Nonnull JClass serializerClass, @Nonnull DomainObjectDescriptor domainObjectDescriptor ) {
    JClass domainType = codeGenerator.ref( domainObjectDescriptor.getQualifiedName() );

    JMethod method = testClass.method( JMod.PROTECTED, Void.TYPE, METHOD_NAME_VERIFY_DESERIALIZED )._throws( Exception.class );
    method.annotate( Override.class );
    JVar deserialized = method.param( domainType, PARAM_NAME_DESERIALIZED );
    method.param( Version.class, PARAM_NAME_VERSION );

    JClass assertClass = codeGenerator.ref( CLASS_NAME_ASSERT );

    for ( FieldWithInitializationInfo fieldInfo : domainObjectDescriptor.getFieldInfos() ) {
      method.body().add( assertClass.staticInvoke( METHOD_NAME_ASSERT_EQUALS ).arg( "daValue" ).arg( deserialized.invoke( fieldInfo.getGetterDeclaration().getSimpleName() ) ) );
    }
  }
View Full Code Here

  protected Map<FieldWithInitializationInfo, JVar> fillDeSerializationMethods( @Nonnull DomainObjectDescriptor domainObjectDescriptor, @Nonnull JDefinedClass serializerClass, @Nonnull JMethod serializeMethod, @Nonnull JMethod deserializeMethod ) {
    try {
      return super.fillDeSerializationMethods( domainObjectDescriptor, serializerClass, serializeMethod, deserializeMethod );
    } finally {
      //Call closeTag( deserializeFrom ); on deserialize
      JVar deserializeFrom = deserializeMethod.listParams()[0];
      deserializeMethod.body().directStatement( "//Finally closing element" );
      deserializeMethod.body().invoke( StaxMateGenerator.METHOD_NAME_CLOSE_TAG ).arg( deserializeFrom );
    }
  }
View Full Code Here

    for ( JStatement expression : readExpressions.getBefore() ) {
      deserializeMethod.body().add( expression );
    }

    //The field
    JVar field = deserializeMethod.body().decl( serializeToHandler.generateFieldType( fieldInfo ), fieldInfo.getSimpleName(), readExpressions.getExpression() );

    //Add the optional statements after
    for ( JStatement expression : readExpressions.getAfter() ) {
      deserializeMethod.body().add( expression );
    }
View Full Code Here

        getter.body()._return( field );

        final JMethod setter = c.implClass.method( JMod.PUBLIC, c.parent().getCodeModel().VOID,
                                                   "set" + String.valueOf( chars ) );

        final JVar valueParam = setter.param( JMod.FINAL, type, "value" );
        setter.body().directStatement( "// " + getMessage( "title" ) );
        setter.body().assign( JExpr._this().ref( field ), valueParam );

        getter.javadoc().append( "Gets the value of the " + name + " property." );
        getter.javadoc().addReturn().append( "The value of the " + name + " property." );
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." );
View Full Code Here

        // Setter.
        final JMethod setter = f.parent().implClass.method(
            JMod.PUBLIC, f.parent().parent().getCodeModel().VOID, "setJpa" + f.getPropertyInfo().getName( true ) );

        final JVar calendar = setter.param( JMod.FINAL, Calendar.class, "value" );

        setter.body().directStatement( "// " + getMessage( "title" ) );
        setter.body().assign( JExpr.refthis( field.name() ), calendar );
        setter.body().assign( JExpr.refthis( f.getPropertyInfo().getName( false ) ), f.parent()._package().
            objectFactory().staticInvoke( "createXMLGregorianCalendar" ).arg( calendar ) );

        // Update to the JAXB property setter to also update the jpa field.
        final JMethod transientSetter = this.getSetter( f );
        transientSetter.body().assign( JExpr.refthis( field.name() ), f.parent()._package().objectFactory().
            staticInvoke( "createCalendar" ).arg( transientSetter.listParams()[0] ) );

        setter.javadoc().append(
            "Sets the value of the jpa" + f.getPropertyInfo().getName( true ) + " property." + lineSeparator );

        setter.javadoc().append(
            "<p>This method sets the value of the " + f.getPropertyInfo().getName( false ) + " property by "
            + "transforming {@code " + calendar.name() + "} to a " + XMLGregorianCalendar.class.getName()
            + " instance.</p>" + lineSeparator );

        setter.javadoc().addParam( calendar ).append(
            "The new value of the jpa" + f.getPropertyInfo().getName( true ) + " property." );
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.