PsiStatement (PsiStatement anchor, PsiStatement newStatement) { PsiStatement oldStatement = anchor; PsiElement parent = oldStatement.getParent(); while (parent instanceof PsiLabeledStatement) { oldStatement = (PsiStatement)parent; parent = oldStatement.getParent(); } if (!(parent instanceof PsiCodeBlock)) { oldStatement = expandSingleStatementToBlockStatement(oldStatement); parent = oldStatement.getParent(); } return (PsiStatement)parent.addAfter(newStatement, oldStatement); }