0

I am trying to create a snippet using Java parser to add a if block.

Expression condition = JavaParser.buildSnippet(
    String.format("if (logger.%sEnabled())", logLevel)
    ).get(0);

For the above code, I am getting error in buildSnippet() method, stating its not found. I am using jdk 17 with rewrite-version 6.1.15

I am expecting an alternative for JavaParser.buildSnippet() method

1 Answers1

0

You'll likely want to look at JavaTemplate instead of JavaParser. That has an API to actually create the LST elements that you need here.

Tim
  • 19,793
  • 8
  • 70
  • 95
  • I dont have a proper understanding of template that was given in the documentation, can you suggest me in my case, how I. need to proceed. – Bhavya Penumarthi Jul 21 '23 at 22:57
  • Continued here: https://github.com/openrewrite/rewrite-logging-frameworks/issues/111 – Tim Jul 24 '23 at 11:50