public void addFirstChild(@NotNull PackagingElement<?> child) {
    this.update(
      () -> myAddFirstChild(child),
      (builder, packagingElementEntity) -> {
        MutableExternalEntityMapping<PackagingElement<?>> mapping = builder.getMutableExternalMapping(PackagingExternalMapping.key);
        CompositePackagingElementEntity entity = (CompositePackagingElementEntity)packagingElementEntity;
        List<Pair<PackagingElementEntity.Builder<? extends PackagingElementEntity>, PackagingElement<?>>> pairs =
          new ArrayList<>(ContainerUtil.map(entity.getChildren().iterator(), o -> {
            Ref<PackagingElementEntity.Builder<? extends PackagingElementEntity>> thief = Ref.create();
            builder.modifyEntity(PackagingElementEntity.Builder.class, o, x -> {
              thief.set(x);
              return Unit.INSTANCE;
            });
            PackagingElementEntity.Builder<? extends PackagingElementEntity> entityBuilder = thief.get();
            PackagingElement<?> data = mapping.getDataByEntity(o);
            if (data == null) {
              return new Pair<>(entityBuilder, myPackagingElementInitializer.initialize(o, myProject, builder));
            }
            return new Pair<>(entityBuilder, data);
          }));
        PackagingElementEntity.Builder<? extends PackagingElementEntity> childEntity = child.getOrAddEntityBuilder(builder, entity.getEntitySource(), myProject);
        pairs.add(0, new Pair<>(childEntity, child));
        for (int i = 1; i < pairs.size(); i++) {
          PackagingElement<?> element = pairs.get(i).getSecond();
          if (element.isEqualTo(child)) {
            if (element instanceof CompositePackagingElement<?>) {
              ((CompositePackagingElement<?>)child).addOrFindChildren(((CompositePackagingElement<?>)element).getChildren());
            }
            pairs.remove(i);
            break;
          }
        }
        List<PackagingElementEntity.Builder<? extends PackagingElementEntity>> newChildren = ContainerUtil.map(pairs, o -> o.getFirst());
        //noinspection unchecked
        builder.modifyEntity(CompositePackagingElementEntity.Builder.class, entity, o -> {
          //noinspection unchecked
          o.setChildren(newChildren);
          return Unit.INSTANCE;
        });
        // Set storage for the new child
        setStorageForPackagingElement(child);
      }
    );
  }
public void addFirstChild(@NotNull PackagingElement<?> child)