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

Fix LoggerEnclosingClass edge cases for type parameters and anonymous classes #1171

Merged
merged 2 commits into from
Jan 16, 2020

Conversation

carterkozak
Copy link
Contributor

Before this PR

Possible to suggest LoggerFactory.getLogger(Bar<T>.class) instead of LoggerFactory.getLogger(Bar.class).
Also possible to fail when loggers are defined as fields of anonymous classes.

After this PR

==COMMIT_MSG==
Fix LoggerEnclosingClass edge cases for type parameters and anonymous classes
==COMMIT_MSG==

@changelog-app
Copy link

changelog-app bot commented Jan 16, 2020

Generate changelog in changelog/@unreleased

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

Fix LoggerEnclosingClass edge cases for type parameters and anonymous classes

Check the box to generate changelog(s)

  • Generate changelog entry

private static Symbol.ClassSymbol enclosingConcreteClass(Symbol.ClassSymbol input) {
Symbol.ClassSymbol current = input;
while (current != null && current.isAnonymous()) {
current = ASTHelpers.enclosingClass(current);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I haven't encountered this in the wild (it's an odd thing to do) but fixed it while I'm here.

@@ -83,8 +83,16 @@ public Description matchVariable(VariableTree tree, VisitorState state) {
return buildDescription(classArgument)
.addFix(fix.replace(
classArgument,
SuggestedFixes.prettyType(state, fix, enclosingClassSymbol.type) + ".class")
enclosingClassSymbol.name + ".class")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Simple name is sufficient here because the code we're updating is nested within the type -- the previous approach using prettyType wasn't necessary and included type parameters.

@carterkozak
Copy link
Contributor Author

dozer?

@bulldozer-bot bulldozer-bot bot merged commit b2678ed into develop Jan 16, 2020
@bulldozer-bot bulldozer-bot bot deleted the ckozak/fix_logger_enclosing_class branch January 16, 2020 13:41
@svc-autorelease
Copy link
Collaborator

Released 2.49.1

This was referenced Jan 16, 2020
This was referenced Jan 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants