openrewrite / rewrite-logging-frameworks

OpenRewrite recipes for assisting with Java logging migration tasks.
Apache License 2.0
26 stars 21 forks source link

Fix Log4jToSlf4 Single Statement If `Could not parse as Java` #186

Closed FlorianWege-HS-KL closed 1 week ago

FlorianWege-HS-KL commented 1 month ago

What's changed?

What's your motivation?

Anything in particular you'd like reviewers to focus on?

Is this in the right test class? Should there be a separate Log4jToSlf4Test class?

Checklist

timtebeek commented 1 month ago

hi @FlorianWege-HS-KL ; thanks for reporting as a runnable test! There appears to be a failure in the way the JavaTemplate is created, which only shows if the braces are missing. Here's the generated template; notice the missing ; after the logging statement.

import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.openrewrite.java.internal.template.__M__;
import org.openrewrite.java.internal.template.__P__;
public class SingleStatementIf{Logger log;
public void foo(){
/*__TEMPLATE__*/log.debug("first" + "second")/*__TEMPLATE_STOP__*/
}
private String bar(){
return null;
}
}

That likely needs a fix in openrewrite/rewrite, meaning other recipes would benefit from this fix as well. Thanks for bringing that to our attention!

timtebeek commented 1 week ago

Thanks again for the help here @FlorianWege-HS-KL ! Fixed upstream such that there's no need to test it again here.