Skip to content

Commit

Permalink
Add lombok-mapstruct-binding during Java 17 migration when both lom…
Browse files Browse the repository at this point in the history
…bok and mapstruct are used (#610)

* Add recipe for adding lombok-mapstruct-binding annotation processor when both mapstruct and lombok are used

* Apply suggestions from code review

* Fix failing test by rewriting adjusting the MethodType

---------

Co-authored-by: Tim te Beek <[email protected]>
  • Loading branch information
Laurens-W and timtebeek authored Nov 21, 2024
1 parent 46abd43 commit ead663e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
J.MethodInvocation m = super.visitMethodInvocation(method, ctx);

if (MULTICAST_METHOD.matches(m) && m.getArguments().size() == 2) {
return m.withArguments(Collections.singletonList(m.getArguments().get(0)));
return m.withArguments(Collections.singletonList(m.getArguments().get(0)))
.withMethodType(m.getMethodType()
.withParameterNames(m.getMethodType().getParameterNames().subList(0, 1))
.withParameterTypes(m.getMethodType().getParameterTypes().subList(0, 1))
);
}
return m;
}
Expand Down
22 changes: 22 additions & 0 deletions src/main/resources/META-INF/rewrite/java-version-17.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ recipeList:
groupId: com.google.inject
artifactId: guice
newVersion: 5.x
- org.openrewrite.java.migrate.AddLombokMapstructBinding

---
type: specs.openrewrite.org/v1beta/recipe
Expand Down Expand Up @@ -285,3 +286,24 @@ recipeList:
methodPattern: 'java.lang.Runtime traceInstructions(boolean)'
- org.openrewrite.java.RemoveMethodInvocations:
methodPattern: 'java.lang.Runtime traceMethodCalls(boolean)'
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.migrate.AddLombokMapstructBinding
displayName: Add `lombok-mapstruct-binding` when both MapStruct and Lombok are used
description: Add the `lombok-mapstruct-binding` annotation processor as needed when both MapStruct and Lombok are used.
tags:
- java17
preconditions:
- org.openrewrite.java.dependencies.DependencyInsight:
groupIdPattern: org.projectlombok
artifactIdPattern: lombok
- org.openrewrite.java.dependencies.DependencyInsight:
groupIdPattern: org.mapstruct
artifactIdPattern: mapstruct
recipeList:
- org.openrewrite.gradle.AddDependency:
groupId: org.projectlombok
artifactId: lombok-mapstruct-binding
version: 0.2.0
configuration: annotationProcessor
acceptTransitive: false

0 comments on commit ead663e

Please sign in to comment.