EqualityCheck (PsiExpression expression) { expression = PsiUtil.skipParenthesizedExprDown(expression); if (expression instanceof PsiMethodCallExpression call) { if (MethodCallUtils.isEqualsCall(call)) { PsiExpression left = call.getMethodExpression().getQualifierExpression(); PsiExpression right = ArrayUtil.getFirstElement(call.getArgumentList().getExpressions()); if (left == null || right == null) return null; return new EqualityCheck(left, right, true); } if (OBJECT_EQUALS.test(call)) { PsiExpression[] args = call.getArgumentList().getExpressions(); return new EqualityCheck(args[0], args[1], false); } } else if (expression instanceof PsiConditionalExpression ternary) { EqualityCheck nestedCheck = from(ternary.getThenExpression()); PsiExpression other = ternary.getElseExpression(); boolean equalsToNull = false; if (nestedCheck == null) { nestedCheck = from(ternary.getElseExpression()); other = ternary.getThenExpression(); equalsToNull = true; } if(nestedCheck != null && nestedCheck.isLeftDereferenced() && other != null) { PsiReferenceExpression leftRef = ExpressionUtils.getReferenceExpressionFromNullComparison(ternary.getCondition(), equalsToNull); EquivalenceChecker equivalence = EquivalenceChecker.getCanonicalPsiEquivalence(); if (equivalence.expressionsAreEquivalent(leftRef, nestedCheck.getLeft())) { PsiReferenceExpression rightRef = ExpressionUtils.getReferenceExpressionFromNullComparison(other, true); if (equivalence.expressionsAreEquivalent(rightRef, nestedCheck.getRight())) { return new EqualityCheck(nestedCheck.getLeft(), nestedCheck.getRight(), false); } } } } return null; }