From e42c3ee1e4b278d801cfdfe4a1b35aa818dcd063 Mon Sep 17 00:00:00 2001 From: Mikhail Pyltsin Date: Fri, 14 Jun 2024 15:22:48 +0200 Subject: [PATCH] IJ-MR-136429 [java-generation] IDEA-344399 generate annotation based on type_use option - fix message - fix comparator GitOrigin-RevId: 842fbf9e29150159ae92a47eddb84eb9a8d7288a --- .../generation/GenerateMembersUtil.java | 20 +++++++++---------- .../resources/messages/JavaBundle.properties | 2 +- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/generation/GenerateMembersUtil.java b/java/java-impl/src/com/intellij/codeInsight/generation/GenerateMembersUtil.java index 8f823a4c5f43..487ad03f3f60 100644 --- a/java/java-impl/src/com/intellij/codeInsight/generation/GenerateMembersUtil.java +++ b/java/java-impl/src/com/intellij/codeInsight/generation/GenerateMembersUtil.java @@ -377,17 +377,15 @@ public final class GenerateMembersUtil { } } } - Comparator comparator = (a1, a2) -> { - String q1 = a1.getQualifiedName(); - String q2 = a2.getQualifiedName(); - if (q1 == null || q2 == null) return 0; - PsiAnnotation oldA1 = oldAnnotations.get(q1); - PsiAnnotation oldA2 = oldAnnotations.get(q2); - if (oldA1 != null && oldA2 != null) { - return oldA1.getTextRange().getStartOffset() - oldA2.getTextRange().getStartOffset(); - } - return 0; - }; + Comparator comparator = Comparator.comparingInt(a -> { + String q = a.getQualifiedName(); + if (q == null) return -1; + PsiAnnotation old = oldAnnotations.get(q); + //Probably, it is better to have it at the bottom if it is new. + //For example, it preserves the current behavior for @Override + if (old == null) return Integer.MAX_VALUE; + return old.getTextRange().getStartOffset(); + }); PsiModifierList newList2 = ModifierListUtil.createSortedModifierList(newList, comparator, false); if (newList2 != null) { new CommentTracker().replace(newList, newList2); diff --git a/java/openapi/resources/messages/JavaBundle.properties b/java/openapi/resources/messages/JavaBundle.properties index fa3372d86bbf..3ba12b0bcca1 100644 --- a/java/openapi/resources/messages/JavaBundle.properties +++ b/java/openapi/resources/messages/JavaBundle.properties @@ -1345,7 +1345,7 @@ usage.target.exception=Exception usage.target.package.in.directory={0} (in {1}) use.external.annotations=Use &external annotations generate.type.use.before.type=Generate annotations allowed for TYPE_USE directly &before a type -generate.type.use.before.type.description=Annotations with TYPE_USE as their target will be placed directly before a type. Otherwise, they will be placed before all modifiers +generate.type.use.before.type.description=Annotations with TYPE_USE as their target will be placed directly before a type. Otherwise, they will be placed before all modifiers. wrapping.annotation.enums=Enum field annotations wrapping.annotation.parameters=Annotation parameters wrapping.record.components=Record components