Fix application of ATs to anonymous class members - #67
Merged
Merged
Conversation
Last commit published: f9275998fe28b9a2d30a2bd093cfa79af916c93e - version: PR PublishingThe artifacts published by this PR:
Repository DeclarationIn order to use the artifacts published by the PR, add the following repository to your buildscript: repositories {
maven {
name = "Maven for PR #67" // https://github.com/neoforged/JavaSourceTransformer/pull/67
url = uri("https://prmaven.neoforged.net/JavaSourceTransformer/pr67")
content {
includeModule("net.neoforged.jst", "jst-api")
includeModule("net.neoforged.jst", "jst-cli")
includeModule("net.neoforged.jst", "jst-cli-bundle")
}
}
} |
Matyrobbrt
approved these changes
Sep 10, 2026
|
🚀 This PR has been released as JavaSourceTransformer version |
This was referenced Sep 10, 2026
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 application of access transformers (specific or wildcard) to anonymous class members.
The targeted class check in
ApplyATsVisitorexists to skip visiting a class or its members when it is not a target, but still visit its inner classes. However, anonymous classes are not inner classes, and exists only as part of a method code or field declaration. Therefore, the check will fail for any ATs targeting anonymous classes, unless the parent class is also a target.Further to that,
ClassUtil.getJVMClassNamedoes not work for anonymous classes, which means even if the above check were worked around with an AT targeting the parent class, the AT for anonymous class targets would still fail because the visitor thinks these classes have no names.To fix these, we (a)
remove the targeted class check, so it reaches any class, even those defined anonymouslymodify the targeted class check to visit classes whose child classes are targeted; and (b) create a helper that invokesPsiHelper.getBinaryClassNamewhen necessary to get class names even for anonymous classes.A side-effect here is that the visitor will visit every single class in full, which may reduce performance. I couldn't think of or find a way to reintroduce the targeted class check that would work.UPDATE: I've found a way to modify the targeted class check such that it visits classes whose child classes are targeted. See the comments in the visitor for more details.