public <T extends PackagingElement<?>> T addOrFindChild(@NotNull T child) {
    return this.update(
      () -> myAddOrFindChild(child),
      (builder, packagingElementEntity) -> {
        MutableExternalEntityMapping<PackagingElement<?>> mapping = builder.getMutableExternalMapping(PackagingExternalMapping.key);
        CompositePackagingElementEntity entity = (CompositePackagingElementEntity)packagingElementEntity;
        List<? extends PackagingElement<?>> children = ContainerUtil.map(entity.getChildren().iterator(), o -> {
          PackagingElement<?> data = mapping.getDataByEntity(o);
          return Objects
            .requireNonNullElseGet(data, () -> (PackagingElement<?>)myPackagingElementInitializer.initialize(o, myProject, builder));
        });
        for (PackagingElement<?> element : children) {
          if (element.isEqualTo(child)) {
            if (element instanceof CompositePackagingElement) {
              final List<PackagingElement<?>> childrenOfChild = ((CompositePackagingElement<?>)child).getChildren();
              ((CompositePackagingElement<?>)element).addOrFindChildren(childrenOfChild);
            }

            // Set correct storage if needed
            setStorageForPackagingElement(element);
            //noinspection unchecked
            return (T) element;
          }
        }
        // TODO not sure if the entity source is correct
        PackagingElementEntity.Builder<? extends PackagingElementEntity> childEntity = child.getOrAddEntityBuilder(builder, entity.getEntitySource(), myProject);
        builder.modifyEntity(CompositePackagingElementEntity.Builder.class, entity, o -> {
          List<PackagingElementEntity.Builder<? extends PackagingElementEntity>> existingChildren = o.getChildren();
          List<PackagingElementEntity.Builder<? extends PackagingElementEntity>> mutableList = new ArrayList<>(existingChildren);
          mutableList.add(childEntity);
          o.setChildren(mutableList);
          return Unit.INSTANCE;
        });
        // Set storage for the new child
        setStorageForPackagingElement(child);
        return child;
      }
    );
  }
public <T extends PackagingElement<?>> T addOrFindChild(@NotNull T child)