Package org.eclipse.emf.compare.merge
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
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.eclipse.emf.compare.merge.IMerger
IMerger.Registry, IMerger.Registry2, IMerger.RegistryImpl
-
Field Summary
Modifier and TypeFieldDescriptionThe map of all merge options that this merger should be aware of.static final String
The key of the merge option that allows to the mergers to consider sub-diffs of a diff as a whole. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
Accept the given difference.protected <E> void
Adds the givenvalue
into the givenlist
at the givenindex
.boolean
apply
(IMergeCriterion criterion) Default implementation of apply for mergers that extends this class.protected void
Executes a copy in the given merge direction.void
copyLeftToRight
(Diff target, Monitor monitor) Executes the copy from left to right.void
copyRightToLeft
(Diff target, Monitor monitor) Executes the copy from right to left.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).getDirectMergeDependencies
(Diff diff, boolean mergeRightToLeft) Retrieves the set of directly required diffs needed in order to merge the current one.getDirectResultingMerges
(Diff target, boolean mergeRightToLeft) Returns all differences that will be merged because of our merging the giventarget
difference.getDirectResultingRejections
(Diff target, boolean rightToLeft) Returns the set of all differences that need to be rejected iftarget
is merged in the given direction.getImpliedMerges
(Diff target, boolean mergeRightToLeft) Returns all differences that are automatically set to the targetsstate
if the given target diff is merged.getLogicallyResultingMerges
(Diff diff, boolean mergeRightToLeft) Returns a set of differences that should be logically merged with the given diff.Get the map of options that the merger will have to take into account.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.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.int
Returns the ranking of this merger.Get the registry.static boolean
isAccepting
(Diff diff, boolean mergeRightToLeft) Checks whether the given merge direction will result in accepting this difference based on the difference'ssource
.protected boolean
isAdd
(ReferenceChange diff, boolean rightToLeft) Specifies whether the givendiff
will add a value in the target model for the current merging.static boolean
isInTerminalState
(Diff target) Returns whether the given difference is in a terminal state or not.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.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.protected void
This can be used by mergers to merge another (required, equivalent...) difference using the right merger for that diff.protected void
Reject the given difference.void
setMergeOptions
(Map<Object, Object> options) Set the map of options that the merger will have to take into account.void
setRanking
(int r) Set the ranking of this merger.void
setRegistry
(IMerger.Registry registry) Set the registry containing this merger.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.eclipse.emf.compare.merge.IMerger
isMergerFor
-
Field Details
-
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
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 interfaceIMerger
- Returns:
- The ranking.
- See Also:
-
setRanking
public void setRanking(int r) Set the ranking of this merger.- Specified by:
setRanking
in interfaceIMerger
- Parameters:
r
- The ranking.- See Also:
-
getRegistry
Get the registry.- Specified by:
getRegistry
in interfaceIMerger
- Returns:
- The registry.
- See Also:
-
setRegistry
Set the registry containing this merger.- Specified by:
setRegistry
in interfaceIMerger
- Parameters:
registry
- The merger registry.- See Also:
-
apply
Default implementation of apply for mergers that extends this class. Will acceptnull
or AdditiveMergeCriterion.INSTANCE.- Specified by:
apply
in interfaceIMergeCriterionAware
- Parameters:
criterion
- The merge criterion- Returns:
true
if the given criterion is null or is AdditiveMergeCriterion.INSTANCE.- Since:
- 3.4
-
getMergeOptions
Get the map of options that the merger will have to take into account.- Specified by:
getMergeOptions
in interfaceIMergeOptionAware
- Returns:
- the map of options.
- See Also:
-
setMergeOptions
Set the map of options that the merger will have to take into account.- Specified by:
setMergeOptions
in interfaceIMergeOptionAware
- Parameters:
options
- the map of options.- Since:
- 3.3
- See Also:
-
getDirectMergeDependencies
Retrieves the set of directly required diffs needed in order to merge the current one. This may includes the diff'srequirements
or any other diff that we need to merge before the given one.- Specified by:
getDirectMergeDependencies
in interfaceIMerger2
- 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
Returns all differences that will be merged because of our merging the giventarget
difference. This may include the diff'simplications
, the diff'sequivalences
, the diff'srefinements
or any other diff that we need to merge together with the given diff.- Specified by:
getDirectResultingMerges
in interfaceIMerger2
- 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
Returns the set of all differences that need to be rejected iftarget
is merged in the given direction.- Specified by:
getDirectResultingRejections
in interfaceIMerger2
- 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
Returns a set of differences that should be logically merged with the given diff. As opposed tomerge dependencies
, it is not structurally necessary to merge these diffs before the given diff. This may include the diff'simplications
, the diff'srefinement
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
Returns all differences that are automatically set to the targetsstate
if the given target diff is merged. This may include the diff'simplications
, the diff'sequivalences
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 mergedtarget
. - Since:
- 3.5
-
copyDiff
Executes a copy in the given merge direction. This method is a generalization ofcopyLeftToRight(Diff, Monitor)
andcopyRightToLeft(Diff, Monitor)
.- Parameters:
target
- The difference to handle.monitor
- Monitor.rightToLeft
- Merge direction.- Since:
- 3.5
-
copyLeftToRight
Executes the copy from left to right.- Specified by:
copyLeftToRight
in interfaceIMerger
- Parameters:
target
- The difference to handle.monitor
- Monitor.- Since:
- 3.1
- See Also:
-
copyRightToLeft
Executes the copy from right to left.- Specified by:
copyRightToLeft
in interfaceIMerger
- Parameters:
target
- The difference to handle.monitor
- Monitor.- Since:
- 3.1
- See Also:
-
accept
Accept the given difference. This may be overridden by clients.- Parameters:
diff
- the difference to mergerightToLeft
- the direction of the merge- Since:
- 3.1
-
reject
Reject the given difference. This may be overridden by clients.- Parameters:
diff
- the difference to mergerightToLeft
- the direction of the merge- Since:
- 3.1
-
mergeDiff
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
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 diffregistry
- The registry of mergers where to look for mergerscriterion
- 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
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
Specifies whether the givendiff
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 inrightToLeft
and thesource of the diff
. Therefore, this method delegates toisLeftAddOrRightDelete(ReferenceChange)
andisLeftDeleteOrRightAdd(ReferenceChange)
.- Parameters:
diff
- The difference to check.rightToLeft
- Direction of the merge.- Returns:
true
ifdiff
will add a value with this merge,false
otherwise.- Since:
- 3.2
-
isUnset
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
ifdiff
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
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
ifdiff
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
Checks whether the given merge direction will result in accepting this difference based on the difference'ssource
.| LEFT | RIGHT --------------------+-------+------- Merge Left to Right | true | false Merge Right to Left | false | true
- Parameters:
diff
- differencemergeRightToLeft
- merge direction- Returns:
- true if the merge source direction matches the difference source, false otherwise.
- Since:
- 3.5
- See Also:
-
isRejecting(Diff, boolean)
-
createCopy
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
Adds the givenvalue
into the givenlist
at the givenindex
. Anindex
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 whichvalue
should be added.value
- The value we need to add tolist
.insertionIndex
- The index at whichvalue
should be inserted intolist
.-1
if it should be appended at the end of the list.
-