Description
Since ab45284 the PatternMatchingInstanceof
check leaves parentheses that are flagged by the UnnecessaryParentheses check. I guess it is not desired that one Error Prone check produces code that another check than complains about?
One particular important case is:
if (o instanceof Test) {
Test t = ((Test) o);
}
The parentheses make Error Prone miss the fact that it can eliminate the variable declaration and directly use o instanceof Test t
.
Other cases found inside our code case and flagged by UnnecessaryParentheses are in return statements, inside divisions, and ternary operators. It is easy to extend PatternMatchingInstanceof.requiresParentheses()
and fix particular cases, and I could do so in a PR, but I wonder whether this is the best approach, or whether the function should instead use a list of cases with required parentheses? So I wanted to clarify this upfront.