void (@NotNull Project project, @NotNull ProblemDescriptor descriptor) { // expect the descriptor to point to the unresolved identifier. final PsiElement element = descriptor.getPsiElement(); final PyClassType type = getClassType(element); if (type == null) return; final PyClass cls = type.getPyClass(); if (!FileModificationService.getInstance().preparePsiElementForWrite(cls)) return; WriteAction.run(() -> { PsiElement initStatement; if (!type.isDefinition()) { initStatement = addFieldToInit(project, cls, myIdentifier, new CreateFieldCallback(project, myIdentifier, myInitializer)); } else { PyStatement field = PyElementGenerator.getInstance(project) .createFromText(LanguageLevel.getDefault(), PyStatement.class, myIdentifier + " = " + myInitializer); initStatement = PyPsiRefactoringUtil.addElementToStatementList(field, cls.getStatementList(), true); } if (initStatement != null) { showTemplateBuilder(initStatement, cls.getContainingFile()); return; } // somehow we failed. tell about this PythonUiService.getInstance().showBalloonError(project, PyPsiBundle.message("QFIX.failed.to.add.field")); }); }