diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/ComparableImplementedButEqualsNotOverriddenInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/ComparableImplementedButEqualsNotOverriddenInspection.java index 863ce5652cac..8ff2ef8d4e17 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/ComparableImplementedButEqualsNotOverriddenInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/ComparableImplementedButEqualsNotOverriddenInspection.java @@ -91,6 +91,7 @@ public class ComparableImplementedButEqualsNotOverriddenInspection extends BaseI private static class AddNoteFix extends InspectionGadgetsFix { private static final Pattern PARAM_PATTERN = Pattern.compile("\\*[ \t]+@"); + private static final String NOTE = " * Note: this class has a natural ordering that is inconsistent with equals.\n"; @Nls @NotNull @@ -103,28 +104,17 @@ public class ComparableImplementedButEqualsNotOverriddenInspection extends BaseI protected void doFix(Project project, ProblemDescriptor descriptor) { final PsiClass aClass = (PsiClass)descriptor.getPsiElement().getParent(); final PsiDocComment comment = aClass.getDocComment(); - final PsiElementFactory factory = JavaPsiFacade.getElementFactory(project); if (comment == null) { - final PsiDocComment newComment = factory.createDocCommentFromText( - "/**\n" + - "* Note: this class has a natural ordering that is inconsistent with equals.\n" + - "*/", aClass); + final PsiDocComment newComment = JavaPsiFacade.getElementFactory(project).createDocCommentFromText("/**\n" + NOTE + "*/", aClass); aClass.addBefore(newComment, aClass.getFirstChild()); } else { final String text = comment.getText(); final Matcher matcher = PARAM_PATTERN.matcher(text); - String newCommentText; - if (matcher.find()) { - newCommentText = text.substring(0, matcher.start()) + - " * Note: this class has a natural ordering that is inconsistent with equals.\n" + - text.substring(matcher.start()); - } - else { - newCommentText = text.substring(0, text.length() - 2) + - " * Note: this class has a natural ordering that is inconsistent with equals.\n*/"; - } - final PsiDocComment newComment = factory.createDocCommentFromText(newCommentText); + final String newCommentText = matcher.find() + ? text.substring(0, matcher.start()) + NOTE + text.substring(matcher.start()) + : text.substring(0, text.length() - 2) + NOTE + "*/"; + final PsiDocComment newComment = JavaPsiFacade.getElementFactory(project).createDocCommentFromText(newCommentText); comment.replace(newComment); } }