PsiExpression (PsiExpression expression) { PsiExpression top = expression; while (true) { PsiElement parent = top.getParent(); if (parent instanceof PsiParenthesizedExpression || (parent instanceof PsiTypeCastExpression && !(((PsiTypeCastExpression)parent).getType() instanceof PsiPrimitiveType))) { top = (PsiExpression)parent; } else { return top; } } }