public abstract class AbstractMerger extends Object implements IMerger2, IMergeOptionAware, IMergeCriterionAware
IMerger
. This can be used as a base implementation to avoid
re-implementing the whole contract.IMerger.Registry, IMerger.Registry2, IMerger.RegistryImpl
Modifier and Type | Field and Description |
---|---|
protected Map<Object,Object> |
mergeOptions
The map of all merge options that this merger should be aware of.
|
static 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.
|
Constructor and Description |
---|
AbstractMerger()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
protected void |
accept(Diff diff,
boolean rightToLeft)
Accept the given difference.
|
protected <E> void |
addAt(List<E> list,
E value,
int insertionIndex)
Adds the given
value into the given list at the given index . |
boolean |
apply(IMergeCriterion criterion)
Default implementation of apply for mergers that extends this class.
|
protected void |
copyDiff(Diff target,
Monitor monitor,
boolean rightToLeft)
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).
|
Set<Diff> |
getDirectMergeDependencies(Diff diff,
boolean mergeRightToLeft)
Retrieves the set of directly required diffs needed in order to merge the current one.
|
Set<Diff> |
getDirectResultingMerges(Diff target,
boolean mergeRightToLeft)
Returns all differences that will be merged because of our merging the given
target
difference. |
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. |
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. |
protected Set<Diff> |
getLogicallyResultingMerges(Diff diff,
boolean mergeRightToLeft)
Returns a set of differences that should be logically merged with the given diff.
|
Map<Object,Object> |
getMergeOptions()
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 |
getRanking()
Returns the ranking of this merger.
|
IMerger.Registry |
getRegistry()
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's
source . |
protected boolean |
isAdd(ReferenceChange diff,
boolean rightToLeft)
Specifies whether the given
diff 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 |
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.
|
protected void |
reject(Diff diff,
boolean rightToLeft)
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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
isMergerFor
public static final String SUB_DIFF_AWARE_OPTION
public int getRanking()
getRanking
in interface IMerger
IMerger.getRanking()
public void setRanking(int r)
setRanking
in interface IMerger
r
- The ranking.IMerger.setRanking(int)
public IMerger.Registry getRegistry()
getRegistry
in interface IMerger
IMerger.getRegistry()
public void setRegistry(IMerger.Registry registry)
setRegistry
in interface IMerger
registry
- The merger registry.IMerger.setRegistry(org.eclipse.emf.compare.merge.IMerger.Registry)
public boolean apply(IMergeCriterion criterion)
null
or
AdditiveMergeCriterion.INSTANCE.apply
in interface IMergeCriterionAware
criterion
- The merge criteriontrue
if the given criterion is null or is AdditiveMergeCriterion.INSTANCE.public Map<Object,Object> getMergeOptions()
getMergeOptions
in interface IMergeOptionAware
IMergeOptionAware.getMergeOptions()
public void setMergeOptions(Map<Object,Object> options)
setMergeOptions
in interface IMergeOptionAware
options
- the map of options.IMergeOptionAware.setMergeOptions(java.util.Map)
public Set<Diff> getDirectMergeDependencies(Diff diff, boolean mergeRightToLeft)
requirements
or any other diff that we need to merge
before the given one.getDirectMergeDependencies
in interface IMerger2
diff
- The diff which direct requirements we need.mergeRightToLeft
- The direction in which we're considering a merge.public Set<Diff> getDirectResultingMerges(Diff target, boolean mergeRightToLeft)
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.getDirectResultingMerges
in interface IMerger2
target
- The difference we're considering merging.mergeRightToLeft
- The direction in which we're considering a merge.target
.public Set<Diff> getDirectResultingRejections(Diff target, boolean rightToLeft)
target
is merged in the
given direction.getDirectResultingRejections
in interface IMerger2
target
- The difference we're considering merging.rightToLeft
- The direction in which we're considering a merge.target
.protected Set<Diff> getLogicallyResultingMerges(Diff diff, boolean mergeRightToLeft)
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.diff
- The difference we're considering merging.mergeRightToLeft
- The direction in which we're considering a merge.diff
.protected Set<Diff> getImpliedMerges(Diff target, boolean mergeRightToLeft)
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.target
- The difference we're considering merging.mergeRightToLeft
- The direction in which we're considering a merge.MERGED
because we've merged
target
.protected void copyDiff(Diff target, Monitor monitor, boolean rightToLeft)
copyLeftToRight(Diff, Monitor)
and copyRightToLeft(Diff, Monitor)
.target
- The difference to handle.monitor
- Monitor.rightToLeft
- Merge direction.public void copyLeftToRight(Diff target, Monitor monitor)
copyLeftToRight
in interface IMerger
target
- The difference to handle.monitor
- Monitor.IMerger.copyLeftToRight(org.eclipse.emf.compare.Diff,
org.eclipse.emf.common.util.Monitor)
public void copyRightToLeft(Diff target, Monitor monitor)
copyRightToLeft
in interface IMerger
target
- The difference to handle.monitor
- Monitor.IMerger.copyRightToLeft(org.eclipse.emf.compare.Diff,
org.eclipse.emf.common.util.Monitor)
protected void accept(Diff diff, boolean rightToLeft)
diff
- the difference to mergerightToLeft
- the direction of the mergeprotected void reject(Diff diff, boolean rightToLeft)
diff
- the difference to mergerightToLeft
- the direction of the mergeprotected void mergeDiff(Diff diff, boolean rightToLeft, Monitor monitor)
diff
- The diff we need to merge.rightToLeft
- Direction of that merge.monitor
- The monitor we should use to report progress.protected DelegatingMerger getMergerDelegate(Diff diff)
diff
- The diffpublic static DelegatingMerger getMergerDelegate(Diff diff, IMerger.Registry2 registry, IMergeCriterion criterion)
diff
- The diffregistry
- The registry of mergers where to look for mergerscriterion
- The merge criterion to usepublic static boolean isInTerminalState(Diff target)
target
- differenceprotected boolean isAdd(ReferenceChange diff, boolean rightToLeft)
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)
.
diff
- The difference to check.rightToLeft
- Direction of the merge.true
if diff
will add a value with this merge, false
otherwise.protected boolean isUnset(ReferenceChange diff, boolean mergeRightToLeft)
diff
- The difference to check.mergeRightToLeft
- Direction of the merge.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.protected boolean isSet(ReferenceChange diff, boolean mergeRightToLeft)
diff
- The difference to check.mergeRightToLeft
- Direction of the merge.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.public static boolean isAccepting(Diff diff, boolean mergeRightToLeft)
source
.
| LEFT | RIGHT --------------------+-------+------- Merge Left to Right | true | false Merge Right to Left | false | true
diff
- differencemergeRightToLeft
- merge directionisRejecting(Diff, boolean)
protected EObject createCopy(EObject referenceObject)
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.
referenceObject
- The EObject for which we'll create a copy.referenceObject
.EMFCompareCopier.copy(EObject)
protected <E> void addAt(List<E> list, E value, int insertionIndex)
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.E
- Type of objects contained in the list.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.
Copyright (c) 2006, 2015 Obeo and others. All rights reserved.