Skip to content

Conversation

@thunderhook
Copy link
Contributor

@thunderhook thunderhook commented Nov 18, 2023

I hope this change has no unwanted side effects. It checks whether a fluent setters return type also can be assigned to one of its super types to support classes like this:

public static abstract class TargetBuilder<C extends Target, B extends TargetBuilder<C, B>> {

            private String testName;

            public B testName(String testName) {
                this.testName = testName;
                return self();
            }
            // ...
}

Fixes #159

@thunderhook thunderhook requested a review from filiphr November 18, 2023 22:13
@filiphr
Copy link
Member

filiphr commented Nov 26, 2023

Check my comment in #159 (comment). Is the test code working even properly with the MapStruct processor. We don't really support @SuperBuilder from Lombok, so the fix here will be a bit misleading.

@thunderhook
Copy link
Contributor Author

@filiphr Could you please have another look? I think it is now valid to support super types like this in the IDE plugin.
The example using in the test has the same structure as provided in mapstruct/mapstruct#3524, see https://github.com/mapstruct/mapstruct/pull/3542/files

Copy link
Member

@filiphr filiphr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good @thunderhook, I've added some small comments

Comment on lines 224 to 225
return Arrays.stream( returnType.getSuperTypes() )
.anyMatch( superType -> isAssignableFrom( psiType, superType ) );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to create a stream and then use anyMatch. Let's just iterate through the returnType.getSuperTypes() and do a check in the for loop.


private static boolean isAssignableFromReturnTypeOrSuperTypes(PsiType psiType, @Nullable PsiType returnType) {

if ( returnType == null ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The returnType cannot be null because in isFluentSetter we are checking method.getReturnType() != null.

@thunderhook
Copy link
Contributor Author

@filiphr Thanks for the feedback. I have made the requested changes.

@filiphr filiphr merged commit 27c6cfc into main Mar 24, 2024
@filiphr filiphr deleted the 159 branch March 24, 2024 11:45
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.

Code completion doesn't work with lombok @SuperBuilder annotation

3 participants