PsiExpression (@Nullable final PsiExpression expression) { if (expression == null) return null; @NotNull PsiExpression current = expression; while (true) { PsiExpression parentExpr = ObjectUtils.tryCast(current.getParent(), PsiExpression.class); if (parentExpr == null) break; current = parentExpr; } return current; }