private static void addAnnotationClasses(@NotNull PsiClass psiClass, boolean isDeclared, @NotNull CompletionResultSet result) {
    Set<PsiAnnotation> declaredAnnotations =
      isDeclared ? ContainerUtil.immutableSet(AnnotationUtil.getAllAnnotations(psiClass, false, null, false)) : null;

    PsiAnnotation[] annotations = AnnotationUtil.getAllAnnotations(psiClass, true, null, false);
    for (PsiAnnotation annotation : annotations) {
      PsiJavaCodeReferenceElement referenceElement = annotation.getNameReferenceElement();
      if (referenceElement != null) {
        PsiElement resolved = referenceElement.resolve();
        if (resolved instanceof PsiClass annotationClass) {
          String className = annotationClass.getName();
          if (className != null) {
            LookupElement lookupElement = LookupElementBuilder.createWithIcon(annotationClass)
              .withPresentableText(className + ".class")
              .withInsertHandler(JavaReflectionCompletionContributor::handleAnnotationClassInsertion);
            if (isDeclared) {
              lookupElement = withPriority(lookupElement, declaredAnnotations.contains(annotation));
            }
            result.addElement(lookupElement);
          }
        }
      }
    }
  }
private static void addAnnotationClasses(@NotNull PsiClass psiClass, boolean isDeclared, @NotNull CompletionResultSet result)