void () { if (!HighlightingFeature.PATTERN_GUARDS_AND_RECORD_PATTERNS.isAvailable(myPosition)) { return; } PsiElement element = PsiTreeUtil.skipWhitespacesAndCommentsForward(myPrevLeaf); if (element instanceof PsiErrorElement) { return; } element = PsiTreeUtil.skipWhitespacesAndCommentsBackward(PsiTreeUtil.prevLeaf(myPosition)); if (element instanceof PsiErrorElement) { return; } PsiPattern psiPattern = PsiTreeUtil.getParentOfType(myPrevLeaf, PsiPattern.class, true, PsiStatement.class, PsiMember.class, PsiClass.class); if (psiPattern == null || (psiPattern instanceof PsiTypeTestPattern testPattern && testPattern.getPatternVariable() != null && testPattern.getPatternVariable().getNameIdentifier() == myPosition)) { return; } PsiElement parentOfPattern = PsiTreeUtil.skipParentsOfType(psiPattern, PsiPattern.class, PsiDeconstructionList.class); if (!(parentOfPattern instanceof PsiCaseLabelElementList)) { return; } addKeyword(new OverridableSpace(createKeyword(PsiKeyword.WHEN), TailTypes.insertSpaceType())); }