error-prone-support icon indicating copy to clipboard operation
error-prone-support copied to clipboard

Introduce a check to simplify time expressions in annotations

Open nathankooij opened this issue 3 years ago • 3 comments

I wish to expand the test suite further, but it should already give a good indication of what is possible with this check.

A few things:

  • I am not entirely certain if what I'm doing in getTimeUnit and getDefaultTimeUnit is always safe.
  • We can extract some of the things to utilities which will a) make this code cleaner b) allow us to re-use it in other checks, some things: - Returning a map of attributes -> expression (or assignment trees if that's always the tree) by the matcher; - Extracting enum value from an expression; - Extracting default attributes on annotations; - An "annotation builder" to avoid special casing the implict value attribute.

I know @Stephan202 mentioned he has some of these on a branch already, so curious to see what we can already do out of the box. :)

nathankooij avatar Sep 30 '21 15:09 nathankooij

Thx for the feedback guys! I'll try to circle back to this PR somewhere this week. :)

nathankooij avatar Oct 11 '21 09:10 nathankooij

I encountered the CanonicalDuration BugPattern today. I made me think of this check, maybe there is some logic there that we can (re-)use?

rickie avatar Aug 24 '23 11:08 rickie

Yep, likely! Too bad it's all private, so that would entail some copying. Alternatively we could try to contribute improvements upstream, possibly by extracting shared logic to a separate class. (For this annotation case I'm not sure that a banlist applies.) Would then first open an issue to discuss that possibility, though.

Thx for the feedback guys! I'll try to circle back to this PR somewhere this week. :)

I suppose that @nathankooij currently resides in the vicinity of a black hole ;)

Stephan202 avatar Aug 26 '23 07:08 Stephan202