mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IG: extract note to constant
This commit is contained in:
+6
-16
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user