PsiReferenceExpression (PsiExpression condition) { while (condition != null && BoolUtils.isNegation(condition)) { condition = BoolUtils.getNegated(condition); } PsiMethodCallExpression call = ObjectUtils.tryCast(condition, PsiMethodCallExpression.class); if (!OPTIONAL_IS_PRESENT.matches(call) && !OPTIONAL_IS_EMPTY.matches(call)) return null; PsiReferenceExpression qualifier = ObjectUtils.tryCast(PsiUtil.skipParenthesizedExprDown(call.getMethodExpression().getQualifierExpression()), PsiReferenceExpression.class); if (qualifier == null) return null; PsiElement element = qualifier.resolve(); if (!(element instanceof PsiVariable) || isRaw((PsiVariable)element)) return null; return qualifier; }