← 输入框|github.com|刷新
Skip to content

#1924 Correct handling of org.immutables.value.Value.Style.typeImmutable - #3189

Closed
Drevsh wants to merge 2 commits into
mapstruct:mainfrom
Drevsh:issue-1924
Closed

Drevsh wants to merge 2 commits into
mapstruct:mainfrom
Drevsh:issue-1924

Conversation

@Drevsh

@Drevsh Drevsh commented Mar 8, 2023 •

Copy link
Copy Markdown

Immutables allows adapting the name of the generated classes via @org.immutables.value.Value.Style
Also see: https://immutables.github.io/style.html

This PR adds correct handling for prefix/infix/postfix handling.
Example:

@Value.Immutable
@Value.Style(defaultAsDefault = true, typeImmutable = "_*_")
public interface NotificationMessageDtoInifx {
	String getMessage();
	String getTableId();
	String getType();
}

@Value.Immutable
@Value.Style(defaultAsDefault = true, typeImmutable = "*_")
public interface NotificationMessageDtoPostfix {
	String getMessage();
	String getTableId();
	String getType();
}

@Value.Immutable
@Value.Style(defaultAsDefault = true, typeImmutable = "_*")
public interface NotificationMessageDtoPrefix {
	String getMessage();
	String getTableId();
	String getType();
}

Now results in the correct Builder:

public class MessageMapperInfixImpl implements MessageMapperInfix {

    @Override
    public NotificationMessageDto map(NotificationMessageInfix msg) {
        if ( msg == null ) {
            return null;
        }

        _NotificationMessageDto_.Builder notificationMessageDto = _NotificationMessageDto_.builder();

        notificationMessageDto.message( msg.getMessage() );
        notificationMessageDto.tableId( msg.getTableId() );
        notificationMessageDto.type( msg.getType() );

        return notificationMessageDto.build();
    }
}

public class MessageMapperPostfixImpl implements MessageMapperPostfix {

    @Override
    public NotificationMessageDto map(NotificationMessagePostfix msg) {
        if ( msg == null ) {
            return null;
        }

        NotificationMessageDto_.Builder notificationMessageDto = NotificationMessageDto_.builder();

        notificationMessageDto.message( msg.getMessage() );
        notificationMessageDto.tableId( msg.getTableId() );
        notificationMessageDto.type( msg.getType() );

        return notificationMessageDto.build();
    }
}

public class MessageMapperPrefixImpl implements MessageMapperPrefix {

    @Override
    public NotificationMessageDto map(NotificationMessagePrefix msg) {
        if ( msg == null ) {
            return null;
        }

        _NotificationMessageDto.Builder notificationMessageDto = _NotificationMessageDto.builder();

        notificationMessageDto.message( msg.getMessage() );
        notificationMessageDto.tableId( msg.getTableId() );
        notificationMessageDto.type( msg.getType() );

        return notificationMessageDto.build();
    }
}

@sleicht

sleicht commented Mar 20, 2023 •

Copy link
Copy Markdown

Thanks for this improved handling of immutables. I created out of your examples some IT cases: sleicht@ed826f3 You can cherrypick or copy them as you like.

@Drevsh

Drevsh commented Mar 21, 2023

Copy link
Copy Markdown
Author

Nice I could not find the correct integration test (where I would have had access to the immutables annotations).
Will add them to the PR first thin tomorrow.

@Drevsh

Drevsh commented Mar 23, 2023

Copy link
Copy Markdown
Author

Could you give me a hint on how to setup the integration tests correctly? I'm unable to correctly import the tests. I tried to import them via Eclipse and Intelij but both IDEs seem to struggle with the project hierarchy... and having the tests in the resource folder

@sleicht

sleicht commented Mar 24, 2023 •

Copy link
Copy Markdown

Unfortunately I did not find a documentation how to do it "the right way". So I had to fiddle around a little bit.
After applying this patch you can import the folder integrationtest/src/test/resources/immutablesBuilderTest into intellij. With those further steps I could then run the 'ImmutablesMapperTest' in IntelliJ:

  • cd <project_root>/integrationtest/src/test/resources/immutablesBuilderTest
  • mvn clean compile -P generate-via-compiler-plugin

@Drevsh Drevsh closed this by deleting the head repository Nov 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants