Skip to content
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

Don't use static import on collision with local method #3729

Merged

Conversation

Bananeweizen
Copy link
Contributor

If a class declares a method with the same name as a candidate for a static import, then that will always lead to compile errors if the static import is applied. Therefore the recipe must check for not having any similarly named method locally.

What's changed?

Additional precondition for static import, namely not(DeclaresMethod("* sameNameAsMethodPattern(..)".

What's your motivation?

Quite some compile errors on larger code bases with UseStaticImport recipe. The included unit test demonstrates this and leads to uncompilable code without the change.

Anything in particular you'd like reviewers to focus on?

The method pattern is created via String manipulation. Not sure if there are better ways using MethodPattern, MethodPatternParser etc. but that was hard to explore.

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've added the license header to any new files through ./gradlew licenseFormat
  • I've used the IntelliJ IDEA auto-formatter on affected files

If a class declares a method with the same name as a candidate for a static import, then that will always lead to compile errors if the static import is applied. Therefore the recipe must check for not having any similarly named method locally.
Copy link
Contributor

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

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

Thanks for the clear example and fix! I don't think there's any other way to check really check the same from what you've done.

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
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants