Skip to content

Fix application of ATs to anonymous class members - #67

Merged
sciwhiz12 merged 4 commits into
mainfrom
anonymous-classes
Sep 10, 2026
Merged

sciwhiz12 merged 4 commits into
mainfrom
anonymous-classes

Conversation

@sciwhiz12

@sciwhiz12 sciwhiz12 commented Sep 9, 2026

Copy link
Copy Markdown
Member

This PR fixes the application of access transformers (specific or wildcard) to anonymous class members.

The targeted class check in ApplyATsVisitor exists 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.getJVMClassName does 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 invokes PsiHelper.getBinaryClassName when 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.

@sciwhiz12
sciwhiz12 requested a review from Matyrobbrt September 9, 2026 12:14
@sciwhiz12 sciwhiz12 added the bug Something isn't working label Sep 9, 2026
@neoforged-pr-publishing

neoforged-pr-publishing Bot commented Sep 9, 2026

Copy link
Copy Markdown
  • Publish PR to GitHub Packages

Last commit published: f9275998fe28b9a2d30a2bd093cfa79af916c93e - version: 2.0.15-pr-67-anonymous-classes

PR Publishing

The artifacts published by this PR:

Repository Declaration

In 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")
        }
    }
}

@sciwhiz12
sciwhiz12 merged commit fbf92a7 into main Sep 10, 2026
2 checks passed
@sciwhiz12
sciwhiz12 deleted the anonymous-classes branch September 10, 2026 16:24
@neoforged-releases

Copy link
Copy Markdown

🚀 This PR has been released as JavaSourceTransformer version 2.0.11.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants