void (@NotNull Project project, @NotNull PsiElement startElement, @NotNull ModPsiUpdater updater) { final PsiClass aClass = (PsiClass)startElement.getParent(); final @NonNls StringBuilder methodText = new StringBuilder(); if (PsiUtil.isLanguageLevel5OrHigher(aClass)) { methodText.append("@java.lang.Override "); } methodText.append("public "); methodText.append("boolean equals(Object o) {\n"); methodText.append("return o instanceof ").append(aClass.getName()); methodText.append("&& compareTo((").append(aClass.getName()).append(")o) == 0;\n"); methodText.append("}"); final PsiMethod method = JavaPsiFacade.getElementFactory(project).createMethodFromText(methodText.toString(), aClass, PsiUtil.getLanguageLevel(aClass)); final PsiElement newMethod = aClass.add(method); CodeStyleManager.getInstance(project).reformat(newMethod); }