Package com.sun.codemodel

Examples of com.sun.codemodel.JMethod


  @Nonnull
  protected abstract JMethod createConstructor( @Nonnull JDefinedClass serializerClass, @Nonnull DomainObjectDescriptor domainObjectDescriptor );

  @Nonnull
  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() ) {
      if ( decorator instanceof GeneratorDecorator ) {
        ( ( GeneratorDecorator ) decorator ).decorateSerializeMethod( codeGenerator, domainType, serializerClass, serializeMethod );
      }
View Full Code Here


    return serializeMethod;
  }

  @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 );

    for ( Decorator decorator : codeGenerator.getDecorators() ) {
      if ( decorator instanceof GeneratorDecorator ) {
        ( ( GeneratorDecorator ) decorator ).decorateDeserializeMethod( codeGenerator, domainType, serializerClass, deserializeMethod );
      }
View Full Code Here

        }
    }

    private void annotate( final ClassOutline c, final Transient t )
    {
        final JMethod getter = this.getGetter( c, t.getName() );
        getter.annotate( c.parent().getCodeModel().ref( javax.persistence.Transient.class ) );
    }
View Full Code Here

        getter.annotate( c.parent().getCodeModel().ref( javax.persistence.Transient.class ) );
    }

    private void annotate( final ClassOutline c, final Basic b )
    {
        final JMethod getter = this.getGetter( c, b.getName() );
        final JAnnotationUse ann =
            getter.annotate( c.parent().getCodeModel().ref( javax.persistence.Basic.class ) );

        if ( b.isOptional() != null )
        {
            ann.param( "optional", b.isOptional().booleanValue() );
        }
        if ( b.getFetch() != null )
        {
            ann.param( "fetch", javax.persistence.FetchType.valueOf( b.getFetch().value() ) );
        }
        if ( b.getColumn() != null )
        {
            final JAnnotationUse ac = getter.annotate(
                c.parent().getCodeModel().ref( javax.persistence.Column.class ) );
            this.annotate( ac, b.getColumn() );
        }
        if ( b.getEnumerated() != null )
        {
            final JAnnotationUse ac = getter.annotate(
                c.parent().getCodeModel().ref( javax.persistence.Enumerated.class ) );

            ac.param( "value", javax.persistence.EnumType.valueOf( b.getEnumerated().value() ) );
        }
        if ( b.getLob() != null )
        {
            getter.annotate( c.parent().getCodeModel().ref( javax.persistence.Lob.class ) );
        }
        if ( b.getTemporal() != null )
        {
            final JAnnotationUse ta =
                getter.annotate( c.parent().getCodeModel().ref( javax.persistence.Temporal.class ) );

            ta.param( "value", javax.persistence.TemporalType.valueOf( b.getTemporal().value() ) );
        }
    }
View Full Code Here

        return false;
    }

    private JMethod getGetter( final ClassOutline c, final String fieldName )
    {
        JMethod getter = null;
        FieldOutline field = null;

        final char[] chars = c.parent().getModel().getNameConverter().toPropertyName( fieldName ).toCharArray();
        chars[0] = Character.toUpperCase( chars[0] );
        String publicName = String.valueOf( chars );
View Full Code Here

    private JMethod getGetter( final FieldOutline f )
    {
        final JDefinedClass clazz = f.parent().implClass;
        final String name = f.getPropertyInfo().getName( true );
        JMethod getter = clazz.getMethod( "get" + name, NO_JTYPES );

        if ( getter == null )
        {
            getter = clazz.getMethod( "is" + name, NO_JTYPES );
        }
View Full Code Here

        return getter;
    }

    private JMethod getSetter( final FieldOutline f )
    {
        JMethod setter = null;
        final JMethod getter = this.getGetter( f );

        if ( getter != null )
        {
            final JType t = getter.type();
            final JDefinedClass clazz = f.parent().implClass;
            final String name = f.getPropertyInfo().getName( true );
            setter = clazz.getMethod( "set" + name, new JType[]
                {
                    t
View Full Code Here

        final String publicName = String.valueOf( chars );
        final String getterName = ( type == Boolean.TYPE || type == Boolean.class ? "is" : "get" ) + publicName;
        final JFieldVar field = c.implClass.field( JMod.PROTECTED, type, name );
        field.annotate( XmlTransient.class );

        final JMethod getter = c.implClass.method( JMod.PUBLIC, type, getterName );
        getter.body().directStatement( "// " + getMessage( "title" ) );
        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." );

        setter.javadoc().append( "Sets the value of the " + name + " property." );
        setter.javadoc().addParam( valueParam ).append( "The new 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." );
        setter.javadoc().addParam( valueParam ).append( "The new value of the " + p.getName( false ) + " property." );
    }
View Full Code Here

        final JFieldVar field = f.parent().implClass.field( JMod.PROTECTED, f.parent().parent().getCodeModel().ref(
            "java.util.Calendar" ), "jpa" + f.getPropertyInfo().getName( true ) );

        field.annotate( XmlTransient.class );

        final JMethod getter =
            f.parent().implClass.method( JMod.PUBLIC, f.parent().parent().getCodeModel().ref( Calendar.class ),
                                         "getJpa" + f.getPropertyInfo().getName( true ) );

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

        getter.body()._return( JExpr.refthis( field.name() ) );

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

        getter.javadoc().append(
            "<p>This method returns the value of the " + f.getPropertyInfo().getName( false ) + " property "
            + "transformed to a " + Calendar.class.getName() + " instance.</p>" + lineSeparator );

        getter.javadoc().addReturn().append(
            "The value of the jpa" + f.getPropertyInfo().getName( true ) + " property." );

        // 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(
View Full Code Here

TOP

Related Classes of com.sun.codemodel.JMethod

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.