PsiSwitchLabelStatementBase (String labelExpression, PsiElement anchor, PsiSwitchBlock switchBlock, boolean isRuleBasedFormat, boolean isPatternsGenerated) { if (anchor instanceof PsiSwitchLabelStatement) { PsiElement sibling = PsiTreeUtil.skipWhitespacesBackward(anchor); while (sibling instanceof PsiSwitchLabelStatement) { anchor = sibling; sibling = PsiTreeUtil.skipWhitespacesBackward(anchor); } } PsiElement correctedAnchor = anchor; final PsiElement parent = anchor.getParent(); final PsiElementFactory factory = JavaPsiFacade.getElementFactory(anchor.getProject()); PsiSwitchLabelStatementBase result = null; for (String text : generateStatements(labelExpression, switchBlock, isRuleBasedFormat, isPatternsGenerated)) { PsiStatement statement = factory.createStatementFromText(text, parent); PsiElement inserted = parent.addBefore(statement, correctedAnchor); if (inserted instanceof PsiSwitchLabelStatementBase) { result = (PsiSwitchLabelStatementBase)inserted; } correctedAnchor = inserted.getNextSibling(); } return result; }