void (PsiSwitchBlock block) { PsiElementFactory factory = JavaPsiFacade.getElementFactory(block.getProject()); PsiTypesUtil.replaceWithExplicitType(myVariable.getTypeElement()); CommentTracker ct = new CommentTracker(); PsiSwitchStatement switchStatement = new VarSavingSwitchGenerator(block, myVariable.getName(), "=").generate(ct); ct.markUnchanged(block); PsiDeclarationStatement variableDeclaration = (PsiDeclarationStatement)factory.createStatementFromText(myVariable.getTypeElement().getText() + " " + myVariable.getName() + ";", myVariable); ct.markUnchanged(switchStatement); PsiStatement declaration = (PsiStatement)ct.replaceAndRestoreComments(myVariable.getParent(), variableDeclaration); BlockUtils.addAfter(declaration, switchStatement); }