Class AbstractMerger

java.lang.Object
org.eclipse.emf.compare.merge.AbstractMerger
All Implemented Interfaces:
IMergeCriterionAware, IMergeOptionAware, IMerger, IMerger2
Direct Known Subclasses:
AttributeChangeMerger, ConflictMerger, FeatureMapChangeMerger, PseudoConflictMerger, ReferenceChangeMerger, ResourceAttachmentChangeMerger, ResourceLocationChangeMerger

public abstract class AbstractMerger extends Object implements IMerger2, IMergeOptionAware, IMergeCriterionAware
Abstract implementation of an IMerger. This can be used as a base implementation to avoid re-implementing the whole contract.
Since:
3.0
  • Field Details

    • SUB_DIFF_AWARE_OPTION

      public static final String SUB_DIFF_AWARE_OPTION
      The key of the merge option that allows to the mergers to consider sub-diffs of a diff as a whole.
      See Also:
    • mergeOptions

      protected Map<Object,Object> mergeOptions
      The map of all merge options that this merger should be aware of.
      Since:
      3.4
  • Constructor Details

    • AbstractMerger

      public AbstractMerger()
      Default constructor.
  • Method Details

    • getRanking

      public int getRanking()
      Returns the ranking of this merger.
      Specified by:
      getRanking in interface IMerger
      Returns:
      The ranking.
      See Also:
    • setRanking

      public void setRanking(int r)
      Set the ranking of this merger.
      Specified by:
      setRanking in interface IMerger
      Parameters:
      r - The ranking.
      See Also:
    • getRegistry

      public IMerger.Registry getRegistry()
      Get the registry.
      Specified by:
      getRegistry in interface IMerger
      Returns:
      The registry.
      See Also:
    • setRegistry

      public void setRegistry(IMerger.Registry registry)
      Set the registry containing this merger.
      Specified by:
      setRegistry in interface IMerger
      Parameters:
      registry - The merger registry.
      See Also:
    • apply

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

      public Map<Object,Object> getMergeOptions()
      Get the map of options that the merger will have to take into account.
      Specified by:
      getMergeOptions in interface IMergeOptionAware
      Returns:
      the map of options.
      See Also:
    • setMergeOptions

      public void setMergeOptions(Map<Object,Object> options)
      Set the map of options that the merger will have to take into account.
      Specified by:
      setMergeOptions in interface IMergeOptionAware
      Parameters:
      options - the map of options.
      Since:
      3.3
      See Also:
    • getDirectMergeDependencies

      public Set<Diff> getDirectMergeDependencies(Diff diff, boolean mergeRightToLeft)
      Retrieves the set of directly required diffs needed in order to merge the current one. This may includes the diff's requirements or any other diff that we need to merge before the given one.
      Specified by:
      getDirectMergeDependencies in interface IMerger2
      Parameters:
      diff - The diff which direct requirements we need.
      mergeRightToLeft - The direction in which we're considering a merge.
      Returns:
      The set of directly required diffs in order to merge the current one.
      Since:
      3.2
    • getDirectResultingMerges

      public Set<Diff> getDirectResultingMerges(Diff target, boolean mergeRightToLeft)
      Returns all differences that will be merged because of our merging the given target difference. This may include the diff's implications, the diff's equivalences, the diff's refinements or any other diff that we need to merge together with the given diff.
      Specified by:
      getDirectResultingMerges in interface IMerger2
      Parameters:
      target - The difference we're considering merging.
      mergeRightToLeft - The direction in which we're considering a merge.
      Returns:
      The Set of all differences that will be merged because we've merged target.
      Since:
      3.2
    • getDirectResultingRejections

      public Set<Diff> getDirectResultingRejections(Diff target, boolean rightToLeft)
      Returns the set of all differences that need to be rejected if target is merged in the given direction.
      Specified by:
      getDirectResultingRejections in interface IMerger2
      Parameters:
      target - The difference we're considering merging.
      rightToLeft - The direction in which we're considering a merge.
      Returns:
      The Set of all differences that will be rejected if we are to merge merged target.
      Since:
      3.2
    • getLogicallyResultingMerges

      protected Set<Diff> getLogicallyResultingMerges(Diff diff, boolean mergeRightToLeft)
      Returns a set of differences that should be logically merged with the given diff. As opposed to merge dependencies, it is not structurally necessary to merge these diffs before the given diff. This may include the diff's implications, the diff's refinement or any other diff that should be logically merged with the given diff.
      Parameters:
      diff - The difference we're considering merging.
      mergeRightToLeft - The direction in which we're considering a merge.
      Returns:
      The Set of all differences that will be merged because we've merged diff.
      Since:
      3.5
    • getImpliedMerges

      protected Set<Diff> getImpliedMerges(Diff target, boolean mergeRightToLeft)
      Returns all differences that are automatically set to the targets state if the given target diff is merged. This may include the diff's implications, the diff's equivalences or any other diff that requires no merging by itself.
      Parameters:
      target - The difference we're considering merging.
      mergeRightToLeft - The direction in which we're considering a merge.
      Returns:
      The Set of all differences that will be set to MERGED because we've merged target.
      Since:
      3.5
    • copyDiff

      protected void copyDiff(Diff target, Monitor monitor, boolean rightToLeft)
      Executes a copy in the given merge direction. This method is a generalization of copyLeftToRight(Diff, Monitor) and copyRightToLeft(Diff, Monitor).
      Parameters:
      target - The difference to handle.
      monitor - Monitor.
      rightToLeft - Merge direction.
      Since:
      3.5
    • copyLeftToRight

      public void copyLeftToRight(Diff target, Monitor monitor)
      Executes the copy from left to right.
      Specified by:
      copyLeftToRight in interface IMerger
      Parameters:
      target - The difference to handle.
      monitor - Monitor.
      Since:
      3.1
      See Also:
    • copyRightToLeft

      public void copyRightToLeft(Diff target, Monitor monitor)
      Executes the copy from right to left.
      Specified by:
      copyRightToLeft in interface IMerger
      Parameters:
      target - The difference to handle.
      monitor - Monitor.
      Since:
      3.1
      See Also:
    • accept

      protected void accept(Diff diff, boolean rightToLeft)
      Accept the given difference. This may be overridden by clients.
      Parameters:
      diff - the difference to merge
      rightToLeft - the direction of the merge
      Since:
      3.1
    • reject

      protected void reject(Diff diff, boolean rightToLeft)
      Reject the given difference. This may be overridden by clients.
      Parameters:
      diff - the difference to merge
      rightToLeft - the direction of the merge
      Since:
      3.1
    • mergeDiff

      protected void mergeDiff(Diff diff, boolean rightToLeft, Monitor monitor)
      This can be used by mergers to merge another (required, equivalent...) difference using the right merger for that diff.
      Parameters:
      diff - The diff we need to merge.
      rightToLeft - Direction of that merge.
      monitor - The monitor we should use to report progress.
    • getMergerDelegate

      protected DelegatingMerger getMergerDelegate(Diff diff)
      Find the best merger for diff and wrap it in a delegate that will take the current merge criterion into account. The current merge criterion should be stored in the merger's mergeOptions map using IMergeCriterion.OPTION_MERGE_CRITERION as a key.
      Parameters:
      diff - The diff
      Returns:
      the best merger to use for merging the diff
      Since:
      3.4
    • getMergerDelegate

      public static DelegatingMerger getMergerDelegate(Diff diff, IMerger.Registry2 registry, IMergeCriterion criterion)
      Find the best merger for diff and wrap it in a delegate that will take the given merge criterion into account. This is NOT Thread-safe!
      Parameters:
      diff - The diff
      registry - The registry of mergers where to look for mergers
      criterion - The merge criterion to use
      Returns:
      The best merger for diff and criterion, wrapped in a delegate to deal with setting/restoring the criterion in the merger used.
      Since:
      3.4
    • isInTerminalState

      public static boolean isInTerminalState(Diff target)
      Returns whether the given difference is in a terminal state or not. Differences that are in a terminal state, i.e., either MERGED or DISCARDED, do not need to be handled by the merger.
      Parameters:
      target - difference
      Returns:
      true if the target should be merged, false otherwise.
      Since:
      3.5
    • isAdd

      protected boolean isAdd(ReferenceChange diff, boolean rightToLeft)
      Specifies whether the given diff will add a value in the target model for the current merging.

      To check whether the diff is an addition, we have to check the direction of the merge, specified in rightToLeft and the source of the diff. Therefore, this method delegates to isLeftAddOrRightDelete(ReferenceChange) and isLeftDeleteOrRightAdd(ReferenceChange).

      Parameters:
      diff - The difference to check.
      rightToLeft - Direction of the merge.
      Returns:
      true if diff will add a value with this merge, false otherwise.
      Since:
      3.2
    • isUnset

      protected boolean isUnset(ReferenceChange diff, boolean mergeRightToLeft)
      Checks whether the given diff will result in the unsetting of a reference in the given merge direction.
      Parameters:
      diff - The difference to check.
      mergeRightToLeft - Direction of the merge.
      Returns:
      true if diff will unset a value with this merge, false if this will either "set" or "change" values... or if the given diff is affecting a multi-valued reference.
    • isSet

      protected boolean isSet(ReferenceChange diff, boolean mergeRightToLeft)
      Checks whether the given diff will result in the setting of a reference in the given merge direction.
      Parameters:
      diff - The difference to check.
      mergeRightToLeft - Direction of the merge.
      Returns:
      true if diff will set a value with this merge, false if this will either "unset" or "change" values... or if the given diff is affecting a multi-valued reference.
      Since:
      3.5
    • isAccepting

      public static boolean isAccepting(Diff diff, boolean mergeRightToLeft)
      Checks whether the given merge direction will result in accepting this difference based on the difference's source.
                           | LEFT  | RIGHT
       --------------------+-------+-------
       Merge Left to Right | true  | false
       Merge Right to Left | false | true
       
      Parameters:
      diff - difference
      mergeRightToLeft - merge direction
      Returns:
      true if the merge source direction matches the difference source, false otherwise.
      Since:
      3.5
      See Also:
      • isRejecting(Diff, boolean)
    • createCopy

      protected EObject createCopy(EObject referenceObject)
      This will create a copy of the given EObject that can be used as the target of an addition (or the reverting of a deletion).

      The target will be self-contained and will have no reference towards any other EObject set (neither containment nor "classic" references). All of its attributes' values will match the given referenceObject's.

      Parameters:
      referenceObject - The EObject for which we'll create a copy.
      Returns:
      A self-contained copy of referenceObject.
      See Also:
    • addAt

      protected <E> void addAt(List<E> list, E value, int insertionIndex)
      Adds the given value into the given list at the given index. An index lower than zero or greater than the list's size will mean that the value should be appended at the end of the list.
      Type Parameters:
      E - Type of objects contained in the list.
      Parameters:
      list - The list into which value should be added.
      value - The value we need to add to list.
      insertionIndex - The index at which value should be inserted into list. -1 if it should be appended at the end of the list.