Package com.sun.codemodel

Examples of com.sun.codemodel.JVar


  private void createMappingDataPoint() {
    JMethod method = mappingTestClass.method( JMod.STATIC | JMod.PUBLIC, codeGenerator.ref( Entry.class ).narrow( modelType.wildcard() ), DEFAULT_DATA_POINT_NAME );
    method.annotate( codeGenerator.ref( "org.junit.experimental.theories.DataPoint" ) );

    JVar field = method.body().decl( modelType, OBJECT, createDomainObjectCreationExpression() );

    method.body()._return( codeGenerator.ref( AbstractJaxbTest.class ).staticInvoke( METHOD_NAME_CREATE )
      .arg( field )
      .arg( createGetResourceStatement( mappingTestClass, DEFAULT_DATA_POINT_NAME ) )
      .arg( createGetResourceStatement( mappingTestClass, STUB_DATA_POINT_NAME ) )
View Full Code Here


  }

  private void createCollectionDataPoint( String identifier ) {
    JMethod method = createDataPointMethod( identifier, jaxbCollection );

    JVar stub0 = method.body().decl( jaxbStub, "firstStub", JExpr._new( jaxbStub ).arg( "daId0" ) );

    JBlock block0 = new JBlock( true, true );
    method.body().add( block0 );
    addFieldCopy( block0, jaxbStub, stub0 );


    JVar stub1 = method.body().decl( jaxbStub, "secondStub", JExpr._new( jaxbStub ).arg( "daId1" ) );

    JBlock block1 = new JBlock( true, true );
    method.body().add( block1 );
    addFieldCopy( block1, jaxbStub, stub1 );

    JExpression stubsExpression = codeGenerator.getClassRefSupport().ref( Arrays.class ).staticInvoke( NewInstanceFactory.METHOD_NAME_AS_LIST )
      .arg( stub0 )
      .arg( stub1 );
    JVar jaxbObjectInstance = method.body().decl( jaxbCollection, OBJECT, JExpr._new( jaxbCollection ).arg( stubsExpression ) );

    //Sets the href
    addHrefSet( method.body(), jaxbObjectInstance );

View Full Code Here

  }

  private void createDataPoint( @NotNull @NonNls String identifier, @NotNull JClass objectType ) {
    JMethod method = createDataPointMethod( identifier, objectType );

    JVar jaxbObjectInstance = addJaxbObjectCreation( method.body(), objectType );

    method.body()._return( JExpr.invoke( METHOD_NAME_CREATE ).arg( jaxbObjectInstance ).arg( createGetResourceStatement( jaxbTestClass, identifier ) ) );

    createTestResource( jaxbTestClass, identifier );
  }
View Full Code Here

    return method;
  }

  @NotNull
  private JVar addJaxbObjectCreation( @NotNull JBlock block, @NotNull JClass objectType ) {
    JVar field = block.decl( objectType, OBJECT, JExpr._new( objectType ).arg( "daId" ) );
    addFieldCopy( block, objectType, field );
    return field;
  }
View Full Code Here

    //Default constructor
    type.constructor( mod );

    //constructor with id
    JMethod constructor = type.constructor( mod );
    JVar id = constructor.param( String.class, ID );

    constructor.body().invoke( "super" ).arg( id );
  }
View Full Code Here

  private void createCreateJaxbMethod( @NotNull JClass jaxbType, @NotNull @NonNls String methodName ) {
    JMethod method = mappingClass.method( JMod.PROTECTED, jaxbType, methodName );
    method.annotate( Override.class );

    JVar object = method.param( codeGenerator.ref( descriptor.getQualifiedName() ), OBJECT );
    method.body()._return( JExpr._new( jaxbType ).arg( object.invoke( METHOD_NAME_GET_ID ) ) );
  }
View Full Code Here

  private void createCopyMethod( String methodName, JDefinedClass targetType, boolean stub ) {
    JMethod method = mappingClass.method( JMod.PROTECTED, Void.TYPE, methodName );
    method.annotate( Override.class );

    JVar source = method.param( codeGenerator.ref( descriptor.getQualifiedName() ), "source" );
    JVar target = method.param( targetType, "target" );
    JVar context = method.param( codeGenerator.ref( UriContext.class ), CONTEXT );

    addFieldCopyOperations( source, target, context, method.body(), stub );
  }
View Full Code Here

        return;
      }
    }

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

    constructor.body().add(
      JExpr.invoke( METHOD_NAME_GET_DELEGATES_MAPPING ).invoke( METHOD_NAME_ADD_MAPPING )
        .arg( fieldJaxbObject.dotclass() )
        .arg( fieldJaxbStub.dotclass() )
View Full Code Here

  private void createHrefMethod() {
    assert mappingClass != null;

    JMethod method = mappingClass.method( JMod.PROTECTED, UriBuilder.class, METHOD_NAME_GET_URIS );
    JVar object = method.param( JaxbObject.class, OBJECT );
    JVar context = method.param( UriContext.class, CONTEXT );
    method.annotate( Override.class );

    JFieldVar pathConst = mappingClass.field( JMod.PUBLIC | JMod.STATIC | JMod.FINAL, String.class, CONST_PATH,
                                              JExpr.lit( NamingSupport.plural( NamingSupport.createXmlElementName( getDescriptor().getClassDeclaration().getSimpleName() ) ) ) );
    method.body()._return( context.invoke( METHOD_GET_BASE_URI_BUILDER ).invoke( METHOD_NAME_PATH ).arg( pathConst ).invoke( METHOD_NAME_PATH ).arg( object.invoke( METHOD_NAME_GET_ID ) ) );
  }
View Full Code Here

    //Add constructors
    jaxbCollection.constructor( JMod.PUBLIC );

    {
      JMethod constructor = jaxbCollection.constructor( JMod.PUBLIC );
      JVar stubsParam = constructor.param( stubsListType, stubsField.name() );
      constructor.body().invoke( "this" ).arg( stubsParam ).arg( JExpr.lit( 0 ) ).arg( JExpr.lit( 0 ) );
    }

    {
      JMethod constructor = jaxbCollection.constructor( JMod.PUBLIC );
      JVar stubsParam = constructor.param( stubsListType, stubsField.name() );
      JVar startIndex = constructor.param( Integer.TYPE, "startIndex" );
      JVar maxLength = constructor.param( Integer.TYPE, "maxLength" );
      constructor.body().invoke( "super" ).arg( startIndex ).arg( maxLength );

      constructor.body().assign( JExpr.refthis( stubsField.name() ), stubsParam );
    }
  }
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.