Search in sources :

Example 11 with Diff

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

the class UtilServices method getSubDiffs.

public List<DBDiff> getSubDiffs(Diff diff) {
    List<Diff> subDiffs = getDiffContentService().getSubDiffs(diff);
    List<DBDiff> changes = new ArrayList<DBDiff>();
    for (Diff subDiff : subDiffs) {
        if (subDiff instanceof DBDiff) {
            changes.add((DBDiff) subDiff);
        }
    }
    orderChanges(changes);
    return changes;
}
Also used : Diff(org.eclipse.emf.compare.Diff) DBDiff(org.obeonetwork.dsl.database.dbevolution.DBDiff) ArrayList(java.util.ArrayList) DBDiff(org.obeonetwork.dsl.database.dbevolution.DBDiff)

Example 12 with Diff

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

the class DatabasePostProcessor method postComparison.

@Override
public void postComparison(final Comparison comparison, Monitor monitor) {
    // Create DBDiffs
    new DatabaseDiffExtension().visit(comparison);
    // Delete all empty DBDiffs
    final DiffContentService service = new DiffContentService();
    Collection<Diff> toDelete = Collections2.filter(comparison.getDifferences(), new Predicate<Diff>() {

        public boolean apply(Diff input) {
            return input instanceof DBDiff && service.getSubDiffs(input, comparison).isEmpty() && input.getRefinedBy().isEmpty();
        }
    });
    for (Diff diff : toDelete) {
        // It could be optimized doing diff.eContainer().eContents().delete(diff) since no object references it.
        EcoreUtil.delete(diff);
    }
}
Also used : Diff(org.eclipse.emf.compare.Diff) DBDiff(org.obeonetwork.dsl.database.dbevolution.DBDiff) DiffContentService(org.obeonetwork.dsl.database.compare.extensions.services.DiffContentService) DBDiff(org.obeonetwork.dsl.database.dbevolution.DBDiff)

Example 13 with Diff

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

the class DBDiffImpl method setMatch.

/**
 *Copied from DiffSpec
 */
@Override
public void setMatch(Match newMatch) {
    Match oldMatch = basicGetMatch();
    if (newMatch != null) {
        EList<Diff> differences = newMatch.getDifferences();
        differences.add(this);
        eNotify(new ENotificationImpl(this, Notification.SET, ComparePackage.DIFF__MATCH, oldMatch, newMatch));
    } else if (eContainer() instanceof Match) {
        EList<Diff> differences = ((Match) eContainer()).getDifferences();
        differences.remove(this);
        eNotify(new ENotificationImpl(this, Notification.UNSET, ComparePackage.DIFF__MATCH, oldMatch, newMatch));
    }
}
Also used : EList(org.eclipse.emf.common.util.EList) Diff(org.eclipse.emf.compare.Diff) DBDiff(org.obeonetwork.dsl.database.dbevolution.DBDiff) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) Match(org.eclipse.emf.compare.Match)

Example 14 with Diff

use of org.eclipse.emf.compare.Diff 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)14 Comparison (org.eclipse.emf.compare.Comparison)7 EList (org.eclipse.emf.common.util.EList)6 EMFCompare (org.eclipse.emf.compare.EMFCompare)6 ReferenceChange (org.eclipse.emf.compare.ReferenceChange)6 DefaultComparisonScope (org.eclipse.emf.compare.scope.DefaultComparisonScope)6 IComparisonScope (org.eclipse.emf.compare.scope.IComparisonScope)6 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 EObject (org.eclipse.emf.ecore.EObject)4 DBDiff (org.obeonetwork.dsl.database.dbevolution.DBDiff)4 Match (org.eclipse.emf.compare.Match)3 HashSet (java.util.HashSet)2 DiffContentService (org.obeonetwork.dsl.database.compare.extensions.services.DiffContentService)2 CompareConfiguration (org.eclipse.compare.CompareConfiguration)1 CompareEditorInput (org.eclipse.compare.CompareEditorInput)1 AdapterFactory (org.eclipse.emf.common.notify.AdapterFactory)1 AttributeChange (org.eclipse.emf.compare.AttributeChange)1 ICompareEditingDomain (org.eclipse.emf.compare.domain.ICompareEditingDomain)1