mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Really fix IDEA-75562
This commit is contained in:
+1
-1
@@ -185,7 +185,7 @@ public class ReplaceAssignmentWithOperatorAssignmentInspection extends BaseInspe
|
||||
if (operands.length < 2) {
|
||||
return;
|
||||
}
|
||||
if (operands.length > 2 && !ParenthesesUtils.isCommutativeBinaryOperator(polyadicExpression.getOperationTokenType())) {
|
||||
if (operands.length > 2 && !ParenthesesUtils.isAssociativeOperation(polyadicExpression)) {
|
||||
return;
|
||||
}
|
||||
for (PsiExpression operand : operands) {
|
||||
|
||||
@@ -96,6 +96,32 @@ public class ParenthesesUtils {
|
||||
token.equals(JavaTokenType.GTGTGT));
|
||||
}
|
||||
|
||||
public static boolean isAssociativeOperation(PsiPolyadicExpression expression) {
|
||||
final IElementType tokenType = expression.getOperationTokenType();
|
||||
final PsiType type = expression.getType();
|
||||
final PsiPrimitiveType primitiveType;
|
||||
if (type instanceof PsiClassType) {
|
||||
primitiveType = PsiPrimitiveType.getUnboxedType(type);
|
||||
if (primitiveType == null) {
|
||||
return false;
|
||||
}
|
||||
} else if (type instanceof PsiPrimitiveType) {
|
||||
primitiveType = (PsiPrimitiveType)type;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (JavaTokenType.PLUS == tokenType || JavaTokenType.ASTERISK == tokenType) {
|
||||
return primitiveType != PsiType.FLOAT && primitiveType != PsiType.DOUBLE;
|
||||
} else if (JavaTokenType.EQEQ == tokenType || JavaTokenType.NE == tokenType) {
|
||||
return primitiveType == PsiType.BOOLEAN;
|
||||
} else if (JavaTokenType.AND == tokenType || JavaTokenType.OR == tokenType || JavaTokenType.XOR == tokenType) {
|
||||
return true;
|
||||
} else if (JavaTokenType.OROR == tokenType || JavaTokenType.ANDAND == tokenType) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int getPrecedence(PsiExpression expression) {
|
||||
if (expression instanceof PsiThisExpression ||
|
||||
expression instanceof PsiLiteralExpression ||
|
||||
|
||||
+3
@@ -24,5 +24,8 @@ public class ReplaceAssignmentWithOperatorAssignment
|
||||
|
||||
x = x / 2 / 4;
|
||||
x = x >> 1 >> 1;
|
||||
x = x * 2 * 2;
|
||||
float f = 1;
|
||||
f = f * 2 * 2;
|
||||
}
|
||||
}
|
||||
+7
@@ -34,4 +34,11 @@
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Assignment replaceable with operator assignment</problem_class>
|
||||
<description><code>x = x + 2 + 2 + 2</code> could be simplified to 'x += 2 + 2 + 2' #loc</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>ReplaceAssignmentWithOperatorAssignment.java</file>
|
||||
<line>27</line>
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Assignment replaceable with operator assignment</problem_class>
|
||||
<description><code>x = x * 2 * 2</code> could be simplified to 'x *= 2 * 2' #loc</description>
|
||||
</problem>
|
||||
</problems>
|
||||
Reference in New Issue
Block a user