From ead663e7da49ea521341d786d25a2a903070d7e5 Mon Sep 17 00:00:00 2001 From: Laurens Westerlaken Date: Thu, 21 Nov 2024 14:17:37 +0100 Subject: [PATCH] Add `lombok-mapstruct-binding` during Java 17 migration when both lombok 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 --- .../lang/MigrateSecurityManagerMulticast.java | 6 ++++- .../META-INF/rewrite/java-version-17.yml | 22 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/openrewrite/java/migrate/lang/MigrateSecurityManagerMulticast.java b/src/main/java/org/openrewrite/java/migrate/lang/MigrateSecurityManagerMulticast.java index 2caea0a49f..9ed8628394 100644 --- a/src/main/java/org/openrewrite/java/migrate/lang/MigrateSecurityManagerMulticast.java +++ b/src/main/java/org/openrewrite/java/migrate/lang/MigrateSecurityManagerMulticast.java @@ -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; } diff --git a/src/main/resources/META-INF/rewrite/java-version-17.yml b/src/main/resources/META-INF/rewrite/java-version-17.yml index e16fded782..0aa6afffda 100644 --- a/src/main/resources/META-INF/rewrite/java-version-17.yml +++ b/src/main/resources/META-INF/rewrite/java-version-17.yml @@ -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 @@ -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