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
FieldsModifier and TypeFieldDescriptionThe map of all merge options that this merger should be aware of.static final StringThe key of the merge option that allows to the mergers to consider sub-diffs of a diff as a whole. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidAccept the given difference.protected <E> voidAdds the givenvalueinto the givenlistat the givenindex.booleanapply(IMergeCriterion criterion) Default implementation of apply for mergers that extends this class.protected voidExecutes a copy in the given merge direction.voidcopyLeftToRight(Diff target, Monitor monitor) Executes the copy from left to right.voidcopyRightToLeft(Diff target, Monitor monitor) Executes the copy from right to left.protected EObjectcreateCopy(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 giventargetdifference.getDirectResultingRejections(Diff target, boolean rightToLeft) Returns the set of all differences that need to be rejected iftargetis merged in the given direction.getImpliedMerges(Diff target, boolean mergeRightToLeft) Returns all differences that are automatically set to the targetsstateif 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 DelegatingMergergetMergerDelegate(Diff diff) Find the best merger for diff and wrap it in a delegate that will take the current merge criterion into account.static DelegatingMergergetMergerDelegate(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.intReturns the ranking of this merger.Get the registry.static booleanisAccepting(Diff diff, boolean mergeRightToLeft) Checks whether the given merge direction will result in accepting this difference based on the difference'ssource.protected booleanisAdd(ReferenceChange diff, boolean rightToLeft) Specifies whether the givendiffwill add a value in the target model for the current merging.static booleanisInTerminalState(Diff target) Returns whether the given difference is in a terminal state or not.protected booleanisSet(ReferenceChange diff, boolean mergeRightToLeft) Checks whether the given diff will result in the setting of a reference in the given merge direction.protected booleanisUnset(ReferenceChange diff, boolean mergeRightToLeft) Checks whether the given diff will result in the unsetting of a reference in the given merge direction.protected voidThis can be used by mergers to merge another (required, equivalent...) difference using the right merger for that diff.protected voidReject the given difference.voidsetMergeOptions(Map<Object, Object> options) Set the map of options that the merger will have to take into account.voidsetRanking(int r) Set the ranking of this merger.voidsetRegistry(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, waitMethods 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:
getRankingin interfaceIMerger- Returns:
- The ranking.
- See Also:
-
setRanking
public void setRanking(int r) Set the ranking of this merger.- Specified by:
setRankingin interfaceIMerger- Parameters:
r- The ranking.- See Also:
-
getRegistry
Get the registry.- Specified by:
getRegistryin interfaceIMerger- Returns:
- The registry.
- See Also:
-
setRegistry
Set the registry containing this merger.- Specified by:
setRegistryin interfaceIMerger- Parameters:
registry- The merger registry.- See Also:
-
apply
Default implementation of apply for mergers that extends this class. Will acceptnullor AdditiveMergeCriterion.INSTANCE.- Specified by:
applyin interfaceIMergeCriterionAware- Parameters:
criterion- The merge criterion- Returns:
trueif 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:
getMergeOptionsin 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:
setMergeOptionsin 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'srequirementsor any other diff that we need to merge before the given one.- Specified by:
getDirectMergeDependenciesin 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 giventargetdifference. This may include the diff'simplications, the diff'sequivalences, the diff'srefinementsor any other diff that we need to merge together with the given diff.- Specified by:
getDirectResultingMergesin 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 iftargetis merged in the given direction.- Specified by:
getDirectResultingRejectionsin 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'srefinementor 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 targetsstateif the given target diff is merged. This may include the diff'simplications, the diff'sequivalencesor 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
MERGEDbecause 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:
copyLeftToRightin interfaceIMerger- Parameters:
target- The difference to handle.monitor- Monitor.- Since:
- 3.1
- See Also:
-
copyRightToLeft
Executes the copy from right to left.- Specified by:
copyRightToLeftin 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 givendiffwill add a value in the target model for the current merging.To check whether the
diffis an addition, we have to check the direction of the merge, specified inrightToLeftand thesource of the diff. Therefore, this method delegates toisLeftAddOrRightDelete(ReferenceChange)andisLeftDeleteOrRightAdd(ReferenceChange).- Parameters:
diff- The difference to check.rightToLeft- Direction of the merge.- Returns:
trueifdiffwill add a value with this merge,falseotherwise.- 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:
trueifdiffwill unset a value with this merge,falseif 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:
trueifdiffwill set a value with this merge,falseif 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:
-
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 givenvalueinto the givenlistat the givenindex. Anindexlower 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 whichvalueshould be added.value- The value we need to add tolist.insertionIndex- The index at whichvalueshould be inserted intolist.-1if it should be appended at the end of the list.
-