CodeBlockSurrounder (PsiStatement statement, PsiExpression expression) { PsiElement statementParent = statement.getParent(); PsiForStatement forStatement = tryCast(statementParent, PsiForStatement.class); if (statementParent instanceof PsiLabeledStatement || (forStatement != null && forStatement.getBody() != statement)) { statement = (PsiStatement)statementParent; statementParent = statement.getParent(); } if (statementParent instanceof PsiCodeBlock) { return new NoOpSurrounder(expression, statement); } if (statement instanceof PsiExpressionStatement && statementParent instanceof PsiSwitchLabeledRuleStatement && ((PsiSwitchLabeledRuleStatement)statementParent).getEnclosingSwitchBlock() instanceof PsiSwitchExpression) { return new YieldSurrounder(expression, (PsiExpressionStatement)statement); } return new SimpleSurrounder(expression, statement); }