org.eclipse.emf.compare.merge

## Class AttributeChangeMerger

- java.lang.Object
- - org.eclipse.emf.compare.merge.AbstractMerger
  - - org.eclipse.emf.compare.merge.AttributeChangeMerger

All Implemented Interfaces:
  IMergeCriterionAware, IMergeOptionAware, IMerger, IMerger2

    public class AttributeChangeMerger
    extends AbstractMerger

This specific implementation of `AbstractMerger` will be used to merge attribute changes.

### Nested Class Summary

### Nested classes/interfaces inherited from interface org.eclipse.emf.compare.merge.IMerger

`IMerger.Registry, IMerger.Registry2, IMerger.RegistryImpl`

### Field Summary

### Fields inherited from class org.eclipse.emf.compare.merge.AbstractMerger

`mergeOptions, SUB_DIFF_AWARE_OPTION`

### Constructor Summary

Constructors
Constructor and Description
`AttributeChangeMerger()`

### Method Summary

All Methods Instance Methods Concrete Methods Deprecated Methods
`protected void` `accept(Diff diff, boolean rightToLeft)` Accept the given difference.
`protected void` `addInTarget(AttributeChange diff, boolean rightToLeft)` This will be called when we need to create an element in the target side.
`protected void` `changeValue(AttributeChange diff, boolean rightToLeft)` This will be called by the merge operations in order to change single-valued attributes.
`protected void` `doMove(AttributeChange diff, Comparison comparison, EObject expectedContainer, Object expectedValue, boolean rightToLeft)` This will do the actual work of moving the element into its attribute.
`protected int` `findInsertionIndex(Comparison comparison, Diff diff, boolean rightToLeft)` 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.
`boolean` `isMergerFor(Diff target)` Check if the merger is a good candidate to merge the given difference.
`protected void` `moveElement(AttributeChange diff, boolean rightToLeft)` This will be called when trying to copy a "MOVE" diff.
`protected String` `performThreeWayTextMerge(String left, String right, String origin)` Performs a three-way text merge for the given `origin`, `left`, and `right` text versions.
`protected void` `reject(Diff diff, boolean rightToLeft)` Reject the given difference.
`protected void` `removeFromTarget(AttributeChange diff, boolean rightToLeft)` This will be called when we need to remove an element from the target side.
`protected void` `resetInTarget(AttributeChange diff, boolean rightToLeft)` Deprecated. this has been refactored into `changeValue(AttributeChange, boolean)`.

### Methods inherited from class org.eclipse.emf.compare.merge.AbstractMerger

`addAt, apply, copyDiff, copyLeftToRight, copyRightToLeft, createCopy, getDirectMergeDependencies, getDirectResultingMerges, getDirectResultingRejections, getImpliedMerges, getLogicallyResultingMerges, getMergeOptions, getMergerDelegate, getMergerDelegate, getRanking, getRegistry, isAccepting, isAdd, isInTerminalState, isSet, isUnset, mergeDiff, setMergeOptions, setRanking, setRegistry`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### AttributeChangeMerger

    public AttributeChangeMerger()

### Method Detail

#### 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:
  `IMerger.isMergerFor(org.eclipse.emf.compare.Diff)`

#### 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:
  `AbstractMerger.accept(org.eclipse.emf.compare.Diff, boolean)`

#### 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:
  `AbstractMerger.reject(org.eclipse.emf.compare.Diff, boolean)`

#### addInTarget

    protected void addInTarget(AttributeChange 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 or add an objet to an attribute. 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 object 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 object in the right).

Parameters:
  `diff` - The diff we are currently merging.
  `rightToLeft` - Tells us whether we are to add an object on the left or right side.

#### removeFromTarget

    protected void removeFromTarget(AttributeChange 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 object in 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 object in the right).

Parameters:
  `diff` - The diff we are currently merging.
  `rightToLeft` - Tells us whether we are to add an object on the left or right side.

#### moveElement

    protected void moveElement(AttributeChange diff,
                               boolean rightToLeft)

This will be called when trying to copy a "MOVE" diff.

Parameters:
  `diff` - The diff we are currently merging.
  `rightToLeft` - Whether we should move the value in the left or right side.

#### doMove

    protected void doMove(AttributeChange diff,
                          Comparison comparison,
                          EObject expectedContainer,
                          Object expectedValue,
                          boolean rightToLeft)

This will do the actual work of moving the element into its attribute. All sanity checks were made in `#moveElement(boolean)` and no more verification will be made here.

Parameters:
  `diff` - The diff we are currently merging.
  `comparison` - Comparison holding this Diff.
  `expectedContainer` - The container in which we are reorganizing an attribute.
  `expectedValue` - The value that is to be moved within its attribute.
  `rightToLeft` - Whether we should move the value in the left or right side.

#### resetInTarget

    @Deprecated
    protected void resetInTarget(AttributeChange diff,
                                             boolean rightToLeft)

Deprecated. this has been refactored into `changeValue(AttributeChange, boolean)`.
This will be called by the merge operations in order to reset an attribute to its original value, be that the left or right side.

Should never be called on multi-valued attributes.

Parameters:
  `diff` - The diff we are currently merging.
  `rightToLeft` - Tells us the direction of this merge operation.

#### changeValue

    protected void changeValue(AttributeChange diff,
                               boolean rightToLeft)

This will be called by the merge operations in order to change single-valued attributes.

Parameters:
  `diff` - The diff we are currently merging.
  `rightToLeft` - Direction of the merge.

#### performThreeWayTextMerge

    protected String performThreeWayTextMerge(String left,
                                              String right,
                                              String origin)

Performs a three-way text merge for the given `origin`, `left`, and `right` text versions.

Parameters:
  `left` - The left version of the String.
  `right` - The right version of the String.
  `origin` - The original version of the String.
Returns:
  The merged version.
Since:
  3.2

#### findInsertionIndex

    protected int findInsertionIndex(Comparison comparison,
                                     Diff diff,
                                     boolean rightToLeft)

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.

Parameters:
  `comparison` - This will be used in order to retrieve the Match for EObjects when comparing them.
  `diff` - The diff which merging will trigger the need for an insertion index in its target list.
  `rightToLeft` - `true` if the merging will be done into the left list, so that we should consider the right model as the source and the left as the target.
Returns:
  The index at which this `diff`'s value should be inserted into the 'target' list, as inferred from `rightToLeft`. `-1` if the value should be inserted at the end of its target list.
See Also:
  `DiffUtil.findInsertionIndex(Comparison, Diff, boolean)`