Search in sources :

Example 6 with ReferenceChange

use of org.eclipse.emf.compare.ReferenceChange in project InformationSystem by ObeoNetwork.

the class ChangeBuilder method handle.

public Diff handle(EObject comparisonElement) {
    Diff createdDiffElement = null;
    if (comparisonElement instanceof Diff) {
        Diff diff = (Diff) comparisonElement;
        if (isReferenceAdd(diff)) {
            createdDiffElement = handleAddChange((ReferenceChange) diff);
        } else if (isReferenceDelete(diff)) {
            createdDiffElement = handleRemoveChange((ReferenceChange) diff);
        } else if (diff.getKind() == DifferenceKind.CHANGE) {
            if (diff instanceof AttributeChange) {
                AttributeChange attributeChange = (AttributeChange) diff;
                // Ignore TechID
                if (DatabasePackage.eINSTANCE.getDatabaseElement_TechID() != attributeChange.getAttribute()) {
                    createdDiffElement = handleAlterChange(attributeChange);
                }
            }
            if (diff instanceof ReferenceChange) {
                createdDiffElement = handleAlterChange((ReferenceChange) diff);
            }
        }
        // Attach newly created element to its parent
        if (createdDiffElement != null) {
            createdDiffElement.getRefinedBy().add(diff);
            diff.getMatch().getDifferences().add(createdDiffElement);
        }
    } else if (comparisonElement instanceof Match) {
        Match match = (Match) comparisonElement;
        if (match.getAllDifferences().iterator().hasNext()) {
            // There is at least one Diff in this match or one of its submatches,
            // thus we created a Diff that marks that there is some update to perform inside the match's contents.
            createdDiffElement = handleAlterChange((Match) comparisonElement);
        }
        if (createdDiffElement != null) {
            Match parent = null;
            EObject container = match.eContainer();
            if (container instanceof Match) {
                parent = (Match) container;
            } else {
                parent = (Match) comparisonElement;
            }
            parent.getDifferences().add(createdDiffElement);
        }
    }
    return createdDiffElement;
}
Also used : Diff(org.eclipse.emf.compare.Diff) DBDiff(org.obeonetwork.dsl.database.dbevolution.DBDiff) AttributeChange(org.eclipse.emf.compare.AttributeChange) EObject(org.eclipse.emf.ecore.EObject) ReferenceChange(org.eclipse.emf.compare.ReferenceChange) Match(org.eclipse.emf.compare.Match)

Aggregations

Diff (org.eclipse.emf.compare.Diff)6 ReferenceChange (org.eclipse.emf.compare.ReferenceChange)6 ArrayList (java.util.ArrayList)3 List (java.util.List)3 EList (org.eclipse.emf.common.util.EList)3 Comparison (org.eclipse.emf.compare.Comparison)3 EMFCompare (org.eclipse.emf.compare.EMFCompare)3 DefaultComparisonScope (org.eclipse.emf.compare.scope.DefaultComparisonScope)3 IComparisonScope (org.eclipse.emf.compare.scope.IComparisonScope)3 EObject (org.eclipse.emf.ecore.EObject)3 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)3 HashSet (java.util.HashSet)2 AttributeChange (org.eclipse.emf.compare.AttributeChange)1 Match (org.eclipse.emf.compare.Match)1 DBDiff (org.obeonetwork.dsl.database.dbevolution.DBDiff)1 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)1 TdTable (org.talend.cwm.relational.TdTable)1 TaggedValue (orgomg.cwm.objectmodel.core.TaggedValue)1