Branch (@NotNull PsiSwitchLabelStatement label) { PsiCodeBlock codeBlock = ObjectUtils.tryCast(label.getParent(), PsiCodeBlock.class); if (codeBlock == null) { return null; } PsiElement lBrace = codeBlock.getLBrace(), rBrace = codeBlock.getRBrace(); if (lBrace == null || rBrace == null) { return null; } PsiElement firstElement = label.getNextSibling(); if (!isInBranch(firstElement, rBrace)) { return null; } PsiStatement firstStatement = firstElement instanceof PsiStatement statement ? statement : getNextSiblingOfType(firstElement, PsiStatement.class); PsiStatement lastStatement = null; for (PsiStatement next = firstStatement; isInBranch(next, rBrace); next = getNextSiblingOfType(next, PsiStatement.class)) { lastStatement = next; } if (lastStatement == null) { return null; } return new Branch(firstElement, lastStatement, label.getGuardExpression(), codeBlock, lBrace); }