void () { if (myPrevLeaf == null || !(myPrevLeaf instanceof PsiIdentifier || myPrevLeaf.textMatches(">") || myPrevLeaf.textMatches(")"))) { return; } PsiClass psiClass = null; PsiElement prevParent = myPrevLeaf.getParent(); if (myPrevLeaf instanceof PsiIdentifier && prevParent instanceof PsiClass) { psiClass = (PsiClass)prevParent; } else { PsiReferenceList referenceList = PsiTreeUtil.getParentOfType(myPrevLeaf, PsiReferenceList.class); if (referenceList != null && referenceList.getParent() instanceof PsiClass) { psiClass = (PsiClass)referenceList.getParent(); } else if ((prevParent instanceof PsiTypeParameterList || prevParent instanceof PsiRecordHeader) && prevParent.getParent() instanceof PsiClass) { psiClass = (PsiClass)prevParent.getParent(); } } if (psiClass != null) { if (!psiClass.isEnum() && !psiClass.isRecord()) { addKeyword(new OverridableSpace(createKeyword(PsiKeyword.EXTENDS), TailTypes.humbleSpaceBeforeWordType())); if (HighlightingFeature.SEALED_CLASSES.isAvailable(psiClass)) { PsiModifierList modifiers = psiClass.getModifierList(); if (myParameters.getInvocationCount() > 1 || (modifiers != null && !modifiers.hasExplicitModifier(PsiModifier.FINAL) && !modifiers.hasExplicitModifier(PsiModifier.NON_SEALED))) { InsertHandler<LookupElement> handler = (context, item) -> { PsiClass aClass = PsiTreeUtil.findElementOfClassAtOffset(context.getFile(), context.getStartOffset(), PsiClass.class, false); if (aClass != null) { PsiModifierList modifierList = aClass.getModifierList(); if (modifierList != null) { modifierList.setModifierProperty(PsiModifier.SEALED, true); } } }; LookupElement element = new OverridableSpace(LookupElementDecorator.withInsertHandler(createKeyword(PsiKeyword.PERMITS), handler), TailTypes.humbleSpaceBeforeWordType()); addKeyword(element); } } } if (!psiClass.isInterface()) { addKeyword(new OverridableSpace(createKeyword(PsiKeyword.IMPLEMENTS), TailTypes.humbleSpaceBeforeWordType())); } } }