-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#124 Add custom Immutables and FreeBuilder fluent setter MapstructUtils
- Loading branch information
Stephan Leicht Vogt (C803964)
committed
May 9, 2023
1 parent
c27f853
commit 8c3d9ee
Showing
14 changed files
with
386 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/org/mapstruct/intellij/util/DefaultMapstructUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright MapStruct Authors. | ||
* | ||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package org.mapstruct.intellij.util; | ||
|
||
public class DefaultMapstructUtil extends MapstructUtil { | ||
/** | ||
* Hide constructor. | ||
*/ | ||
protected DefaultMapstructUtil() { | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/org/mapstruct/intellij/util/FreeBuildersMapstructUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright MapStruct Authors. | ||
* | ||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package org.mapstruct.intellij.util; | ||
|
||
import com.intellij.psi.PsiMethod; | ||
import com.intellij.psi.PsiType; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* Mapstruct util for FreeBuilder. | ||
* FreeBuilder adds a lot of other methods that can be considered as fluent setters. Such as: | ||
* <ul> | ||
* <li>{@code from(Target)}</li> | ||
* <li>{@code mapXXX(UnaryOperator)}</li> | ||
* <li>{@code mutateXXX(Consumer)}</li> | ||
* <li>{@code mergeFrom(Target)}</li> | ||
* <li>{@code mergeFrom(Target.Builder)}</li> | ||
* </ul> | ||
* <p> | ||
* When the JavaBean convention is not used with FreeBuilder then the getters are non-standard and MapStruct | ||
* won't recognize them. Therefore, one needs to use the JavaBean convention in which the fluent setters | ||
* start with {@code set}. | ||
*/ | ||
public class FreeBuildersMapstructUtil extends MapstructUtil { | ||
/** | ||
* Hide constructor. | ||
*/ | ||
protected FreeBuildersMapstructUtil() { | ||
} | ||
|
||
@Override | ||
public boolean isFluentSetter(@NotNull PsiMethod method, PsiType psiType) { | ||
// When using FreeBuilder one needs to use the JavaBean convention, which means that all setters will start | ||
// with set | ||
return false; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/org/mapstruct/intellij/util/ImmutablesMapstructUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright MapStruct Authors. | ||
* | ||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package org.mapstruct.intellij.util; | ||
|
||
import com.intellij.psi.PsiMethod; | ||
import com.intellij.psi.PsiType; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* Mapstruct util for Immutables. | ||
* The generated Immutables also have a from that works as a copy. Our default strategy considers this method | ||
* as a setter with a name {@code from}. Therefore, we are ignoring it. | ||
*/ | ||
public class ImmutablesMapstructUtil extends MapstructUtil { | ||
/** | ||
* Hide constructor. | ||
*/ | ||
protected ImmutablesMapstructUtil() { | ||
} | ||
|
||
@Override | ||
public boolean isFluentSetter(@NotNull PsiMethod method, PsiType psiType) { | ||
return super.isFluentSetter( method, psiType ) && !method.getName().equals( "from" ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.