void (@NotNull Project project, @NotNull PsiElement nameElement, @NotNull ModPsiUpdater updater) { final PsiModifierList modifierList = (PsiModifierList)nameElement.getParent(); assert modifierList != null; final PsiMethod method = (PsiMethod)modifierList.getParent(); modifierList.setModifierProperty(PsiModifier.SYNCHRONIZED, false); assert method != null; final PsiCodeBlock body = method.getBody(); if (body == null) { return; } final String text = body.getText(); @NonNls final String replacementText; if (method.hasModifierProperty(PsiModifier.STATIC)) { final PsiClass containingClass = method.getContainingClass(); assert containingClass != null; final String className = containingClass.getName(); replacementText = "{ synchronized(" + className + ".class)" + text + '}'; } else { replacementText = "{ synchronized(this)" + text + '}'; } final PsiCodeBlock block = JavaPsiFacade.getElementFactory(project).createCodeBlockFromText(replacementText, method); body.replace(block); final CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(project); codeStyleManager.reformat(method); }