rewrite icon indicating copy to clipboard operation
rewrite copied to clipboard

Rename argument to hint that autoFormat expects parent cursor

Open timtebeek opened this issue 7 months ago • 0 comments

When folks accidentally pass in getCursor() they see an error in the tests:

Caused by: java.lang.AssertionError: The `parent` cursor must not point to the same `tree` as the tree to be visited.
This usually indicates that you have used getCursor() where getCursor().getParent() is appropriate.
This is a test-only validation which can be opted out of by configuring your test's type validation options with `cursorAcyclic(false)`.
	at org.openrewrite.TreeVisitor.visit(TreeVisitor.java:145)
	at org.openrewrite.java.format.AutoFormatVisitor.visit(AutoFormatVisitor.java:58)
	at org.openrewrite.java.format.AutoFormatVisitor.visit(AutoFormatVisitor.java:35)
	at org.openrewrite.java.JavaVisitor.autoFormat(JavaVisitor.java:95)
	at org.openrewrite.staticanalysis.ReorderAnnotations$1.visitMethodDeclaration(ReorderAnnotations.java:60)
	at org.openrewrite.staticanalysis.ReorderAnnotations$1.visitMethodDeclaration(ReorderAnnotations.java:47)
	at org.openrewrite.java.tree.J$MethodDeclaration.acceptJava(J.java:4036)
	at org.openrewrite.java.tree.J.accept(J.java:63)

Figured we can hint at proper use in the API as well by renaming the arguments to show what's expected.

timtebeek avatar Jun 14 '25 19:06 timtebeek