List<PsiElement> (@NotNull PsiElement element) { List<PsiElement> result = new ArrayList<>(); while (true) { PsiExpression expression = PsiTreeUtil.getNonStrictParentOfType(element, PsiExpression.class); if (expression == null) break; if (PsiTreeUtil.getParentOfType(expression, PsiAnnotationMethod.class, true, PsiStatement.class) != null) { break; } while (shouldParenthesizeParent(expression)) { expression = (PsiExpression)expression.getParent(); } PsiElement parent = expression.getParent(); if (ExpressionUtils.isVoidContext(expression) || parent instanceof PsiNameValuePair || parent instanceof PsiArrayInitializerMemberValue || parent instanceof PsiExpressionList && parent.getParent() instanceof PsiSwitchLabelStatementBase || parent instanceof PsiBreakStatement && ((PsiBreakStatement)parent).getLabelIdentifier() != null) { break; } if (parent instanceof PsiVariable && expression instanceof PsiArrayInitializerExpression) break; result.add(expression); element = expression.getParent(); } return result; }