private static CompositePackagingElement<?> getOrCreateModifiableParent(CompositePackagingElement<?> parentElement, PackagingElementNode<?> node) {
    PackagingElementNode<?> current = node;
    List<String> dirNames = new ArrayList<>();
    while (current != null && !(current instanceof ArtifactRootNode)) {
      final PackagingElement<?> packagingElement = current.getFirstElement();
      if (!(packagingElement instanceof DirectoryPackagingElement)) {
        return parentElement;
      }
      dirNames.add(((DirectoryPackagingElement)packagingElement).getDirectoryName());
      current = current.getParentNode();
    }

    if (current == null) return parentElement;
    final PackagingElement<?> rootElement = current.getElementIfSingle();
    if (!(rootElement instanceof CompositePackagingElement<?>)) return parentElement;

    Collections.reverse(dirNames);
    String path = StringUtil.join(dirNames, "/");
    return PackagingElementFactory.getInstance().getOrCreateDirectory((CompositePackagingElement<?>)rootElement, path);
  }
private static CompositePackagingElement<?> getOrCreateModifiableParent(CompositePackagingElement<?> parentElement, PackagingElementNode<?> node)