Class ResourceAttachmentChangeMerger

java.lang.Object
org.eclipse.emf.compare.merge.AbstractMerger
org.eclipse.emf.compare.merge.ResourceAttachmentChangeMerger
All Implemented Interfaces:
IMergeCriterionAware, IMergeOptionAware, IMerger, IMerger2
Direct Known Subclasses:
AdditiveResourceAttachmentChangeMerger

public class ResourceAttachmentChangeMerger extends AbstractMerger
This specific implementation of AbstractMerger will be used to merge resource attachment changes.
  • Constructor Details

    • ResourceAttachmentChangeMerger

      public ResourceAttachmentChangeMerger()
  • Method Details

    • isMergerFor

      public boolean isMergerFor(Diff target)
      Check if the merger is a good candidate to merge the given difference.
      Parameters:
      target - The given target difference.
      Returns:
      True if it is the good candidate, false otherwise.
      See Also:
    • apply

      public boolean apply(IMergeCriterion criterion)
      Description copied from class: AbstractMerger
      Default implementation of apply for mergers that extends this class. Will accept null or AdditiveMergeCriterion.INSTANCE.
      Specified by:
      apply in interface IMergeCriterionAware
      Overrides:
      apply in class AbstractMerger
      Parameters:
      criterion - The merge criterion
      Returns:
      true if the given criterion is null or is AdditiveMergeCriterion.INSTANCE.
    • accept

      protected void accept(Diff diff, boolean rightToLeft)
      Accept the given difference. This may be overridden by clients.
      Overrides:
      accept in class AbstractMerger
      Parameters:
      diff - the difference to merge
      rightToLeft - the direction of the merge
      See Also:
    • reject

      protected void reject(Diff diff, boolean rightToLeft)
      Reject the given difference. This may be overridden by clients.
      Overrides:
      reject in class AbstractMerger
      Parameters:
      diff - the difference to merge
      rightToLeft - the direction of the merge
      See Also:
    • move

      protected void move(ResourceAttachmentChange diff, boolean rightToLeft)
      Handle moves of ResourceAttachmentChanges.
      Parameters:
      diff - The difference we are to merge.
      rightToLeft - Tells us whether we are to add an object on the left or right side.
    • deleteFormerResourceIfNecessary

      @Deprecated protected void deleteFormerResourceIfNecessary(Comparison comparison, Resource oldResource, boolean rightToLeft)
      Deprecated.
      Use ResourceAttachmentChangeMerger#deleteFormerResourceIfNecessary(ResourceAttachmentChange, Resource, boolean) instead.
      A move of an EObject to a different resource has just been made. Do whatever post-treatment is needed. The default implementation deletes the former resource if it's no longer supposed to be here.
      Parameters:
      comparison - The comparison
      oldResource - The resource from where the EObject has been moved
      rightToLeft - The direction of the change
    • mustDelete

      @Deprecated protected boolean mustDelete(Resource resource, ResourceAttachmentChange diff, boolean rightToLeft)
      Deprecated.
      Don't use this method.
      Indicate whether the given resource must be marked for deletion or not. Can be overridden in sub-classes if necessary.
      Parameters:
      resource - The resource candidate for deletion
      diff - The ResourceAttachmentChange that's just been merged
      rightToLeft - The direction of the merge
      Returns:
      true if the given resource must be deleted.
    • deleteResource

      @Deprecated protected void deleteResource(Resource resource)
      Deprecated.
      Not used anymore, it's not the responsibility of the ResourceAttachmentChangeMerger to delete resources. This is now achieved by installing a ResourceChangeAdapter on comparisons.
      This method doesn't do anything now. The deletion of resources that need to be deleted is performed elsewhere.
      Parameters:
      resource - The resource to delete
    • addInTarget

      protected void addInTarget(ResourceAttachmentChange diff, boolean rightToLeft)
      This will be called when we need to create an element in the target side.

      All necessary sanity checks have been made to ensure that the current operation is one that should create an object in its side. In other words, either :

      • We are copying from right to left and
        • we are copying an addition to the right side (we need to create the same root in the left), or
        • we are copying a deletion from the left side (we need to revert the deletion).
      • We are copying from left to right and
        • we are copying a deletion from the right side (we need to revert the deletion), or
        • we are copying an addition to the left side (we need to create the same root in the right).

      Parameters:
      diff - The difference we are to merge.
      rightToLeft - Tells us whether we are to add an object on the left or right side.
    • findOrCreateTargetResource

      protected Resource findOrCreateTargetResource(Match match, boolean rightToLeft)
      This will try and locate the "target" resource of this merge in the current comparison. If we can't locate it, we assume that it needs to be created as we are in the process of adding a new element to it.
      Parameters:
      match - Match of the root which resource we need to find or create.
      rightToLeft - Direction of the merge. This will tell us which side we are to look up for the target resource.
      Returns:
      The resource we could find in the current comparison if any. Otherwise, we'll return either a newly created resource that can serve as a target of this merge, or null if no valid target resource can be created.
    • computeTargetURI

      protected URI computeTargetURI(Match match, boolean rightToLeft)
      Computes the URI of the "target" resource. Will be used if we need to create or "find" it.
      Parameters:
      match - Match of the root for which we need a resource URI.
      rightToLeft - Direction of the merge.
      Returns:
      The URI that is to be used for our target resource. null if we cannot compute a valid target URI.
    • getMatchResource

      protected MatchResource getMatchResource(Comparison comparison, Resource resource)
      Returns the MatchResource corresponding to the given resource.
      Parameters:
      comparison - The current comparison.
      resource - Resource for which we need a MatchResource.
      Returns:
      The MatchResource corresponding to the given resource.
    • removeFromTarget

      protected void removeFromTarget(ResourceAttachmentChange diff, boolean rightToLeft)
      This will be called when we need to remove an element from the target side.

      All necessary sanity checks have been made to ensure that the current operation is one that should delete an object. In other words, we are :

      • Copying from right to left and either
        • we are copying a deletion from the right side (we need to remove the same root from the left) or,
        • we are copying an addition to the left side (we need to revert the addition).
      • Copying from left to right and either
        • we are copying an addition to the right side (we need to revert the addition), or.
        • we are copying a deletion from the left side (we need to remove the same root from the right).

      Parameters:
      diff - The difference we are to merge.
      rightToLeft - Tells us whether we are to add an object on the left or right side.
    • findInsertionIndex

      protected <E> int findInsertionIndex(Comparison comparison, List<E> source, List<E> target, E newElement)
      This will be used by the distinct merge actions in order to find the index at which a value should be inserted in its target list. See DiffUtil.findInsertionIndex(Comparison, Diff, boolean) for more on this.

      Sub-classes can override this if the insertion order is irrelevant. A return value of -1 will be considered as "no index" and the value will be inserted at the end of its target list.

      Type Parameters:
      E - Type of the sequences content.
      Parameters:
      comparison - This will be used in order to retrieve the Match for EObjects when comparing them.
      source - The List from which one element has to be added to the target list.
      target - The List into which one element from source has to be added.
      newElement - The element from source that needs to be added into target.
      Returns:
      The index at which the new value should be inserted into the 'target' list, as inferred from its position in source. -1 if the value should be inserted at the end of its target list.
      See Also: