PsiExpression (@NotNull PsiExpression expression) { while (true) { final PsiElement parent = expression.getParent(); if (parent instanceof PsiParenthesizedExpression || parent instanceof PsiTypeCastExpression) { expression = (PsiExpression)parent; continue; } else if (parent instanceof PsiConditionalExpression && ((PsiConditionalExpression)parent).getCondition() != expression) { expression = (PsiExpression)parent; continue; } else if (parent instanceof PsiExpressionStatement) { final PsiElement grandParent = parent.getParent(); if (grandParent instanceof PsiSwitchLabeledRuleStatement) { final PsiSwitchBlock block = ((PsiSwitchLabeledRuleStatement)grandParent).getEnclosingSwitchBlock(); if (block instanceof PsiSwitchExpression) { expression = (PsiExpression)block; continue; } } } else if (parent instanceof PsiYieldStatement) { PsiSwitchExpression enclosing = ((PsiYieldStatement)parent).findEnclosingExpression(); if (enclosing != null) { expression = enclosing; continue; } } return expression; } }