error-prone-support
error-prone-support copied to clipboard
Introduce a check to simplify time expressions in annotations
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
andgetDefaultTimeUnit
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. :)
Thx for the feedback guys! I'll try to circle back to this PR somewhere this week. :)
I encountered the CanonicalDuration
BugPattern today. I made me think of this check, maybe there is some logic there that we can (re-)use?
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 ;)