Package com.sun.codemodel

Examples of com.sun.codemodel.JMethod


      superInvocation.arg( jaxbCollection.dotclass() );
    }
  }

  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


    createTestResource( jaxbTestClass, identifier );
  }

  private JMethod createDataPointMethod( @NotNull @NonNls String identifier, @NotNull JClass objectType ) {
    JMethod method = jaxbTestClass.method( JMod.STATIC | JMod.PUBLIC, codeGenerator.ref( Entry.class ).narrow( objectType.wildcard() ), identifier );
    method.annotate( codeGenerator.ref( "org.junit.experimental.theories.DataPoint" ) );
    return method;
  }
View Full Code Here

  private void addConstructors( @NotNull JDefinedClass type, int mod ) {
    //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

    createCopyMethod( "copyFieldsToJaxbObject", jaxbObject, false );
    createCopyMethod( "copyFieldsToStub", jaxbStub, true );
  }

  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

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

  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

      block.add( statement );
    }
  }

  private void ensureDelegateAvailable( @NotNull JClass fieldJaxbObject, @NotNull JClass fieldJaxbStub ) {
    JMethod constructor = getOrCreateConstructor();

    String paramName = NamingSupport.createVarName( fieldJaxbObject.outer().name() + MAPPING_SUFFIX );

    JClass mappingType = codeGenerator.ref( getMappingNameFor( fieldJaxbObject ) );

    //Check whether the mapping still exists
    for ( JVar param : constructor.listParams() ) {
      if ( param.type().equals( mappingType ) ) {
        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() )
        .arg( param )
    );
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

  private void addGetJaxbType() {
    assert jaxbStub != null;
    assert jaxbObject != null;

    JMethod method = jaxbStub.method( JMod.PUBLIC, codeGenerator.ref( Class.class ).narrow( jaxbObject ), "getJaxbType" );
    method.annotate( Override.class );
    method.body()._return( jaxbObject.dotclass() );
  }
View Full Code Here

  protected boolean shallAddField( @NotNull FieldTypeInformation fieldInfo, @NotNull Scope type ) {
    return ( ( JaxbObjectGenerator.StubDecisionCallback ) codeGenerator.getDecisionCallback() ).shallAddFieldStatement( this, fieldInfo, type );
  }

  private static void addSetter( @NotNull JDefinedClass currentClass, @NotNull JType fieldType, @NotNull JVar field, String name ) {
    JMethod setter = currentClass.method( JMod.PUBLIC, Void.TYPE, NamingSupport.createSetter( name ) );
    JVar param = setter.param( fieldType, name );
    setter.body().assign( JExpr._this().ref( field ), param );
  }
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.