Skip to content

#211 Remove methods should not be considered fluent setters. #212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/main/java/org/mapstruct/intellij/util/MapstructUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ public static boolean isFluentSetter(@NotNull PsiMethod method, PsiType psiType)
return !psiType.getCanonicalText().startsWith( "java.lang" ) &&
method.getReturnType() != null &&
!isAdderWithUpperCase4thCharacter( method ) &&
!isRemoverWithUpperCase7thCharacter( method ) &&
isAssignableFromReturnTypeOrSuperTypes( psiType, method.getReturnType() );
}

Expand Down Expand Up @@ -239,6 +240,13 @@ private static boolean isAdderWithUpperCase4thCharacter(@NotNull PsiMethod metho
Character.isUpperCase( methodName.charAt( 3 ) );
}

private static boolean isRemoverWithUpperCase7thCharacter(@NotNull PsiMethod method) {
String methodName = method.getName();
return methodName.startsWith( "remove" ) &&
methodName.length() > 6 &&
Character.isUpperCase( methodName.charAt( 6 ) );
}

/**
* Checks if the {@code method} is a possible builder creation method.
* <p>
Expand Down
6 changes: 6 additions & 0 deletions testData/mapping/dto/CarDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ public void addPassenger(PersonDto passenger) {
this.passengers.add( passenger );
}

public void removePassenger(PersonDTO passenger) {
if ( this.passengers != null ) {
this.passengers.remove( passenger );
}
}

public Long getPrice() {
return price;
}
Expand Down
7 changes: 7 additions & 0 deletions testData/mapping/dto/FluentCarDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ public FluentCarDto addPassenger(PersonDto passenger) {
return this;
}

public FluentCarDto removePassenger(PersonDto passenger) {
if ( this.passengers != null ) {
this.passengers.remove( passenger );
}
return this;
}

public Long getPrice() {
return price;
}
Expand Down