@Override
  public void insert(final @NotNull PsiClass aClass, @Nullable PsiElement anchor, boolean before) throws IncorrectOperationException {
    T member = Objects.requireNonNull(getPsiMember());
    final PsiMember existingMember;
    if (member instanceof PsiField) {
      existingMember = aClass.findFieldByName(member.getName(), false);
    }
    else if (member instanceof PsiMethod) {
      existingMember = aClass.findMethodBySignature((PsiMethod)member, false);
    }
    else {
      existingMember = null;
    }
    if (existingMember == null || !existingMember.isPhysical() || !myMergeIfExists) {
      PsiElement newMember = GenerateMembersUtil.insert(aClass, member, anchor, before);
      member = (T)JavaCodeStyleManager.getInstance(aClass.getProject()).shortenClassReferences(newMember);
      LOG.assertTrue(member.isValid(), member);
    }
    else {
      final PsiModifierList modifierList = member.getModifierList();
      final PsiModifierList existingModifierList = existingMember.getModifierList();
      if (modifierList != null && existingModifierList != null) {
        final PsiAnnotation[] psiAnnotations = modifierList.getAnnotations();
        PsiElement annoAnchor = existingModifierList.getAnnotations().length > 0 ? existingModifierList.getAnnotations()[0] : existingModifierList.getFirstChild();
        for (PsiAnnotation annotation : psiAnnotations) {
          final PsiAnnotation existingAnno = existingModifierList.findAnnotation(annotation.getQualifiedName());
          if (existingAnno != null) {
            annoAnchor = existingAnno.replace(annotation);
          }
          else {
            existingModifierList.addBefore(annotation, annoAnchor);
          }
        }
      }
      member = (T)existingMember;
      if (!member.isValid()) {
        LOG.error("invalid member: " + member +
                  " self modified list: " + modifierList +
                  " existing modified list: " + existingModifierList);
      }
    }
    setMember(member);
  }
@Override
  public void insert(final @NotNull PsiClass aClass, @Nullable PsiElement anchor, boolean before)