PicnicSupermarket / error-prone-support

Error Prone extensions: extra bug checkers and a large battery of Refaster rules.

Home Page:https://error-prone.picnic.tech

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rewrite `buildDescription(tree).addFix(fix).build()` to `describeMatch(tree, fix)`

rickie opened this issue · comments

Problem

In commit google/error-prone@570f0bf the DescribeMatch BugChecker got removed from Error Prone with the explanation that it got ported to Refaster. As we cannot see these kind of changes, we have to write these Refaster rules ourselves 😄.

Description of the proposed new feature

  • Support a stylistic preference.
  • Avoid a common gotcha, or potential problem.

I would like to rewrite the following code:

return buildDescription(tree).addFix(fix).build();

to:

return describeMatch(tree, fix);

Considerations

In the test code of the deleted BugChecker there is an edge case where it shouldn't propose a fix in the abstract class BugChecker { itself. However, to be honest, I don't think we need to take this case into account.

We might need to introduce a new Refaster rule collection for this Refaster rule or list it under AssortedRules.

I looked into this a few months ago, but for some reason this doesn't seem to work with Refaster as one would expect. My code is here; perhaps I overlooked something? (I did not yet attach a debugger.)