-
Notifications
You must be signed in to change notification settings - Fork 355
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
Handle erroneous nodes in open rewrite #4412
Conversation
rewrite-java-test/src/test/java/org/openrewrite/java/JavaParserTest.java
Outdated
Show resolved
Hide resolved
rewrite-java-test/src/test/java/org/openrewrite/java/JavaParserTest.java
Outdated
Show resolved
Hide resolved
rewrite-java-test/src/test/java/org/openrewrite/java/JavaParserTest.java
Outdated
Show resolved
Hide resolved
rewrite-java-test/src/test/java/org/openrewrite/java/JavaParserTest.java
Outdated
Show resolved
Hide resolved
Thanks for the continued work on this @vudayani ! I must say it's great to see this come in, also taking into account the out-of-bounds-delivered raw feedback. :) I've fixed a minor conflict with imports on main, and added two missing license headers. Let us know if/when you consider this ready for review, or whether there's additional work you still plan to do. |
I think this PR is ready for review and more feedback... Likely , there will be more work to do. |
rewrite-java-test/src/test/java/org/openrewrite/java/JavaParserTest.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/main/java/org/openrewrite/java/search/FindCompileErrors.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/main/java/org/openrewrite/java/table/CompileErrors.java
Outdated
Show resolved
Hide resolved
rewrite-java-17/src/main/java/org/openrewrite/java/isolated/ReloadableJava17ParserVisitor.java
Show resolved
Hide resolved
Thanks for the continued work on this @vudayani ! We're on to a downstream failure right now it seems. `class org.openrewrite.java.tree.J$Erroneous cannot be cast to class org.openrewrite.java.tree.Expression` in `org.openrewrite.java.format.SpacesVisitor`.
|
…rTest.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…rTest.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
d6a680a
to
611d18b
Compare
Thanks for your patience @timtebeek |
@timtebeek It is ready for review and all tests seem to pass locally. Thanks again for your patience, and sorry for the delay in getting back on this. |
Thanks a lot for all the hard work here @vudayani ! I've tagged Knut for help with review as I'm traveling, and I know Jonathan has been quite busy these past couple of weeks. I hope we can get this in before Wednesday's release, but that'll depend on their feedback as well. |
rewrite-java/src/main/java/org/openrewrite/java/table/CompileErrors.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some suggestions could not be made:
- rewrite-core/src/test/java/org/openrewrite/RecipeLifecycleTest.java
- lines 142-142
Where are we with this @timtebeek ? What do you think? Is there anything specific missing before this can be merged? Would be awesome to finally push this forward into main... :-) |
Thanks for the reminder @martinlippert ; I'd already tagged folks for additional review, but I've now also raised this on an internal channel, as I understand you're eager to get this in for your purposes, as are we to see this finalized. |
rewrite-java/src/main/java/org/openrewrite/java/search/FindCompileErrors.java
Outdated
Show resolved
Hide resolved
rightPadded = (JRightPadded<J2>) JRightPadded.build(getErroneous(List.of(rightPadded))); | ||
} | ||
if (endPos(t) == cursor && rightPadded.getElement() instanceof J.Erroneous) { | ||
cursor++; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part is unclear to me. Why advance the cursor a single character? Can we add a comment explaining this? Is there a specific test case which would demonstrate this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd have to dig into this to recall why this was done. Hopefully a test would fail if I comment this out. Will get back on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some suggestions could not be made:
- rewrite-groovy/src/test/java/org/openrewrite/groovy/tree/BinaryTest.java
- lines 209-209
- rewrite-groovy/src/test/java/org/openrewrite/groovy/tree/ClassDeclarationTest.java
- lines 297-297
- lines 311-311
- rewrite-groovy/src/test/java/org/openrewrite/groovy/tree/CompilationUnitTest.java
- lines 132-132
- rewrite-groovy/src/test/java/org/openrewrite/groovy/tree/MethodDeclarationTest.java
- lines 189-189
- rewrite-groovy/src/test/java/org/openrewrite/groovy/tree/VariableDeclarationsTest.java
- lines 190-190
Thanks a lot @sambsnyd for taking a look, providing feedback, and for your approval here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the work done here @vudayani , @BoykoAlex and all the others involved. Appreciate you working through the feedback, and the patience shown as we figured out how to best fit this in. Great to see that you took it upon yourselves to add this feature.
* Handle erroneous nodes in a tree * Add visitErroneous to all java parser visitors * Override the visitVariable to handle erroneous identifier names set by JavacParser * retain name and suffix for erroneous varDecl * override the visitVariable to handle error identifiers in all java parser visitors * Remove sysout * Update rewrite-java-test/src/test/java/org/openrewrite/java/JavaParserTest.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update rewrite-java-test/src/test/java/org/openrewrite/java/JavaParserTest.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * handle errors in method params, variable declarations, fix tests * Add missing license headers * fix compilation error * fix compilation error in Java8ParserVisitor * Apply code suggestions from bot * fix cases for statementDelim * fix block statement template generator to handle adding semicolon * fix ChangeStaticFieldToMethod recipe * Record compiler errors from erroneous LST nodes * Adjustments for comments * Java 17 parser adjustment alos in 8, 11 and 21 * Add `FindCompileErrorsTest` & move away from deprecated `print()` --------- Co-authored-by: Jonathan Schnéider <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Tim te Beek <[email protected]> Co-authored-by: aboyko <[email protected]>
What's changed?
The PR introduces handling for erroneous nodes in OpenRewrite. Currently, when there is an error in the LST, the parser may attempt to recover by ignoring or removing the erroneous node to produce a valid LST. The changes in this PR address this by adding a mechanism to handle these erroneous nodes instead of ignoring them, ensuring that they are preserved and correctly processed.
What's your motivation?
The motivation behind this PR is to handle scenarios where errors in the source code could lead to discrepancies in the computed results. When any recipe is executed, the edits are computed on a parsed LST without the error statement. By handling erroneous nodes, we ensure that the error lines are retained and reflected correctly in the LST, leading to more accurate edits and transformations.
Anything in particular you'd like reviewers to focus on?
Anyone you would like to review specifically?
Have you considered any alternatives or workarounds?
Any additional context
This update is crucial for ensuring consistency in scenarios where error lines could affect the outcome of recipes and transformations.
Checklist