Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand cursor documentation #264

Open
mike-solomon opened this issue Feb 6, 2024 · 1 comment
Open

Expand cursor documentation #264

mike-solomon opened this issue Feb 6, 2024 · 1 comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@mike-solomon
Copy link
Contributor

mike-solomon commented Feb 6, 2024

From Slack:

Q: I have a case where I have one line in a method and need to insert say 5-6 lines replacing it.
When I do it using visitMethodDecl I get the error that expected a template which will replace 1 statement with 1 but created 6 ..What is the workaround for it ?

Answer: Read this thread

From Tim:

one option is to return a block of statements { a; b; c; }.. and then call RemoveUnneededBlock right after

it's a creative way to solve this that I've used in the past as well.. works well enough for the code you already have most likely

the other option is to look up to the block that the variable declaration that you have is defined within, and replace the statements within that block with a new or mapped collection

both of those end up with the same result: your variable declaration replaced by multiple statements, but each only replacing one element of the LST with another

here's an example where I call RemoveUnneededBlock after a replacement

To help, we should expand on getCursor, updateCursor, and new Cursor as well as provide examples.

@mike-solomon mike-solomon added documentation Improvements or additions to documentation enhancement New feature or request labels Feb 6, 2024
@mike-solomon
Copy link
Contributor Author

@timtebeek When you have time, would you mind assisting with examples here?

Specifically:

  • I am not sure when you'd use the different cursor options (getCursor, updateCursor, new Cursor).
    • For these, it would be swell to have an example with them.
  • I'd love an example of some code that returns a block of statements and then calls the remove unneeded block to have some context as to why someone might do that.

Once I have some examples and more context, I'm happy to update the doc accordingly. ^_^

@timtebeek timtebeek moved this to Backlog in OpenRewrite Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
Status: Backlog
Development

No branches or pull requests

1 participant