PsiReferenceExpression (PsiExpression expression, boolean equals) { expression = PsiUtil.skipParenthesizedExprDown(expression); if (!(expression instanceof PsiPolyadicExpression polyadicExpression)) { return null; } final IElementType tokenType = polyadicExpression.getOperationTokenType(); if (equals) { if (!JavaTokenType.EQEQ.equals(tokenType)) { return null; } } else { if (!JavaTokenType.NE.equals(tokenType)) { return null; } } final PsiExpression[] operands = polyadicExpression.getOperands(); if (operands.length != 2) { return null; } PsiExpression comparedToNull = null; if (PsiTypes.nullType().equals(operands[0].getType())) { comparedToNull = operands[1]; } else if (PsiTypes.nullType().equals(operands[1].getType())) { comparedToNull = operands[0]; } comparedToNull = PsiUtil.skipParenthesizedExprDown(comparedToNull); return comparedToNull instanceof PsiReferenceExpression ? (PsiReferenceExpression)comparedToNull : null; }