Skip to content

Commit 3dbefb5

Browse files
Use JavaTemplate.apply() static method
Use this link to re-run the recipe: https://app.moderne.io/recipes/org.openrewrite.java.recipes.UseJavaTemplateStaticApply?organizationId=QUxML01vZGVybmUvTW9kZXJuZSArIE9wZW5SZXdyaXRl Co-authored-by: Moderne <team@moderne.io>
1 parent 86e5a6b commit 3dbefb5

2 files changed

Lines changed: 2 additions & 11 deletions

File tree

src/main/java/org/openrewrite/java/logging/ParameterizedLogging.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
132132
newArgList.add(possibleThrowable);
133133
}
134134

135-
m = JavaTemplate.builder(escapeDollarSign(messageBuilder.toString()))
136-
.build()
137-
.apply(new Cursor(getCursor().getParent(), m), m.getCoordinates().replaceArguments(), newArgList.toArray());
135+
m = JavaTemplate.apply(escapeDollarSign(messageBuilder.toString()), new Cursor(getCursor().getParent(), m), m.getCoordinates().replaceArguments(), newArgList.toArray());
138136
} else if (logMsg instanceof J.Identifier && TypeUtils.isAssignableTo("java.lang.Throwable", logMsg.getType())) {
139137
return m;
140138
} else if (!TypeUtils.isString(logMsg.getType()) && logMsg.getType() instanceof JavaType.Class &&

src/main/java/org/openrewrite/java/logging/slf4j/JulParameterizedArguments.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
131131
}
132132

133133
String slf4jFormatString = escapeForJavaStringLiteral(originalFormatString.replaceAll("\\{\\d*}", "{}"));
134-
J.MethodInvocation updatedMi = JavaTemplate.builder(newName + "(\"#{}\",#{anyArray(Object)})")
135-
.build()
136-
.apply(
137-
getCursor(),
138-
method.getCoordinates().replaceMethod(),
139-
slf4jFormatString,
140-
updatedStringFormatArgument
141-
);
134+
J.MethodInvocation updatedMi = JavaTemplate.apply(newName + "(\"#{}\",#{anyArray(Object)})", getCursor(), method.getCoordinates().replaceMethod(), slf4jFormatString, updatedStringFormatArgument);
142135

143136
// In case of logger.log(Level.INFO, "Hello {0}, {0}", "foo")
144137
if (!(stringFormatArgument instanceof J.NewArray) && originalIndices.size() > 1) {

0 commit comments

Comments
 (0)