PsiCaseLabelElement (@NotNull PsiElement element, @NotNull PsiCaseLabelElementList labelElementList, @NotNull ActionContext context) { PsiCaseLabelElement labelElement = PsiTreeUtil.getNonStrictParentOfType(element, PsiCaseLabelElement.class); if (!isInList(labelElement, labelElementList)) { PsiElement previousElement = getPreviousElement(context, element); labelElement = PsiTreeUtil.getNonStrictParentOfType(previousElement, PsiCaseLabelElement.class); } PsiElement caseLabel = PsiTreeUtil.findFirstParent(labelElement, parent -> parent instanceof PsiCaseLabelElement && parent.getParent() instanceof PsiCaseLabelElementList ); return (PsiCaseLabelElement)caseLabel; }