Skip to content

Commit

Permalink
Merge branch 'util-extend'
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianmoeller committed Jul 6, 2023
2 parents cd6823d + 80eaa1e commit e14d354
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.eclipse.emf.ecore.util.EContentsEList;
import org.eclipse.emf.ecore.util.ECrossReferenceAdapter;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.util.EcoreUtil.Copier;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.eclipse.pde.core.plugin.IPluginModelBase;
import org.eclipse.pde.core.plugin.PluginRegistry;
Expand Down Expand Up @@ -1139,5 +1140,18 @@ private static boolean containsClassifierWithSameName(final GenPackage genPackag
.filter(genClassifier -> genClassifier.getName().equals(genPackage.getPackageName())).findAny()
.isPresent();
}


public static <T> CopyResult<T> copyAll(Collection<? extends T> eObjects) {
Copier copier = new Copier();
Collection<T> result = copier.copyAll(eObjects);
copier.copyReferences();

Map<EObject, EObject> inversed = new HashMap<>();
for (var entry : copier.entrySet())
inversed.put(entry.getValue(), entry.getKey());
return new CopyResult<T>(result, inversed);
}

public record CopyResult<T>(Collection<T> copies, Map<EObject, EObject> copies2originals) {
}
}

0 comments on commit e14d354

Please sign in to comment.