IDEA-120799 (Quick-fix for "Unnecessary parentheses" changes expression semantics)

This commit is contained in:
Bas Leijdekkers
2014-02-18 12:32:48 +01:00
parent 0ced324b06
commit 17dcc983f5
2 changed files with 12 additions and 3 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2013 Dave Griffith, Bas Leijdekkers
* Copyright 2003-2014 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -505,15 +505,16 @@ public class ParenthesesUtils {
}
}
final IElementType parentOperator = parentPolyadicExpression.getOperationTokenType();
final IElementType childOperator = childPolyadicExpression.getOperationTokenType();
if (ignoreClarifyingParentheses) {
final IElementType childOperator = childPolyadicExpression.getOperationTokenType();
if (!childOperator.equals(parentOperator)) {
return true;
}
}
final PsiExpression[] parentOperands = parentPolyadicExpression.getOperands();
if (!PsiTreeUtil.isAncestor(parentOperands[0], expression, false)) {
if (!isCommutativeOperator(parentOperator)) {
if (!isAssociativeOperation(parentPolyadicExpression) ||
JavaTokenType.DIV == childOperator || JavaTokenType.PERC == childOperator) {
return true;
}
}
@@ -112,4 +112,12 @@ public class UnnecessaryParenthesesInspection
Object info = new Object[]{"abc"};
String s = (String)((Object[])info)[0];
}
void zz() {
int a = 10;
int b = 20;
final int i = a * ((b + 2) / 3); // no warn
final int j = a * ((b + 2) % 3); // no warn
}
}