Skip to content

Added recipe to remove @VisibleForTesting annotation when used from production code #689

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

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

JohannisK
Copy link
Contributor

@JohannisK JohannisK commented Apr 2, 2025

What's changed?

Added recipe to remove @VisibleForTesting annotation when used from production code

What's your motivation?

Anyone you would like to review specifically?

@jevanlingen
@Laurens-W
@greg-at-moderne

@JohannisK JohannisK requested a review from jkschneider April 3, 2025 14:43
return target;
}
};
return Preconditions.check(new IsLikelyNotTest().getVisitor(), visitor);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UseType<>() is not working here. It does work with the FQN, but not with "*.VisibleForTesting"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That might be a limitation in openrewrite/rewrite; ideally we'd detect the use of that annotation on the type, especially when we include implicit usages, but it appears we do not for now. Could require a fix upstream, but not pressing for now.

@timtebeek timtebeek changed the title Added recipe to remove @VisibleForTesting annotation when used from production code Added recipe to remove @VisibleForTesting annotation when used from production code Apr 4, 2025
@timtebeek timtebeek added the recipe Recipe request label Apr 4, 2025
@timtebeek
Copy link
Contributor

As discussed we're still seeing performance issues, likely because we're having to visit & determine the type of all references to classes, methods and fields to see if their target is annotated with VisibleForTesting. That's because we can not currently use any narrower precondition in our scanning visitor:
https://github.com/openrewrite/rewrite-testing-frameworks/pull/689/files#diff-7ad8934e882d4b7ce7b095083167e188aa0bb1b228249f8e76afab4da7e876d2R129

Perhaps it'd be an option to expand UsesType such that whenincludeImplicit = True, that it then also matches compilation units where references to targets annotated with the typePattern, but that would require changes to the parser to prepopulate TypesInUse, which could shift performance impact to the parser instead.

@timtebeek timtebeek marked this pull request as draft April 16, 2025 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
recipe Recipe request
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

Remove @VisibleForTesting if variable is accessed from production code
5 participants