void (@NotNull Project project, @NotNull ProblemDescriptor descriptor) { PsiElement exceptPart = descriptor.getPsiElement(); if (exceptPart instanceof PyExceptPart) { PyElementGenerator elementGenerator = PyElementGenerator.getInstance(project); PsiElement element = ((PyExceptPart)exceptPart).getExceptClass().getNextSibling(); while (element instanceof PsiWhiteSpace) { element = element.getNextSibling(); } assert element != null; PyTryExceptStatement newElement = elementGenerator.createFromText(LanguageLevel.forElement(exceptPart), PyTryExceptStatement.class, "try: pass except a as b: pass"); ASTNode node = newElement.getExceptParts()[0].getNode().findChildByType(PyTokenTypes.AS_KEYWORD); assert node != null; element.replace(node.getPsi()); } }