public static List<String> getSortedModifiers(@NotNull PsiModifierList modifierList,
                                                @Nullable Comparator<? super PsiAnnotation> customAnnotationComparator,
                                                boolean allowAnnotationTypeBeInAnyAllowedPlace) {
    final List<String> modifiers = new SmartList<>();
    final List<PsiAnnotation> typeAnnotations = new SmartList<>();
    final List<PsiAnnotation> annotations = new SmartList<>();
    for (PsiElement child : modifierList.getChildren()) {
      if (child instanceof PsiJavaToken) {
        modifiers.add(child.getText());
      }
      else if (child instanceof PsiAnnotation annotation) {
        if (PsiImplUtil.isTypeAnnotation(child) && !isMethodWithVoidReturnType(modifierList.getParent())) {
          final PsiAnnotation.TargetType[] targets = AnnotationTargetUtil.getTargetsForLocation(annotation.getOwner());
          PsiClass annotationClass = annotation.resolveAnnotationType();
          Set<PsiAnnotation.TargetType> annotationAllowedTypes = EnumSet.noneOf(PsiAnnotation.TargetType.class);
          if (annotationClass != null) {
            Set<PsiAnnotation.TargetType> annotationTargets = AnnotationTargetUtil.getAnnotationTargets(annotationClass);
            if (annotationTargets != null) {
              annotationAllowedTypes.addAll(annotationTargets);
            }
          }
          annotationAllowedTypes.removeAll(Arrays.stream(targets).collect(Collectors.toSet()));
          if (isTypeAnnotationAlwaysUseWithType(annotation) ||
              (allowAnnotationTypeBeInAnyAllowedPlace && !modifiers.isEmpty()) ||
              AnnotationTargetUtil.findAnnotationTarget(annotation, targets[0]) == PsiAnnotation.TargetType.UNKNOWN ||
              (annotationAllowedTypes.size() == 1 && annotationAllowedTypes.contains(PsiAnnotation.TargetType.TYPE_USE))) {
            typeAnnotations.add(annotation);
            continue;
          }
        }
        annotations.add(annotation);
      }
    }
    modifiers.sort(new ModifierComparator());
    final List<String> result = new SmartList<>();
    if (customAnnotationComparator != null) {
      annotations.sort(customAnnotationComparator);
      typeAnnotations.sort(customAnnotationComparator);
    }
    result.addAll(ContainerUtil.map(annotations, a -> a.getText()));
    result.addAll(modifiers);
    result.addAll(ContainerUtil.map(typeAnnotations, a -> a.getText()));
    return result;
  }
public static List<String> getSortedModifiers(@NotNull PsiModifierList modifierList,
                                                @Nullable Comparator<? super PsiAnnotation> customAnnotationComparator,
                                                boolean allowAnnotationTypeBeInAnyAllowedPlace)