private static boolean afterCaseForType(@Nullable PsiElement position) {
    if (position == null) return false;
    return psiElement().afterLeaf(PsiKeyword.CASE).accepts(position) &&
           ((position.getParent() instanceof PsiReferenceExpression referenceExpression &&
             referenceExpression.getParent() instanceof PsiCaseLabelElementList)
            || (position.getParent() instanceof PsiJavaCodeReferenceElement referenceElement &&
                referenceElement.getParent() instanceof PsiTypeElement typeElement &&
                typeElement.getParent() instanceof PsiPatternVariable patternVariable &&
                patternVariable.getParent() instanceof PsiTypeTestPattern typeTestPattern &&
                typeTestPattern.getParent() instanceof PsiCaseLabelElementList));
  }
private static boolean afterCaseForType(@Nullable PsiElement position)