boolean (PsiElement element, PsiExpression condition) { condition = skipParenthesizedExprDown(condition); if (condition == null) return false; boolean isNegated = false; PsiBinaryExpression binOp = tryCast(condition, PsiBinaryExpression.class); if (binOp == null && BoolUtils.isNegation(condition)) { final PsiExpression operand = skipParenthesizedExprDown(((PsiPrefixExpression) condition).getOperand()); binOp = tryCast(operand, PsiBinaryExpression.class); isNegated = true; } if (binOp == null) return false; final IElementType tokenType = binOp.getOperationTokenType(); final PsiBinaryExpression lOperand = tryCast(skipParenthesizedExprDown(binOp.getLOperand()), PsiBinaryExpression.class); final PsiBinaryExpression rOperand = tryCast(skipParenthesizedExprDown(binOp.getROperand()), PsiBinaryExpression.class); if (lOperand == null || rOperand == null) return false; final PsiExpression lValue = ExpressionUtils.getValueComparedWithNull(lOperand); final PsiExpression rValue = ExpressionUtils.getValueComparedWithNull(rOperand); if (lValue == null || rValue == null) return false; final IElementType lTokenType = lOperand.getOperationTokenType(); final IElementType rTokenType = rOperand.getOperationTokenType(); boolean areBothOperandsComparedWithNull = lTokenType == EQEQ && rTokenType == EQEQ; boolean areBothOperandsComparedWithNotNull = lTokenType == NE && rTokenType == NE; if (areBothOperandsComparedWithNull == areBothOperandsComparedWithNotNull) return false; List<IElementType> targetTokenTypes = areBothOperandsComparedWithNull ? Arrays.asList(OROR, OR) : Arrays.asList(ANDAND, AND); if (!targetTokenTypes.contains(tokenType)) return false; final PsiElement elementContainsNumberEquality; if (element instanceof PsiBinaryExpression) { elementContainsNumberEquality = getAnotherOperand((PsiBinaryExpression)element, condition); } else { elementContainsNumberEquality = getElementMustContainNumberEquality(element, isNegated, areBothOperandsComparedWithNull); } if (!PsiTreeUtil.isAncestor(elementContainsNumberEquality, lhs, false)) return false; final EquivalenceChecker checker = EquivalenceChecker.getCanonicalPsiEquivalence(); final PsiReferenceExpression lReference = tryCast(skipParenthesizedExprDown(lhs), PsiReferenceExpression.class); if (lReference == null) return false; final PsiReferenceExpression rReference = tryCast(skipParenthesizedExprDown(rhs), PsiReferenceExpression.class); if (rReference == null) return false; final PsiVariable lVariable = tryCast(lReference.resolve(), PsiVariable.class); if (lVariable == null) return false; final PsiVariable rVariable = tryCast(rReference.resolve(), PsiVariable.class); if (rVariable == null) return false; final boolean isEffectivelyFinal = isEffectivelyFinal(lVariable, elementContainsNumberEquality, null) && isEffectivelyFinal(rVariable, elementContainsNumberEquality, null); if (!isEffectivelyFinal) return false; return (checker.expressionsMatch(lhs, lValue).isExactMatch() && checker.expressionsMatch(rhs, rValue).isExactMatch()) || (checker.expressionsMatch(lhs, rValue).isExactMatch() && checker.expressionsMatch(rhs, lValue).isExactMatch()); }