mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IG: a != b and b != a and other commutative binary operations are equivalent
This commit is contained in:
+6
-3
@@ -899,14 +899,17 @@ public class EquivalenceChecker {
|
||||
final PsiExpression right2 = binaryExpression2.getROperand();
|
||||
if (!tokenType1.equals(tokenType2)) {
|
||||
// process matches like "a < b" and "b > a"
|
||||
DfaRelationValue.RelationType rel1 = DfaRelationValue.RelationType.fromElementType(tokenType1);
|
||||
DfaRelationValue.RelationType rel2 = DfaRelationValue.RelationType.fromElementType(tokenType2);
|
||||
final DfaRelationValue.RelationType rel1 = DfaRelationValue.RelationType.fromElementType(tokenType1);
|
||||
final DfaRelationValue.RelationType rel2 = DfaRelationValue.RelationType.fromElementType(tokenType2);
|
||||
if(rel1 != null && rel2 != null && rel1.getFlipped() == rel2) {
|
||||
return expressionsAreEquivalent(new PsiExpression[] {left1, right1}, new PsiExpression[] {right2, left2});
|
||||
}
|
||||
return EXACT_MISMATCH;
|
||||
}
|
||||
return expressionsAreEquivalent(new PsiExpression[] {left1, right1}, new PsiExpression[] {left2, right2});
|
||||
final Match match = expressionsAreEquivalent(new PsiExpression[] {left1, right1}, new PsiExpression[] {left2, right2});
|
||||
return match == EXACT_MISMATCH && ParenthesesUtils.isCommutativeOperation(binaryExpression1)
|
||||
? expressionsAreEquivalent(new PsiExpression[]{left1, right1}, new PsiExpression[]{right2, left2})
|
||||
: match;
|
||||
}
|
||||
|
||||
protected Match assignmentExpressionsMatch(@NotNull PsiAssignmentExpression assignmentExpression1, @NotNull PsiAssignmentExpression assignmentExpression2) {
|
||||
|
||||
+12
-6
@@ -100,12 +100,18 @@ public class ParenthesesUtils {
|
||||
}
|
||||
|
||||
public static boolean isCommutativeOperator(@NotNull IElementType token) {
|
||||
return !(token.equals(JavaTokenType.MINUS) ||
|
||||
token.equals(JavaTokenType.DIV) ||
|
||||
token.equals(JavaTokenType.PERC) ||
|
||||
token.equals(JavaTokenType.LTLT) ||
|
||||
token.equals(JavaTokenType.GTGT) ||
|
||||
token.equals(JavaTokenType.GTGTGT));
|
||||
return token == JavaTokenType.PLUS || token == JavaTokenType.ASTERISK ||
|
||||
token == JavaTokenType.EQEQ || token == JavaTokenType.NE ||
|
||||
token == JavaTokenType.AND || token == JavaTokenType.OR || token == JavaTokenType.XOR;
|
||||
}
|
||||
|
||||
public static boolean isCommutativeOperation(PsiPolyadicExpression expression) {
|
||||
final IElementType tokenType = expression.getOperationTokenType();
|
||||
if (!isCommutativeOperator(tokenType)) {
|
||||
return false;
|
||||
}
|
||||
final PsiType type = expression.getType();
|
||||
return type != null && !type.equalsToText(CommonClassNames.JAVA_LANG_STRING);
|
||||
}
|
||||
|
||||
public static boolean isAssociativeOperation(PsiPolyadicExpression expression) {
|
||||
|
||||
+6
@@ -33,6 +33,12 @@ public class DuplicateCondition {
|
||||
System.out.println("second");
|
||||
return;
|
||||
}
|
||||
if (<warning descr="Duplicate condition 'x != y'">x != y</warning>) {
|
||||
return;
|
||||
}
|
||||
if ((<warning descr="Duplicate condition '(y) != x'">(y) != x</warning>)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void foo()
|
||||
|
||||
Reference in New Issue
Block a user