How can I get line number of currently visited J.MethodInvocation in visitor?

26 Views Asked by At

I browsed all available variables, methods and arguments and couldn't find anything like this.

1

There are 1 best solutions below

0
Tim On

Copying a response from Slack: This is not a typical request, and I'm curious to know what the use case is to help you best.

We've done this once before for SQL statements I believe, but that's perhaps not something to repeat too often: https://github.com/openrewrite/rewrite-sql/blob/2b5b939112cb34a02d8a738e69d9f7248676d014/src/main/java/org/openrewrite/sql/FindSql.java#L69-L153

You might also be interested to see this implementation that goes the other direction: https://github.com/openrewrite/rewrite/pull/3829/files