boolean (PsiExpression expression) { final PsiAssignmentExpression assignment = PsiTreeUtil.getParentOfType(expression, PsiAssignmentExpression.class, true, PsiStatement.class); if (assignment == null) return false; final PsiReferenceExpression assignedRef = tryCast(assignment.getLExpression(), PsiReferenceExpression.class); if (assignedRef == null) return false; // to support cases like if(foo == null) foo = new Foo(new Bar()); if (assignment.getRExpression() != expression && NullabilityUtil.getExpressionNullability(assignment.getRExpression()) != Nullability.NOT_NULL) { return false; } final PsiIfStatement ifStatement = PsiTreeUtil.getParentOfType(assignment, PsiIfStatement.class); if (ifStatement == null) return false; boolean equals; if (PsiTreeUtil.isAncestor(ifStatement.getThenBranch(), assignment, true)) { equals = true; } else if (PsiTreeUtil.isAncestor(ifStatement.getElseBranch(), assignment, true)) { equals = false; } else { return false; } final PsiExpression condition = ifStatement.getCondition(); PsiReferenceExpression nullCheckedRef = ExpressionUtils.getReferenceExpressionFromNullComparison(condition, equals); return nullCheckedRef != null && PsiEquivalenceUtil.areElementsEquivalent(nullCheckedRef, assignedRef); }