private static @Nullable PsiAnnotation copyAnnotation(@NotNull PsiAnnotation annotation, @NotNull PsiModifierListOwner target) {
    String qualifiedName = annotation.getQualifiedName();
    if (qualifiedName != null) {
      if (JavaPsiFacade.getInstance(annotation.getProject()).findClass(qualifiedName, target.getResolveScope()) == null) {
        return null;
      }

      PsiModifierList modifierList = target.getModifierList();
      PsiType usedType = null;
      if(target instanceof PsiVariable){
        usedType = ((PsiVariable)target).getType();
      }
      else if (target instanceof PsiMethod) {
        usedType = ((PsiMethod)target).getReturnType();
      }
      // type annotations are part of target's type and should not to be copied explicitly to avoid duplication
      if (modifierList != null &&
          (!AnnotationTargetUtil.isStrictlyTypeUseAnnotation(modifierList, annotation) ||
           (usedType != null && !usedType.hasAnnotation(qualifiedName))) &&
          !modifierList.hasAnnotation(qualifiedName)) {
        return modifierList.addAnnotation(qualifiedName);
      }
    }

    return null;
  }
private static @Nullable PsiAnnotation copyAnnotation(@NotNull PsiAnnotation annotation, @NotNull PsiModifierListOwner target)