Skip to content

Commit 64f9362

Browse files
committed
#211 Remove methods should not be considered fluent setters.
1 parent fe429d9 commit 64f9362

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

src/main/java/org/mapstruct/intellij/util/MapstructUtil.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ public static boolean isFluentSetter(@NotNull PsiMethod method, PsiType psiType)
208208
return !psiType.getCanonicalText().startsWith( "java.lang" ) &&
209209
method.getReturnType() != null &&
210210
!isAdderWithUpperCase4thCharacter( method ) &&
211+
!isRemoverWithUpperCase7thCharacter( method ) &&
211212
isAssignableFromReturnTypeOrSuperTypes( psiType, method.getReturnType() );
212213
}
213214

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

243+
private static boolean isRemoverWithUpperCase7thCharacter(@NotNull PsiMethod method) {
244+
String methodName = method.getName();
245+
return methodName.startsWith( "remove" ) &&
246+
methodName.length() > 6 &&
247+
Character.isUpperCase( methodName.charAt( 6 ) );
248+
}
249+
242250
/**
243251
* Checks if the {@code method} is a possible builder creation method.
244252
* <p>

testData/mapping/dto/CarDto.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ public void addPassenger(PersonDto passenger) {
8383
this.passengers.add( passenger );
8484
}
8585

86+
public void removePassenger(PersonDTO passenger) {
87+
if ( this.passengers != null ) {
88+
this.passengers.remove( passenger );
89+
}
90+
}
91+
8692
public Long getPrice() {
8793
return price;
8894
}

testData/mapping/dto/FluentCarDto.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ public FluentCarDto addPassenger(PersonDto passenger) {
7575
return this;
7676
}
7777

78+
public FluentCarDto removePassenger(PersonDto passenger) {
79+
if ( this.passengers != null ) {
80+
this.passengers.remove( passenger );
81+
}
82+
return this;
83+
}
84+
7885
public Long getPrice() {
7986
return price;
8087
}

0 commit comments

Comments
 (0)