/** * Returns a collection containing a copy of each EObject in the given collection. * @param eObjects the collection of objects to copy. * @return the collection of copies. */ public <T> Collection<T> copyAll(Collection<? extends T> eObjects) { Collection<T> result = new ArrayList<T>(eObjects.size()); for (Object object : eObjects) { @SuppressWarnings("unchecked") T t = (T)copy((EObject)object); if (t != null) { result.add(t); } } return result; }
/** * Returns a collection containing a copy of each EObject in the given collection. * @param eObjects the collection of objects to copy. * @return the collection of copies. */ public <T> Collection<T> copyAll(Collection<? extends T> eObjects) { Collection<T> result = new ArrayList<T>(eObjects.size()); for (Object object : eObjects) { @SuppressWarnings("unchecked") T t = (T)copy((EObject)object); if (t != null) { result.add(t); } } return result; }
@Override public EObject copy(EObject eObject) { EObject copyEObject = super.copy(eObject); if (eObject != copyEObject) { List<EObject> mergedEObjects = resultingToMergedEObjectMap .get(copyEObject); if (mergedEObjects == null) { resultingToMergedEObjectMap .put( copyEObject, mergedEObjects = new UniqueEList.FastCompare<EObject>( 1)); } mergedEObjects.add(eObject); } if (DEBUG) { System.out.println(getQualifiedText(eObject) + "->" //$NON-NLS-1$ + getQualifiedText(copyEObject)); } return copyEObject; }
AbstractElement clone = (AbstractElement) copier.copy(element); copier.copyReferences(); return clone;
AbstractElement clone = (AbstractElement) copier.copy(result); copier.copyReferences(); return clone;
final EObject result = super.copy(eobject); if (result instanceof JvmWildcardTypeReference) { final JvmWildcardTypeReference wildcardType = (JvmWildcardTypeReference) result;
public void merge(BuildPlan source) { Assert.isNotNull(source); @SuppressWarnings("serial") EcoreUtil.Copier copier = new EcoreUtil.Copier() { @Override protected EObject createCopy(EObject source) { return BuildPlan.this; // TODO This will certainly fail for nested plans! }; @Override protected void copyAttribute(EAttribute eAttribute, EObject eObject, EObject copyEObject) { super.copyAttribute(eAttribute, eObject, copyEObject); } @Override protected void copyContainment(EReference eReference, EObject eObject, EObject copyEObject) { // XXX do nothing, throws a ClassCastException due to overridded createCopy() method } }; copier.copy(source); // FIXME implement proper merge getParameterDefinitions().clear(); getParameterDefinitions().addAll(EcoreUtil.copyAll(source.getParameterDefinitions())); getFlags().clear(); getFlags().addAll(source.getFlags()); getHealthReports().clear(); getHealthReports().addAll(EcoreUtil.copyAll(source.getHealthReports())); getAttributes().clear(); getAttributes().putAll(source.getAttributes()); }
/** * Called to handle the copying of a containment feature; * this adds a list of copies or sets a single copy as appropriate for the multiplicity. * @param eReference the feature to copy. * @param eObject the object from which to copy. * @param copyEObject the object to copy to. */ protected void copyContainment(EReference eReference, EObject eObject, EObject copyEObject) { if (eObject.eIsSet(eReference)) { EStructuralFeature.Setting setting = getTarget(eReference, eObject, copyEObject); if (setting != null) { Object value = eObject.eGet(eReference); if (eReference.isMany()) { @SuppressWarnings("unchecked") List<EObject> target = (List<EObject>)value; setting.set(copyAll(target)); } else { setting.set(copy((EObject)value)); } } } }
/** * Called to handle the copying of a containment feature; * this adds a list of copies or sets a single copy as appropriate for the multiplicity. * @param eReference the feature to copy. * @param eObject the object from which to copy. * @param copyEObject the object to copy to. */ protected void copyContainment(EReference eReference, EObject eObject, EObject copyEObject) { if (eObject.eIsSet(eReference)) { EStructuralFeature.Setting setting = getTarget(eReference, eObject, copyEObject); if (setting != null) { Object value = eObject.eGet(eReference); if (eReference.isMany()) { @SuppressWarnings("unchecked") List<EObject> target = (List<EObject>)value; setting.set(copyAll(target)); } else { setting.set(copy((EObject)value)); } } } }
/** * Creates a deep copy of the given object and associates each copied instance with the * clone. Does not resolve any proxies. * * @param original the root element to be cloned. * @return a clone of tree rooted in original associated with the original, <code>null</code> if original is <code>null</code>. */ protected <T extends EObject> T cloneAndAssociate(T original) { final boolean canAssociate = languageInfo.isLanguage(original.eResource()); EcoreUtil.Copier copier = new EcoreUtil.Copier(false) { private static final long serialVersionUID = 1L; @Override/* @Nullable */ protected EObject createCopy(/* @Nullable */ EObject eObject) { EObject result = super.createCopy(eObject); if (canAssociate && result != null && eObject != null && !eObject.eIsProxy()) { associator.associate(eObject, result); } return result; } }; @SuppressWarnings("unchecked") T copy = (T) copier.copy(original); copier.copyReferences(); return copy; }
/** * Call to handle copying the contained objects within a feature map. * @param featureMap the feature map the copy. * @since 2.10 */ protected void copyFeatureMap(FeatureMap featureMap) { for (int i = 0, size = featureMap.size(); i < size; ++i) { EStructuralFeature feature = featureMap.getEStructuralFeature(i); if (feature instanceof EReference && ((EReference)feature).isContainment()) { Object value = featureMap.getValue(i); if (value != null) { // The containment references are hooked up later during copyReferences. // copy((EObject)value); } } } }
public void applyToOriginal() { if (original == null) { throw new IllegalStateException(); } @SuppressWarnings("serial") EcoreUtil.Copier copier = new EcoreUtil.Copier() { @Override protected EObject createCopy(EObject source) { return original; }; @Override protected void copyAttribute(EAttribute eAttribute, EObject eObject, EObject copyEObject) { if (eAttribute.getFeatureID() == BuildPackage.BUILD_SERVER__LOCATION) { return; } super.copyAttribute(eAttribute, eObject, copyEObject); } @Override protected void copyContainment(EReference eReference, EObject eObject, EObject copyEObject) { // do nothing } }; copier.copy(this); }
@Override public EObject copy(EObject eObject) { // Ensure that objects that appear both as a contained child and directly in the list, will not be copied twice. // EObject result = get(eObject); if (result != null) { return result; } else { // Otherwise create a normal copy. // return super.copy(eObject); } } };
/** * Call to handle copying the contained objects within a feature map. * @param featureMap the feature map the copy. * @since 2.10 */ protected void copyFeatureMap(FeatureMap featureMap) { for (int i = 0, size = featureMap.size(); i < size; ++i) { EStructuralFeature feature = featureMap.getEStructuralFeature(i); if (feature instanceof EReference && ((EReference)feature).isContainment()) { Object value = featureMap.getValue(i); if (value != null) { // The containment references are hooked up later during copyReferences. // copy((EObject)value); } } } }
@Override public EObject copy(EObject eObject) { // Ensure that objects that appear both as a contained child and directly in the list, will not be copied twice. // EObject result = get(eObject); if (result != null) { return result; } else { // Otherwise create a normal copy. // return super.copy(eObject); } } };
/** * Returns a self-contained copy of the eObject. * @param eObject the object to copy. * @return the copy. * @see Copier */ public static <T extends EObject> T copy(T eObject) { Copier copier = new Copier(); EObject result = copier.copy(eObject); copier.copyReferences(); @SuppressWarnings("unchecked")T t = (T)result; return t; }
/** * Returns a self-contained copy of the eObject. * @param eObject the object to copy. * @return the copy. * @see Copier */ public static <T extends EObject> T copy(T eObject) { Copier copier = new Copier(); EObject result = copier.copy(eObject); copier.copyReferences(); @SuppressWarnings("unchecked")T t = (T)result; return t; }
public BuildElement createWorkingCopy() { EcoreUtil.Copier copier = new EcoreUtil.Copier(); BuildElement newElement = (BuildElement) copier.copy(this); // FIXME clone containment hierarchy instead copier.copyReferences(); newElement.original = this; return newElement; }
/** * Clones the given EObject without resolving any proxies. */ @SuppressWarnings("unchecked") public static <T extends EObject> T cloneWithProxies(T original) { if (original == null) return original; EcoreUtil.Copier copier = new EcoreUtil.Copier(false); T copy = (T) copier.copy(original); copier.copyReferences(); return copy; }