Adding or subtracting a number and itself
Over a year ago, I ran a check over Google code for two patterns:
x - x(x + x) / 2(but probably evenx + xis suspicious)
Results are in internal CL 49788955. I see some of the same kinds of things you see for x == x (e.g., foo1.getX() - foo1.getX() instead of foo1.getX() - foo2.getX()). I also see some people using bad date APIs that require January = 0, for which they write 1 - 1 for January, 12 - 1 for December, etc. There may be other patterns where we wouldn't want to do this. Maybe we can just throw out anything with literals?
Making it an error might be too aggressive, but this could be a useful warning.
I agree that we'd probably want to ignore literals, and maybe also floating point.
IdentityBinaryExpression exists but currently lets both of the patterns above through. I suspect that we could find a useful heuristic (e.g., "anything with literals"), but I don't know how hard it would end up being.