Repository navigation
Properly number anonymous classes within anonymous classes - #69
Merged
Merged
Conversation
The numbering of anonymous classes is done independently by traversing the containing class in a post-order depth-first traversal, collecting any anonymous (nonqualified) classes, and numbering them in encounter order. This poses a problem when there are anonymous classes nested within the top-level anonymous classes (where top-level is in reference to the root containing class.) The traversal also encounters those classes, so it includes them in the numbering. This is contrary to the actual numbering scheme, which only accounts for the 'immediate' children of the containing class. In the added test, this would show up as `example.C$1` being numbered as `example.C$2`, because the actual `example.C$1$1` would be erroneously numbered as `example.C$1`. Fix this by skipping traversal of the children of nested classes (but not the nested classes themselves).
Because of post-order traversal, the root node would get added to the end of the map if the root node itself was an anonmyous/nonqualified class.
|
covers1624
approved these changes
Oct 24, 2026
covers1624
approved these changes
Oct 24, 2026
Matyrobbrt
approved these changes
Oct 24, 2026
|
🚀 This PR has been released as JavaSourceTransformer version |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes the numbering of nested anonymous classes (anonymous classes within anonymous classes) by skipping traversal of the children of nested classes (but not the nested classes themselves) in
PsiHelper#getNonQualifiedClassIdx.The numbering of anonymous classes is done independently by traversing the containing class in a post-order depth-first traversal, collecting any anonymous (nonqualified) classes, and numbering them in encounter order.
This poses a problem when there are anonymous classes nested within the top-level anonymous classes (where top-level is in reference to the root containing class.) The traversal also encounters those classes, so it includes them in the numbering. This is contrary to the actual numbering scheme, which only accounts for the 'immediate' children of the containing class.
In the added test, this would show up as
example.C$1being numbered asexample.C$2, because the actualexample.C$1$1would be erroneously numbered asexample.C$1.This PR also fixes a problem found while debugging, where the root node itself (if also an anonymous class) would be traversed and numbered in the map. This would be problematic for both AT validation, where an invalid nested anonymous class reference might not be caught but silently applied against the containing anonymous class, and for debugging where the map seems to have one more entry than expected. For the sake of both (and the sanity of whoever else needs to debug this), we fix that by skipping the root node for numbering.
Thanks to @covers1624 for reporting the issue.