SizeReplaceableByIsEmpty: support parentheses

This commit is contained in:
Tagir Valeev
2018-07-06 13:58:41 +07:00
parent 3b93111a69
commit 6a0d246b06
2 changed files with 8 additions and 4 deletions
@@ -93,9 +93,9 @@ public class SizeReplaceableByIsEmptyInspection extends BaseInspection {
@Override
protected void doFix(Project project, ProblemDescriptor descriptor) {
final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)descriptor.getPsiElement();
PsiExpression operand = binaryExpression.getLOperand();
PsiExpression operand = PsiUtil.skipParenthesizedExprDown(binaryExpression.getLOperand());
if (!(operand instanceof PsiMethodCallExpression)) {
operand = binaryExpression.getROperand();
operand = PsiUtil.skipParenthesizedExprDown(binaryExpression.getROperand());
}
if (!(operand instanceof PsiMethodCallExpression)) {
return;
@@ -131,8 +131,8 @@ public class SizeReplaceableByIsEmptyInspection extends BaseInspection {
if (!ComparisonUtils.isComparison(expression)) {
return;
}
final PsiExpression rhs = expression.getROperand();
final PsiExpression lhs = expression.getLOperand();
final PsiExpression rhs = PsiUtil.skipParenthesizedExprDown(expression.getROperand());
final PsiExpression lhs = PsiUtil.skipParenthesizedExprDown(expression.getLOperand());
final boolean flipped;
if (lhs instanceof PsiMethodCallExpression) {
flipped = false;
@@ -17,6 +17,10 @@ public class SizeReplaceableByIsEmpty {
return <warning descr="'c.size() == 0' can be replaced with 'c.isEmpty()'">c.size() == 0</warning>;
}
boolean parens(Collection c) {
return <warning descr="'(c.size()) == (0)' can be replaced with 'c.isEmpty()'">(c.size()) == (0)</warning>;
}
class String {
public int length() {
return 1;