void (@NotNull PsiElement match, @NotNull String referenceText) { WriteCommandAction.runWriteCommandAction(match.getProject(), null, null, () -> { PsiFile file = match.getContainingFile(); if (!file.isValid()) { return; } match.replace(createLinkDeclarationAndReference(match.getProject(), match, referenceText).getFirst()); }); }