public static void sortModifiers(@NotNull PsiMethod targetMethod, @Nullable PsiMethod sourceMethod) {
    if (targetMethod instanceof LightMethod ||
        !targetMethod.isWritable() ||
        targetMethod.getLanguage() != JavaLanguage.INSTANCE) {
      return;
    }
    PsiModifierList newList = targetMethod.getModifierList();
    Map<@NotNull String, @NotNull PsiAnnotation> oldAnnotations = new HashMap<>();
    if (sourceMethod != null) {
      PsiModifierList oldList = sourceMethod.getModifierList();
      for (@NotNull PsiElement child : oldList.getChildren()) {
        if (child instanceof PsiAnnotation psiAnnotation) {
          String annotationQualifiedName = psiAnnotation.getQualifiedName();
          if (annotationQualifiedName != null) {
            oldAnnotations.put(annotationQualifiedName, psiAnnotation);
          }
        }
      }
    }
    Comparator<PsiAnnotation> 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);
    }
  }
public static void sortModifiers(@NotNull PsiMethod targetMethod, @Nullable PsiMethod sourceMethod)